/* ==========================================================================
   Device Inventory Management System - application styles
   Accent green #4CAF50 (brand). Buttons/links use a darker green so white
   text keeps readable contrast.
   ========================================================================== */
:root {
  --ah: 123; --as: 45%;
  --tint: #f5f8f5;
  --brand: hsl(var(--ah) var(--as) 49%);
  --brand-dark: hsl(var(--ah) var(--as) 33%);
  --brand-darker: hsl(var(--ah) var(--as) 24%);
  --brand-soft: hsl(var(--ah) calc(var(--as) * .8) 94%);
  --brand-ring: color-mix(in srgb, var(--brand) 30%, transparent);
  --ink: #1f2933;
  --muted: #667085;
  --line: color-mix(in srgb, var(--tint) 30%, #e2e6e3);
  --bg: #f5f8f5;
  --card: color-mix(in srgb, var(--tint) 14%, #fff);
  --surface-2: color-mix(in srgb, var(--tint) 22%, #fff);
  --hover: color-mix(in srgb, var(--tint) 26%, #fff);
  --nav-hover: color-mix(in srgb, var(--tint) 32%, #fff);
  --nav-ink: #3b4651;
  --nav-icon: #7b8791;
  --track: color-mix(in srgb, var(--tint) 45%, #fff);
  --soft-line: color-mix(in srgb, var(--tint) 28%, #fff);
  --loader: rgba(255, 255, 255, .6);
  --brand-text: var(--brand-dark);
  --brand-text-strong: var(--brand-darker);
  --auth-bg: linear-gradient(160deg, #eef7ee 0%, #f8fbf8 55%, #e6f2e7 100%);
  /* page background + text that sits directly on it (overridden by the user's appearance settings) */
  --page-bg: #f5f8f5;
  --page-bg-solid: #f5f8f5;
  --page-ink: #1f2933;
  --page-muted: #667085;
  --sidebar-w: 262px;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 16, .05), 0 1px 3px rgba(16, 24, 16, .06);

  --bs-primary: var(--brand-dark);
  --bs-primary-rgb: 46, 125, 50;
  --bs-link-color: var(--brand-text);
  --bs-link-color-rgb: 46, 125, 50;
  --bs-link-hover-color: var(--brand-text-strong);
  --bs-body-font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --bs-body-color: var(--ink);
  --bs-body-bg: var(--bg);
  --bs-border-color: var(--line);
  --bs-border-radius: 8px;
}

html { -webkit-text-size-adjust: 100%; }
body { font-size: .925rem; background: var(--page-bg) fixed; background-color: var(--page-bg-solid); color: var(--ink); min-height: 100vh; }
a { text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4, h5 { letter-spacing: -.01em; }
.text-muted { color: var(--muted) !important; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* ------------------------------------------------------------ buttons ---- */
.btn { font-weight: 500; border-radius: 8px; }
.btn-primary { --bs-btn-bg: var(--brand-dark); --bs-btn-border-color: var(--brand-dark); --bs-btn-hover-bg: var(--brand-darker);
  --bs-btn-hover-border-color: var(--brand-darker); --bs-btn-active-bg: var(--brand-darker); --bs-btn-active-border-color: var(--brand-darker);
  --bs-btn-disabled-bg: var(--brand-dark); --bs-btn-disabled-border-color: var(--brand-dark);  }
.btn-outline-primary { --bs-btn-color: var(--brand-dark); --bs-btn-border-color: var(--brand-dark); --bs-btn-hover-bg: var(--brand-dark);
  --bs-btn-hover-border-color: var(--brand-dark); --bs-btn-active-bg: var(--brand-darker); --bs-btn-active-border-color: var(--brand-darker); }
.btn-icon { border: 0; background: transparent; padding: .25rem .5rem; }
.btn-light { --bs-btn-bg: var(--card); --bs-btn-color: var(--ink); --bs-btn-border-color: var(--line);
  --bs-btn-hover-bg: var(--hover); --bs-btn-hover-color: var(--ink); --bs-btn-hover-border-color: var(--line);
  --bs-btn-active-bg: var(--hover); --bs-btn-active-color: var(--ink); --bs-btn-active-border-color: var(--line);
  --bs-btn-disabled-bg: var(--card); --bs-btn-disabled-color: var(--muted); --bs-btn-disabled-border-color: var(--line); }
.btn-loading { pointer-events: none; opacity: .85; }
.form-control:focus, .form-select:focus, .btn:focus-visible, .page-link:focus {
  border-color: var(--brand); box-shadow: 0 0 0 .2rem var(--brand-ring); }
.form-check-input:checked { background-color: var(--brand-dark); border-color: var(--brand-dark); }
.form-label { font-weight: 500; font-size: .84rem; margin-bottom: .3rem; }
.form-text { font-size: .78rem; }
.required::after { content: ' *'; color: #d33; }

/* ------------------------------------------------------------- layout ---- */
.app-shell { display: flex; min-height: 100vh; }
.app-main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }
.content { padding: 1.5rem 1.75rem 2rem; flex: 1; }
.app-footer { padding: 1rem 1.75rem; font-size: .78rem; color: var(--muted); border-top: 1px solid var(--line); background: var(--card); }

.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); background: var(--card); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; z-index: 1040; transition: transform .22s ease; }
.sidebar-brand { display: flex; align-items: center; gap: .7rem; padding: 1.1rem 1.25rem; color: var(--ink); border-bottom: 1px solid var(--line); }
.sidebar-brand:hover { text-decoration: none; }
.brand-sub { font-size: .66rem; letter-spacing: .06em; color: var(--muted); font-weight: 500; }
.sidebar-nav { padding: .85rem .75rem; flex: 1; overflow-y: auto; }
.sidebar-nav .nav-link { display: flex; align-items: center; gap: .75rem; padding: .62rem .85rem; margin-bottom: 2px; border-radius: 9px;
  color: var(--nav-ink); font-weight: 500; border-left: 3px solid transparent; }
.sidebar-nav .nav-link i { font-size: 1.1rem; color: var(--nav-icon); width: 1.3rem; text-align: center; }
.sidebar-nav .nav-link:hover { background: var(--nav-hover); text-decoration: none; }
.sidebar-nav .nav-link.active { background: var(--brand-soft); color: var(--brand-text-strong); border-left-color: var(--brand); }
.sidebar-nav .nav-link.active i { color: var(--brand-text); }
.sidebar-foot { padding: .85rem 1.25rem; font-size: .75rem; color: var(--muted); border-top: 1px solid var(--line); }
.sidebar-backdrop { display: none; }

.topbar { height: 60px; background: var(--card); border-bottom: 1px solid var(--line); display: flex; align-items: center; padding: 0 1.25rem; gap: .5rem;
  position: sticky; top: 0; z-index: 1020; }
.topbar-title { font-weight: 600; color: var(--muted); font-size: .85rem; letter-spacing: .04em; }
.btn-user { display: flex; align-items: center; gap: .6rem; border: 0; background: transparent; padding: .25rem .5rem; }
.btn-user::after { margin-left: .2rem; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand); color: #fff; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; flex: none; }

.page-head { display: flex; flex-wrap: wrap; gap: .75rem 1rem; align-items: flex-start; justify-content: space-between; margin-bottom: 1.25rem; }
.page-title { font-size: 1.45rem; font-weight: 700; margin: 0; color: var(--page-ink); }
.page-head .text-muted { color: var(--page-muted) !important; }
.page-actions { display: flex; flex-wrap: wrap; gap: .5rem; }

@media (max-width: 991.98px) {
  .app-main { margin-left: 0; }
  .sidebar { transform: translateX(-100%); box-shadow: none; }
  body.sidebar-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .25); }
  body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 1030; }
  .content { padding: 1.1rem 1rem 1.5rem; }
}

/* -------------------------------------------------------------- cards ---- */
.card { border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); background: var(--card); }
.card-header { background: transparent; border-bottom: 1px solid var(--line); font-weight: 600; padding: .85rem 1.1rem; display: flex; align-items: center; gap: .5rem; }
.card-header .bi { color: var(--brand-text); }
.card-body { padding: 1.1rem; }
.card-footer { background: transparent; border-top: 1px solid var(--line); }

.stat-card { display: flex; align-items: center; gap: .9rem; padding: 1rem 1.1rem; height: 100%; color: inherit; }
a.stat-card:hover { text-decoration: none; border-color: var(--brand); }
.stat-icon { width: 46px; height: 46px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.35rem; flex: none;
  background: var(--brand-soft); color: var(--brand-text); }
.stat-icon.warn { background: #fff4e0; color: #b26a00; }
.stat-icon.bad { background: #fde8e8; color: #b42318; }
.stat-icon.mute { background: #eef0f2; color: #536069; }
.stat-icon.blue { background: #e7f0fd; color: #1d4ed8; }
.stat-value { font-size: 1.65rem; font-weight: 700; line-height: 1.1; }
.stat-label { font-size: .78rem; color: var(--muted); font-weight: 500; }

/* ------------------------------------------------------------- tables ---- */
.table { --bs-table-bg: transparent; margin-bottom: 0; }
.table > :not(caption) > * > * { padding: .7rem .85rem; vertical-align: middle; }
.table thead th { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--surface-2);
  border-bottom: 1px solid var(--line); white-space: nowrap; }
.table-hover > tbody > tr:hover > * { --bs-table-bg-state: var(--hover); }
.table-responsive { border-radius: var(--radius); }
.cell-main { font-weight: 600; }
.cell-sub { font-size: .76rem; color: var(--muted); }
.asset-code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-weight: 700; color: var(--brand-text-strong); white-space: nowrap; }
.badge { font-weight: 600; }
.badge-soft { padding: .38em .65em; border-radius: 999px; font-size: .72rem; }
.badge-soft.bg-success { background: #e3f4e4 !important; color: #17591b; }
.badge-soft.bg-primary { background: var(--brand-soft) !important; color: var(--brand-text-strong); box-shadow: inset 0 0 0 1px var(--brand-ring); }
.badge-soft.bg-warning { background: #fff1d6 !important; color: #8a5300; }
.badge-soft.bg-danger { background: #fde4e2 !important; color: #a1261b; }
.badge-soft.bg-secondary { background: #eceff1 !important; color: #46525b; }
.badge-soft.bg-info { background: #e1effd !important; color: #1d4a99; }

.filter-bar { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem 1rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.empty-state i { font-size: 2.2rem; color: #b8c3bb; display: block; margin-bottom: .5rem; }

.dl-grid { display: grid; grid-template-columns: minmax(120px, 190px) 1fr; gap: .45rem 1rem; margin: 0; }
.dl-grid dt { font-weight: 500; color: var(--muted); font-size: .82rem; }
.dl-grid dd { margin: 0; word-break: break-word; }
@media (max-width: 575.98px) { .dl-grid { grid-template-columns: 1fr; gap: 0; } .dl-grid dd { margin-bottom: .55rem; } }

.form-section-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--brand-text); font-weight: 700; margin-bottom: .85rem; }
.nav-tabs .nav-link { color: var(--muted); font-weight: 500; }
.nav-tabs .nav-link.active { color: var(--brand-text-strong); font-weight: 600; background: var(--card); border-color: var(--line) var(--line) var(--card); }

/* bar lists (distribution widgets) */
.bar-row { display: grid; grid-template-columns: minmax(90px, 38%) 1fr auto; gap: .6rem; align-items: center; margin-bottom: .55rem; font-size: .84rem; }
.bar-track { background: var(--track); border-radius: 999px; height: 10px; overflow: hidden; }
.bar-fill { background: var(--brand); height: 100%; border-radius: 999px; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain > li { padding: .6rem 0; border-bottom: 1px solid var(--line); }
.list-plain > li:last-child { border-bottom: 0; padding-bottom: 0; }
.list-plain > li:first-child { padding-top: 0; }

/* ----------------------------------------------------- typeahead picker ---- */
.ta-wrap { position: relative; }
.ta-menu { position: absolute; left: 0; right: 0; top: 100%; z-index: 1050; background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .12); max-height: 290px; overflow-y: auto; margin-top: 4px; display: none; }
.ta-menu.show { display: block; }
.ta-item { display: block; width: 100%; text-align: left; border: 0; background: var(--card); color: var(--ink); padding: .55rem .8rem; border-bottom: 1px solid var(--soft-line); }
.ta-item:last-child { border-bottom: 0; }
.ta-item:hover, .ta-item.active { background: var(--brand-soft); }
.ta-empty { padding: .8rem; color: var(--muted); font-size: .85rem; }
.ta-selected { background: var(--brand-soft); border: 1px solid #c9e4cb; border-radius: 10px; padding: .6rem .8rem; display: none; }
.ta-selected.show { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }

/* --------------------------------------------------- permission matrix ---- */
.perm-group { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; height: 100%; background: var(--card); }
.perm-group-head { background: var(--hover); padding: .6rem .9rem; font-weight: 600; display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.perm-item { padding: .5rem .9rem; border-top: 1px solid var(--soft-line); }
.perm-item label { cursor: pointer; width: 100%; }
.perm-item .perm-code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .72rem; color: var(--muted); }

/* ------------------------------------------------------------ feedback ---- */
.page-loader { position: fixed; inset: 0; background: var(--loader); z-index: 3000; display: none; align-items: center; justify-content: center; }
.page-loader.show { display: flex; }
.toast { border: 0; box-shadow: 0 8px 24px rgba(0, 0, 0, .15); border-radius: 10px; overflow: hidden; }
.toast-accent { width: 5px; align-self: stretch; }

/* ---------------------------------------------------------------- auth ---- */
.auth-body { background: var(--auth-bg) fixed; min-height: 100vh; }
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.25rem; }
.auth-card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 12px 40px rgba(30, 80, 35, .12); padding: 2.2rem 2rem; width: 100%; max-width: 420px; }
.auth-card.wide { max-width: 640px; }

/* -------------------------------------------------------------- print ---- */
@media print {
  :root { --page-ink: #000 !important; --page-muted: #444 !important; }
  body { background: #fff !important; font-size: 11px; }
  .sidebar, .topbar, .sidebar-backdrop, .app-footer, .no-print, .filter-bar, .pagination, .toast-container, .page-loader { display: none !important; }
  .app-main { margin: 0 !important; }
  .content { padding: 0 !important; }
  .card { box-shadow: none !important; border: 0 !important; }
  .table thead th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .table > :not(caption) > * > * { padding: .25rem .4rem; border-bottom: 1px solid #ccc; }
  .table-responsive { overflow: visible !important; }
  a { color: inherit !important; text-decoration: none !important; }
  .page-title { font-size: 16px; }
  .badge-soft { border: 1px solid #999; background: #fff !important; color: #000 !important; }
  .print-only { display: block !important; }
}
.print-only { display: none; }

/* ====================================================================
   Appearance: theme switch button, dark palette
   ==================================================================== */
.theme-ico { display: none; }
html[data-theme-pref="light"] .theme-ico-light,
html[data-theme-pref="dark"] .theme-ico-dark,
html[data-theme-pref="auto"] .theme-ico-auto { display: inline; }

:root[data-bs-theme="dark"] {
  color-scheme: dark;
  --line: color-mix(in srgb, var(--tint) 55%, #2b3631);
  --card: color-mix(in srgb, var(--tint) 55%, #18211c);
  --surface-2: color-mix(in srgb, var(--tint) 60%, #1f2a24);
  --hover: color-mix(in srgb, var(--tint) 60%, #232f28);
  --nav-hover: color-mix(in srgb, var(--tint) 60%, #232f28);
  --track: color-mix(in srgb, var(--tint) 50%, #2a362f);
  --soft-line: color-mix(in srgb, var(--tint) 50%, #26312b);
  --bg: var(--tint);
  --brand-soft: hsl(var(--ah) calc(var(--as) * .6) 18%);
  --brand-text: hsl(var(--ah) var(--as) 70%);
  --brand-text-strong: hsl(var(--ah) var(--as) 80%);
  --bs-secondary-bg: var(--surface-2);
  --bs-tertiary-bg: var(--surface-2);
  --ink: #e4eae6;
  --muted: #9aa7a0;
  --nav-ink: #cfd8d2;
  --nav-icon: #8a978f;
  --loader: rgba(8, 12, 10, .65);
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 1px 3px rgba(0, 0, 0, .3);
  --auth-bg: linear-gradient(160deg, #0b110d 0%, #131c16 55%, #0d1510 100%);
}
[data-bs-theme="dark"] .bg-light, [data-bs-theme="dark"] .text-bg-light { background-color: var(--surface-2) !important; color: var(--ink) !important; }
[data-bs-theme="dark"] .border { border-color: var(--line) !important; }
[data-bs-theme="dark"] .required::after { color: #ff8a80; }
[data-bs-theme="dark"] .form-control:focus, [data-bs-theme="dark"] .form-select:focus { box-shadow: 0 0 0 .2rem var(--brand-ring); }
[data-bs-theme="dark"] .btn-outline-primary { --bs-btn-color: var(--brand-text); }
[data-bs-theme="dark"] .empty-state i { color: #4a5a50; }
[data-bs-theme="dark"] .ta-selected { border-color: var(--brand-dark); }
[data-bs-theme="dark"] .auth-card { box-shadow: 0 12px 40px rgba(0, 0, 0, .5); }
[data-bs-theme="dark"] .stat-icon.warn { background: rgba(255, 167, 38, .16); color: #ffb74d; }
[data-bs-theme="dark"] .stat-icon.bad { background: rgba(244, 67, 54, .18); color: #ff8a80; }
[data-bs-theme="dark"] .stat-icon.mute { background: rgba(176, 190, 197, .14); color: #b0bec5; }
[data-bs-theme="dark"] .stat-icon.blue { background: rgba(66, 135, 245, .18); color: #82b1ff; }
[data-bs-theme="dark"] .badge-soft.bg-success { background: rgba(76, 175, 80, .2) !important; color: #9ad79d; }
[data-bs-theme="dark"] .badge-soft.bg-primary { background: var(--brand-soft) !important; color: var(--brand-text-strong); box-shadow: inset 0 0 0 1px var(--brand-ring); }
[data-bs-theme="dark"] .badge-soft.bg-warning { background: rgba(255, 193, 7, .16) !important; color: #ffd54f; }
[data-bs-theme="dark"] .badge-soft.bg-danger { background: rgba(244, 67, 54, .2) !important; color: #ff8a80; }
[data-bs-theme="dark"] .badge-soft.bg-secondary { background: rgba(176, 190, 197, .16) !important; color: #c3ced4; }
[data-bs-theme="dark"] .badge-soft.bg-info { background: rgba(66, 165, 245, .18) !important; color: #90caf9; }
[data-bs-theme="dark"] .btn-close { filter: invert(1) grayscale(100%) brightness(200%); }

/* appearance picker */
.btn-link { --bs-btn-color: var(--brand-text); --bs-btn-hover-color: var(--brand-text-strong); }
.form-control-color { height: 42px; min-width: 3.2rem; }
.theme-swatch { display: block; cursor: pointer; margin: 0; }
.theme-swatch input { position: absolute; opacity: 0; pointer-events: none; }
.theme-swatch .sw { height: 62px; border-radius: 10px; border: 2px solid var(--line); transition: transform .12s, border-color .12s; }
.theme-swatch:hover .sw { transform: translateY(-1px); }
.theme-swatch input:checked + .sw { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.theme-swatch input:focus-visible + .sw { outline: 2px solid var(--brand); outline-offset: 2px; }
.theme-swatch .sw-name { font-size: .78rem; margin-top: .3rem; text-align: center; color: var(--muted); }
.mode-choice { display: flex; align-items: center; gap: .6rem; padding: .7rem .9rem; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; background: var(--card); margin: 0; height: 100%; }
.mode-choice:has(input:checked) { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.mode-choice i { font-size: 1.3rem; color: var(--brand-text); }
.sidebar-brand img, .auth-card img { filter: hue-rotate(calc((var(--ah) - 123) * 1deg)); }
