/* ============================================================
   EEC Presale Suite v1.2 — Modern UI/UX Design System
   Drop-in replacement for style.css (100% backward compatible)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@500;600&display=swap');

:root {
  /* Surface & Canvas */
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;

  /* Borders */
  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  /* Typography */
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;

  /* Brand & Semantic Accents */
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-soft: #eff6ff;
  --primary-ring: rgba(29, 78, 216, 0.16);

  --success: #059669;
  --success-soft: #ecfdf5;
  --success-border: #a7f3d0;

  --warning: #d97706;
  --warning-soft: #fffbeb;
  --warning-border: #fde68a;

  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --danger-border: #fecaca;

  --info: #0284c7;
  --info-soft: #f0f9ff;
  --info-border: #bae6fd;

  /* Sidebar */
  --sb-bg: #0b1120;
  --sb-surface: #131c31;
  --sb-border: rgba(255, 255, 255, 0.08);
  --sb-text: #94a3b8;
  --sb-text-hover: #f8fafc;

  /* Radii & Elevation */
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px -1px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 10px 25px -5px rgba(15, 23, 42, 0.08), 0 4px 10px -4px rgba(15, 23, 42, 0.04);

  /* Layout */
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sidebar-w: 256px;
  --header-h: 62px;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  font-size: 14.5px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; transition: color .15s ease; }
a:hover { color: var(--primary-hover); text-decoration: underline; }

/* ---- Scrollbars ---- */
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ---- App Shell & Sidebar ---- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--sb-bg);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 120;
  border-right: 1px solid var(--sb-border);
  transition: transform .25s cubic-bezier(.4, 0, .2, 1);
}

body.presale .sidebar { background: #0f172a; }

.sidebar-brand {
  height: var(--header-h);
  padding: 0 18px;
  font-weight: 700;
  font-size: 1.02rem;
  letter-spacing: -.02em;
  color: #fff;
  border-bottom: 1px solid var(--sb-border);
  display: flex;
  align-items: center;
  gap: 11px;
}

.sidebar-brand span {
  display: inline-flex;
  width: 34px; height: 34px;
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.45);
  border-radius: 9px;
  align-items: center;
  justify-content: center;
  font-size: .82rem;
  font-weight: 800;
  letter-spacing: .02em;
  flex-shrink: 0;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
}

.sidebar-nav .nav-section {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #64748b;
  padding: 16px 12px 6px;
  font-weight: 700;
}
.sidebar-nav .nav-section:first-child { padding-top: 4px; }

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--sb-text);
  font-size: .89rem;
  font-weight: 500;
  text-decoration: none;
  margin-bottom: 2px;
  position: relative;
  transition: background .15s ease, color .15s ease, transform .1s ease;
}

.sidebar-nav a:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--sb-text-hover);
  text-decoration: none;
}

.sidebar-nav a.active {
  background: linear-gradient(90deg, rgba(37, 99, 235, 0.22) 0%, rgba(37, 99, 235, 0.08) 100%);
  color: #ffffff;
  font-weight: 600;
  box-shadow: inset 3px 0 0 #3b82f6;
}

.sidebar-nav a .ico {
  width: 20px;
  text-align: center;
  opacity: .9;
  font-size: 1rem;
  flex-shrink: 0;
}

.sidebar-foot {
  padding: 14px 16px;
  background: var(--sb-surface);
  border-top: 1px solid var(--sb-border);
  font-size: .8rem;
  color: var(--sb-text);
}
.sidebar-foot .user-name { color: #fff; font-weight: 600; font-size: .9rem; margin-bottom: 1px; }
.sidebar-foot .user-role {
  display: inline-block;
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #93c5fd;
  background: rgba(59, 130, 246, 0.15);
  padding: 1px 7px;
  border-radius: 4px;
  margin-bottom: 8px;
}
.sidebar-foot a {
  display: inline-block;
  color: #cbd5e1;
  margin-right: 12px;
  font-weight: 500;
  font-size: .78rem;
}
.sidebar-foot a:hover { color: #fff; text-decoration: none; }

/* ---- Main Workspace & Topbar ---- */
.main-wrap {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--header-h);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 28px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 60;
}

.topbar h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--text);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar .actions { display: flex; gap: 8px; align-items: center; }

.menu-toggle {
  display: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--text);
  padding: 5px 10px;
}

.content {
  padding: 24px 28px 40px;
  flex: 1;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}

/* ---- Cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px;
  margin-bottom: 20px;
  transition: box-shadow .2s ease;
}

.card h2 {
  margin: 0 0 16px;
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: -.015em;
  color: var(--text);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--surface-3);
  flex-wrap: wrap;
}
.card-header h2 { margin: 0; }

/* ---- KPI / Stat Cards ---- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-xs);
  position: relative;
  overflow: hidden;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.stat:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}
.stat::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--border-strong);
}
.stat.primary::before { background: var(--primary); }
.stat.success::before { background: var(--success); }
.stat.warning::before { background: var(--warning); }
.stat.danger::before  { background: var(--danger); }

.stat .label {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-2);
  font-weight: 600;
  margin-bottom: 6px;
}
.stat .value {
  font-size: 1.65rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -.03em;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}
.stat .sub { font-size: .76rem; color: var(--text-3); margin-top: 6px; font-weight: 500; }
.stat.primary .value { color: var(--primary); }
.stat.success .value { color: var(--success); }
.stat.warning .value { color: var(--warning); }
.stat.danger .value  { color: var(--danger); }

/* ---- Data Tables ---- */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

table.data, table.tasks, table.am, table.d {
  width: 100%;
  border-collapse: collapse;
  font-size: .865rem;
}

table.data th, table.tasks th, table.am th, table.d th {
  text-align: left;
  padding: 11px 14px;
  background: var(--surface-2);
  color: var(--text-2);
  font-weight: 700;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 5;
}

table.data td, table.tasks td, table.am td, table.d td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text);
}

table.data tr:last-child td,
table.tasks tr:last-child td,
table.am tr:last-child td,
table.d tr:last-child td { border-bottom: 0; }

table.data tbody tr:hover td,
table.tasks tbody tr:hover td,
table.am tbody tr:hover td,
table.d tbody tr:hover td { background: #f8fafc; }

table.data td.n, table.data th.n {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
  font-size: .82rem;
}
table.data a { font-weight: 600; }

/* ---- Semantic Pills, Badges & Importance Chips ---- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .01em;
  white-space: nowrap;
  line-height: 1.3;
}
.pill::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: .75;
}

.pill.ok, .pill.success { background: var(--success-soft); color: #047857; border: 1px solid var(--success-border); }
.pill.warn, .pill.warning, .pill.soon, .pill.imp-Mid { background: var(--warning-soft); color: #b45309; border: 1px solid var(--warning-border); }
.pill.hot, .pill.danger, .pill.ov, .pill.imp-High { background: var(--danger-soft); color: #b91c1c; border: 1px solid var(--danger-border); }
.pill.muted, .pill.imp-Low { background: var(--surface-3); color: #475569; border: 1px solid var(--border); }
.pill.primary, .pill.info { background: var(--primary-soft); color: var(--primary); border: 1px solid #bfdbfe; }

/* ---- Forms & Inputs ---- */
label {
  display: block;
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 5px;
}

input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="date"], input[type="search"],
select, textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: .88rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}

input:hover, select:hover, textarea:hover { border-color: #94a3b8; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

/* Compact inputs inside BOQ/data tables */
table.data input[type="text"],
table.data input[type="number"],
table.data select {
  padding: 6px 8px;
  font-size: .83rem;
  border-radius: var(--radius-xs);
}

textarea { resize: vertical; min-height: 76px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
}
.grid .full { grid-column: 1 / -1; }
.form-row { margin-bottom: 14px; }

/* ---- Buttons ---- */
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 15px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 600;
  font-size: .85rem;
  cursor: pointer;
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  box-shadow: var(--shadow-xs);
  transition: background .15s ease, box-shadow .15s ease, transform .08s ease;
  white-space: nowrap;
}

button:hover, .btn:hover {
  background: var(--primary-hover);
  text-decoration: none;
  color: #fff;
  box-shadow: 0 2px 6px rgba(29, 78, 216, 0.25);
}
button:active, .btn:active { transform: translateY(1px); }

.btn.secondary, button.secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn.secondary:hover, button.secondary:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: #94a3b8;
  box-shadow: var(--shadow-xs);
}

.btn.ghost, button.ghost {
  background: transparent;
  color: var(--text-2);
  box-shadow: none;
}
.btn.ghost:hover, button.ghost:hover {
  background: var(--surface-3);
  color: var(--text);
  box-shadow: none;
}

.btn.danger, button.danger { background: var(--danger); }
.btn.danger:hover, button.danger:hover {
  background: #b91c1c;
  box-shadow: 0 2px 6px rgba(220, 38, 38, 0.25);
}

.btn.g { background: var(--success); }
.btn.g:hover {
  background: #047857;
  box-shadow: 0 2px 6px rgba(5, 150, 105, 0.25);
}

.btn.sm, button.sm { padding: 5px 10px; font-size: .78rem; border-radius: var(--radius-xs); }

/* ---- Filter Toolbars ---- */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 18px;
  padding: 14px 16px;
  background: var(--surface-2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.filters > div { min-width: 135px; flex: 1 1 150px; max-width: 240px; }
.filters label { margin-bottom: 4px; font-size: .74rem; text-transform: uppercase; letter-spacing: .03em; }

/* ---- Alerts & Banners ---- */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: .88rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
}
.alert.ok   { background: var(--success-soft); color: #065f46; border: 1px solid var(--success-border); }
.alert.err  { background: var(--danger-soft);  color: #991b1b; border: 1px solid var(--danger-border); }
.alert.info { background: var(--info-soft);    color: #075985; border: 1px solid var(--info-border); }

/* ---- Project BOQ Tabs ---- */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 18px;
  padding: 6px;
  background: var(--surface-3);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.tabs a {
  padding: 8px 15px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-weight: 600;
  font-size: .84rem;
  text-decoration: none;
  transition: all .15s ease;
}
.tabs a:hover { color: var(--text); background: rgba(255, 255, 255, 0.6); text-decoration: none; }
.tabs a.on {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-xs);
}

/* ---- Category Chips (ICT, ELV, SCS, DC) ---- */
.cat {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 5px;
  font-size: .69rem;
  font-weight: 700;
  letter-spacing: .03em;
  margin-right: 4px;
}
.cat-ICT { background: #dbeafe; color: #1e40af; }
.cat-ELV { background: #fce7f3; color: #9d174d; }
.cat-SCS { background: #d1fae5; color: #065f46; }
.cat-DC  { background: #fef3c7; color: #92400e; }

/* ---- Progress Bar ---- */
.progress {
  height: 7px;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
  min-width: 64px;
  border: 1px solid var(--border);
}
.progress > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #2563eb, #3b82f6);
  border-radius: 999px;
  transition: width .3s ease;
}

/* ---- Login Screen ---- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top right, #1e3a8a 0%, #0f172a 55%, #020617 100%);
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border-radius: 18px;
  padding: 40px 36px;
  width: 100%;
  max-width: 410px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.1);
}
.login-card h2 { margin: 0 0 4px; font-size: 1.4rem; font-weight: 800; letter-spacing: -.02em; }
.login-card .sub { color: var(--text-2); margin: 0 0 24px; font-size: .88rem; }
.login-card label { margin-top: 14px; }
.login-card button { width: 100%; margin-top: 22px; padding: 11px; font-size: .95rem; }
.login-brand { text-align: center; margin-bottom: 22px; }
.login-brand .logo {
  display: inline-flex;
  width: 52px; height: 52px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #fff;
  border-radius: 14px;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.15rem;
  margin-bottom: 12px;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.35);
}

/* ---- Empty States & Logos ---- */
.empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-3);
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}
.empty b { display: block; color: var(--text); font-size: .98rem; margin-bottom: 6px; }
img.lg { max-height: 54px; border-radius: var(--radius-xs); border: 1px solid var(--border); padding: 4px; background: #fff; margin: 6px 0; }

/* ---- Grids & Responsive Breakpoints ---- */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.wl-grid, .dash-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.wl-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }

/* Mobile backdrop */
.sb-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(2px);
  z-index: 110;
}
.sidebar.open ~ .sb-backdrop { display: block; }

@media (max-width: 960px) {
  .two-col { grid-template-columns: 1fr; }
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-wrap { margin-left: 0; }
  .menu-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .topbar { padding: 0 16px; }
  .content { padding: 16px 16px 32px; }
}
@media (max-width: 700px) {
  .form-grid { grid-template-columns: 1fr; }
  .filters > div { max-width: none; }
}

/* ---- Legacy Overrides ---- */
header { display: none !important; }
main { padding: 0 !important; max-width: none !important; }
.wrap { max-width: none; }

/* ---- Print Styles (Proposals & Reports) ---- */
@media print {
  .sidebar, .topbar, .filters, .tabs, .btn, button, .sb-backdrop { display: none !important; }
  .main-wrap { margin-left: 0 !important; }
  .content { padding: 0 !important; }
  .card { box-shadow: none !important; border: 1px solid #cbd5e1 !important; break-inside: avoid; }
  body { background: #fff !important; }
}