/* ── Reset & Base ─────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --navy:    #0f2744;
  --blue:    #1a3f6f;
  --sky:     #2563eb;
  --accent:  #e8820c;
  --accent2: #f59e0b;
  --green:   #16a34a;
  --red:     #dc2626;
  --purple:  #7c3aed;
  --light:   #f1f5f9;
  --border:  #e2e8f0;
  --text:    #1e293b;
  --muted:   #64748b;
  --white:   #ffffff;
  --sidebar-w: 250px;
  --header-h:  60px;
  --radius:    10px;
  --shadow:    0 2px 12px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.14);

  /* Login / boot backdrop: a dark scrim over the plant photograph. The scrim is
     deliberately heavy — the photo is atmosphere, not subject, and white type
     plus the login card have to stay legible over it. Swap the url() for
     login-bg-alt.jpg to use the darker, hazier variant. */
  --hero-scrim: linear-gradient(180deg, rgba(15,39,68,.42) 0%, rgba(15,39,68,.52) 45%, rgba(15,39,68,.78) 100%);
  --hero-bg: var(--hero-scrim), url('../img/login-bg.jpg');
}
html, body { height: 100%; font-family: 'Inter', system-ui, sans-serif; font-size: 14px; color: var(--text); background: var(--light); }
a { text-decoration: none; color: inherit; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 14px; }
ul { list-style: none; }

/* ── Boot / screen switching ───────────────────── */
/* Both screens default to hidden and are shown by App.init() once it knows
   which one applies. A screen must never be made visible with an inline
   style — that outranks these rules and reintroduces the first-paint flash. */
#boot {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  /* background-color is the fallback if the photo fails to load */
  background-color: var(--navy);
  background-image: var(--hero-bg);
  background-size: cover;
  background-position: center;
  z-index: 10;
}
#boot.hidden { display: none; }
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--sky);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.spinner-light { border-color: rgba(255,255,255,.25); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Login Page ───────────────────────────────── */
/* Split layout: imagery on the left, form on the right. Collapses to the form
   alone (plus a compact brand header) below 900px. */
#login-screen {
  min-height: 100vh;
  display: none;
  background: var(--white);
}
#login-screen.visible { display: flex; }

.login-aside {
  flex: 1 1 52%;
  min-width: 0;
  position: relative;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 56px 52px;
  background-color: var(--navy);
  background-image: var(--hero-scrim), url('../img/login-side.jpg');
  background-size: cover;
  background-position: center;
  color: #fff;
}
.login-aside-top { max-width: 440px; }
.login-aside .brand-logo { margin-bottom: 30px; }
.brand-logo {
  width: 74px; height: 74px;
  background: #fff;
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  padding: 11px;
  box-shadow: 0 10px 30px rgba(0,0,0,.22);
}
.brand-logo img { width: 100%; height: 100%; object-fit: contain; }
.brand-tagline {
  font-size: 34px; font-weight: 700; line-height: 1.18;
  letter-spacing: -.6px; margin-bottom: 18px;
}
.brand-sub {
  font-size: 14.5px; line-height: 1.6;
  color: rgba(255,255,255,.72); max-width: 380px;
}
.login-aside-foot {
  font-size: 11.5px; font-weight: 600; letter-spacing: 1.2px;
  text-transform: uppercase; color: rgba(255,255,255,.42);
}

.login-main {
  flex: 1 1 48%;
  min-width: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 40px;
  background: var(--white);
}
.login-card { width: 100%; max-width: 384px; }

/* Compact brand header — only shown once the imagery panel is hidden */
.login-brand-compact { display: none; align-items: center; gap: 13px; margin-bottom: 30px; }
.login-brand-compact .brand-logo {
  width: 46px; height: 46px; border-radius: 11px; padding: 6px;
  border: 1px solid var(--border); box-shadow: none;
}
.login-brand-compact-text { font-size: 14px; font-weight: 700; line-height: 1.3; }

.login-card h2 { font-size: 25px; font-weight: 700; margin-bottom: 7px; letter-spacing: -.3px; }
.login-card .subtitle { color: var(--muted); font-size: 13.5px; margin-bottom: 28px; }

.form-group { margin-bottom: 18px; }
.form-group label {
  display: block; font-weight: 600; font-size: 12px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .5px; margin-bottom: 7px;
}

/* Inputs with a leading icon and an optional trailing action button */
.input-wrap { position: relative; display: flex; align-items: center; }
.input-icon {
  position: absolute; left: 14px;
  font-size: 13px; color: #94a3b8; pointer-events: none; transition: color .2s;
}
.input-wrap input {
  width: 100%; padding: 12px 14px 12px 40px;
  border: 1.5px solid var(--border); border-radius: 9px;
  font-size: 14px; outline: none; background: #fafbfc;
  transition: border-color .2s, background .2s, box-shadow .2s;
}
.input-wrap input:focus {
  border-color: var(--sky); background: #fff;
  box-shadow: 0 0 0 3px rgba(37,99,235,.10);
}
.input-wrap input:focus ~ .input-icon,
.input-wrap input:focus + .input-action + .input-icon { color: var(--sky); }
.input-wrap:focus-within .input-icon { color: var(--sky); }
.input-wrap input[aria-invalid="true"] { border-color: #fca5a5; }
.input-action {
  position: absolute; right: 6px;
  background: none; border: none; padding: 8px 10px;
  color: #94a3b8; font-size: 13.5px; border-radius: 7px; line-height: 1;
}
.input-action:hover { color: var(--text); background: var(--light); }
.input-wrap input[type="password"], .input-wrap input[type="text"] { padding-right: 44px; }
#inp-email { padding-right: 14px; }

.field-hint {
  display: none; align-items: center; gap: 6px;
  margin-top: 7px; font-size: 12px; color: #92400e; font-weight: 500;
}
.field-hint.show { display: flex; }

.btn-login {
  width: 100%; padding: 13px; background: var(--navy); color: white;
  border: none; border-radius: 9px; font-size: 14.5px; font-weight: 700;
  letter-spacing: .3px; transition: all .2s; margin-top: 6px;
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
}
.btn-login:hover:not(:disabled) { background: var(--blue); box-shadow: 0 6px 18px rgba(15,39,68,.24); }
.btn-login:disabled { opacity: .65; cursor: not-allowed; }

.login-error {
  display: none; align-items: flex-start; gap: 9px;
  background: #fef2f2; border: 1px solid #fecaca; color: #991b1b;
  padding: 11px 14px; border-radius: 9px; font-size: 13px;
  margin-bottom: 18px; line-height: 1.45;
}
.login-error.show { display: flex; }
.login-error i { margin-top: 2px; flex-shrink: 0; }

.login-foot { margin-top: 26px; padding-top: 18px; border-top: 1px solid var(--border); }
.login-foot p { font-size: 11.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }

/* ── App Shell ────────────────────────────────── */
#app-screen { display: none; height: 100vh; overflow: hidden; }
#app-screen.visible { display: block; }

/* Sidebar */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--navy);
  display: flex; flex-direction: column;
  z-index: 100; transition: transform .25s ease;
}
.sidebar-logo {
  padding: 16px 20px;
  display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  min-height: var(--header-h);
}
.sidebar-logo .logo-icon {
  width: 34px; height: 34px; background: #fff; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; padding: 4px; flex-shrink: 0;
}
.sidebar-logo .logo-icon img { width: 100%; height: 100%; object-fit: contain; }
.sidebar-logo .logo-text {
  font-size: 12.5px; font-weight: 700; color: white; line-height: 1.3;
}
.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 0; }
.nav-section-label {
  padding: 14px 20px 6px;
  font-size: 10px; font-weight: 700; letter-spacing: 1px;
  color: rgba(255,255,255,.3); text-transform: uppercase;
}
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 20px; color: rgba(255,255,255,.65); font-size: 13.5px; font-weight: 500;
  cursor: pointer; transition: all .15s; border-left: 3px solid transparent;
  border: none; background: none; width: 100%; text-align: left;
}
.nav-item i { width: 18px; text-align: center; font-size: 14px; }
.nav-item:hover { color: white; background: rgba(255,255,255,.06); }
.nav-item.active { color: white; background: rgba(255,255,255,.1); border-left: 3px solid var(--accent); padding-left: 17px; }
.sidebar-user {
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center; gap: 10px;
}
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent); color: white; display: flex;
  align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.user-info {
  flex: 1; min-width: 0;
  background: none; border: none; padding: 4px 6px; margin: -4px -6px;
  text-align: left; border-radius: 7px; cursor: pointer;
  transition: background .15s;
}
.user-info:hover { background: rgba(255,255,255,.08); }
.user-name { font-size: 13px; font-weight: 600; color: white; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: rgba(255,255,255,.45); }
.btn-logout { background: none; border: none; color: rgba(255,255,255,.4); font-size: 16px; cursor: pointer; padding: 4px; transition: color .2s; }
.btn-logout:hover { color: white; }
.btn-logout:disabled { opacity: .4; cursor: not-allowed; }

/* Main */
.main-wrap { margin-left: var(--sidebar-w); height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.main-header {
  height: var(--header-h); background: white; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; flex-shrink: 0;
}
.page-title { font-size: 17px; font-weight: 700; }
.header-actions { display: flex; gap: 10px; align-items: center; }
.main-content { flex: 1; overflow-y: auto; padding: 24px; }

/* ── Buttons ──────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 9px 18px; border-radius: 8px; font-size: 13.5px; font-weight: 600; border: none; transition: all .15s; cursor: pointer; }
.btn-primary { background: var(--navy); color: white; }
.btn-primary:hover { background: var(--blue); }
.btn-accent { background: var(--accent); color: white; }
.btn-accent:hover { background: #d4730a; }
.btn-outline { background: white; color: var(--text); border: 1.5px solid var(--border); }
.btn-outline:hover { background: var(--light); }
.btn-danger { background: var(--red); color: white; }
.btn-sm { padding: 5px 12px; font-size: 12px; }

/* ── Cards & Stats ────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: white; border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); display: flex; align-items: flex-start; gap: 16px;
  border: 1px solid var(--border);
}
.stat-icon {
  width: 46px; height: 46px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0;
}
.stat-icon.blue   { background: #eff6ff; color: var(--sky); }
.stat-icon.orange { background: #fff7ed; color: var(--accent); }
.stat-icon.green  { background: #f0fdf4; color: var(--green); }
.stat-icon.purple { background: #f5f3ff; color: var(--purple); }
.stat-value { font-size: 28px; font-weight: 800; line-height: 1; }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 4px; font-weight: 500; }

/* ── Card / Table ─────────────────────────────── */
.card { background: white; border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.card-header h3 { font-size: 15px; font-weight: 700; }
.card-body { padding: 20px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th { padding: 11px 16px; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); background: #f8fafc; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
tbody td { padding: 13px 16px; border-bottom: 1px solid var(--border); font-size: 13.5px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }

/* ── Badges ───────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; }
.badge-neutral { background: #f1f5f9; color: #475569; } .badge-neutral::before { background: #94a3b8; }
.badge-warn    { background: #fffbeb; color: #92400e; } .badge-warn::before    { background: var(--accent2); }
.badge-ok      { background: #f0fdf4; color: #166534; } .badge-ok::before      { background: var(--green); }
.badge-info    { background: #eff6ff; color: #1d4ed8; } .badge-info::before    { background: var(--sky); }
.badge-bad     { background: #fef2f2; color: #991b1b; } .badge-bad::before     { background: var(--red); }

/* ── Placeholder (pages not built yet) ────────── */
.placeholder {
  background: white; border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 48px 32px; text-align: center;
  max-width: 620px; margin: 0 auto;
}
.placeholder-icon {
  width: 60px; height: 60px; margin: 0 auto 18px;
  border-radius: 14px; background: var(--light);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; color: var(--muted);
}
.placeholder h2 { font-size: 19px; font-weight: 700; margin-bottom: 8px; }
.placeholder p { color: var(--muted); font-size: 13.5px; line-height: 1.6; max-width: 460px; margin: 0 auto; }
.placeholder-note {
  margin-top: 22px; padding: 14px 16px; text-align: left;
  background: #fffbeb; border: 1px solid #fde68a; border-radius: 9px;
  font-size: 12.5px; color: #92400e; line-height: 1.55;
}
.placeholder-note strong { font-weight: 700; }

/* ── Modal ────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(15,23,42,.55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 20px; overflow-y: auto;
}
.modal {
  background: #fff; border-radius: 14px;
  width: 100%; max-width: 480px;
  box-shadow: var(--shadow-lg);
  animation: modalIn .18s ease;
}
.modal-wide { max-width: 720px; }
@keyframes modalIn { from { transform: translateY(-8px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-header {
  padding: 18px 22px 15px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-close {
  background: none; border: none; color: var(--muted);
  font-size: 15px; padding: 6px 8px; border-radius: 7px; line-height: 1;
}
.modal-close:hover { background: var(--light); color: var(--text); }
.modal-body { padding: 20px 22px; }
.modal-footer {
  padding: 15px 22px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}
.modal-error {
  display: none;
  background: #fef2f2; border: 1px solid #fecaca; color: #991b1b;
  padding: 10px 13px; border-radius: 8px; font-size: 13px;
  margin-bottom: 16px; line-height: 1.45;
}
.modal-error.show { display: block; }

/* Form controls inside modals */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.modal .form-group input,
.modal .form-group select {
  width: 100%; padding: 10px 13px;
  border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 14px; outline: none; background: #fafbfc;
  transition: border-color .2s, background .2s;
}
.modal .form-group select { cursor: pointer; }
.modal .form-group input:focus,
.modal .form-group select:focus { border-color: var(--sky); background: #fff; }
.modal .form-group input:disabled,
.modal .form-group select:disabled { background: var(--light); color: var(--muted); cursor: not-allowed; }
.field-note { margin-top: 6px; font-size: 11.5px; color: var(--muted); line-height: 1.45; }

@media (max-width: 520px) {
  .modal-overlay { padding: 16px 12px; }
  .form-row { grid-template-columns: 1fr; }
}

/* ── Empty state ──────────────────────────────── */
.empty-state { padding: 60px 20px; text-align: center; }
.empty-state i { font-size: 48px; color: var(--border); margin-bottom: 12px; }
.empty-state p { color: var(--muted); font-size: 14px; }

/* ── Loader ───────────────────────────────────── */
.loader { display: flex; align-items: center; justify-content: center; padding: 60px; }

/* ── Toast ────────────────────────────────────── */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--navy); color: white; padding: 12px 18px;
  border-radius: 10px; font-size: 13.5px; font-weight: 500;
  box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 10px;
  animation: slideIn .3s ease; max-width: 340px;
}
.toast.success { background: var(--green); }
.toast.error   { background: var(--red); }
.toast.warning { background: var(--accent); }
@keyframes slideIn { from { transform: translateX(120%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Mobile-only elements (hidden on desktop) ───── */
.mobile-menu-btn, .mobile-brand, .mobile-page-title { display: none; }
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(15,23,42,.5); z-index: 98;
}
.sidebar-overlay.show { display: block; }

/* ── Utilities ────────────────────────────────── */
.text-muted { color: var(--muted); }
.hidden { display: none !important; }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin-bottom: 14px; }

/* ── Responsive ───────────────────────────────── */
@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); z-index: 99; }
  .sidebar.open { transform: translateX(0); }
  .main-wrap { margin-left: 0; }

  .header-left-desktop { display: none; }
  .main-header { padding: 10px 14px; gap: 12px; }
  .mobile-menu-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; border-radius: 9px;
    border: 1px solid var(--border); background: #fff;
    color: var(--text); cursor: pointer; flex-shrink: 0; font-size: 15px;
  }
  .mobile-brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
  .mobile-brand-logo {
    width: 36px; height: 36px; border-radius: 9px;
    background: var(--navy); padding: 5px;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  }
  .mobile-brand-logo img { width: 100%; height: 100%; object-fit: contain; }
  .mobile-brand-name {
    font-size: 12px; font-weight: 700; color: var(--text); line-height: 1.2;
  }
  .mobile-page-title {
    display: block; padding: 10px 16px; background: #fff;
    border-bottom: 1px solid var(--border);
    font-size: 14px; font-weight: 600; color: var(--text);
  }
  .main-content { padding: 16px; }
  .placeholder { padding: 34px 22px; }
}
@media (max-width: 640px) {
  .stats-grid { grid-template-columns: 1fr; }
}
/* ── Login responsive ─────────────────────────── */
@media (max-width: 1100px) {
  .login-aside { padding: 44px 40px; flex-basis: 46%; }
  .brand-tagline { font-size: 28px; }
  .brand-sub { font-size: 13.5px; }
}
@media (max-width: 900px) {
  /* Drop the imagery panel and let the form own the screen. The compact brand
     header inside the card carries the identity from here down. */
  .login-aside { display: none; }
  .login-main { flex: 1 1 100%; padding: 32px 24px; }
  .login-brand-compact { display: flex; }
  .login-card { max-width: 400px; }
}
@media (max-width: 420px) {
  .login-main { padding: 24px 18px; }
  .login-card h2 { font-size: 22px; }
  .login-brand-compact { margin-bottom: 24px; }
}
