/* ── Reset / Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, "Hiragino Sans", "PingFang SC", BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 14px; color: #111827; background: #f3f4f6; }
a { color: inherit; text-decoration: none; }

/* ── Layout ───────────────────────────────────────────────── */
.admin-wrap { display: flex; min-height: 100vh; }

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  width: 220px; flex-shrink: 0;
  background: #1f2937;
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 100;
}
.sidebar-logo {
  padding: 24px 20px 20px;
  font-size: 16px; font-weight: 700; color: #fff;
  border-bottom: 1px solid #374151;
  letter-spacing: .02em;
}
.sidebar-nav { flex: 1; padding: 12px 0; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 20px;
  color: #d1d5db; font-size: 14px;
  transition: background .15s, color .15s;
  border-radius: 0;
}
.sidebar-nav a:hover, .sidebar-nav a.active {
  background: #374151; color: #fff;
  border-left: 3px solid #f0760a;
}
.sidebar-nav a .nav-icon { font-size: 16px; width: 20px; text-align: center; }
.sidebar-bottom {
  padding: 12px 0;
  border-top: 1px solid #374151;
}
.sidebar-bottom a {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 20px;
  color: #9ca3af; font-size: 13px;
  transition: color .15s;
}
.sidebar-bottom a:hover { color: #f87171; }

/* ── Main area ────────────────────────────────────────────── */
.main-area { margin-left: 220px; flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* ── Topbar ───────────────────────────────────────────────── */
.topbar {
  background: #fff; border-bottom: 1px solid #e5e7eb;
  padding: 0 28px;
  height: 56px; display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
}
.topbar-title { font-size: 18px; font-weight: 600; color: #111827; }
.lang-switcher { display: flex; align-items: center; gap: 10px; font-size: 13px; color: #6b7280; }
.lang-switcher span { font-size: 12px; }
.lang-switcher a { color: #6b7280; padding: 3px 8px; border-radius: 4px; transition: background .12s; }
.lang-switcher a:hover { background: #f3f4f6; }
.lang-switcher a.lang-active { font-weight: 700; color: #f0760a; background: #fff7ed; }

/* ── Content ──────────────────────────────────────────────── */
.content { padding: 28px; flex: 1; }

/* ── Card ─────────────────────────────────────────────────── */
.card {
  background: #fff; border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08), 0 0 0 1px rgba(0,0,0,.04);
  padding: 24px;
  margin-bottom: 24px;
}
.card-title { font-size: 15px; font-weight: 600; color: #374151; margin-bottom: 18px; }

/* ── Stats grid ───────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-bottom: 24px; }
.stat-card {
  background: #fff; border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08), 0 0 0 1px rgba(0,0,0,.04);
  padding: 22px 24px;
}
.stat-label { font-size: 12px; color: #6b7280; margin-bottom: 8px; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 30px; font-weight: 700; color: #111827; }

/* ── Tables ───────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead tr { background: #f9fafb; }
th { padding: 10px 14px; text-align: left; font-weight: 600; color: #374151; border-bottom: 1px solid #e5e7eb; white-space: nowrap; }
td { padding: 10px 14px; border-bottom: 1px solid #f3f4f6; vertical-align: middle; }
tbody tr:hover { background: #fafafa; }
tbody tr:last-child td { border-bottom: none; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 7px 16px; border-radius: 6px;
  font-size: 13px; font-weight: 500; cursor: pointer;
  border: none; transition: opacity .15s, box-shadow .15s;
  text-decoration: none; white-space: nowrap;
  min-height: 40px;
}
.btn:hover { opacity: .88; }
.btn-primary { background: #f0760a; color: #fff; }
.btn-secondary { background: #f3f4f6; color: #374151; border: 1px solid #d1d5db; }
.btn-secondary:hover { background: #e5e7eb; opacity: 1; }
.btn-danger { background: #ef4444; color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12px; min-height: 40px; }
.btn-icon { padding: 5px 9px; }
.action-group { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; }

/* ── Forms ────────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 24px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full { grid-column: 1 / -1; }
label { font-size: 13px; font-weight: 500; color: #374151; }
input[type=text], input[type=password], input[type=url], input[type=number], select, textarea {
  width: 100%; padding: 8px 12px;
  border: 1px solid #d1d5db; border-radius: 6px;
  font-size: 16px; color: #111827; background: #fff;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
input[type=text]:focus, input[type=password]:focus, input[type=url]:focus,
input[type=number]:focus, select:focus, textarea:focus {
  border-color: #f0760a;
  box-shadow: 0 0 0 3px rgba(240,118,10,.15);
}
textarea { resize: vertical; min-height: 80px; }
.field-hint { font-size: 11.5px; color: #9ca3af; margin-top: 3px; line-height: 1.5; }
.checkbox-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.checkbox-row input[type=checkbox] { width: 16px; height: 16px; accent-color: #f0760a; cursor: pointer; }
.checkbox-row label { font-size: 13.5px; color: #374151; cursor: pointer; margin: 0; }
.input-with-btn { display: flex; gap: 8px; }
.input-with-btn input { flex: 1; }
.form-actions { display: flex; align-items: center; gap: 12px; margin-top: 8px; padding-top: 20px; border-top: 1px solid #f3f4f6; }
.form-error { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; border-radius: 6px; padding: 10px 14px; font-size: 13px; margin-bottom: 16px; }

/* ── Geocode results ──────────────────────────────────────── */
#geo-results { margin-top: 6px; border: 1px solid #e5e7eb; border-radius: 6px; background: #fff; max-height: 200px; overflow-y: auto; }
#geo-results .geo-item {
  padding: 9px 12px; cursor: pointer; font-size: 13px; border-bottom: 1px solid #f3f4f6;
  transition: background .1s;
}
#geo-results .geo-item:last-child { border-bottom: none; }
#geo-results .geo-item:hover { background: #fff7ed; color: #f0760a; }
#geo-msg { font-size: 12.5px; color: #9ca3af; margin-top: 5px; }

/* ── QR thumb ─────────────────────────────────────────────── */
.qr-thumb { width: 80px; height: 80px; object-fit: contain; border: 1px solid #e5e7eb; border-radius: 4px; }

/* ── Badge / tag ──────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 500;
}
.badge-green { background: #d1fae5; color: #065f46; }
.badge-gray  { background: #f3f4f6; color: #6b7280; }
.badge-orange { background: #ffedd5; color: #9a3412; }

/* ── Stars ────────────────────────────────────────────────── */
.star { color: #f59e0b; }

/* ── Alert / notice ───────────────────────────────────────── */
.alert { padding: 10px 16px; border-radius: 6px; margin-bottom: 18px; font-size: 13.5px; }
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }

/* ── Page header row ──────────────────────────────────────── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.page-header h2 { font-size: 16px; font-weight: 600; color: #111827; }

/* ── Template downloads ───────────────────────────────────── */
.template-toolbar {
  display: grid;
  grid-template-columns: minmax(260px, 360px) 1fr;
  gap: 18px 24px;
  align-items: end;
}
.template-note {
  color: #6b7280;
  font-size: 13px;
  line-height: 1.7;
  padding-bottom: 2px;
}
.template-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
}
.template-card {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08), 0 0 0 1px rgba(0,0,0,.04);
  overflow: hidden;
}
.template-card-body {
  padding: 14px;
}
.template-card h3 {
  font-size: 14px;
  color: #111827;
  margin-bottom: 6px;
}
.template-card p {
  color: #6b7280;
  font-size: 12.5px;
  line-height: 1.6;
  min-height: 42px;
  margin-bottom: 12px;
}
.template-preview {
  position: relative;
  aspect-ratio: 210 / 297;
  background: #f15a00;
  overflow: hidden;
}
.template-preview::before {
  content: "";
  position: absolute;
  inset: 10px;
  border: 3px solid rgba(255,255,255,.8);
}
.preview-header {
  position: absolute;
  top: 24px;
  left: 24px;
  right: 24px;
  height: 38px;
  border-radius: 10px;
  background: #fff1e8;
  border: 5px solid #e69a5c;
}
.preview-title {
  position: absolute;
  top: 92px;
  left: 20px;
  right: 20px;
  color: #fff;
  font-size: 28px;
  font-weight: 800;
  text-align: center;
}
.preview-qr {
  position: absolute;
  left: 50%;
  top: 45%;
  width: 44%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  background:
    linear-gradient(90deg, #111 10%, transparent 10% 20%, #111 20% 30%, transparent 30% 42%, #111 42% 55%, transparent 55% 65%, #111 65% 75%, transparent 75%),
    linear-gradient(#111 10%, transparent 10% 20%, #111 20% 30%, transparent 30% 42%, #111 42% 55%, transparent 55% 65%, #111 65% 75%, transparent 75%),
    #fff;
  background-size: 22px 22px;
  border: 12px solid #fff;
}
.preview-strip {
  position: absolute;
  left: 28px;
  right: 28px;
  bottom: 44px;
  height: 50px;
  border-radius: 10px;
  background: #fff1e8;
  border: 5px solid #e69a5c;
}
.template-preview-orange-steps .preview-qr { top: 77%; width: 28%; }
.template-preview-orange-steps .preview-title { top: 26px; font-size: 30px; text-shadow: 2px 2px 0 rgba(0,0,0,.2); }
.template-preview-orange-steps .preview-header,
.template-preview-orange-steps .preview-strip {
  left: 32px;
  right: 32px;
}
.template-preview-warm-qr::after {
  content: "";
  position: absolute;
  left: -20%;
  top: -6%;
  width: 140%;
  height: 42%;
  background: #fff3dc;
  border-radius: 0 0 50% 50%;
}
.template-preview-warm-qr .preview-header,
.template-preview-warm-qr .preview-title,
.template-preview-warm-qr .preview-qr,
.template-preview-warm-qr .preview-strip {
  z-index: 1;
}
.template-preview-simple-ticket { background: #fff5e8; }
.template-preview-simple-ticket::before { border-color: #f15a00; }
.template-preview-simple-ticket .preview-header { background: #f15a00; border-color: #f15a00; }
.template-preview-simple-ticket .preview-title { color: #3a2015; top: 96px; }
.template-preview-simple-ticket .preview-strip { border-style: dashed; border-color: #e35b17; }
.template-preview-premium-black { background: #1f1410; }
.template-preview-premium-black::before { border-color: #f2b15f; }
.template-preview-premium-black .preview-header,
.template-preview-premium-black .preview-strip {
  background: transparent;
  border-color: #f2b15f;
}
.template-preview-premium-black .preview-title { color: #f2b15f; }

/* ── Detail grid ──────────────────────────────────────────── */
.detail-grid { display: grid; grid-template-columns: 160px 1fr; gap: 12px 20px; }
.detail-label { font-size: 13px; color: #6b7280; font-weight: 500; padding-top: 2px; }
.detail-value { font-size: 14px; color: #111827; }
.detail-divider { grid-column: 1/-1; border: none; border-top: 1px solid #f3f4f6; margin: 6px 0; }
.draft-box {
  background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 6px;
  padding: 14px 16px; font-size: 14px; line-height: 1.7; white-space: pre-wrap;
  color: #374151;
}

/* ── Login page ───────────────────────────────────────────── */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: #f3f4f6;
}
.login-card {
  background: #fff; border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0,0,0,.1);
  padding: 40px 40px 36px; width: 360px;
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo h1 { font-size: 20px; font-weight: 700; color: #1f2937; }
.login-logo p  { font-size: 12px; color: #9ca3af; margin-top: 4px; }
.login-card .form-group { margin-bottom: 16px; }
.login-card .btn-primary { width: 100%; justify-content: center; padding: 10px; font-size: 15px; margin-top: 8px; }
.login-error { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; border-radius: 6px; padding: 9px 14px; font-size: 13px; margin-bottom: 14px; }

/* ── Stats bar ────────────────────────────────────────────── */
.stats-bar { display: flex; align-items: center; gap: 24px; font-size: 13px; padding: 10px 0 18px; flex-wrap: wrap; }
.stats-bar span { color: #6b7280; }
.stats-bar strong { color: #111827; }

/* ── Responsive ───────────────────────────────────────────── */

/* Tablet: 769px – 900px — hide sidebar, restore margin */
@media (max-width: 900px) and (min-width: 769px) {
  .sidebar { transform: translateX(-220px); }
  .main-area { margin-left: 0; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .template-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .template-toolbar { grid-template-columns: 1fr; }
}

/* ── Mobile (≤768px): sidebar → top horizontal nav ──────── */
@media (max-width: 768px) {
  /* Layout: stack vertically */
  .admin-wrap { flex-direction: column; }

  /* Sidebar becomes a top nav bar */
  .sidebar {
    width: 100%;
    position: sticky;
    top: 0;
    bottom: auto;
    left: auto;
    flex-direction: row;
    align-items: stretch;
    height: auto;
    z-index: 200;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Hide the logo text to save space */
  .sidebar-logo { display: none; }

  /* Nav links go horizontal */
  .sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: row;
    align-items: stretch;
    padding: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }

  .sidebar-nav a {
    display: inline-flex;
    align-items: center;
    padding: 12px 16px;
    border-left: none;
    border-bottom: 3px solid transparent;
    border-radius: 0;
    font-size: 13px;
    flex-shrink: 0;
  }

  .sidebar-nav a:hover,
  .sidebar-nav a.active {
    background: #374151;
    color: #fff;
    border-left: none;
    border-bottom: 3px solid #f0760a;
  }

  /* Logout pushed to the right end of the bar */
  .sidebar-bottom {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    padding: 0;
    border-top: none;
    border-left: 1px solid #374151;
    flex-shrink: 0;
    margin-left: auto;
  }

  .sidebar-bottom a {
    display: inline-flex;
    align-items: center;
    padding: 12px 16px;
    font-size: 13px;
    white-space: nowrap;
  }

  /* Main area: full width, no left margin */
  .main-area { margin-left: 0; width: 100%; }

  /* Topbar: prevent wrapping, ellipsis on title */
  .topbar {
    padding: 0 12px;
    height: auto;
    min-height: 48px;
    gap: 8px;
    flex-wrap: nowrap;
  }

  .topbar-title {
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    flex: 1;
  }

  .lang-switcher {
    flex-shrink: 0;
    gap: 4px;
    font-size: 12px;
  }

  .lang-switcher span { display: none; }  /* hide "Language:" label */

  .lang-switcher a {
    padding: 2px 6px;
    font-size: 12px;
  }

  /* Content: full width, compact padding */
  .content { padding: 12px; }

  /* Stats grid: 2 columns */
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
  .stat-card { padding: 16px; }
  .stat-value { font-size: 24px; }

  /* Forms: single column */
  .form-grid { grid-template-columns: 1fr; gap: 14px; }
  .template-toolbar { grid-template-columns: 1fr; gap: 10px; }
  .template-grid { grid-template-columns: 1fr; gap: 14px; }
  .template-card { display: grid; grid-template-columns: 118px 1fr; }
  .template-preview { aspect-ratio: 210 / 297; height: 168px; }
  .template-card p { min-height: 0; }

  /* Tables: all tables scrollable horizontally */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 520px; }

  /* Page header: keep on one line, wrap buttons if needed */
  .page-header { gap: 8px; flex-wrap: wrap; }
  .page-header h2 { font-size: 15px; }

  /* Cards */
  .card { padding: 16px; margin-bottom: 16px; }

  /* Login card */
  .login-card { width: calc(100vw - 32px); padding: 28px 24px; }

  /* Detail grid */
  .detail-grid { grid-template-columns: 120px 1fr; }
}


/* Analytics */
.analytics-filter {
  display: grid;
  grid-template-columns: minmax(220px, 360px) minmax(160px, 220px) auto;
  gap: 18px;
  align-items: end;
}
.analytics-filter-action { justify-content: flex-end; }
.analytics-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, .65fr);
  gap: 18px;
  margin-bottom: 24px;
}
.analytics-layout.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.analytics-panel { min-width: 0; }
.analytics-stats .stat-value { font-size: 28px; }
.analysis-text { white-space: pre-wrap; line-height: 1.8; color: #1f2937; font-size: 14px; }
.rating-row { display: grid; grid-template-columns: 56px 1fr 52px; gap: 10px; align-items: center; padding: 8px 0; }
.rating-row.compact { grid-template-columns: 44px 1fr 40px; }
.rating-label { color: #374151; font-size: 13px; }
.rating-track { height: 8px; border-radius: 999px; background: #f3f4f6; overflow: hidden; }
.rating-track span { display: block; height: 100%; background: #f0760a; border-radius: inherit; }
.rating-value { text-align: right; color: #111827; font-weight: 600; font-size: 13px; }
.mini-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid #f3f4f6; font-size: 13px; }
.mini-row:last-child { border-bottom: none; }
.mini-row span { color: #374151; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-row strong { color: #111827; }
.muted-text { color: #9ca3af; font-size: 13px; }
@media (max-width: 980px) {
  .analytics-filter, .analytics-layout, .analytics-layout.three { grid-template-columns: 1fr; }
  .analytics-filter-action { justify-content: flex-start; }
}
