:root {
  --hik-red: #CC0000;
  --hik-red-dark: #990000;
  --hik-red-light: #FFEEEE;
  --blue: #185FA5;
  --blue-light: #E6F1FB;
  --green: #2D7D46;
  --green-light: #E8F5ED;
  --amber: #92600A;
  --amber-light: #FEF3CD;
  --gray-50: #F8F8F8;
  --gray-100: #F0F0F0;
  --gray-200: #E0E0E0;
  --gray-400: #9E9E9E;
  --gray-600: #555;
  --gray-900: #1A1A1A;
  --sidebar-w: 220px;
  --radius: 8px;
  --shadow: 0 1px 4px rgba(0,0,0,0.08);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--gray-50); color: var(--gray-900); font-size: 14px; }

/* LOGIN */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #CC0000 0%, #660000 100%); }
.login-box { background: #fff; border-radius: 16px; padding: 2.5rem; width: 360px; box-shadow: 0 8px 40px rgba(0,0,0,0.25); }
.login-logo { width: 64px; height: 64px; background: var(--hik-red); border-radius: 14px; display: flex; align-items: center; justify-content: center; margin: 0 auto 1rem; }
.login-title { text-align: center; font-size: 22px; font-weight: 700; color: var(--gray-900); }
.login-sub { text-align: center; font-size: 13px; color: var(--gray-400); margin-bottom: 1.5rem; }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-hint { text-align: center; font-size: 11px; color: var(--gray-400); margin-top: 1rem; }
.login-hint code { background: var(--gray-100); padding: 2px 6px; border-radius: 4px; font-size: 11px; }

/* LAYOUT */
.sidebar { position: fixed; top: 0; left: 0; width: var(--sidebar-w); height: 100vh; background: #1A1A1A; display: flex; flex-direction: column; z-index: 10; }
.sidebar-logo { display: flex; align-items: center; gap: 10px; padding: 1.25rem 1rem; border-bottom: 1px solid rgba(255,255,255,0.08); font-weight: 700; color: #fff; font-size: 14px; }
.sidebar-nav { flex: 1; padding: 0.75rem 0; overflow-y: auto; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 0.6rem 1rem; cursor: pointer; color: rgba(255,255,255,0.65); font-size: 13px; border-radius: 6px; margin: 1px 8px; transition: all 0.15s; }
.nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-item.active { background: var(--hik-red); color: #fff; }
.nav-item svg { flex-shrink: 0; }
.nav-section { font-size: 10px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: rgba(255,255,255,0.3); padding: 0.5rem 1rem 0.25rem; margin-top: 0.5rem; }
.sidebar-footer { padding: 0.75rem; border-top: 1px solid rgba(255,255,255,0.08); }
.sidebar-user { font-size: 12px; color: rgba(255,255,255,0.55); padding: 0.4rem 0.5rem; margin-bottom: 6px; line-height: 1.4; }
.sidebar-user strong { display: block; color: rgba(255,255,255,0.9); font-size: 13px; }
.sidebar-logout { width: 100%; padding: 7px; background: transparent; border: 1px solid rgba(255,255,255,0.15); border-radius: 6px; color: rgba(255,255,255,0.5); cursor: pointer; font-size: 12px; }
.sidebar-logout:hover { background: rgba(255,255,255,0.08); color: #fff; }
.main-content { margin-left: var(--sidebar-w); min-height: 100vh; padding: 1.5rem; }

/* PAGE HEADER */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 1.25rem; flex-wrap: wrap; gap: 10px; }
.page-title { font-size: 20px; font-weight: 700; color: var(--gray-900); }
.page-subtitle { font-size: 13px; color: var(--gray-400); margin-top: 2px; }

/* CARDS */
.card { background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius); padding: 1.25rem; }
.card-sm { padding: 1rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }

/* KPI CARDS */
.kpi-card { background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius); padding: 1rem 1.25rem; }
.kpi-label { font-size: 11px; color: var(--gray-400); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px; }
.kpi-value { font-size: 28px; font-weight: 800; color: var(--gray-900); }
.kpi-sub { font-size: 11px; color: var(--gray-400); margin-top: 3px; }

/* PROGRESS BAR */
.progress-wrap { margin-top: 8px; }
.progress-label { display: flex; justify-content: space-between; font-size: 11px; color: var(--gray-600); margin-bottom: 4px; }
.progress-track { height: 8px; background: var(--gray-100); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 4px; background: var(--hik-red); transition: width 0.5s ease; }
.progress-fill.good { background: var(--green); }
.progress-fill.warn { background: #F59E0B; }

/* FORMS */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field label { font-size: 12px; font-weight: 600; color: var(--gray-600); }
.field input, .field select, .field textarea { padding: 8px 10px; border: 1px solid var(--gray-200); border-radius: 6px; background: #fff; color: var(--gray-900); font-size: 13px; font-family: inherit; outline: none; width: 100%; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--hik-red); box-shadow: 0 0 0 3px rgba(204,0,0,0.08); }
.field textarea { resize: vertical; min-height: 70px; }
.req { color: var(--hik-red); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

/* BUTTONS */
.btn { padding: 8px 16px; border-radius: 6px; font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit; border: 1px solid transparent; transition: all 0.15s; display: inline-flex; align-items: center; gap: 6px; }
.btn-primary { background: var(--hik-red); color: #fff; border-color: var(--hik-red); }
.btn-primary:hover { background: var(--hik-red-dark); }
.btn-secondary { background: #fff; color: var(--gray-600); border-color: var(--gray-200); }
.btn-secondary:hover { background: var(--gray-50); }
.btn-danger { background: #fff; color: #CC0000; border-color: #CC0000; }
.btn-danger:hover { background: var(--hik-red-light); }
.btn-success { background: var(--green); color: #fff; border-color: var(--green); }
.btn-success:hover { background: #236338; }
.btn-full { width: 100%; justify-content: center; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11px; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* TABLE */
.table-wrap { overflow-x: auto; border: 1px solid var(--gray-200); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th { background: var(--gray-50); padding: 10px 12px; text-align: left; font-weight: 600; color: var(--gray-600); font-size: 12px; border-bottom: 1px solid var(--gray-200); white-space: nowrap; }
tbody td { padding: 9px 12px; border-bottom: 1px solid var(--gray-100); color: var(--gray-900); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--gray-50); }
.table-empty { text-align: center; padding: 2.5rem; color: var(--gray-400); font-size: 13px; }

/* BADGES */
.badge { display: inline-block; padding: 3px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-green { background: var(--green-light); color: var(--green); }
.badge-blue { background: var(--blue-light); color: var(--blue); }
.badge-amber { background: var(--amber-light); color: var(--amber); }
.badge-red { background: var(--hik-red-light); color: var(--hik-red); }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }

/* MODAL */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: flex-start; justify-content: center; padding-top: 60px; z-index: 100; }
.modal-box { background: #fff; border-radius: 12px; width: 640px; max-width: 95vw; max-height: 88vh; overflow-y: auto; box-shadow: 0 8px 40px rgba(0,0,0,0.2); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.25rem; border-bottom: 1px solid var(--gray-200); position: sticky; top: 0; background: #fff; z-index: 1; }
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-x { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--gray-400); padding: 2px 6px; border-radius: 4px; }
.modal-x:hover { background: var(--gray-100); }
.modal-body { padding: 1.25rem; }

/* TOAST */
.toast { position: fixed; bottom: 24px; right: 24px; background: #1A1A1A; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 13px; font-weight: 500; opacity: 0; transform: translateY(8px); transition: all 0.25s; pointer-events: none; z-index: 200; max-width: 320px; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: var(--green); }
.toast.error { background: var(--hik-red); }

/* FILTERS BAR */
.filters-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: flex-end; }
.filters-bar select, .filters-bar input { padding: 7px 10px; border: 1px solid var(--gray-200); border-radius: 6px; font-size: 13px; background: #fff; color: var(--gray-900); outline: none; font-family: inherit; }
.filters-bar select:focus, .filters-bar input:focus { border-color: var(--hik-red); }

/* CALENDAR */
.cal-nav { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.cal-month-title { font-size: 18px; font-weight: 700; flex: 1; }
.cal-grid { border: 1px solid var(--gray-200); border-radius: var(--radius); overflow: hidden; }
.cal-header-row { display: grid; grid-template-columns: repeat(5,1fr); background: var(--hik-red); }
.cal-dow { padding: 8px; text-align: center; font-size: 12px; font-weight: 600; color: #fff; }
.cal-body { display: grid; grid-template-columns: repeat(5,1fr); }
.cal-cell { border-right: 1px solid var(--gray-100); border-bottom: 1px solid var(--gray-100); min-height: 100px; padding: 6px; background: #fff; vertical-align: top; }
.cal-cell:nth-child(5n) { border-right: none; }
.cal-cell.empty { background: var(--gray-50); }
.cal-cell.today { background: #FFF8F8; }
.cal-day-num { font-size: 13px; font-weight: 700; margin-bottom: 4px; color: var(--gray-900); }
.cal-cell.today .cal-day-num { color: var(--hik-red); }
.cal-evt { position: relative; border-radius: 4px; padding: 2px 6px; font-size: 10px; margin-bottom: 3px; cursor: pointer; line-height: 1.4; font-weight: 500; }
.cal-evt:hover { opacity: 0.85; }
.evt-cert { background: #B5D4F4; color: #042C53; }
.evt-web { background: #F5C4B3; color: #4A1B0C; }
.evt-work { background: #9FE1CB; color: #04342C; }
.evt-norm { background: #E0E0E0; color: #333; }
.evt-int { background: #FAC775; color: #412402; }
.cal-legend { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.leg { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--gray-600); }
.leg-dot { width: 10px; height: 10px; border-radius: 3px; }

/* IMPORT */
.drop-zone { border: 2px dashed var(--gray-200); border-radius: var(--radius); padding: 2.5rem; text-align: center; cursor: pointer; transition: all 0.2s; }
.drop-zone:hover, .drop-zone.drag-over { border-color: var(--hik-red); background: var(--hik-red-light); }
.drop-title { font-size: 14px; font-weight: 600; color: var(--gray-900); margin-bottom: 4px; }
.drop-sub { font-size: 12px; color: var(--gray-400); }

/* CHARTS */
.bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.bar-label { font-size: 11px; color: var(--gray-600); width: 120px; text-align: right; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1; background: var(--gray-100); border-radius: 3px; height: 20px; }
.bar-fill { height: 100%; border-radius: 3px; background: var(--hik-red); display: flex; align-items: center; justify-content: flex-end; padding-right: 6px; min-width: 24px; transition: width 0.4s; }
.bar-fill span { font-size: 11px; font-weight: 700; color: #fff; }

/* KPI PROGRESS */
.kpi-progress-section { margin-bottom: 1.5rem; }
.kpi-progress-title { font-size: 13px; font-weight: 700; color: var(--gray-900); margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--gray-100); }
.kpi-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.kpi-name { font-size: 12px; color: var(--gray-600); width: 160px; flex-shrink: 0; }
.kpi-track { flex: 1; min-width: 120px; }
.kpi-numbers { font-size: 12px; font-weight: 700; white-space: nowrap; }
.kpi-numbers.good { color: var(--green); }
.kpi-numbers.warn { color: #D97706; }
.kpi-numbers.bad { color: var(--hik-red); }

/* UTILS */
.text-muted { color: var(--gray-400); }
.text-sm { font-size: 12px; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.error-msg { background: var(--hik-red-light); color: var(--hik-red); padding: 8px 12px; border-radius: 6px; font-size: 13px; }
.section-title { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--gray-400); margin-bottom: 10px; padding-bottom: 6px; border-bottom: 1px solid var(--gray-100); }
.divider { border: none; border-top: 1px solid var(--gray-100); margin: 1rem 0; }
input[type="file"] { display: none; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }

/* RESPONSIVE */
/* Old responsive removed — see full responsive section below */

/* Bulk selection */
tr.selected-row td { background: var(--blue-light) !important; }
tr.selected-row:hover td { background: #D6E8F8 !important; }

/* ═══════════════════════════════════════════════════════════════
   FULL RESPONSIVE — MOBILE FIRST
   ═══════════════════════════════════════════════════════════════ */

/* ── Mobile hamburger button ─────────────────────────────────── */
.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: #1A1A1A;
  border: none;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 5px;
  padding: 10px;
}
.mobile-menu-btn span {
  display: block;
  width: 20px;
  height: 2px;
  background: #fff;
  border-radius: 2px;
  transition: all 0.25s;
}

/* ── Mobile overlay ──────────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}
.sidebar-overlay.visible { display: block; }

/* ── Tablet breakpoint (≤1024px) ─────────────────────────────── */
@media (max-width: 1024px) {
  :root { --sidebar-w: 200px; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .field-row-3 { grid-template-columns: 1fr 1fr; }
}

/* ── Mobile breakpoint (≤768px) ─────────────────────────────── */
@media (max-width: 768px) {

  /* Sidebar — slide-over drawer */
  .mobile-menu-btn { display: flex; }

  .sidebar {
    position: fixed;
    top: 0; left: 0;
    width: 260px;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 100;
  }
  .sidebar.open { transform: translateX(0); }

  /* Main content — full width, top padding for hamburger */
  .main-content {
    margin-left: 0;
    padding: 1rem;
    padding-top: 60px;
  }

  /* Page header — stack title and buttons */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .page-header .btn-group {
    width: 100%;
    flex-wrap: wrap;
  }
  .page-header .btn-group .btn {
    flex: 1;
    min-width: 120px;
    text-align: center;
    justify-content: center;
  }

  /* Grids → single column */
  .grid-2, .grid-4, .grid-3 {
    grid-template-columns: 1fr !important;
  }

  /* KPI cards — 2 columns on mobile */
  #poc-kpis, #pem-kpis, #pst-kpis, #sp-kpis,
  [id$="-kpis"], .kpi-strip {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }

  .kpi-card { padding: 10px 12px; }
  .kpi-value { font-size: 22px !important; }
  .kpi-label { font-size: 10px; }

  /* Forms — single column */
  .field-row, .field-row-3 {
    grid-template-columns: 1fr;
  }

  /* Modal — full screen */
  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }
  .modal {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 90vh;
    border-radius: 16px 16px 0 0;
    overflow-y: auto;
  }
  .modal-body { padding: 0 4px; }

  /* Tables — horizontal scroll with fixed first col */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  table { min-width: 600px; font-size: 12px; }
  th, td { padding: 8px 6px !important; }

  /* Filters bar — wrap and compact */
  .filters-bar {
    flex-wrap: wrap;
    gap: 6px;
  }
  .filters-bar input,
  .filters-bar select {
    min-width: 0 !important;
    flex: 1;
    font-size: 13px;
  }
  .filters-bar .btn { flex-shrink: 0; }

  /* Buttons — full width in stacked contexts */
  .btn-group.stacked { flex-direction: column; }

  /* Calendar — compact */
  .cal-nav { gap: 8px; }
  .cal-month-title { font-size: 15px; }
  .cal-dow { font-size: 9px; padding: 4px 2px; }
  .cal-cell { min-height: 60px; padding: 4px 2px; }
  .cal-day-num { font-size: 11px; }
  .cal-evt { font-size: 9px; padding: 1px 3px; margin-bottom: 1px; }
  .cal-legend { gap: 6px; }
  .leg { font-size: 10px; }
  .leg-dot { width: 8px; height: 8px; }

  /* Dashboard bars */
  .bar-label { width: 80px !important; font-size: 11px; }
  .bar-row { gap: 6px; }

  /* KPI progress rows */
  .kpi-row { flex-wrap: wrap; gap: 4px; }
  .kpi-name { width: 100% !important; font-size: 12px; }
  .kpi-track { width: 100%; }
  .kpi-numbers { width: 100%; text-align: right; font-size: 11px; }

  /* Drop zone */
  .drop-zone { padding: 1.5rem 1rem; }
  .drop-title { font-size: 14px; }

  /* Page title */
  .page-title { font-size: 20px; }
  .page-subtitle { font-size: 12px; }

  /* Cards */
  .card { padding: 12px; }

  /* Bulk action bar */
  #sp-bulk-bar, #t-bulk-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  /* Login */
  .login-box {
    width: 100%;
    margin: 1rem;
    padding: 1.5rem;
    border-radius: 12px;
  }

  /* Presales dashboard grid */
  [style*="grid-template-columns: repeat(4"] {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

/* ── Small mobile (≤480px) ───────────────────────────────────── */
@media (max-width: 480px) {
  .main-content { padding: 0.75rem; padding-top: 56px; }

  .btn { padding: 7px 12px; font-size: 12px; }
  .btn-sm { padding: 5px 10px; font-size: 11px; }
  .btn-xs { padding: 3px 7px; font-size: 10px; }

  /* KPI cards — 2 per row even on tiny screens */
  .kpi-card { padding: 8px; }
  .kpi-value { font-size: 20px !important; }

  /* Pagination */
  #sp-pagination, #t-pagination, #poc-pg, #pem-pg, #pst-pg {
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
  }

  /* Section titles */
  .section-title { font-size: 11px; }

  /* Table font even smaller */
  table { font-size: 11px; }
}

/* ── Modal mobile override ───────────────────────────────────── */
@media (max-width: 768px) {
  .modal-overlay {
    align-items: flex-end !important;
    padding-top: 0 !important;
    padding: 0 !important;
  }
  .modal-box {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 92vh !important;
    border-radius: 16px 16px 0 0 !important;
    overflow-y: auto;
  }
  .modal-header {
    padding: 0.875rem 1rem !important;
  }
  .modal-body {
    padding: 1rem !important;
  }
  /* Fields in modal — full width */
  .modal-body .field-row,
  .modal-body .field-row-3 {
    grid-template-columns: 1fr !important;
  }
  /* Sticky save buttons in modal */
  .modal-body > .btn-group:last-child {
    position: sticky;
    bottom: 0;
    background: #fff;
    padding: 12px 0 4px;
    margin-top: 12px;
    border-top: 1px solid var(--gray-100);
  }
}
