/* ── 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);
}
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; }

/* ── Login Page ───────────────────────────────── */
#login-screen {
  min-height: 100vh;
  display: flex;
  background: linear-gradient(135deg, var(--navy) 0%, #1e4a8a 50%, #0f2744 100%);
  position: relative;
  overflow: hidden;
}
#login-screen::before {
  content: '';
  position: absolute;
  width: 600px; height: 600px;
  border-radius: 50%;
  background: rgba(255,255,255,.03);
  top: -200px; right: -150px;
}
#login-screen::after {
  content: '';
  position: absolute;
  width: 400px; height: 400px;
  border-radius: 50%;
  background: rgba(232,130,12,.06);
  bottom: -100px; left: -100px;
}
.login-left {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 60px;
  color: white;
  position: relative; z-index: 1;
}
.login-left .brand { display: flex; align-items: center; gap: 14px; margin-bottom: 40px; }
.login-left .brand-icon {
  width: 52px; height: 52px; background: #fff;
  border-radius: 12px; display: flex; align-items: center; justify-content: center;
  padding: 6px;
}
.login-left .brand-icon img { width: 100%; height: 100%; object-fit: contain; }
.login-left .brand-name { font-size: 22px; font-weight: 700; letter-spacing: -.3px; }
.login-left .brand-name span { color: var(--accent2); }
.login-left h1 { font-size: 36px; font-weight: 800; line-height: 1.2; margin-bottom: 16px; }
.login-left p { font-size: 15px; opacity: .75; max-width: 380px; line-height: 1.7; }
.login-features { margin-top: 40px; display: flex; flex-direction: column; gap: 14px; }
.login-features li { display: flex; align-items: center; gap: 12px; opacity: .85; font-size: 14px; }
.login-features li i { color: var(--accent2); width: 20px; text-align: center; }
.login-right {
  width: 460px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  position: relative; z-index: 1;
}
.login-card {
  background: white;
  border-radius: 20px;
  padding: 40px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}
.portal-tabs { display: flex; gap: 0; margin-bottom: 32px; border-radius: 10px; overflow: hidden; border: 1.5px solid var(--border); }
.portal-tab {
  flex: 1; padding: 11px 0; text-align: center; font-weight: 600; font-size: 13.5px;
  cursor: pointer; color: var(--muted); background: var(--light); transition: all .2s;
  border: none;
}
.portal-tab.active { background: var(--navy); color: white; }
.portal-tab i { margin-right: 6px; }
.login-card h2 { font-size: 22px; font-weight: 700; margin-bottom: 6px; }
.login-card .subtitle { color: var(--muted); font-size: 13px; margin-bottom: 28px; }
.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-weight: 600; font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 7px; }
.form-group input {
  width: 100%; padding: 11px 14px; border: 1.5px solid var(--border);
  border-radius: 8px; font-size: 14px; outline: none; transition: border .2s;
  background: #fafbfc;
}
.form-group input:focus { border-color: var(--sky); background: white; }
.btn-login {
  width: 100%; padding: 13px; background: var(--navy); color: white;
  border: none; border-radius: 8px; font-size: 15px; font-weight: 700;
  letter-spacing: .3px; transition: all .2s; margin-top: 4px;
}
.btn-login:hover { background: var(--blue); transform: translateY(-1px); box-shadow: 0 4px 16px rgba(15,39,68,.3); }
.btn-login:disabled { opacity: .6; cursor: not-allowed; transform: none; }
.login-error { background: #fef2f2; border: 1px solid #fecaca; color: var(--red); padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; display: none; }

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

/* 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 .3s;
}
.sidebar-logo {
  padding: 18px 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: 14px; font-weight: 700; color: white; line-height: 1.2; }
.sidebar-logo .logo-sub { font-size: 11px; color: rgba(255,255,255,.45); }
.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; }
.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; }

/* 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; }
.btn-icon { padding: 7px; border-radius: 7px; }

/* ── 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; }

/* ── 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; }
.card-header h3 { font-size: 15px; font-weight: 700; }
.card-body { padding: 0; }
.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; }
tbody tr:hover { background: #fafbfc; }
tbody tr { cursor: pointer; }

/* ── 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-draft        { background: #f1f5f9; color: #475569; } .badge-draft::before { background: #94a3b8; }
.badge-under_review { background: #fffbeb; color: #92400e; } .badge-under_review::before { background: var(--accent2); }
.badge-approved     { background: #f0fdf4; color: #166534; } .badge-approved::before { background: var(--green); }
.badge-issued       { background: #eff6ff; color: #1d4ed8; } .badge-issued::before { background: var(--sky); }
.badge-cancelled    { background: #fef2f2; color: #991b1b; } .badge-cancelled::before { background: var(--red); }
.badge-active       { background: #f0fdf4; color: #166534; } .badge-active::before { background: var(--green); }
.badge-on_hold      { background: #fffbeb; color: #92400e; } .badge-on_hold::before { background: var(--accent2); }
.badge-completed    { background: #eff6ff; color: #1d4ed8; } .badge-completed::before { background: var(--sky); }

/* ── Filters ──────────────────────────────────── */
.filters { display: flex; gap: 10px; padding: 14px 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap; align-items: center; }
.filter-input {
  padding: 8px 12px; border: 1.5px solid var(--border); border-radius: 7px;
  font-size: 13px; outline: none; background: var(--light);
}
.filter-input:focus { border-color: var(--sky); background: white; }
.filter-search { flex: 1; min-width: 180px; }

/* ── Modal ────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,39,68,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px; backdrop-filter: blur(2px);
}
.modal-overlay.hidden { display: none; }
.modal {
  background: white; border-radius: 16px; width: 100%; max-width: 560px;
  max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg);
}
.modal-lg { max-width: 780px; }
.modal-header { padding: 20px 24px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: 17px; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 20px; color: var(--muted); cursor: pointer; padding: 4px; border-radius: 6px; }
.modal-close:hover { background: var(--light); color: var(--text); }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* Form inside modal */
.modal .form-group label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; display: block; margin-bottom: 6px; }
.modal .form-group { margin-bottom: 16px; }
.modal .form-group input,
.modal .form-group select,
.modal .form-group textarea {
  width: 100%; padding: 10px 13px; border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 14px; outline: none; transition: border .15s; background: #fafbfc;
}
.modal .form-group input:focus,
.modal .form-group select:focus,
.modal .form-group textarea:focus { border-color: var(--sky); background: white; }
.modal .form-group textarea { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ── Document Detail ──────────────────────────── */
.doc-meta-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 20px; }
.doc-meta-item { background: var(--light); border-radius: 8px; padding: 12px 14px; }
.doc-meta-item .label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin-bottom: 4px; }
.doc-meta-item .value { font-size: 14px; font-weight: 600; }
.workflow-steps { display: flex; align-items: center; gap: 0; margin-bottom: 20px; }
.workflow-step { flex: 1; text-align: center; position: relative; }
.workflow-step::after { content: ''; position: absolute; top: 15px; left: 50%; width: 100%; height: 2px; background: var(--border); z-index: 0; }
.workflow-step:last-child::after { display: none; }
.step-circle {
  width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 6px; background: white; position: relative; z-index: 1;
  font-size: 13px; color: var(--muted);
}
.step-circle.done { background: var(--green); border-color: var(--green); color: white; }
.step-circle.active { background: var(--sky); border-color: var(--sky); color: white; }
.workflow-step .step-label { font-size: 11px; color: var(--muted); font-weight: 500; }
.status-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.audit-log { max-height: 220px; overflow-y: auto; }
.audit-item { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.audit-item:last-child { border-bottom: none; }
.audit-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--sky); margin-top: 5px; flex-shrink: 0; }
.audit-action { font-size: 13px; font-weight: 600; }
.audit-meta { font-size: 12px; color: var(--muted); }

/* ── 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; }

/* ── 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; } }

/* ── Loader ───────────────────────────────────── */
.loader { display: flex; align-items: center; justify-content: center; padding: 60px; }
.spinner { width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--sky); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Pagination ───────────────────────────────── */
.pagination { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-top: 1px solid var(--border); }
.pagination-info { font-size: 13px; color: var(--muted); }
.pagination-btns { display: flex; gap: 6px; }
.page-btn { padding: 5px 12px; border: 1.5px solid var(--border); background: white; border-radius: 6px; font-size: 13px; cursor: pointer; font-weight: 500; }
.page-btn:hover { background: var(--light); }
.page-btn.active { background: var(--navy); color: white; border-color: var(--navy); }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ── 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: 998;
}
.sidebar-overlay.show { display: block; }

/* ── Responsive ───────────────────────────────── */
@media (max-width: 900px) {
  .login-left { display: none; }
  .login-right { width: 100%; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
    z-index: 999;
    transition: transform .25s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .main-wrap { margin-left: 0; }

  /* Hide desktop title, show mobile branded header */
  .header-left-desktop { display: none; }
  .main-header {
    padding: 10px 14px !important;
    gap: 12px;
    align-items: center;
  }
  .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: 13px; font-weight: 700; color: var(--text); line-height: 1.15;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .mobile-brand-sub {
    font-size: 10px; color: var(--muted); line-height: 1.15;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .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);
  }
  .header-actions .btn span,
  .header-actions .btn { font-size: 12px; padding: 7px 10px; }
}
@media (max-width: 640px) {
  .stats-grid { grid-template-columns: 1fr; }
  .doc-meta-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
}

/* ── Misc ─────────────────────────────────────── */
.serial-badge { font-family: 'Courier New', monospace; font-size: 12.5px; font-weight: 700; background: var(--navy); color: var(--accent2); padding: 3px 9px; border-radius: 5px; letter-spacing: .5px; }
.text-muted { color: var(--muted); }
.text-sm { font-size: 12px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.hidden { display: none !important; }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin-bottom: 14px; margin-top: 20px; }
hr.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* client portal accent */
.client-mode .sidebar { background: #1a1a2e; }
.client-mode .sidebar-logo .logo-icon { background: #fff; }
.client-mode .btn-login { background: #7c3aed; }
.client-mode .btn-login:hover { background: #6d28d9; }
.client-mode .portal-tab.active { background: #1a1a2e; }
