@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Light mode (default) ──────────────────────────────────────── */
:root {
  --bg:               #edf4ff;
  --surface:          #ffffff;
  --surface-raised:   #f4f8ff;
  --sidebar-bg:       #0d1f5c;
  --sidebar-text:     #7da9cc;
  --sidebar-active:   #ffffff;
  --sidebar-accent:   #60a5fa;
  --text-primary:     #0b1733;
  --text-secondary:   #4d6b8a;
  --border:           #c5d8f1;
  --accent:           #2563eb;
  --accent-hover:     #1d4ed8;
  --accent-glow:      rgba(37, 99, 235, 0.15);
  --danger:           #ef4444;
  --success:          #10b981;
  --warning:          #f59e0b;
  --info:             #0ea5e9;
  --status-ok:        #10b981;
  --status-low:       #f59e0b;
  --status-out:       #ef4444;
  --status-expired:   #8b5cf6;
  --radius:           8px;
  --shadow:           0 1px 3px rgba(13, 31, 92, 0.08), 0 1px 2px rgba(13, 31, 92, 0.05);
  --shadow-md:        0 4px 12px rgba(13, 31, 92, 0.1), 0 2px 4px rgba(13, 31, 92, 0.06);
  --font-display:     'DM Sans', sans-serif;
  --font-body:        'DM Sans', sans-serif;
  --font-mono:        'JetBrains Mono', monospace;
  --sidebar-width:    240px;
  --topbar-height:    56px;
  --input-bg:         #ffffff;
  --input-border:     #bfdbfe;
  --row-hover:        #eff6ff;
  --badge-ok-bg:      rgba(16, 185, 129, 0.1);
  --badge-low-bg:     rgba(245, 158, 11, 0.1);
  --badge-out-bg:     rgba(239, 68, 68, 0.1);
  --badge-expired-bg: rgba(139, 92, 246, 0.1);
}

/* ── Dark mode (auto) ──────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:               #05101f;
    --surface:          #0a1929;
    --surface-raised:   #0e2038;
    --sidebar-bg:       #030b15;
    --sidebar-text:     #4d7a9e;
    --sidebar-active:   #dbeafe;
    --sidebar-accent:   #60a5fa;
    --text-primary:     #dbeafe;
    --text-secondary:   #4d7a9e;
    --border:           #142d4a;
    --accent:           #3b82f6;
    --accent-hover:     #60a5fa;
    --accent-glow:      rgba(59, 130, 246, 0.2);
    --danger:           #f87171;
    --success:          #34d399;
    --warning:          #fbbf24;
    --info:             #38bdf8;
    --status-ok:        #34d399;
    --status-low:       #fbbf24;
    --status-out:       #f87171;
    --status-expired:   #a78bfa;
    --shadow:           0 1px 3px rgba(0, 0, 0, 0.5), 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md:        0 4px 12px rgba(0, 0, 0, 0.5), 0 2px 4px rgba(0, 0, 0, 0.4);
    --input-bg:         #061422;
    --input-border:     #142d4a;
    --row-hover:        rgba(59, 130, 246, 0.07);
    --badge-ok-bg:      rgba(52, 211, 153, 0.12);
    --badge-low-bg:     rgba(251, 191, 36, 0.12);
    --badge-out-bg:     rgba(248, 113, 113, 0.12);
    --badge-expired-bg: rgba(167, 139, 250, 0.12);
  }
}

/* ── Dark mode (manual) ────────────────────────────────────────── */
:root[data-theme="dark"] {
  --bg:               #05101f;
  --surface:          #0a1929;
  --surface-raised:   #0e2038;
  --sidebar-bg:       #030b15;
  --sidebar-text:     #4d7a9e;
  --sidebar-active:   #dbeafe;
  --sidebar-accent:   #60a5fa;
  --text-primary:     #dbeafe;
  --text-secondary:   #4d7a9e;
  --border:           #142d4a;
  --accent:           #3b82f6;
  --accent-hover:     #60a5fa;
  --accent-glow:      rgba(59, 130, 246, 0.2);
  --danger:           #f87171;
  --success:          #34d399;
  --warning:          #fbbf24;
  --info:             #38bdf8;
  --status-ok:        #34d399;
  --status-low:       #fbbf24;
  --status-out:       #f87171;
  --status-expired:   #a78bfa;
  --shadow:           0 1px 3px rgba(0, 0, 0, 0.5), 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md:        0 4px 12px rgba(0, 0, 0, 0.5), 0 2px 4px rgba(0, 0, 0, 0.4);
  --input-bg:         #061422;
  --input-border:     #142d4a;
  --row-hover:        rgba(59, 130, 246, 0.07);
  --badge-ok-bg:      rgba(52, 211, 153, 0.12);
  --badge-low-bg:     rgba(251, 191, 36, 0.12);
  --badge-out-bg:     rgba(248, 113, 113, 0.12);
  --badge-expired-bg: rgba(167, 139, 250, 0.12);
}

/* ── Light mode (manual) ───────────────────────────────────────── */
:root[data-theme="light"] {
  --bg:               #edf4ff;
  --surface:          #ffffff;
  --surface-raised:   #f4f8ff;
  --sidebar-bg:       #0d1f5c;
  --sidebar-text:     #7da9cc;
  --sidebar-active:   #ffffff;
  --sidebar-accent:   #60a5fa;
  --text-primary:     #0b1733;
  --text-secondary:   #4d6b8a;
  --border:           #c5d8f1;
  --accent:           #2563eb;
  --accent-hover:     #1d4ed8;
  --accent-glow:      rgba(37, 99, 235, 0.15);
  --input-bg:         #ffffff;
  --input-border:     #bfdbfe;
  --row-hover:        #eff6ff;
  --badge-ok-bg:      rgba(16, 185, 129, 0.1);
  --badge-low-bg:     rgba(245, 158, 11, 0.1);
  --badge-out-bg:     rgba(239, 68, 68, 0.1);
  --badge-expired-bg: rgba(139, 92, 246, 0.1);
}

/* ── Reset & base ──────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.15s ease;
}

.sidebar, .toast, .spinner {
  transition: none;
}

html, body {
  height: 100%;
}

body {
  font-family: var(--font-body);
  font-size: clamp(13px, 1.4vw, 16px);
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.5;
}

h1 { font-size: clamp(1.35rem, 3.5vw, 2rem);   font-weight: 700; }
h2 { font-size: clamp(1.1rem, 2.5vw, 1.5rem);  font-weight: 600; }
h3 { font-size: clamp(0.95rem, 2vw, 1.25rem);  font-weight: 600; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ── App layout ────────────────────────────────────────────────── */
.app-layout {
  min-height: 100vh;
}

/* ── Sidebar ───────────────────────────────────────────────────── */
.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: var(--sidebar-width);
  z-index: 100;
  overflow-y: auto;
}

.sidebar-header {
  padding: clamp(16px, 2.5vw, 24px) 20px clamp(14px, 2vw, 20px);
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.sidebar-logo {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  flex-shrink: 0;
}

.sidebar-title {
  font-size: clamp(1rem, 1.5vw, 1.2rem);
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.02em;
}

.sidebar-close {
  display: none;
  margin-left: auto;
  background: none;
  border: none;
  color: var(--sidebar-text);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 6px;
  line-height: 1;
  min-width: 32px;
  min-height: 32px;
  align-items: center;
  justify-content: center;
}

.sidebar-nav {
  flex: 1;
  padding: clamp(10px, 1.5vw, 16px) 0;
  overflow-y: auto;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: clamp(9px, 1.2vw, 11px) 20px;
  color: var(--sidebar-text);
  font-size: clamp(0.85rem, 1.1vw, 0.95rem);
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: all 0.15s ease;
}

.sidebar-nav a:hover {
  color: var(--sidebar-active);
  background: rgba(255, 255, 255, 0.06);
}

.sidebar-nav a.active {
  color: var(--sidebar-active);
  border-left-color: var(--sidebar-accent);
  background: rgba(96, 165, 250, 0.12);
}

.sidebar-nav .nav-icon {
  font-size: 1.05rem;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: clamp(12px, 1.5vw, 16px) 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.875rem;
  color: var(--sidebar-text);
  min-width: 0;
}

.sidebar-user .username-display {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--sidebar-accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.sidebar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

#theme-toggle {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  color: var(--sidebar-text);
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#theme-toggle:hover {
  background: rgba(255, 255, 255, 0.08);
}

.btn-logout {
  flex: 1;
  padding: 7px 12px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  color: var(--sidebar-text);
  font-size: 0.8rem;
  cursor: pointer;
  text-align: center;
  font-family: var(--font-body);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn-logout:hover {
  background: rgba(248, 113, 113, 0.15);
  border-color: rgba(248, 113, 113, 0.3);
  color: var(--danger);
}

/* ── Sidebar overlay ───────────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

/* ── Main content ──────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  background: var(--bg);
}

.page-content {
  padding: clamp(16px, 4vw, 48px);
  width: 100%;
}

/* ── Topbar (mobile) ───────────────────────────────────────────── */
.topbar {
  display: none;
}

/* ── Buttons ───────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: clamp(8px, 1.2vw, 10px) clamp(12px, 2vw, 18px);
  border-radius: var(--radius);
  font-size: clamp(0.8rem, 1.1vw, 0.9rem);
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  border: none;
  min-height: 44px;
  transition: background 0.15s, transform 0.1s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); color: #fff; }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover { opacity: 0.88; color: #fff; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.btn-ghost:hover {
  background: var(--surface-raised);
  color: var(--text-primary);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.8rem;
  min-height: 34px;
}

/* ── Cards ─────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(14px, 2.5vw, 20px);
  border: 1px solid var(--border);
}

/* ── Status badges ─────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: clamp(0.65rem, 1vw, 0.75rem);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.badge-ok      { background: var(--badge-ok-bg);      color: var(--status-ok); }
.badge-low     { background: var(--badge-low-bg);     color: var(--status-low); }
.badge-out     { background: var(--badge-out-bg);     color: var(--status-out); }
.badge-expired { background: var(--badge-expired-bg); color: var(--status-expired); }

/* ── Page header ───────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: clamp(18px, 3vw, 28px);
  flex-wrap: wrap;
  gap: clamp(10px, 2vw, 16px);
}

.page-header h1 {
  color: var(--text-primary);
}

/* ── Form elements ─────────────────────────────────────────────── */
input, select, textarea {
  width: 100%;
  padding: clamp(8px, 1.2vw, 11px) clamp(10px, 1.5vw, 14px);
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: clamp(14px, 1.5vw, 16px);
  min-height: 44px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

label {
  display: block;
  font-size: clamp(0.78rem, 1.1vw, 0.875rem);
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group {
  display: flex;
  flex-direction: column;
}

.field-error {
  font-size: 0.8rem;
  color: var(--danger);
  margin-top: 4px;
}

/* ── Toast notifications ───────────────────────────────────────── */
.toast-container {
  position: fixed;
  top: clamp(12px, 3vw, 24px);
  right: clamp(12px, 3vw, 24px);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, calc(100vw - 24px));
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(10px, 1.5vw, 14px) clamp(12px, 2vw, 18px);
  box-shadow: var(--shadow-md);
  font-size: clamp(0.8rem, 1.2vw, 0.875rem);
  color: var(--text-primary);
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideInToast 0.2s ease;
}

.toast-success { border-left: 3px solid var(--success); }
.toast-error   { border-left: 3px solid var(--danger); }
.toast-warning { border-left: 3px solid var(--warning); }

@keyframes slideInToast {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ── Scrollbar ─────────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ── Spinner ───────────────────────────────────────────────────── */
.spinner {
  width: clamp(20px, 3vw, 26px);
  height: clamp(20px, 3vw, 26px);
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty state ───────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: clamp(32px, 6vw, 60px) 20px;
  color: var(--text-secondary);
}

.empty-state-icon {
  font-size: clamp(2rem, 5vw, 3rem);
  margin-bottom: 16px;
}

.empty-state h3 {
  margin-bottom: 8px;
  color: var(--text-primary);
}

/* ── Modal ─────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: clamp(18px, 3vw, 28px);
  max-width: min(400px, 100%);
  width: 100%;
  box-shadow: var(--shadow-md);
}

.modal h3      { margin-bottom: 12px; }
.modal p       { color: var(--text-secondary); margin-bottom: 20px; font-size: 0.9rem; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

/* ── Responsive: tablet & mobile ──────────────────────────────── */
@media (max-width: 1023px) {
  .app-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    left: -100%;
    transition: left 0.25s ease;
  }

  .sidebar.open {
    left: 0;
  }

  .sidebar-overlay {
    display: block;
  }

  .sidebar.open ~ .sidebar-overlay {
    opacity: 1;
    pointer-events: all;
  }

  .sidebar-close {
    display: flex;
  }

  .main-content {
    margin-left: 0;
    padding-top: var(--topbar-height);
  }

  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-height);
    background: var(--sidebar-bg);
    color: white;
    padding: 0 clamp(12px, 3vw, 20px);
    z-index: 98;
    gap: 8px;
  }

  .topbar-title {
    font-weight: 700;
    font-size: clamp(0.9rem, 2vw, 1rem);
    color: white;
    flex: 1;
    text-align: center;
  }

  .topbar-left, .topbar-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
  }

  .hamburger {
    background: none;
    border: none;
    color: white;
    font-size: clamp(1.2rem, 3vw, 1.4rem);
    cursor: pointer;
    padding: 6px;
    min-height: 44px;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .topbar-user-btn {
    background: var(--sidebar-accent);
    border: none;
    border-radius: 50%;
    width: 34px;
    height: 34px;
    color: #fff;
    font-weight: 700;
    font-size: 0.8rem;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
  }

  .topbar-user-dropdown {
    position: fixed;
    top: var(--topbar-height);
    right: clamp(8px, 2vw, 12px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 0;
    min-width: clamp(140px, 40vw, 180px);
    box-shadow: var(--shadow-md);
    z-index: 200;
    display: none;
  }

  .topbar-user-dropdown.open {
    display: block;
  }

  .topbar-user-dropdown .dropdown-name {
    padding: 8px 16px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar-user-dropdown button {
    width: 100%;
    background: none;
    border: none;
    padding: 9px 16px;
    text-align: left;
    color: var(--danger);
    font-size: 0.875rem;
    cursor: pointer;
    font-family: var(--font-body);
  }

  .topbar-user-dropdown button:hover {
    background: var(--surface-raised);
  }

  #topbar-theme-toggle {
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: white;
    width: 34px;
    height: 34px;
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }
}

@media (max-width: 767px) {
  .sidebar {
    width: min(320px, 85vw);
  }
}

/* ── Print ─────────────────────────────────────────────────────── */
@media print {
  .sidebar, .topbar, .filter-bar, .pagination, .btn-danger { display: none; }
  .main-content { padding: 0; margin: 0; }
  body { background: white; color: black; }
}
