/* ══════════════════════════════════════════════════════
   TenderIQ — Main Stylesheet
   ══════════════════════════════════════════════════════ */

/* ── Variables ─────────────────────────────────────────── */
:root {
  --bg:       #080c14;
  --surface:  #0e1520;
  --surface2: #141e2e;
  --surface3: #1a2638;
  --border:   #1f2f44;
  --border2:  #253548;

  --text:     #e8eef8;
  --muted:    #5a7a9a;
  --muted2:   #3a5570;

  --accent:   #3b82f6;
  --accent-g: rgba(59, 130, 246, 0.15);
  --green:    #10b981;
  --orange:   #f59e0b;
  --red:      #ef4444;
  --purple:   #8b5cf6;
  --teal:     #06b6d4;

  --head: 'Syne', sans-serif;
  --body: 'DM Sans', sans-serif;
  --mono: 'JetBrains Mono', monospace;

  --radius:   10px;
  --radius-lg: 14px;
  --shadow:   0 4px 24px rgba(0, 0, 0, 0.4);
}

/* ── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}
body::before {
  content: '';
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    linear-gradient(rgba(59,130,246,.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(59,130,246,.025) 1px, transparent 1px);
  background-size: 40px 40px;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
input, select, textarea, button { font-family: var(--body); }
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Layout ─────────────────────────────────────────────── */
.app-shell { display: flex; min-height: 100vh; position: relative; z-index: 1; }
.main { margin-left: 240px; flex: 1; display: flex; flex-direction: column; min-height: 100vh; }
.content { padding: 28px 34px; flex: 1; }

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  width: 240px; flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; height: 100vh;
  z-index: 50;
}
.sidebar-logo {
  padding: 22px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.logo-mark {
  width: 34px; height: 34px;
  background: var(--accent);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--head);
  font-size: 1rem; font-weight: 800; color: #fff;
}
.logo-text { font-family: var(--head); font-size: 1.05rem; font-weight: 800; }
.logo-text span { color: var(--accent); }

.sidebar-nav { flex: 1; padding: 14px 10px; overflow-y: auto; }
.nav-label {
  font-size: 0.58rem; letter-spacing: 2px; text-transform: uppercase;
  color: var(--muted2); padding: 10px 8px 5px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 8px;
  font-size: 0.82rem; font-weight: 500; color: var(--muted);
  cursor: pointer; transition: all .15s;
  margin-bottom: 2px; text-decoration: none;
  border: 1px solid transparent;
}
.nav-item:hover { background: var(--surface2); color: var(--text); text-decoration: none; }
.nav-item.active {
  background: var(--accent-g); color: var(--accent);
  border-color: rgba(59, 130, 246, .2);
}
.nav-icon { font-size: 0.95rem; width: 18px; text-align: center; flex-shrink: 0; }
.nav-badge {
  margin-left: auto;
  background: var(--accent); color: #fff;
  font-size: .6rem; padding: 1px 7px; border-radius: 10px;
  font-family: var(--mono);
}
.sidebar-footer { padding: 14px; border-top: 1px solid var(--border); }

/* ── Topbar ──────────────────────────────────────────────── */
.topbar {
  padding: 14px 34px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(8, 12, 20, .85);
  backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 40;
}
.topbar-title { font-family: var(--head); font-size: 1.05rem; font-weight: 700; }
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  padding: 7px 16px; border-radius: 8px;
  font-size: 0.82rem; font-weight: 600;
  cursor: pointer; border: none;
  transition: all .15s;
  display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover  { background: #2563eb; transform: translateY(-1px); box-shadow: 0 4px 14px rgba(59,130,246,.35); }
.btn-ghost    { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover    { border-color: var(--accent); color: var(--accent); }
.btn-green    { background: var(--green); color: #fff; }
.btn-green:hover    { background: #059669; }
.btn-danger   { background: rgba(239,68,68,.1); color: var(--red); border: 1px solid rgba(239,68,68,.2); }
.btn-danger:hover   { background: rgba(239,68,68,.2); }
.btn-ai       { background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff; }
.btn-ai:hover { opacity: .9; transform: translateY(-1px); }
.btn-teal     { background: rgba(6,182,212,.1); color: var(--teal); border: 1px solid rgba(6,182,212,.25); }
.btn-teal:hover { background: rgba(6,182,212,.2); }
.btn-sm { padding: 5px 12px; font-size: 0.73rem; }
.btn-icon { padding: 6px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none !important; }

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-title { font-family: var(--head); font-size: .92rem; font-weight: 700; }
.card-body { padding: 20px; }

/* ── Stats ───────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px; position: relative; overflow: hidden;
}
.stat-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
}
.stat-card.s1::before { background: linear-gradient(90deg, var(--accent), transparent); }
.stat-card.s2::before { background: linear-gradient(90deg, var(--green), transparent); }
.stat-card.s3::before { background: linear-gradient(90deg, var(--orange), transparent); }
.stat-card.s4::before { background: linear-gradient(90deg, var(--purple), transparent); }
.stat-label { font-size: .62rem; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.stat-val { font-family: var(--head); font-size: 2rem; font-weight: 800; line-height: 1; }
.stat-card.s1 .stat-val { color: var(--accent); }
.stat-card.s2 .stat-val { color: var(--green); }
.stat-card.s3 .stat-val { color: var(--orange); }
.stat-card.s4 .stat-val { color: var(--purple); }
.stat-sub { font-size: .68rem; color: var(--muted); margin-top: 6px; }

/* ── Forms ───────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block; font-size: .72rem; font-weight: 600;
  color: var(--muted); margin-bottom: 5px;
  text-transform: uppercase; letter-spacing: .5px;
}
.form-control {
  width: 100%; padding: 9px 13px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text);
  font-family: var(--body); font-size: .85rem;
  transition: border-color .15s;
}
.form-control:focus { outline: none; border-color: var(--accent); }
.form-control::placeholder { color: var(--muted2); }
.form-control[readonly] { opacity: .6; }
select.form-control option { background: var(--surface2); }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-hint { font-size: .68rem; color: var(--muted); margin-top: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-check { display: flex; align-items: center; gap: 8px; font-size: .82rem; cursor: pointer; }
.form-check input { accent-color: var(--accent); }

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.75); backdrop-filter: blur(4px);
  z-index: 100; display: none; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; width: 100%; max-width: 540px;
  max-height: 92vh; overflow-y: auto;
  animation: slideUp .2s ease;
}
.modal.modal-lg { max-width: 720px; }
@keyframes slideUp {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}
.modal-header {
  padding: 20px 24px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; background: var(--surface); z-index: 5;
}
.modal-title { font-family: var(--head); font-size: .98rem; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1.1rem; padding: 2px 6px; border-radius: 4px; }
.modal-close:hover { background: var(--surface2); color: var(--text); }
.modal-body { padding: 24px; }
.modal-footer {
  padding: 16px 24px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: flex-end;
  position: sticky; bottom: 0; background: var(--surface);
}

/* ── Tabs ────────────────────────────────────────────────── */
.tabs {
  display: flex; border-bottom: 1px solid var(--border);
  background: var(--surface); padding: 0 34px;
  overflow-x: auto; flex-shrink: 0;
}
.tab {
  padding: 12px 16px; font-size: .82rem; font-weight: 500;
  color: var(--muted); cursor: pointer;
  border-bottom: 2px solid transparent; transition: all .15s;
  display: flex; align-items: center; gap: 6px; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-badge {
  background: var(--surface3); border-radius: 10px;
  padding: 1px 7px; font-size: .6rem; font-family: var(--mono);
}
.tab.active .tab-badge { background: rgba(59,130,246,.2); color: var(--accent); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Table ───────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  padding: 9px 12px; font-size: .6rem; letter-spacing: 1px;
  text-transform: uppercase; color: var(--muted); text-align: left;
  border-bottom: 1px solid var(--border); background: var(--surface2);
  white-space: nowrap; position: sticky; top: 0; z-index: 3;
}
.data-table td { padding: 9px 12px; font-size: .78rem; border-bottom: 1px solid var(--border); }
.data-table tr:hover td { background: rgba(255,255,255,.015); }
.data-table tr:last-child td { border-bottom: none; }
.data-table .col-right { text-align: right; }
.data-table .col-center { text-align: center; }
.mono-cell { font-family: var(--mono); font-size: .72rem; color: var(--teal); }
.rate-cell { font-family: var(--mono); font-size: .82rem; font-weight: 600; color: var(--orange); }
.amount-cell { font-family: var(--mono); font-size: .82rem; font-weight: 600; color: var(--text); }

/* ── Inline edit input ───────────────────────────────────── */
.inline-edit {
  border: 1px solid transparent; border-radius: 5px;
  padding: 4px 7px; font-family: var(--mono); font-size: .8rem;
  text-align: right; width: 100%; background: transparent; color: var(--text);
  transition: all .15s;
}
.inline-edit:hover { border-color: var(--border); }
.inline-edit:focus { outline: none; border-color: var(--accent); background: var(--surface2); }

/* ── Progress bar ────────────────────────────────────────── */
.progress-wrap { margin: 6px 0; }
.progress-labels { display: flex; justify-content: space-between; font-size: .7rem; color: var(--muted); margin-bottom: 5px; }
.progress-bar { background: var(--surface3); border-radius: 4px; height: 7px; overflow: hidden; }
.progress-fill {
  height: 100%; border-radius: 4px;
  background: linear-gradient(90deg, var(--accent), var(--teal));
  transition: width .35s ease;
}

/* ── Log box ─────────────────────────────────────────────── */
.log-box {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; font-family: var(--mono); font-size: .7rem; color: var(--muted);
  max-height: 180px; overflow-y: auto; line-height: 1.9; margin-top: 10px;
}
.log-ok   { color: var(--green); }
.log-info { color: var(--accent); }
.log-warn { color: var(--orange); }
.log-err  { color: var(--red); }

/* ── Upload zone ─────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--border2); border-radius: var(--radius-lg);
  padding: 36px; text-align: center; cursor: pointer;
  transition: all .2s; background: var(--surface);
}
.upload-zone:hover, .upload-zone.drag {
  border-color: var(--accent); background: var(--accent-g);
}
.upload-zone input[type=file] { display: none; }
.upload-title { font-family: var(--head); font-size: .95rem; font-weight: 700; margin-bottom: 6px; }
.upload-sub { font-size: .76rem; color: var(--muted); line-height: 1.7; }

/* ── File card ───────────────────────────────────────────── */
.file-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 15px;
  display: flex; align-items: flex-start; gap: 12px; transition: border-color .15s;
}
.file-card:hover { border-color: var(--border2); }
.file-icon {
  width: 38px; height: 38px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; flex-shrink: 0;
}
.file-info { flex: 1; min-width: 0; }
.file-name { font-size: .8rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-meta { font-size: .65rem; color: var(--muted); margin-top: 2px; line-height: 1.6; }

/* ── Status chips ────────────────────────────────────────── */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 20px; font-size: .63rem; font-weight: 600; letter-spacing: .4px; border: 1px solid; }
.chip-active  { background: rgba(16,185,129,.1);  color: var(--green);  border-color: rgba(16,185,129,.25); }
.chip-draft   { background: rgba(245,158,11,.1);  color: var(--orange); border-color: rgba(245,158,11,.25); }
.chip-complete{ background: rgba(59,130,246,.1);  color: var(--accent); border-color: rgba(59,130,246,.25); }
.chip-match-auto { background: rgba(16,185,129,.1); color: var(--green);  border-color: rgba(16,185,129,.2); }
.chip-match-partial { background: rgba(245,158,11,.1); color: var(--orange); border-color: rgba(245,158,11,.2); }
.chip-match-none { background: rgba(239,68,68,.1); color: var(--red); border-color: rgba(239,68,68,.2); }

/* ── Chapter rows in BOQ ──────────────────────────────────── */
.ch-header-row td {
  background: var(--surface2); font-family: var(--head);
  font-weight: 700; font-size: .78rem; color: var(--accent);
  padding: 9px 12px; border-top: 2px solid var(--border);
}
.subtotal-row td { background: rgba(59,130,246,.04); font-weight: 700; }
.subtotal-row .amount-cell { color: var(--accent); }

/* ── Grand total strip ───────────────────────────────────── */
.grand-strip {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 22px;
  display: grid; grid-template-columns: repeat(5, 1fr);
}
.gs-item { text-align: center; padding: 4px 12px; border-right: 1px solid var(--border); }
.gs-item:last-child { border-right: none; }
.gs-label { font-size: .58rem; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); margin-bottom: 5px; }
.gs-val { font-family: var(--mono); font-size: 1rem; font-weight: 700; }

/* ── DSR match drawer ────────────────────────────────────── */
.match-drawer {
  position: fixed; right: 0; top: 0; height: 100vh; width: 420px;
  background: var(--surface); border-left: 1px solid var(--border);
  z-index: 80; transform: translateX(100%);
  transition: transform .25s ease; overflow-y: auto; display: flex; flex-direction: column;
}
.match-drawer.open { transform: translateX(0); }
.drawer-header {
  padding: 16px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; background: var(--surface); z-index: 5;
}
.drawer-body { padding: 14px 18px; flex: 1; }
.drawer-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px; border: 1px solid var(--border);
  border-radius: 8px; margin-bottom: 8px; cursor: pointer;
  transition: border-color .15s;
}
.drawer-item:hover { border-color: var(--accent); }
.drawer-item.selected { border-color: var(--green); background: rgba(16,185,129,.05); }
.di-score { font-family: var(--mono); font-size: .7rem; font-weight: 700; color: var(--green); flex-shrink: 0; min-width: 36px; }
.di-desc { font-size: .75rem; line-height: 1.4; flex: 1; }
.di-meta { font-size: .63rem; color: var(--muted); margin-top: 3px; }
.di-rate { font-family: var(--mono); font-size: .8rem; font-weight: 700; color: var(--orange); flex-shrink: 0; }

/* ── Toast ───────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 18px;
  font-size: .82rem; z-index: 300; min-width: 260px;
  box-shadow: var(--shadow); display: flex; align-items: center; gap: 10px;
  animation: toastIn .3s ease;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}
.toast.success { border-color: rgba(16,185,129,.4); }
.toast.error   { border-color: rgba(239,68,68,.4); }
.toast.info    { border-color: rgba(59,130,246,.4); }

/* ── Pagination ──────────────────────────────────────────── */
.pagination {
  padding: 12px 16px; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  font-size: .74rem; color: var(--muted);
}
.page-btns { display: flex; gap: 5px; }
.page-btn {
  padding: 3px 10px; border: 1px solid var(--border);
  border-radius: 5px; background: none; color: var(--muted);
  cursor: pointer; font-size: .72rem;
}
.page-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.page-btn:hover:not(.active) { border-color: var(--accent); color: var(--accent); }

/* ── Empty state ─────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 70px 40px;
  border: 2px dashed var(--border); border-radius: var(--radius-lg);
  background: var(--surface);
}
.empty-icon { font-size: 3rem; margin-bottom: 14px; opacity: .4; }
.empty-title { font-family: var(--head); font-size: 1.1rem; font-weight: 700; margin-bottom: 8px; }
.empty-text { font-size: .82rem; color: var(--muted); max-width: 380px; margin: 0 auto 22px; }

/* ── AI progress panel ───────────────────────────────────── */
.ai-panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; display: none;
}
.ai-panel.active { display: block; }
.ai-panel-header { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.ai-panel-title { font-family: var(--head); font-size: .88rem; font-weight: 700; }

/* ── Inline search / filter bar ─────────────────────────── */
.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filter-input {
  padding: 6px 11px; border: 1px solid var(--border);
  border-radius: 7px; background: var(--surface2);
  color: var(--text); font-family: var(--body); font-size: .78rem;
}
.filter-input:focus { outline: none; border-color: var(--accent); }

/* ── Section header ──────────────────────────────────────── */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.section-title { font-family: var(--head); font-size: .95rem; font-weight: 700; }
.section-meta { font-size: .72rem; color: var(--muted); }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .grand-strip { grid-template-columns: 1fr 1fr; }
  .match-drawer { width: 100%; }
}
@media (max-width: 600px) {
  .sidebar { display: none; }
  .main { margin-left: 0; }
  .stats-grid { grid-template-columns: 1fr; }
}
