/* =========================================================
   Fire & Safety CMS — Core Theme
   ========================================================= */
:root {
  --flame-600: #d62828;
  --flame-700: #b71c1c;
  --flame-500: #ef4444;
  --ember-500: #f97316;
  --ink-900: #14181f;
  --ink-800: #1c222c;
  --ink-700: #29313d;
  --ink-500: #5b6474;
  --ink-300: #9aa3b2;
  --paper-50: #f7f8fa;
  --paper-100: #eef0f3;
  --line-200: #e3e6ec;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
  --shadow-soft: 0 2px 10px rgba(20, 24, 31, 0.06), 0 1px 2px rgba(20,24,31,.04);
  --shadow-lift: 0 12px 30px rgba(20, 24, 31, .10);
  --sidebar-w: 258px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--paper-50);
  color: var(--ink-800);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--ink-900), #0d1015);
  color: #fff;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 40;
  transition: transform .25s ease;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 12px;
  padding: 22px 20px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand .flame-badge {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, var(--ember-500), var(--flame-600));
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(214,40,40,.35);
}
.sidebar-brand .brand-text { font-weight: 700; font-size: 15px; line-height: 1.25; }
.sidebar-brand .brand-text small { display:block; font-weight: 400; font-size: 11.5px; color: var(--ink-300); }

.sidebar-nav { flex: 1; padding: 14px 12px; overflow-y: auto; }
.sidebar-nav .nav-section {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--ink-300); padding: 16px 12px 6px;
}
.sidebar-nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; margin: 2px 0;
  border-radius: var(--radius-sm);
  color: #cfd3db; font-size: 14px; font-weight: 500;
  transition: background .15s, color .15s;
}
.sidebar-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar-nav a.active { background: linear-gradient(90deg, rgba(214,40,40,.28), rgba(249,115,22,.10)); color: #fff; box-shadow: inset 3px 0 0 var(--flame-500); }
.sidebar-nav a .ic { width: 18px; text-align: center; opacity: .9; }

.sidebar-foot { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; color: var(--ink-300); }

.main-area { margin-left: var(--sidebar-w); flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 66px; background: #fff; border-bottom: 1px solid var(--line-200);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; position: sticky; top: 0; z-index: 30;
}
.topbar .page-title { font-size: 17px; font-weight: 700; color: var(--ink-900); }
.topbar .page-sub { font-size: 12.5px; color: var(--ink-500); margin-top: 2px; }
.topbar .right { display: flex; align-items: center; gap: 14px; }
.avatar-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 12px 6px 6px; border-radius: 999px; background: var(--paper-100);
  font-size: 13.5px; font-weight: 600;
}
.avatar-circle {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, var(--flame-600), var(--ember-500));
  color: #fff; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700;
}
.menu-toggle { display: none; background: none; border: none; font-size: 20px; cursor: pointer; color: var(--ink-800); }

.content { padding: 24px; flex: 1; }

/* ---------- Cards / widgets ---------- */
.card {
  background: #fff; border-radius: var(--radius-lg);
  border: 1px solid var(--line-200);
  box-shadow: var(--shadow-soft);
}
.card-pad { padding: 22px; }
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--line-200);
}
.card-header h3 { margin: 0; font-size: 15.5px; font-weight: 700; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-bottom: 22px; }
.stat-card {
  background: #fff; border-radius: var(--radius-lg); border: 1px solid var(--line-200);
  padding: 20px; box-shadow: var(--shadow-soft); position: relative; overflow: hidden;
}
.stat-card .stat-icon {
  width: 42px; height: 42px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
  font-size: 19px; margin-bottom: 14px; color: #fff;
}
.stat-card .stat-value { font-size: 26px; font-weight: 800; color: var(--ink-900); line-height: 1; }
.stat-card .stat-label { font-size: 12.5px; color: var(--ink-500); margin-top: 6px; }
.stat-card.c-red .stat-icon { background: linear-gradient(135deg, var(--flame-600), var(--flame-500)); }
.stat-card.c-orange .stat-icon { background: linear-gradient(135deg, var(--ember-500), #fb923c); }
.stat-card.c-green .stat-icon { background: linear-gradient(135deg, #16a34a, #22c55e); }
.stat-card.c-blue .stat-icon { background: linear-gradient(135deg, #2563eb, #3b82f6); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: var(--radius-md); font-size: 14px; font-weight: 600;
  border: 1px solid transparent; cursor: pointer; transition: all .15s ease; line-height: 1.2;
}
.btn-primary { background: linear-gradient(135deg, var(--flame-600), var(--ember-500)); color: #fff; box-shadow: 0 6px 16px rgba(214,40,40,.28); }
.btn-primary:hover { filter: brightness(1.05); transform: translateY(-1px); }
.btn-secondary { background: #fff; color: var(--ink-800); border-color: var(--line-200); }
.btn-secondary:hover { background: var(--paper-100); }
.btn-outline { background: transparent; border-color: var(--flame-600); color: var(--flame-600); }
.btn-outline:hover { background: rgba(214,40,40,.06); }
.btn-danger { background: #fff; color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

/* ---------- Forms ---------- */
label.form-label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-700); margin-bottom: 6px; }
.form-control, select.form-control, textarea.form-control {
  width: 100%; padding: 10px 13px; font-size: 14px; border-radius: var(--radius-md);
  border: 1.5px solid var(--line-200); background: #fff; color: var(--ink-800);
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus, select.form-control:focus, textarea.form-control:focus {
  outline: none; border-color: var(--flame-500); box-shadow: 0 0 0 3px rgba(239,68,68,.12);
}
.form-group { margin-bottom: 18px; }
.form-row { display: grid; gap: 18px; }
.form-row.cols-2 { grid-template-columns: 1fr 1fr; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-hint { font-size: 12px; color: var(--ink-500); margin-top: 5px; }
.form-error { font-size: 12.5px; color: var(--danger); margin-top: 5px; font-weight: 600; }
.input-invalid { border-color: var(--danger) !important; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius-md); border: 1px solid var(--line-200); }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; background: #fff; }
table.data-table th {
  background: var(--paper-100); text-align: left; padding: 12px 14px; font-weight: 700;
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-500);
  white-space: nowrap; border-bottom: 1px solid var(--line-200);
}
table.data-table td { padding: 12px 14px; border-bottom: 1px solid var(--line-200); vertical-align: middle; }
table.data-table tr:last-child td { border-bottom: none; }
table.data-table tr:hover td { background: #fafbfc; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.badge-success { background: #dcfce7; color: #15803d; }
.badge-warning { background: #fef3c7; color: #b45309; }
.badge-danger { background: #fee2e2; color: #b91c1c; }
.badge-muted { background: var(--paper-100); color: var(--ink-500); }

/* ---------- Row-builder (extinguisher items) ---------- */
#itemsTable { width: 100%; border-collapse: collapse; }
#itemsTable th { background: var(--paper-100); padding: 10px 12px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-500); text-align:left;}
#itemsTable td { padding: 8px; border-bottom: 1px solid var(--line-200); }
#itemsTable td .form-control { min-width: 130px; }
.remove-row-btn { background: #fee2e2; color: var(--danger); border: none; border-radius: 8px; width: 32px; height: 32px; cursor: pointer; font-size: 15px; }
.remove-row-btn:hover { background: #fecaca; }

/* ---------- Alerts / flash ---------- */
.alert { padding: 13px 16px; border-radius: var(--radius-md); font-size: 13.5px; margin-bottom: 16px; font-weight: 500; display:flex; align-items:flex-start; gap:10px;}
.alert-success { background: #ecfdf3; color: #166534; border: 1px solid #bbf7d0; }
.alert-danger { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.alert-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* ---------- Login page ---------- */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 20% 20%, #241414 0, var(--ink-900) 55%);
  padding: 20px;
}
.auth-card {
  width: 100%; max-width: 400px; background: #fff; border-radius: 20px;
  box-shadow: var(--shadow-lift); padding: 36px 32px; text-align: center;
}
.auth-card .flame-badge {
  width: 58px; height: 58px; border-radius: 16px; margin: 0 auto 16px;
  background: linear-gradient(135deg, var(--ember-500), var(--flame-600));
  display: flex; align-items: center; justify-content: center; font-size: 28px; color: #fff;
  box-shadow: 0 8px 20px rgba(214,40,40,.35);
}
.auth-card h1 { font-size: 19px; margin: 0 0 4px; }
.auth-card p.sub { color: var(--ink-500); font-size: 13px; margin: 0 0 24px; }
.auth-card form { text-align: left; }

/* ---------- Verification (public) page ---------- */
.verify-wrap { min-height: 100vh; background: linear-gradient(180deg, #fff5f2, var(--paper-50)); }
.verify-hero { text-align: center; padding: 54px 20px 30px; }
.verify-hero .flame-badge {
  width: 62px; height: 62px; border-radius: 18px; margin: 0 auto 18px;
  background: linear-gradient(135deg, var(--ember-500), var(--flame-600));
  display: flex; align-items: center; justify-content: center; font-size: 30px; color: #fff;
  box-shadow: 0 10px 24px rgba(214,40,40,.3);
}
.verify-hero h1 { font-size: 24px; margin: 0 0 8px; }
.verify-hero p { color: var(--ink-500); max-width: 480px; margin: 0 auto; }
.verify-box { max-width: 480px; margin: 0 auto 40px; padding: 0 20px; }
.verify-search { display: flex; gap: 10px; }
.verify-search input { flex: 1; }
.result-wrap { max-width: 900px; margin: 0 auto 60px; padding: 0 20px; }

.status-pill { display:inline-flex; align-items:center; gap:8px; padding: 8px 18px; border-radius: 999px; font-weight: 800; font-size: 14px; }
.status-pill.valid { background:#dcfce7; color:#15803d; }
.status-pill.expiring { background:#fef3c7; color:#b45309; }
.status-pill.expired { background:#fee2e2; color:#b91c1c; }
.status-pill.notfound { background:#f3f4f6; color:#4b5563; }

/* ---------- Certificate (A4) ---------- */
.cert-toolbar { max-width: 900px; margin: 20px auto; display: flex; justify-content: flex-end; gap: 10px; padding: 0 12px; }
.cert-page {
  width: 210mm; height: 297mm; margin: 0 auto 40px; background: #fff;
  box-shadow: var(--shadow-lift); padding: 14mm 16mm; color: #14181f; position: relative;
  overflow: hidden; /* keep the whole certificate — border included — contained to exactly one A4 sheet */
}
.cert-border {
  border: 2.5px solid var(--flame-700); border-radius: 4px; padding: 8mm; height: 100%; position: relative;
  display: flex; flex-direction: column; overflow: hidden;
}
.cert-header { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid var(--flame-700); padding-bottom: 10px; margin-bottom: 14px; }
.cert-header .firm-block { display: flex; gap: 12px; align-items: center; }
.cert-header .firm-logo { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; }
.cert-header .firm-name { font-size: 19px; font-weight: 800; color: var(--flame-700); margin: 0; }
.cert-header .firm-address { font-size: 10.5px; color: var(--ink-700); margin-top: 2px; line-height: 1.4; max-width: 340px; }
.cert-header .firm-meta { font-size: 10.5px; color: var(--ink-500); margin-top: 2px; line-height: 1.5; }
.cert-title { text-align: center; font-size: 16px; font-weight: 800; letter-spacing: .03em; text-transform: uppercase; margin: 6px 0 16px; color: var(--ink-900); }

.cert-meta-grid { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 14px; }
.cert-meta-left { flex: 1; font-size: 12px; line-height: 1.9; }
.cert-meta-left b { display: inline-block; min-width: 150px; color: var(--ink-700); }
.cert-qr-box { text-align: center; width: 140px; flex-shrink: 0; }
.cert-qr-box img { width: 110px; height: 110px; border: 1px solid var(--line-200); padding: 4px; border-radius: 6px; }
.cert-qr-box .qr-caption { font-size: 9.5px; color: var(--ink-500); margin-top: 6px; font-weight: 600; }

.cert-customer { font-size: 12px; line-height: 1.9; margin-bottom: 16px; border-top: 1px dashed var(--line-200); border-bottom: 1px dashed var(--line-200); padding: 10px 0; }
.cert-customer b { min-width: 222px; display: inline-block; color: var(--ink-700); }

table.cert-items { width: 100%; border-collapse: collapse; margin-bottom: 16px; font-size: 11.5px; }
table.cert-items th { background: #fbeaea; color: var(--flame-700); border: 1px solid #e8c9c9; padding: 7px 8px; text-align: left; }
table.cert-items td { border: 1px solid var(--line-200); padding: 7px 8px; }

.cert-section-title { font-size: 11.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; color: var(--flame-700); margin: 14px 0 4px; }
.cert-section-text { font-size: 10.5px; line-height: 1.6; color: var(--ink-700); text-align: justify; }

.cert-footer { display: flex; justify-content: space-between; align-items: flex-end; margin-top: auto; padding-top: 20px; flex-shrink: 0; }
.cert-sign-box { text-align: center; font-size: 11px; }
.cert-sign-line { width: 160px; border-top: 1.5px solid var(--ink-700); margin-bottom: 6px; }
.cert-generated-note { font-size: 9px; color: var(--ink-300); position: absolute; bottom: 4mm; left: 8mm; }

@media print {
  @page { size: A4; margin: 0; }
  html, body { background: #fff !important; margin: 0; padding: 0; }

  /* Hide every part of the admin/public chrome — only the certificate itself should print */
  .no-print,
  .sidebar, .topbar, .menu-toggle,
  .app-shell > .sidebar { display: none !important; }

  .main-area { margin-left: 0 !important; }
  .content { padding: 0 !important; }
  .verify-wrap .verify-hero, .verify-wrap .verify-box { display: none !important; }

  .cert-page {
    box-shadow: none !important; margin: 0 auto !important; width: 210mm; height: 297mm; overflow: hidden;
  }

  /* Force the side-by-side layout regardless of the print viewport width —
     without this, the screen-only responsive rules below would otherwise
     stack the QR under the details since an A4 page is narrower than 860px. */
  .cert-header, .cert-meta-grid, .cert-footer { flex-direction: row !important; }
  .cert-qr-box { margin: 0 !important; }
}

/* ---------- Responsive (screen only — must not affect print layout) ---------- */
@media screen and (max-width: 1080px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row.cols-3 { grid-template-columns: 1fr 1fr; }
}
@media screen and (max-width: 860px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
  .main-area { margin-left: 0; }
  .menu-toggle { display: inline-flex; }
  .cert-page { width: 100%; height: auto; overflow: visible; padding: 6mm; }
  .cert-border { overflow: visible; }
  .cert-header, .cert-meta-grid, .cert-footer { flex-direction: column; }
  .cert-qr-box { margin: 12px auto 0; }
}
@media screen and (max-width: 640px) {
  .stat-grid { grid-template-columns: 1fr; }
  .form-row.cols-2, .form-row.cols-3 { grid-template-columns: 1fr; }
  .content { padding: 16px; }
  .topbar { padding: 0 16px; }
  .verify-search { flex-direction: column; }
}
