:root {
  --ink: #16181d;
  --ink-soft: #565c66;
  --muted: #8a8f99;
  --border: #e4e6eb;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --accent: #3d5afe;
  --accent-hover: #2f47d1;
  --danger: #e5484d;
  --success: #1a9c6d;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,18,22,0.04), 0 8px 24px rgba(16,18,22,0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
}

a { color: var(--accent); text-decoration: none; }
h1 { font-size: 22px; font-weight: 650; margin: 0 0 4px; letter-spacing: -0.01em; }

.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { padding: 0 24px; height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 32px; }
.brand { font-weight: 700; color: var(--ink); font-size: 15px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.user-chip { font-size: 13px; font-weight: 600; color: var(--ink-soft); background: var(--bg); padding: 5px 12px; border-radius: 20px; }
.logout-link { font-size: 13px; color: var(--muted); font-weight: 500; }
.logout-link:hover { color: var(--ink); }

/* ---------- Left sidebar layout ---------- */
.app-shell { display: flex; align-items: flex-start; max-width: 1280px; margin: 0 auto; }
.sidebar {
  width: 220px; flex: 0 0 220px; position: sticky; top: 58px;
  height: calc(100vh - 58px); overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 20px 12px;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar-nav a {
  color: var(--ink-soft); padding: 9px 14px; border-radius: 7px;
  font-weight: 500; font-size: 14px;
}
.sidebar-nav a:hover { background: var(--bg); color: var(--ink); }
.sidebar-nav a.active { background: #edf0ff; color: var(--accent); font-weight: 650; }
.sidebar-group { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }
.sidebar-group-label { padding: 6px 14px; font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.sidebar-sub { padding-left: 26px !important; font-size: 13.5px; }

.page { flex: 1 1 auto; min-width: 0; max-width: 1080px; margin: 0 auto; padding: 32px 24px 80px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 22px; }
.page-head-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.page-sub { color: var(--muted); margin: 0; font-size: 14px; }

.flash { padding: 11px 16px; border-radius: 8px; font-size: 14px; font-weight: 500; margin-bottom: 12px; }
.flash-success { background: #e7f7f0; color: var(--success); }
.flash-error { background: #fdecec; color: var(--danger); }

.btn { display: inline-flex; align-items: center; justify-content: center; padding: 9px 16px; border-radius: 8px; font-size: 14px; font-weight: 600; border: 1px solid transparent; cursor: pointer; transition: background 0.12s ease; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--ink); color: #fff; }
.btn-secondary:hover { background: #2a2d34; }
.btn-ghost { background: transparent; color: var(--ink-soft); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-block { width: 100%; }
.btn-icon { background: transparent; border: none; color: var(--muted); cursor: pointer; font-size: 14px; padding: 4px 8px; border-radius: 6px; }
.btn-icon:hover { background: #fdecec; color: var(--danger); }

.auth-wrap { display: flex; justify-content: center; padding-top: 8vh; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 40px 36px; width: 100%; max-width: 380px; text-align: center; }
.auth-mark { width: 44px; height: 44px; background: var(--accent); color: #fff; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 18px; margin: 0 auto 18px; }
.auth-card h1 { text-align: center; font-size: 20px; }
.auth-sub { color: var(--muted); font-size: 14px; margin: 0 0 24px; }
.auth-form { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.auth-form label { font-size: 13px; font-weight: 600; color: var(--ink-soft); margin-top: 10px; }
.auth-form button { margin-top: 18px; }

input[type="text"], input[type="email"], input[type="password"], input[type="url"], input[type="number"], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; font-family: inherit; color: var(--ink); background: var(--surface);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(61,90,254,0.12); }
textarea { resize: vertical; }

.filters { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; align-items: flex-end; }
.filters input[type="text"] { flex: 1; min-width: 200px; }
.filters select { width: 160px; }
.filter-date-label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.filter-date-label input[type="date"] {
  padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; font-family: inherit; color: var(--ink); background: var(--surface);
}

.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow); }
.leads-table { width: 100%; border-collapse: collapse; min-width: 1100px; }
.requirement-cell { max-width: 160px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: help; }
.leads-table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; padding: 12px 16px; border-bottom: 1px solid var(--border); background: #fbfbfc; }
.leads-table td { padding: 13px 16px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: middle; }
.leads-table tr:last-child td { border-bottom: none; }
.leads-table tr:hover { background: #fafbfd; }
.lead-name { font-weight: 600; }
.muted { color: var(--muted); font-size: 13px; }

.status-form { display: inline-block; }
.status-badge { border: none; border-radius: 20px; padding: 5px 10px; font-size: 12.5px; font-weight: 600; cursor: pointer; appearance: none; -webkit-appearance: none; }
.status-new { background: #e8ecfd; color: #3d5afe; }
.status-cold { background: #e5f2fd; color: #1877c9; }
.status-hot { background: #ffe8e0; color: #d5541c; }
.status-in-process { background: #fff4e0; color: #b6790c; }
.status-converted { background: #e7f7f0; color: #1a9c6d; }
.status-not-converted { background: #fdecec; color: #e5484d; }

.form-wrap { max-width: 720px; }
.card-form { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-full { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border); }

/* ---------- Reports ---------- */
.report-summary { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; }
.report-stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 20px; min-width: 160px; flex: 1 1 160px;
  display: flex; flex-direction: column; gap: 6px;
}
.report-stat-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }
.report-stat-value { font-size: 22px; font-weight: 700; color: var(--ink); }
.report-stat-highlight { border-color: var(--accent); background: #f3f5ff; }
.report-stat-highlight .report-stat-value { color: var(--accent); }

.empty-state { text-align: center; padding: 60px 20px; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); color: var(--muted); }
.empty-state p { margin-bottom: 16px; }

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .filters { flex-wrap: wrap; }
  .topbar-inner { flex-wrap: wrap; height: auto; padding: 12px 16px; }
}

@media (max-width: 880px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%; flex: none; position: static; height: auto;
    border-right: none; border-bottom: 1px solid var(--border);
    padding: 10px 12px;
  }
  .sidebar-nav { flex-direction: row; flex-wrap: wrap; gap: 6px; }
  .sidebar-group { margin-top: 0; padding-top: 0; border-top: none; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .sidebar-group-label { padding: 6px 4px; }
  .sidebar-sub { padding-left: 14px !important; }
  .page { max-width: none; }
}

/* ---------- Quotations: form additions ---------- */
.form-wrap-wide { max-width: 980px; }
.section-title { font-size: 15px; font-weight: 650; margin: 26px 0 12px; padding-top: 18px; border-top: 1px solid var(--border); }
.card-form .section-title:first-of-type { border-top: none; padding-top: 0; }

.items-table-wrap { margin-bottom: 10px; }
.items-table { min-width: 760px; }
.items-table th, .items-table td { padding: 8px 10px; }
.items-table input[type="text"], .items-table input[type="number"] { padding: 7px 9px; font-size: 13.5px; }
.col-sl { width: 56px; text-align: center; }
.col-sac { width: 100px; }
.col-unit { width: 130px; }
.col-num { width: 110px; text-align: right; }
.col-remove { width: 36px; text-align: center; }
.items-table td.col-sl, .items-table td.col-num { text-align: right; }
.items-table td.col-sl { text-align: center; }
.row-amount { font-weight: 600; }

.btn-add-row { margin-bottom: 22px; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.row-actions { display: flex; align-items: center; gap: 8px; }
.row-actions .status-form { display: inline-flex; }

.totals-box { max-width: 380px; margin-left: auto; background: #fbfbfc; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.totals-row { display: flex; align-items: center; justify-content: space-between; padding: 7px 0; font-size: 14px; }
.totals-row + .totals-row { border-top: 1px solid var(--border); }
.totals-row-final { font-weight: 700; font-size: 16px; color: var(--ink); }
.totals-input { width: 130px; text-align: right; padding: 6px 9px; }

/* ---------- Quotation printable sheet ---------- */
.view-actions { display: flex; justify-content: space-between; margin-bottom: 18px; }

.quote-sheet {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); max-width: 860px; margin: 0 auto; padding: 44px 48px;
}
.quote-top { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 18px; }
.quote-logo img { max-height: 64px; max-width: 240px; }
.quote-logo-text { font-size: 20px; font-weight: 750; color: var(--ink); }
.quote-date { font-size: 14px; color: var(--ink-soft); }

.quote-heading { text-align: center; font-size: 26px; letter-spacing: 0.08em; margin: 10px 0 4px; }
.quote-no { text-align: center; color: var(--ink-soft); margin: 0 0 26px; font-size: 14px; }

.quote-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 28px; }
.quote-party h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.quote-party p { margin: 0 0 4px; font-size: 14px; line-height: 1.5; }
.party-name { font-weight: 650; font-size: 15px !important; }

.quote-items-table { width: 100%; border-collapse: collapse; margin-bottom: 22px; }
.quote-items-table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); font-weight: 600; padding: 10px; border-bottom: 2px solid var(--ink); }
.quote-items-table td { padding: 10px; border-bottom: 1px solid var(--border); font-size: 14px; }
.quote-items-table .col-num { text-align: right; }
.quote-items-table .col-sl { text-align: center; width: 56px; }
.quote-items-table .col-sac { width: 100px; }
.quote-items-table .col-unit { width: 80px; text-align: center; }

.bank-details {
  border-top: 1px solid var(--border); padding-top: 16px; margin: 0 0 22px;
}
.bank-details h4 {
  margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted);
}
.bank-details-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 24px; }
.bank-details-grid div { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.bank-label { color: var(--ink-soft); }

.quote-totals { max-width: 360px; margin: 0 0 30px auto; }
.quote-totals .totals-row { font-size: 14px; }
.quote-totals .totals-row-final { font-size: 17px; border-top: 2px solid var(--ink); padding-top: 10px; margin-top: 4px; }

.quote-footer { border-top: 1px solid var(--border); padding-top: 14px; }
.quote-footer p { margin: 0; font-size: 12.5px; color: var(--muted); }

.cert-sheet { margin-top: 5cm; }
.cert-heading { margin-top: 0; }
.cert-top-row { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 10px 24px; margin: 20px 0 14px; }
.cert-lang-row { margin-top: 0; margin-bottom: 22px; }
.cert-field-line { margin: 0; font-size: 17px; }
.cert-date-line { font-size: 17px; }
.cert-fields { margin: 0 0 18px; }
.cert-fields p { margin: 0 0 10px; font-size: 17px; }
.cert-fields strong { font-weight: 700; }
.cert-divider { border: none; border-top: 1px solid var(--border); margin: 0 0 24px; }
.cert-section-title { font-size: 17px; font-weight: 700; margin: 22px 0 8px; }
.cert-statement { font-size: 17px; line-height: 1.7; margin: 0 0 4px; }
.cert-signature { margin-top: 44px; font-size: 17px; line-height: 1.9; }

@media print {
  .topbar, .no-print, .flash { display: none !important; }
  body { background: #fff; }
  .page { max-width: none; padding: 0; margin: 0; }
  .quote-sheet { border: none; box-shadow: none; padding: 0; max-width: none; margin: 0; }
  .cert-sheet { margin-top: 5cm; }
}

@media (max-width: 640px) {
  .quote-parties { grid-template-columns: 1fr; }
  .quote-sheet { padding: 28px 20px; }
  .bank-details-grid { grid-template-columns: 1fr; }
}

/* ---------- Dashboard ---------- */
.dashboard-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}
.dash-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  border-left: 4px solid var(--accent);
  color: inherit;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.dash-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 2px 4px rgba(16,18,22,0.06), 0 12px 28px rgba(16,18,22,0.09);
}
.dash-card-label { font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 700; }
.dash-card-value { font-size: 32px; font-weight: 750; color: var(--ink); line-height: 1.2; }
.dash-card-foot { font-size: 12.5px; color: var(--muted); }

.dash-card-new { border-left-color: #3d5afe; }
.dash-card-new .dash-card-value { color: #3d5afe; }

.dash-card-converted { border-left-color: #1a9c6d; }
.dash-card-converted .dash-card-value { color: #1a9c6d; }

.dash-card-inprocess { border-left-color: #b6790c; }
.dash-card-inprocess .dash-card-value { color: #b6790c; }

.dash-card-notconverted { border-left-color: #e5484d; }
.dash-card-notconverted .dash-card-value { color: #e5484d; }

.dashboard-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.dashboard-section-head h2 { font-size: 17px; font-weight: 650; margin: 0; color: var(--ink); }

@media (max-width: 900px) {
  .dashboard-stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 520px) {
  .dashboard-stats { grid-template-columns: 1fr; }
}

/* ---------- Dashboard: Lead Sources / Monthly Leads panels ---------- */
.dashboard-panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 32px;
}
.dash-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}
.dash-panel h3 { margin: 0 0 2px; font-size: 17px; font-weight: 700; color: var(--ink); }
.dash-panel-sub { margin: 0 0 16px; font-size: 12.5px; color: var(--muted); }

.dash-empty-box {
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: var(--bg);
  padding: 56px 20px;
  text-align: center;
}
.dash-empty-title { margin: 0 0 4px; font-weight: 650; color: var(--ink); font-size: 15px; }
.dash-empty-sub { margin: 0; color: var(--muted); font-size: 13px; }

.source-list { display: flex; flex-direction: column; gap: 14px; padding: 4px 0; }
.source-row { display: flex; align-items: center; gap: 12px; }
.source-label { width: 130px; flex-shrink: 0; font-size: 13px; color: var(--ink); font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-bar-track { flex: 1; height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.source-bar-fill { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.source-count { width: 28px; text-align: right; font-weight: 700; font-size: 13px; color: var(--ink); flex-shrink: 0; }

.month-scroll-wrap { display: flex; align-items: center; gap: 6px; }
.month-scroll-btn {
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
}
.month-scroll-btn:hover { background: var(--bg); color: var(--ink); }
.month-scroll-track {
  display: flex;
  gap: 28px;
  overflow-x: auto;
  padding: 10px 4px 8px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
}
.month-scroll-track::-webkit-scrollbar { height: 6px; }
.month-scroll-track::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.month-col {
  flex: 0 0 auto;
  min-width: 70px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.month-value { font-size: 15px; font-weight: 700; color: var(--ink); }
.month-bar-track { width: 100%; height: 3px; background: var(--bg); border-radius: 2px; overflow: hidden; }
.month-bar-fill { display: block; height: 100%; background: var(--accent); border-radius: 2px; }
.month-label { font-size: 12px; color: var(--muted); white-space: nowrap; }

@media (max-width: 900px) {
  .dashboard-panels { grid-template-columns: 1fr; }
}

/* ---------- Dashboard: panel head + range filter pills ---------- */
.dash-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.dash-panel-head h3 { margin: 0 0 2px; }
.dash-panel-head .dash-panel-sub { margin: 0; }

.range-pills {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border-radius: 8px;
  padding: 3px;
  flex-shrink: 0;
}
.range-pill {
  padding: 5px 11px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 650;
  color: var(--muted);
  text-decoration: none;
  transition: background 0.12s ease, color 0.12s ease;
}
.range-pill:hover { color: var(--ink); }
.range-pill-active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 1px 2px rgba(16,18,22,0.08);
}
