:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --sidebar-bg: #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #4f46e5;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --success: #059669;
  --success-bg: #d1fae5;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --info: #0284c7;
  --info-bg: #e0f2fe;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --purple: #7e22ce;
  --purple-bg: #f3e8ff;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 25px rgba(15, 23, 42, 0.14);
  --radius: 12px;
}

body.dark {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --border: #273449;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary-soft: #1e1b4b;
  --success-bg: #064e3b;
  --warning-bg: #451a03;
  --info-bg: #0c4a6e;
  --danger-bg: #450a0a;
  --purple-bg: #3b0764;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  font-size: 13.5px;
}

/* Login Screen */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #0f172a 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.login-card {
  background: var(--surface);
  color: var(--text);
  width: 100%;
  max-width: 410px;
  border-radius: 18px;
  padding: 28px 26px;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.45);
  border: 1px solid var(--border);
}

.login-head { text-align: center; margin-bottom: 22px; }

.login-logo {
  width: 54px;
  height: 54px;
  margin: 0 auto 12px;
  border-radius: 14px;
  background: linear-gradient(135deg, #4f46e5, #06b6d4);
  color: #fff;
  font-weight: 800;
  font-size: 22px;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 20px rgba(79, 70, 229, 0.35);
}

.login-head h2 { font-size: 20px; font-weight: 800; }
.login-head p { font-size: 12.5px; color: var(--text-muted); margin-top: 4px; }

.pwd-wrap { position: relative; display: flex; align-items: center; }
.pwd-wrap input { width: 100%; padding-right: 40px; }
.pwd-eye {
  position: absolute;
  right: 10px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 15px;
  color: var(--text-muted);
}

.login-error {
  background: var(--danger-bg);
  color: var(--danger);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 12px;
  display: none;
}

.app-shell { display: none; width: 100%; min-height: 100vh; }
.app-shell.unlocked { display: flex; }

/* Sidebar */
.sidebar {
  width: 250px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 50;
  transition: transform 0.2s ease;
}

.sidebar-brand {
  padding: 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-box {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #06b6d4);
  color: #fff;
  font-weight: 800;
  display: grid;
  place-items: center;
  font-size: 16px;
  flex-shrink: 0;
}

.sidebar-brand h2 { font-size: 15px; color: #fff; font-weight: 700; line-height: 1.2; }
.sidebar-brand span { font-size: 11px; color: #94a3b8; }

.user-box {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.user-info strong { display: block; color: #fff; font-size: 13px; }
.user-info span { font-size: 11px; color: #94a3b8; }

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

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--sidebar-text);
  font-weight: 500;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  font-size: 13.5px;
  transition: all 0.15s ease;
}

.nav-item:hover { background: rgba(255,255,255,0.07); color: #fff; }
.nav-item.active {
  background: var(--sidebar-active);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
}

.nav-count {
  background: rgba(255,255,255,0.14);
  color: #fff;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 99px;
  font-weight: 600;
}

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  flex-direction: column;
  gap: 7px;
}

/* Main */
.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 11px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 35;
}

.topbar-left { display: flex; align-items: center; gap: 10px; }

.mobile-menu-btn {
  display: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.page-title { font-size: 17px; font-weight: 700; }

.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}

.sync-pill.live { background: var(--success-bg); color: var(--success); border-color: #6ee7b7; }
.sync-pill.error { background: var(--danger-bg); color: var(--danger); border-color: #fca5a5; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; }
.sync-pill.live .dot { background: var(--success); box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.25); animation: pulse 1.8s infinite; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

.topbar-actions { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }
.content { padding: 20px 22px 40px; max-width: 1600px; width: 100%; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-danger-soft { color: var(--danger); border-color: #fecaca; background: var(--surface); }
.btn-danger-soft:hover { background: var(--danger-bg); }
.btn-sm { padding: 4px 9px; font-size: 11.5px; border-radius: 6px; }

/* KPIs & Panels */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(195px, 1fr)); gap: 14px; margin-bottom: 18px; }

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 16px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.kpi-card::after { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--primary); }
.kpi-card.success::after { background: var(--success); }
.kpi-card.warning::after { background: var(--warning); }
.kpi-card.info::after { background: var(--info); }
.kpi-card.danger::after { background: var(--danger); }

.kpi-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); font-weight: 700; }
.kpi-num { font-size: 27px; font-weight: 800; margin: 5px 0 2px; }
.kpi-desc { font-size: 12px; color: var(--text-muted); }

.dash-grid { display: grid; grid-template-columns: 1.35fr 1fr; gap: 16px; margin-bottom: 16px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.panel-head h3 { font-size: 15px; font-weight: 700; }

.funnel-list { display: flex; flex-direction: column; gap: 11px; }
.funnel-item { display: flex; flex-direction: column; gap: 5px; cursor: pointer; }
.funnel-top { display: flex; justify-content: space-between; font-size: 12.5px; font-weight: 600; }
.funnel-track { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--border); }
.funnel-fill { height: 100%; border-radius: 99px; transition: width 0.3s ease; }

.alert-list { display: flex; flex-direction: column; gap: 9px; max-height: 290px; overflow-y: auto; }
.alert-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
}

/* Toolbar */
.toolbar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
}

.filter-group { display: flex; flex-wrap: wrap; gap: 8px; flex: 1; align-items: center; }

.input, .select, textarea.input {
  padding: 8px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  outline: none;
  font-family: inherit;
}

.input:focus, .select:focus { border-color: var(--primary); background: var(--surface); }
.search-input { min-width: 220px; flex: 1; max-width: 340px; }

.bulk-bar {
  background: var(--primary);
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  margin-bottom: 12px;
  display: none;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  box-shadow: var(--shadow-lg);
}

.bulk-bar.show { display: flex; }

/* Table */
.table-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.table-scroll { overflow-x: auto; max-height: calc(100vh - 260px); }

table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12.5px; }
th {
  background: var(--surface-2);
  color: var(--text-muted);
  font-weight: 700;
  padding: 10px 9px;
  text-align: left;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 15;
}

td {
  padding: 8px 9px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--surface);
  vertical-align: middle;
}

tr:hover td { background: var(--surface-2); }

th.col-chk, td.col-chk { position: sticky; left: 0; z-index: 16; width: 34px; text-align: center; }
th.col-sl, td.col-sl { position: sticky; left: 34px; z-index: 16; width: 42px; text-align: center; }
th.col-name, td.col-name {
  position: sticky; left: 76px; z-index: 16;
  min-width: 230px; max-width: 265px; white-space: normal;
  border-right: 2px solid var(--border);
}

thead th.col-chk, thead th.col-sl, thead th.col-name { z-index: 25; }

.prog-row { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.prog-bar { flex: 1; height: 5px; background: var(--border); border-radius: 99px; overflow: hidden; }
.prog-fill { height: 100%; background: var(--primary); border-radius: 99px; }
.prog-fill.full { background: var(--success); }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  border: 1px solid transparent;
}

.badge:hover { filter: brightness(0.94); }
.b-done { background: var(--success-bg); color: var(--success); }
.b-proc { background: var(--info-bg); color: var(--info); }
.b-pend { background: var(--warning-bg); color: var(--warning); }
.b-canc { background: var(--danger-bg); color: var(--danger); }
.b-noweb { background: var(--purple-bg); color: var(--purple); }
.b-empty { background: var(--surface-2); color: var(--text-muted); border-color: var(--border); }
.b-faisal { background: var(--primary-soft); color: var(--primary); }
.b-arif { background: var(--info-bg); color: var(--info); }
.b-fin-1 { background: var(--success); color: #fff; }
.b-fin-0 { background: var(--surface-2); color: var(--text-muted); border-color: var(--border); }

.qty-tag {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 11.5px;
  max-width: 155px;
  display: inline-block;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Kanban */
.kanban-board { display: grid; grid-template-columns: repeat(5, minmax(250px, 1fr)); gap: 14px; overflow-x: auto; padding-bottom: 10px; }
.kanban-col { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 200px); }
.kanban-col-head { padding: 12px 14px; border-bottom: 1px solid var(--border); background: var(--surface); border-radius: var(--radius) var(--radius) 0 0; display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 13px; }
.kanban-cards { padding: 10px; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }
.k-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px; }
.k-card-title { font-weight: 700; font-size: 13px; line-height: 1.35; }
.k-card-foot { display: flex; justify-content: space-between; align-items: center; gap: 6px; flex-wrap: wrap; }

/* Popover & Modals */
.popover {
  position: fixed;
  z-index: 120;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 6px;
  display: none;
  flex-direction: column;
  gap: 3px;
  min-width: 165px;
}

.popover button { border: none; background: transparent; color: var(--text); text-align: left; padding: 7px 10px; border-radius: 6px; font-size: 12.5px; font-weight: 600; cursor: pointer; }
.popover button:hover { background: var(--surface-2); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.58);
  backdrop-filter: blur(2px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 820px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-head { padding: 15px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; background: var(--surface-2); }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12px; font-weight: 600; color: var(--text-muted); }

.info-banner {
  background: var(--primary-soft);
  border: 1px solid rgba(79, 70, 229, 0.25);
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 12.5px;
  margin-bottom: 14px;
  line-height: 1.5;
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #0f172a;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 13px;
  z-index: 250;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.2s ease;
  pointer-events: none;
}

.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1024px) { .dash-grid { grid-template-columns: 1fr; } }

@media (max-width: 820px) {
  .sidebar { position: fixed; left: 0; transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .mobile-menu-btn { display: inline-flex; }
  th.col-chk, td.col-chk, th.col-sl, td.col-sl, th.col-name, td.col-name { position: static; border-right: none; }
}

@media print {
  .sidebar, .topbar, .toolbar, .bulk-bar, .no-print, .login-screen { display: none !important; }
  body { background: #fff; color: #000; }
  .table-scroll { max-height: none; overflow: visible; }
  th, td { position: static !important; border: 1px solid #ccc; }
}
/* Email Auth Tabs & Verification */
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface-2);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
  margin-bottom: 16px;
}

.auth-tab {
  padding: 8px;
  border: none;
  background: transparent;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
}

.auth-tab.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow);
}

.auth-box-msg {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-link {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}
