/* ==========================================================================
   Melon CCTV Management System
   Tokens: brand #00552B on a cool neutral canvas. One typeface (Public Sans)
   with tabular figures so amounts line up in every table.
   ========================================================================== */

:root {
    --brand: #00552B;
    --brand-800: #00401F;
    --brand-900: #002E17;
    --brand-100: #DDEEE3;
    --brand-50: #EEF6F1;
    --accent: #7CC79A;          /* light green used on dark green only */
    --canvas: #F5F7F6;
    --surface: #FFFFFF;
    --ink: #1F2937;
    --muted: #6B7280;
    --line: #E1E6E3;
    --line-strong: #CBD3CE;
    --ok: #177245;   --ok-bg: #E3F3EA;
    --warn: #8A5A00; --warn-bg: #FFF3D6;
    --bad: #B42318;  --bad-bg: #FDECEA;
    --info: #1D5FA8; --info-bg: #E6F0FB;
    --radius-sm: 6px;
    --radius: 10px;
    --sidebar-w: 264px;
    --header-h: 60px;
    --font: "Public Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

    --bs-primary: var(--brand);
    --bs-primary-rgb: 0, 85, 43;
    --bs-body-font-family: var(--font);
    --bs-body-color: var(--ink);
    --bs-body-bg: var(--canvas);
    --bs-border-color: var(--line);
    --bs-link-color: var(--brand);
    --bs-link-hover-color: var(--brand-800);
    --bs-link-color-rgb: 0, 85, 43;
}

html { font-size: 15px; }
body {
    font-family: var(--font);
    color: var(--ink);
    background: var(--canvas);
    font-feature-settings: "tnum" 1;
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, h5 { color: var(--ink); letter-spacing: -0.01em; }
.page-title { font-size: 1.45rem; font-weight: 700; margin: 0; }
.text-muted, .form-text { color: var(--muted) !important; }
a { text-underline-offset: 2px; }

:focus-visible { outline: 3px solid rgba(0, 85, 43, .35); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* --------------------------------------------------------------- buttons/forms */
.btn { font-weight: 600; border-radius: var(--radius-sm); padding: .55rem 1rem; }
.btn-primary { --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand);
    --bs-btn-hover-bg: var(--brand-800); --bs-btn-hover-border-color: var(--brand-800);
    --bs-btn-active-bg: var(--brand-900); --bs-btn-active-border-color: var(--brand-900);
    --bs-btn-disabled-bg: var(--brand); --bs-btn-disabled-border-color: var(--brand); }
.btn-outline-primary { --bs-btn-color: var(--brand); --bs-btn-border-color: var(--brand);
    --bs-btn-hover-bg: var(--brand); --bs-btn-hover-border-color: var(--brand);
    --bs-btn-active-bg: var(--brand-800); }
.form-label { font-weight: 600; font-size: .9rem; margin-bottom: .35rem; }
.form-label .req { color: var(--bad); margin-left: 2px; }
.form-control, .form-select { border-color: var(--line-strong); border-radius: var(--radius-sm); padding: .6rem .8rem; }
.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 .2rem rgba(0, 85, 43, .15); }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.input-group .btn-reveal { border-color: var(--line-strong); color: var(--muted); background: var(--surface); }

/* --------------------------------------------------------------- status badges */
.status { display: inline-block; font-size: .78rem; font-weight: 600; padding: .2rem .55rem; border-radius: 999px; white-space: nowrap; }
.status-success   { color: var(--ok);   background: var(--ok-bg); }
.status-warning   { color: var(--warn); background: var(--warn-bg); }
.status-danger    { color: var(--bad);  background: var(--bad-bg); }
.status-info      { color: var(--info); background: var(--info-bg); }
.status-secondary { color: var(--muted); background: #EEF0EF; }

/* --------------------------------------------------------------- app shell */
.app { min-height: 100vh; }
.sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
    background: var(--brand); color: #fff; display: flex; flex-direction: column;
    z-index: 1040; transition: transform .2s ease;
}
.sidebar-brand {
    display: flex; align-items: center; gap: .7rem; height: var(--header-h);
    padding: 0 1.1rem; color: #fff; text-decoration: none; border-bottom: 1px solid rgba(255,255,255,.1);
    flex-shrink: 0;
}
.sidebar-brand img { width: 34px; height: 34px; border-radius: 8px; background: #fff; }
.sidebar-brand strong { display: block; font-size: .98rem; line-height: 1.15; }
.sidebar-brand small { display: block; font-size: .72rem; color: rgba(255,255,255,.7); }
.sidebar-nav { overflow-y: auto; padding: .75rem .6rem 1.5rem; flex: 1; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.25) transparent; }
.nav-link-side, .nav-group-toggle {
    display: flex; align-items: center; gap: .7rem; width: 100%;
    padding: .55rem .75rem; margin: 1px 0; border: 0; background: none; border-radius: var(--radius-sm);
    color: rgba(255,255,255,.84); text-decoration: none; font-size: .92rem; font-weight: 500; text-align: left;
}
.nav-link-side i, .nav-group-toggle i:first-child { font-size: 1.05rem; width: 1.2rem; text-align: center; opacity: .9; }
.nav-link-side:hover, .nav-group-toggle:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-link-side.active { background: rgba(255,255,255,.14); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav-group-toggle .chev { margin-left: auto; font-size: .75rem; transition: transform .15s ease; }
.nav-group-toggle[aria-expanded="true"] .chev { transform: rotate(90deg); }
.nav-sub { padding: 2px 0 6px 1.9rem; }
.nav-sub .nav-link-side { font-size: .87rem; padding: .42rem .7rem; color: rgba(255,255,255,.74); }
.nav-sub .nav-link-side .phase-dot { margin-left: auto; font-size: .68rem; color: rgba(255,255,255,.45); }
.sidebar-foot { padding: .8rem 1.1rem; font-size: .75rem; color: rgba(255,255,255,.6); border-top: 1px solid rgba(255,255,255,.1); }

.main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
    position: sticky; top: 0; z-index: 1030; height: var(--header-h);
    background: var(--surface); border-bottom: 1px solid var(--line);
    display: flex; align-items: center; gap: .75rem; padding: 0 1.25rem;
}
.topbar .menu-toggle { display: none; border: 0; background: none; font-size: 1.4rem; color: var(--ink); padding: .25rem; }
.breadcrumb { margin: 0; font-size: .87rem; }
.breadcrumb-item + .breadcrumb-item::before { content: "/"; color: var(--line-strong); }
.breadcrumb-item.active { color: var(--ink); font-weight: 600; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: .35rem; }
.icon-btn { position: relative; border: 0; background: none; width: 40px; height: 40px; border-radius: 50%; color: var(--ink); font-size: 1.2rem; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.icon-btn:hover { background: var(--canvas); color: var(--ink); }
.icon-btn .count { position: absolute; top: 4px; right: 3px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff; font-size: .68rem; font-weight: 700; line-height: 18px; text-align: center; }
.user-chip { display: flex; align-items: center; gap: .55rem; border: 0; background: none; padding: .25rem .4rem; border-radius: 999px; color: var(--ink); }
.user-chip:hover { background: var(--canvas); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand-100); color: var(--brand); font-weight: 700; font-size: .82rem; display: inline-flex; align-items: center; justify-content: center; }
.user-chip .who { text-align: left; line-height: 1.15; }
.user-chip .who small { color: var(--muted); font-size: .75rem; }

.content { padding: 1.5rem; flex: 1; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.page-head p { margin: .25rem 0 0; color: var(--muted); }
.app-footer { padding: 1rem 1.5rem; font-size: .8rem; color: var(--muted); }

/* panels: flat, bordered; shadow reserved for floating things (menus, modals, toasts) */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel-head { padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.panel-head h2 { font-size: 1rem; font-weight: 700; margin: 0; }
.panel-body { padding: 1.25rem; }
.dropdown-menu { border-color: var(--line); border-radius: var(--radius); box-shadow: 0 12px 32px rgba(15, 40, 25, .12); padding: .4rem; }
.dropdown-item { border-radius: var(--radius-sm); padding: .5rem .75rem; font-size: .9rem; }
.dropdown-item:active { background: var(--brand); }

.table { --bs-table-hover-bg: var(--brand-50); margin: 0; }
.table thead th { font-size: .8rem; font-weight: 600; color: var(--muted); background: #FAFBFA; border-bottom-color: var(--line); white-space: nowrap; }
.table td, .table th { padding: .7rem .9rem; vertical-align: middle; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.alert { border-radius: var(--radius); border: 1px solid transparent; }
.alert-success { background: var(--ok-bg); color: var(--ok); border-color: #C5E6D3; }
.alert-danger  { background: var(--bad-bg); color: var(--bad); border-color: #F6CDC8; }
.alert-warning { background: var(--warn-bg); color: var(--warn); border-color: #F5DFA6; }
.alert-info    { background: var(--info-bg); color: var(--info); border-color: #C9DDF4; }

/* setup checklist on the home page */
.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { display: flex; gap: .8rem; padding: .85rem 0; border-bottom: 1px solid var(--line); }
.checklist li:last-child { border-bottom: 0; }
.checklist .tick { flex: 0 0 26px; height: 26px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: .85rem; }
.checklist .tick.done { background: var(--ok-bg); color: var(--ok); }
.checklist .tick.todo { background: #EEF0EF; color: var(--muted); }
.series-line { display: flex; justify-content: space-between; align-items: baseline; padding: .7rem 0; border-bottom: 1px dashed var(--line); gap: 1rem; }
.series-line:last-child { border-bottom: 0; }
.series-line code { font-size: 1.05rem; color: var(--brand); background: var(--brand-50); padding: .15rem .5rem; border-radius: var(--radius-sm); font-family: var(--font); font-weight: 700; }

.empty-state { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty-state i { font-size: 2.2rem; color: var(--line-strong); display: block; margin-bottom: .75rem; }
.empty-state h2 { font-size: 1.1rem; color: var(--ink); }

.toast-stack { position: fixed; right: 1rem; bottom: 1rem; z-index: 1090; display: flex; flex-direction: column; gap: .5rem; }
.toast { border: 0; border-radius: var(--radius); box-shadow: 0 12px 32px rgba(15, 40, 25, .18); }

.sidebar-backdrop { display: none; }

/* --------------------------------------------------------------- responsive */
@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.25); }
    .sidebar-backdrop.show { display: block; position: fixed; inset: 0; background: rgba(15, 25, 20, .45); z-index: 1035; }
    .main { margin-left: 0; }
    .topbar .menu-toggle { display: inline-flex; }
    .user-chip .who { display: none; }
    .content { padding: 1rem; }
}
@media (max-width: 575.98px) {
    .breadcrumb .breadcrumb-item:not(.active) { display: none; }
    .page-title { font-size: 1.25rem; }
}

/* ==========================================================================
   Sign-in screens. The one expressive moment in the product: a site plan
   with camera coverage cones, drawn in SVG on the brand green.
   ========================================================================== */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); background: var(--surface); }
.auth-visual { position: relative; background: var(--brand); color: #fff; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between; padding: 2.5rem 3rem; }
.auth-visual { background-image: linear-gradient(rgba(255,255,255,.05) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.05) 1px, transparent 1px); background-size: 24px 24px; }
.auth-visual .plan { position: absolute; left: 3rem; right: 3rem; top: 110px; bottom: 270px; width: calc(100% - 6rem); height: calc(100% - 380px); }
.auth-visual .brand-row, .auth-visual .pitch { position: relative; z-index: 1; }
.auth-visual .brand-row { display: flex; align-items: center; gap: .8rem; }
.auth-visual .brand-row img { width: 44px; height: 44px; border-radius: 10px; background: #fff; }
.auth-visual .brand-row strong { font-size: 1.05rem; display: block; }
.auth-visual .brand-row small { color: rgba(255,255,255,.72); }
.auth-visual .pitch h1 { color: #fff; font-size: clamp(1.8rem, 2.6vw, 2.5rem); font-weight: 800; line-height: 1.12; max-width: 18ch; margin-bottom: .9rem; }
.auth-visual .pitch p { color: rgba(255,255,255,.8); max-width: 42ch; font-size: 1.02rem; margin: 0; }
.cone { transform-origin: var(--ox) var(--oy); animation: sweep 9s ease-in-out infinite alternate; }
.cone.c2 { animation-duration: 11s; animation-delay: -3s; }
.cone.c3 { animation-duration: 13s; animation-delay: -6s; }
@keyframes sweep { from { transform: rotate(-9deg); } to { transform: rotate(9deg); } }

.auth-panel { display: flex; align-items: center; justify-content: center; padding: 2.5rem 1.5rem; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card .mobile-brand { display: none; align-items: center; gap: .6rem; margin-bottom: 1.75rem; }
.auth-card .mobile-brand img { width: 38px; height: 38px; }
.auth-card h2 { font-size: 1.55rem; font-weight: 800; margin-bottom: .35rem; }
.auth-card .lead-sm { color: var(--muted); margin-bottom: 1.6rem; }
.auth-card .btn-lg { padding: .75rem 1rem; font-size: 1rem; }
.auth-foot { margin-top: 2rem; font-size: .8rem; color: var(--muted); }

.install-wrap { max-width: 760px; margin: 0 auto; padding: 2.5rem 1rem 4rem; }
.install-wrap .req-list li { display: flex; justify-content: space-between; gap: 1rem; padding: .5rem 0; border-bottom: 1px solid var(--line); }

@media (max-width: 991.98px) {
    .auth-wrap { grid-template-columns: 1fr; }
    .auth-visual { display: none; }
    .auth-card .mobile-brand { display: flex; }
}

@media print {
    .sidebar, .topbar, .app-footer, .no-print { display: none !important; }
    .main { margin: 0; }
    body { background: #fff; }
}

/* ==========================================================================
   Phase 2-4 additions: list toolbars, forms, line-item editor, stat cards
   ========================================================================== */
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; padding: .9rem 1rem; border-bottom: 1px solid var(--line); }
.toolbar .form-control, .toolbar .form-select { min-width: 150px; }
.toolbar .grow { flex: 1 1 220px; }
.table-wrap { overflow-x: auto; }
.table td .sub { display: block; font-size: .8rem; color: var(--muted); }
.table .actions { white-space: nowrap; text-align: right; }
.table tbody tr.row-muted td { color: var(--muted); }
.pagination .page-link { color: var(--brand); }
.pagination .active .page-link { background: var(--brand); border-color: var(--brand); color: #fff; }
.form-section { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 1.5rem 0 .75rem; }
.form-section:first-child { margin-top: 0; }
.form-actions { display: flex; gap: .5rem; flex-wrap: wrap; padding-top: 1.25rem; margin-top: 1.25rem; border-top: 1px solid var(--line); }
.detail-list { display: grid; grid-template-columns: minmax(120px, 38%) 1fr; gap: .45rem 1rem; margin: 0; font-size: .92rem; }
.detail-list dt { font-weight: 400; color: var(--muted); }
.detail-list dd { margin: 0; overflow-wrap: anywhere; }
.stat { padding: 1rem 1.1rem; }
.stat .label { font-size: .8rem; color: var(--muted); display: flex; justify-content: space-between; gap: .5rem; }
.stat .value { font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: .2rem; line-height: 1.2; }
.stat .hint { font-size: .78rem; color: var(--muted); margin-top: .15rem; }
.stat a { color: inherit; text-decoration: none; }
.stat a:hover .value { color: var(--brand); }
.chart-box { position: relative; height: 280px; }
.perm-matrix th, .perm-matrix td { text-align: center; }
.perm-matrix th:first-child, .perm-matrix td:first-child { text-align: left; }
.perm-matrix .group-row td { background: #FAFBFA; font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.lines td, .lines th { padding: .45rem .4rem; vertical-align: top; }
.lines .form-control, .lines .form-select { font-size: .88rem; padding: .35rem .5rem; }
.lines .c-qty { width: 90px; } .lines .c-rate { width: 120px; } .lines .c-tax { width: 90px; } .lines .c-amt { width: 130px; text-align: right; }
.lines .c-del { width: 42px; }
.lines textarea.serials { font-size: .8rem; margin-top: .35rem; }
.totals { max-width: 360px; margin-left: auto; }
.totals div { display: flex; justify-content: space-between; padding: .3rem 0; font-variant-numeric: tabular-nums; }
.totals .grand { font-weight: 800; font-size: 1.1rem; border-top: 2px solid var(--ink); margin-top: .3rem; padding-top: .5rem; }
.doc-head { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .75rem 1.5rem; }
.doc-head .k { font-size: .78rem; color: var(--muted); } .doc-head .v { font-weight: 600; }
.logo-preview { width: 96px; height: 96px; object-fit: contain; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; padding: 6px; }
@media print {
    .btn, .toolbar, form[data-confirm], .page-head .actions { display: none !important; }
    .panel { border: 0; }
}
/* Printable documents (purchase order, GRN, purchase, adjustment) */
.print-page { background: #eef1ee; }
.print-bar { max-width: 210mm; margin: 1rem auto .5rem; display: flex; gap: .5rem; }
.print-sheet { max-width: 210mm; margin: 0 auto 2rem; background: #fff; padding: 12mm; border: 1px solid var(--line); font-size: .9rem; }
.print-head { display: flex; gap: 1rem; align-items: center; border-bottom: 2px solid var(--ink); padding-bottom: .75rem; margin-bottom: 1rem; }
.print-logo { width: 64px; height: 64px; object-fit: contain; }
.print-company { font-size: 1.3rem; font-weight: 800; }
.print-title { text-align: center; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; margin: .25rem 0 1rem; }
.print-sheet .table { font-size: .85rem; }
.print-sheet .table th { background: #F3F5F3; }
.print-sign { display: flex; justify-content: space-between; margin-top: 3rem; font-size: .85rem; }
@media print {
    .print-page { background: #fff; }
    .print-bar { display: none !important; }
    .print-sheet { border: 0; margin: 0; padding: 0; max-width: none; }
    @page { size: A4; margin: 12mm; }
}
@media (max-width: 767.98px) {
    .table-wrap .table th, .table-wrap .table td { white-space: nowrap; }
    .table-wrap .table td .sub { white-space: normal; min-width: 120px; }
    .stat .value { font-size: 1.2rem; }
}
.lines.no-tax .c-tax > * { visibility: hidden; }
