/* IVAC customer portal — navy brand palette, light + dark themes. */

:root,
[data-theme="light"] {
  --navy-900: #0A1733;
  --navy-800: #0F2147;
  --navy-700: #142C5C;
  --navy-600: #1B3A78;
  --navy-500: #234A9A;
  --navy-400: #3D62B0;
  --navy-300: #6B8AC9;
  --navy-200: #A3B6DD;
  --navy-100: #D4DEF0;
  --navy-50:  #EDF1FA;

  --bg: #F7F9FC;
  --surface: #FFFFFF;
  --text: #0A1733;
  --text-muted: rgba(10, 23, 51, 0.62);
  --border: #A3B6DD;
  --border-soft: #D4DEF0;

  --primary: #142C5C;
  --primary-hover: #0A1733;
  --primary-text: #FFFFFF;
  --accent: #4F9CFF;
  --accent-hover: #3D62B0;

  --success: #2BB673;
  --warning: #E0A800;
  --danger: #E5484D;

  --row-hover: #EDF1FA;
  --input-bg: #FFFFFF;
  --shadow: 0 1px 3px rgba(10, 23, 51, 0.08), 0 4px 16px rgba(10, 23, 51, 0.06);
}

[data-theme="dark"] {
  --bg: #0B1226;
  --surface: #0A1733;
  --text: #EDF1FA;
  --text-muted: rgba(237, 241, 250, 0.62);
  --border: #142C5C;
  --border-soft: #0F2147;

  --primary: #234A9A;
  --primary-hover: #1B3A78;
  --primary-text: #FFFFFF;
  --accent: #4F9CFF;
  --accent-hover: #6B8AC9;

  --row-hover: #0F2147;
  --input-bg: #0F2147;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

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

svg { width: 18px; height: 18px; flex-shrink: 0; }

/* ---------------------------------------------------------------- layout */

.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 250px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--navy-700) 0%, var(--navy-900) 100%);
  color: #EDF1FA;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 18px;
  border-bottom: 1px solid rgba(237, 241, 250, 0.12);
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: block;
  object-fit: cover;
}

.brand-mark-lg { width: 52px; height: 52px; border-radius: 14px; margin: 0 auto; }

.brand-name { font-weight: 700; font-size: 17px; letter-spacing: 1px; }
.brand-sub { font-size: 10.5px; color: rgba(237, 241, 250, 0.65); margin-top: 1px; }

.nav { padding: 14px 10px; flex: 1; display: flex; flex-direction: column; gap: 4px; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 9px;
  color: rgba(237, 241, 250, 0.78);
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: background 0.15s, color 0.15s;
}

.nav-link:hover { background: rgba(237, 241, 250, 0.08); color: #FFFFFF; }

.nav-link.active {
  background: var(--navy-500);
  border-left-color: var(--accent);
  color: #FFFFFF;
}

.sidebar-foot { padding: 14px; border-top: 1px solid rgba(237, 241, 250, 0.12); }

.user-chip { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--navy-500);
  color: #FFFFFF;
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; }

.logout-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  border: 1px solid rgba(237, 241, 250, 0.25);
  border-radius: 8px;
  background: transparent;
  color: rgba(237, 241, 250, 0.85);
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
  transition: background 0.15s;
}

.logout-btn:hover { background: rgba(229, 72, 77, 0.25); border-color: rgba(229, 72, 77, 0.5); color: #FFFFFF; }
.logout-btn svg { width: 15px; height: 15px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border-soft);
  position: sticky;
  top: 0;
  z-index: 10;
}

.page-title { font-size: 19px; font-weight: 700; margin: 0; }
.topbar-spacer { flex: 1; }

.content { padding: 28px; width: 100%; }

/* ------------------------------------------------------------- topbar UI */

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover { background: var(--row-hover); color: var(--text); }
.icon-btn-danger:hover { background: rgba(229, 72, 77, 0.12); color: var(--danger); }

.menu-btn { display: none; }

/* ------------------------------------------------- collapsible sidebar */

.sidebar { transition: width 0.18s ease; }

/* Collapsed "rail": icons only. Driven by a class on <html> so it can be
   applied before first paint (no flash). Desktop only — on mobile the
   sidebar uses the off-canvas drawer instead. */
@media (min-width: 901px) {
  html.sidebar-collapsed .sidebar { width: 72px; }
  html.sidebar-collapsed .brand-text,
  html.sidebar-collapsed .nav-text,
  html.sidebar-collapsed .user-name,
  html.sidebar-collapsed .logout-text { display: none; }
  html.sidebar-collapsed .brand { justify-content: center; padding: 20px 0; }
  html.sidebar-collapsed .nav-link { justify-content: center; gap: 0; padding: 11px 0; border-left-width: 0; }
  html.sidebar-collapsed .user-chip { justify-content: center; margin-bottom: 0; }
  html.sidebar-collapsed .logout-btn { justify-content: center; padding: 9px 0; }
  html.sidebar-collapsed .logout-btn { margin-top: 10px; }
}

[data-theme="light"] .icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }

/* ----------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.page-desc { color: var(--text-muted); margin: 0; }

.section-title { font-size: 16px; font-weight: 700; margin: 26px 0 12px; }

/* ---------------------------------------------------------------- tables */

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }

th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  padding: 13px 18px;
  border-bottom: 1px solid var(--border-soft);
  background: color-mix(in srgb, var(--bg) 55%, var(--surface));
  white-space: nowrap;
}

td {
  padding: 13px 18px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
  white-space: nowrap;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--row-hover); }

.cell-strong { font-weight: 600; }
.cell-mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13.5px; }
.muted { color: var(--text-muted); }

.th-actions { text-align: right; }
.td-actions { text-align: right; }
.td-actions form { display: inline-block; margin: 0; }
.td-actions .icon-btn, .td-actions .btn { vertical-align: middle; }

.row-link { color: var(--text); }
.row-link:hover { color: var(--accent); }

.locked { color: var(--text-muted); opacity: 0.7; display: inline-flex; padding: 8px; }
.locked svg { width: 16px; height: 16px; }

/* --------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: 9px;
  border: 1px solid transparent;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  background: var(--row-hover);
  color: var(--text);
}

.btn svg { width: 15px; height: 15px; }

.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary-hover); color: var(--primary-text); }

.btn-accent { background: var(--accent); color: #0A1733; }
.btn-accent:hover { background: var(--accent-hover); color: #0A1733; }

.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--row-hover); }

.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 7px; }
.btn-block { width: 100%; justify-content: center; }

.btn:disabled, button.btn[disabled] {
  background: var(--border-soft);
  color: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.75;
}

/* ---------------------------------------------------------------- badges */

.badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.4;
}

.badge-pending    { background: rgba(224, 168, 0, 0.14);  color: #B68800; }
.badge-processing { background: rgba(79, 156, 255, 0.14); color: #2F7FE0; }
.badge-completed  { background: rgba(43, 182, 115, 0.14); color: #1E9960; }
.badge-cancelled  { background: rgba(229, 72, 77, 0.14);  color: #D63E43; }
.badge-none       { background: var(--border-soft); color: var(--text-muted); }

[data-theme="dark"] .badge-pending    { color: #E0A800; }
[data-theme="dark"] .badge-processing { color: #4F9CFF; }
[data-theme="dark"] .badge-completed  { color: #2BB673; }
[data-theme="dark"] .badge-cancelled  { color: #E5484D; }

/* ---------------------------------------------------------------- alerts */

.alerts { margin-bottom: 18px; display: flex; flex-direction: column; gap: 10px; }

.alert {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid;
  font-size: 14px;
  font-weight: 500;
}

.alert-success { background: rgba(43, 182, 115, 0.1);  border-color: rgba(43, 182, 115, 0.4);  color: var(--success); }
.alert-error   { background: rgba(229, 72, 77, 0.1);   border-color: rgba(229, 72, 77, 0.4);   color: var(--danger); }
.alert-warning { background: rgba(224, 168, 0, 0.1);   border-color: rgba(224, 168, 0, 0.4);   color: var(--warning); }
.alert-info    { background: rgba(79, 156, 255, 0.1);  border-color: rgba(79, 156, 255, 0.4);  color: var(--accent); }

.alert-close {
  background: none;
  border: none;
  color: inherit;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
  opacity: 0.7;
}
.alert-close:hover { opacity: 1; }

/* ----------------------------------------------------------------- forms */

.form-card { max-width: 560px; padding: 28px; }

.form-intro { color: var(--text-muted); margin: 0 0 22px; font-size: 14px; }

.field { margin-bottom: 18px; }

.field label {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  margin-bottom: 7px;
}

.field input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  font-size: 14.5px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 156, 255, 0.22);
}

.field input[type="date"] { color-scheme: light; }
[data-theme="dark"] .field input[type="date"] { color-scheme: dark; }

.field-error { color: var(--danger); font-size: 13px; margin: 6px 0 0; }
.field-help { color: var(--text-muted); font-size: 12px; margin: 6px 0 0; }

.password-wrap { position: relative; }
.password-wrap input { padding-right: 46px; }

.password-toggle {
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
}

.password-toggle .icon-eye-off { display: none; }
.password-toggle.shown .icon-eye { display: none; }
.password-toggle.shown .icon-eye-off { display: block; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 26px;
  padding-top: 20px;
  border-top: 1px solid var(--border-soft);
}

/* ------------------------------------------------------------ empty state */

.empty-state {
  text-align: center;
  padding: 56px 24px;
}

.empty-state svg { width: 44px; height: 44px; color: var(--navy-300); margin-bottom: 14px; }
.empty-state h2 { font-size: 17px; margin: 0 0 6px; }
.empty-state p { color: var(--text-muted); margin: 0 0 20px; }

/* ------------------------------------------------------------- pagination */

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 18px;
}

.page-info { color: var(--text-muted); font-size: 13.5px; }

/* ----------------------------------------------------------- device detail */

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13.5px;
  font-weight: 600;
  margin-bottom: 16px;
}
.back-link svg { width: 15px; height: 15px; }

.device-summary { padding: 22px 24px; margin-bottom: 8px; }

.device-summary-head { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.device-summary-head h2 { margin: 0; font-size: 18px; }
.device-summary-head p { margin: 2px 0 0; font-size: 13px; }

.device-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--navy-50);
  color: var(--navy-700);
  display: flex;
  align-items: center;
  justify-content: center;
}
[data-theme="dark"] .device-icon { background: var(--navy-800); color: var(--accent); }
.device-icon svg { width: 24px; height: 24px; }

.device-meta {
  display: flex;
  gap: 48px;
  flex-wrap: wrap;
  padding-top: 16px;
  border-top: 1px solid var(--border-soft);
}

.device-meta > div { display: flex; flex-direction: column; gap: 2px; font-size: 14px; }

.meta-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

.otp-code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--primary);
}
[data-theme="dark"] .otp-code { color: var(--accent); }

.copy-btn { width: 28px; height: 28px; margin-left: 4px; }
.copy-btn svg { width: 14px; height: 14px; }
.copy-btn.copied { color: var(--success); }

/* ------------------------------------------------------------------ login */

.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(900px 500px at 85% -10%, rgba(79, 156, 255, 0.14), transparent 60%),
    radial-gradient(700px 450px at 0% 110%, rgba(35, 74, 154, 0.16), transparent 55%),
    var(--bg);
}

.login-theme-toggle { position: fixed; top: 18px; right: 18px; }

.login-wrap { width: 100%; max-width: 400px; padding: 24px; }

.login-card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 34px 30px 30px;
}

.login-brand { text-align: center; margin-bottom: 26px; }
.login-brand h1 { font-size: 21px; margin: 14px 0 2px; }
.login-brand p { color: var(--text-muted); font-size: 13px; margin: 0; }

.login-card .alert { margin-bottom: 16px; }

.login-foot {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 18px;
}

/* ------------------------------------------------------------- responsive */

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
  }

  .sidebar.open { transform: translateX(0); }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(10, 23, 51, 0.5);
    z-index: 30;
  }

  .sidebar-overlay.show { display: block; }

  .menu-btn { display: inline-flex; }
  .collapse-btn { display: none; }

  .topbar { padding: 12px 16px; }
  .content { padding: 18px 16px; }
}
