/* ═══════════════════════════════════════
   T-Map Admin — Stylesheet
   ═══════════════════════════════════════ */
:root {
  --primary: #b8860b;
  --primary-hover: #d4a843;
  --primary-dark: #8a6508;
  --primary-bg: #fdf6e3;
  --surface: #ffffff;
  --bg: #f4f2ed;
  --text: #1a1814;
  --text-2: #4a4540;
  --text-3: #7a756d;
  --text-4: #a09a90;
  --border: #e8e3d8;
  --success: #2d8a4e;
  --error: #c53030;
  --side-bg: #1a1d18;
  --side-text: #c5c0b5;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
  --radius: 10px;
  --radius-sm: 6px;
  --ease: cubic-bezier(.4,0,.2,1);
  --font: 'Noto Sans Thai', system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: inherit; text-decoration: none; }

/* ─── Shell ─── */
.admin-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

/* ─── Sidebar ─── */
.admin-side {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--side-bg);
  color: var(--side-text);
  overflow-y: auto;
}

.admin-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.admin-brand strong { display: block; color: #f7c94b; font-size: 18px; font-weight: 800; }
.admin-brand small { display: block; font-size: 11px; opacity: .6; margin-top: 2px; }

.admin-nav {
  display: flex;
  flex-direction: column;
  padding: 12px 10px;
  gap: 2px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  color: var(--side-text);
  transition: all .15s var(--ease);
  text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.is-active {
  background: rgba(184,134,11,.2);
  color: #f7c94b;
}

.admin-side-foot {
  padding: 10px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.admin-user {
  display: block;
  padding: 4px 14px 8px;
  color: rgba(255,255,255,.5);
  font-size: 11px;
  font-weight: 600;
}
.nav-back { font-size: 12px; opacity: .7; }
.nav-back:hover { opacity: 1; }

/* ─── Main ─── */
.admin-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.admin-header h1 { margin: 0; font-size: 20px; font-weight: 700; }

.admin-content {
  padding: 24px 28px;
  flex: 1;
}

/* ─── Stats ─── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  padding: 20px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}
.stat-card small { color: var(--text-3); font-size: 12px; font-weight: 600; }
.stat-card strong { display: block; font-size: 28px; font-weight: 800; color: var(--primary); margin-top: 4px; }

/* ─── Cards ─── */
.section-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}
.section-card h2 { margin: 0 0 16px; font-size: 16px; }

.place-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.pcard {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  transition: box-shadow .2s, transform .15s;
}
.pcard:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }

.pcard-img {
  height: 140px;
  background: linear-gradient(135deg, #c5bfb3, #a09a90);
  background-size: cover;
  background-position: center;
}
.pcard-body { padding: 14px 16px; }
.pcard-body h3 {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pcard-body .badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--primary-bg);
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
}
.pcard-body p {
  margin: 8px 0 0;
  color: var(--text-3);
  font-size: 12px;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.pcard-actions {
  display: flex;
  gap: 6px;
  padding: 0 16px 14px;
}

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 700;
  transition: all .2s var(--ease);
  white-space: nowrap;
}
.btn-sm { height: 32px; padding: 0 12px; font-size: 12px; }
.btn-primary { background: var(--primary); color: #fff; border: 1px solid var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-outline { background: var(--surface); color: var(--text-2); border: 1px solid var(--border); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-danger { background: var(--error); color: #fff; border: 1px solid var(--error); }
.btn-danger:hover { background: #a52020; }
.btn-ghost { color: var(--text-3); }
.btn-ghost:hover { color: var(--primary); }

/* ─── Form ─── */
.form-card {
  max-width: 700px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.form-field {
  display: grid;
  gap: 5px;
  margin-bottom: 14px;
}
.form-field span {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-2);
}
.form-field b { color: var(--error); }
.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 13px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(184,134,11,.1);
}
.form-field textarea { resize: vertical; line-height: 1.5; }
.form-field input, .form-field select { height: 38px; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

/* ─── Cover Manager ─── */
.cover-mgr {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 14px;
  background: #fdfcf9;
}
.cover-mgr-label {
  display: block;
  padding: 10px 14px 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-2);
}

.cover-preview {
  position: relative;
  height: 160px;
  margin: 0 10px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: linear-gradient(135deg, #e8e4da, #d5cfc3);
}
.cover-preview img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: none;
}
.cover-preview img.show { display: block; }
.cover-empty {
  position: absolute; inset: 0;
  display: grid; place-items: center; place-content: center; gap: 4px;
  color: var(--text-4); text-align: center;
}
.cover-empty small { font-size: 11px; }
.cover-del {
  position: absolute; top: 6px; right: 6px;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: rgba(0,0,0,.5);
  color: #fff; font-size: 12px;
  display: none;
  place-items: center;
  backdrop-filter: blur(4px);
}
.cover-preview:hover .cover-del { display: grid; }

.gallery-hint {
  padding: 8px 12px 0;
  color: var(--text-4);
  font-size: 11px;
  font-weight: 600;
}

.gallery-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: 8px;
  padding: 10px;
}
.gallery-list:empty { display: none; }
.gallery-item {
  position: relative;
  aspect-ratio: 4/3;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2px solid transparent;
  background: #ebe5da;
}
.gallery-item.is-cover { border-color: var(--primary); }
.gallery-thumb-btn {
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
}
.gallery-thumb-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.gallery-badge {
  position: absolute;
  left: 5px;
  bottom: 5px;
  min-width: 22px;
  height: 20px;
  display: inline-grid;
  place-items: center;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(0,0,0,.62);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
}
.gallery-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(0,0,0,.62);
  color: #fff;
  font-size: 15px;
  line-height: 1;
}
.gallery-remove:hover { background: var(--error); }

.cover-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-top: 10px;
}
.cover-tabs button {
  position: relative;
  min-height: 34px;
  font-size: 11px; font-weight: 700;
  color: var(--text-3);
  transition: color .2s;
}
.cover-tabs button:hover { color: var(--primary); }
.cover-tabs button.is-active { color: var(--primary); background: #fffaf0; }
.cover-tabs button.is-active::after {
  content: ''; position: absolute; bottom: -1px; left: 0; right: 0;
  height: 2px; background: var(--primary);
}

.cover-panel { padding: 10px; }
.cover-drop {
  display: grid; place-items: center; gap: 4px;
  min-height: 80px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: #fff;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
}
.cover-drop:hover { border-color: var(--primary); background: #fffdf6; }
.cover-drop.drag-over { border-color: var(--primary); background: #fef8e6; }
.cover-drop input { display: none; }
.cover-drop strong { font-size: 12px; color: var(--text-2); }
.cover-drop small { font-size: 11px; color: var(--text-4); }

.cover-input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}
.cover-input-row input {
  width: 100%; height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  outline: none;
}
.cover-input-row input:focus { border-color: var(--primary); }

.cover-results {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 8px;
  max-height: 180px;
  overflow-y: auto;
}
.cover-results:empty { display: none; }

.cres-item {
  aspect-ratio: 4/3;
  border-radius: 4px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color .2s, transform .15s;
}
.cres-item:hover { border-color: var(--primary); transform: scale(1.04); }
.cres-item img { width: 100%; height: 100%; object-fit: cover; }

.cover-status {
  padding: 6px 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--primary);
}

/* ─── Import ─── */
.import-log {
  margin-top: 16px;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-size: 12px;
  color: var(--text-3);
  min-height: 40px;
}
.import-log:empty::after { content: 'ยังไม่ได้นำเข้าข้อมูล'; }

/* ─── Modal ─── */
.modal-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.3);
  z-index: 50;
}
.modal-backdrop.show { display: block; }

/* ─── Login ─── */
.login-page {
  min-height: 100vh;
  background:
    linear-gradient(rgba(26,29,24,.78), rgba(26,29,24,.78)),
    url('map-background.png') center/cover no-repeat;
}
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(100%, 380px);
  padding: 24px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 18px 50px rgba(0,0,0,.24);
}
.login-brand {
  padding: 0 0 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.login-card h1 {
  margin: 0 0 18px;
  font-size: 20px;
  line-height: 1.3;
}
.login-error {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: #fff1f1;
  color: var(--error);
  font-size: 12px;
  font-weight: 700;
}
.login-submit {
  width: 100%;
  margin-top: 4px;
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .admin-shell { grid-template-columns: 1fr; }
  .admin-side {
    position: fixed; inset: 0; width: 260px;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform .3s var(--ease);
  }
  .admin-side.open { transform: translateX(0); }
  .admin-content { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
