:root {
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --border: #E2E8F0;
  --text: #0F172A;
  --muted: #64748B;
  --primary: #0F172A;
  --teal: #2A4B57;
  --gold: #CCB67A;
  --emerald: #059669;
  --danger: #DC2626;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
code { font-family: ui-monospace, Menlo, monospace; font-size: 11.5px; background: #F1F5F9; padding: 2px 6px; border-radius: 5px; }

/* LAYOUT SHELL */
.admin-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: #FFFFFF;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 40;
}

.sidebar-brand {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo-wrap {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--teal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px;
  flex-shrink: 0;
}

.brand-logo-wrap img { width: 100%; height: auto; object-fit: contain; }
.brand-meta strong { display: block; font-size: 14px; font-weight: 700; color: var(--text); }
.brand-meta span { font-size: 11px; color: var(--muted); }

.side-nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-group-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #94A3B8;
  padding: 10px 10px 4px;
}

.nav-item {
  width: 100%;
  border: none;
  background: transparent;
  color: #475569;
  text-decoration: none;
  text-align: left;
  padding: 8px 11px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover { background: #F1F5F9; color: var(--text); }
.nav-item.active { background: var(--teal); color: #FFFFFF; font-weight: 600; }
.nav-item.active .nav-pill { background: rgba(255,255,255,0.2); color: #FFFFFF; }

.nav-pill {
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
  background: #ECFDF5;
  color: var(--emerald);
}

.sidebar-foot {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.env-chip { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 6px; }

/* MAIN AREA */
.main-area { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar h1 { font-size: 17px; font-weight: 700; color: var(--text); line-height: 1.2; }
.topbar p { font-size: 12px; color: var(--muted); }

.btn-menu-mobile {
  display: none;
  border: 1px solid var(--border);
  background: #fff;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  font-size: 18px;
  cursor: pointer;
}

.active-stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: #ECFDF5;
  border: 1px solid #A7F3D0;
  border-radius: 999px;
  font-size: 12.5px;
  color: #065F46;
}

.dot-ok { width: 8px; height: 8px; border-radius: 50%; background: #10B981; display: inline-block; }
.dot-off { width: 8px; height: 8px; border-radius: 50%; background: #CBD5E1; display: inline-block; }

.content { max-width: 1160px; width: 100%; margin: 0 auto; padding: 22px 24px 48px; }

/* CARDS & KPIS */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 15px 16px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.kpi-card strong { display: block; font-size: 22px; letter-spacing: -0.02em; color: var(--text); }
.kpi-card span { font-size: 12px; color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  margin-bottom: 16px;
}

.card h3 { font-size: 14.5px; font-weight: 600; margin-bottom: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head h3 { margin-bottom: 0; }

.arch-list { padding-left: 18px; display: flex; flex-direction: column; gap: 7px; font-size: 13px; color: #334155; }

/* TOOLBARS & FORMS */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
input, select, textarea {
  font-family: inherit;
  font-size: 13px;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}
input:focus, select:focus, textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 2px rgba(42, 75, 87, 0.12); }
.toolbar input { flex: 1; min-width: 220px; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.form-grid label, .form-grid-4 label { min-width: 0; display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 500; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }
.full { grid-column: 1 / -1; }

.checks-wrap { display: flex; flex-wrap: wrap; gap: 6px; }
.check-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
  background: #FFFFFF;
}
.check-chip:has(input:checked) { background: #F0FDF4; border-color: #86EFAC; color: #065F46; }

/* BUTTONS */
.btn {
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}
.btn-dark { background: var(--primary); color: #fff; }
.btn-dark:hover { background: #1E293B; }
.btn-outline { background: #fff; color: var(--text); border-color: var(--border); }
.btn-outline:hover { background: #F8FAFC; }
.btn-danger { background: #FEF2F2; color: var(--danger); border-color: #FECACA; }
.btn-danger:hover { background: #FEE2E2; }
.btn-sm { padding: 5px 9px; font-size: 12px; border-radius: 7px; }
.actions-cell { display: flex; gap: 5px; flex-wrap: wrap; }

/* TABLES */
.table-wrap { overflow-x: auto; padding: 0; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 13px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); background: #F8FAFC; font-weight: 600; }
tr:last-child td { border-bottom: none; }

.drag-row { cursor: grab; }
.drag-row.dragging { opacity: 0.45; background: #EFF6FF; }
.drag-handle { color: #94A3B8; font-weight: 700; font-size: 16px; cursor: grab; user-select: none; }

.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.badge-ok { background: #ECFDF5; color: #059669; border: 1px solid #A7F3D0; }
.badge-warn { background: #FFFBEB; color: #D97706; border: 1px solid #FDE68A; }
.badge-neutral { background: #F1F5F9; color: #475569; border: 1px solid #E2E8F0; }

.indicator { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; }
.muted { color: var(--muted); font-size: 12px; }

.info-banner {
  background: #FFFBEB;
  border: 1px solid #FDE68A;
  color: #92400E;
  padding: 10px 14px;
  border-radius: 10px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
}

/* TEMPLATES GRID */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(195px, 1fr)); gap: 14px; }
.tpl-card { background: #fff; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; }
.tpl-card img { width: 100%; height: 185px; object-fit: cover; display: block; background: #F1F5F9; cursor: pointer; }
.tpl-card-body { padding: 10px 12px; font-size: 12.5px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.tpl-card-actions { display: flex; gap: 5px; margin-top: auto; padding-top: 6px; }

/* MODALS */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-card {
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  background: #fff;
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 20px 44px rgba(15, 23, 42, 0.25);
}
.modal-wide { max-width: 960px; }

/* PRINTABLE TAGS GRID */
.print-tags-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.tag-cell {
  border: 1px dashed #CBD5E1;
  border-radius: 10px;
  padding: 8px;
  text-align: center;
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  break-inside: avoid;
}
.tag-cell img { width: 100%; height: auto; max-height: 295px; object-fit: contain; display: block; }
.tag-cell small { font-size: 10px; color: var(--muted); }

/* TOAST */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--primary);
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 200;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.25);
}

@media (max-width: 900px) {
  .sidebar { position: fixed; left: -260px; transition: left 0.2s; }
  .sidebar.open { left: 0; box-shadow: 0 0 30px rgba(0,0,0,0.25); }
  .btn-menu-mobile { display: inline-flex; align-items: center; justify-content: center; }
  .form-grid, .form-grid-4 { grid-template-columns: 1fr; }
  .print-tags-grid { grid-template-columns: repeat(2, 1fr); }
}

@media print {
  @page { size: letter portrait; margin: 10mm; }
  html, body { background: #fff !important; height: auto !important; overflow: visible !important; }
  body > :not(#modal-print-tags) { display: none !important; }
  #modal-print-tags {
    display: block !important;
    position: static !important;
    background: #fff !important;
    padding: 0 !important;
    inset: auto !important;
  }
  #modal-print-tags .modal-card {
    display: block !important;
    overflow: visible !important;
    box-shadow: none !important;
    max-width: 100% !important;
    max-height: none !important;
    width: 100% !important;
    padding: 0 !important;
    border-radius: 0 !important;
  }
  .no-print { display: none !important; }
  .print-tags-grid {
    display: grid !important;
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 8px !important;
    margin-top: 0 !important;
  }
  .tag-cell { break-inside: avoid !important; page-break-inside: avoid !important; }
  .tag-cell img { max-height: 220px !important; width: auto !important; max-width: 100% !important; }
}
