:root {
  --ink: #1c2530;
  --ink-soft: #4b5768;
  --muted: #8792a2;
  --border: #e3e7ee;
  --bg: #f5f6f9;
  --surface: #ffffff;
  --brand: #2857c9;
  --brand-dark: #1d3f9c;
  --brand-soft: #eaf0ff;
  --success: #1a8a56;
  --success-soft: #e6f6ee;
  --danger: #c33636;
  --danger-soft: #fbeaea;
  --warn: #b8790c;
  --warn-soft: #fdf1de;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(28, 37, 48, 0.06), 0 1px 8px rgba(28, 37, 48, 0.04);
}

/* Dark theme (Admin > System Settings > Appearance). Deliberately leaves
   --brand/--brand-dark/--brand-soft alone here - those are computed per
   request from the chosen highlight colour and injected inline, already
   dark-mode-aware (see deriveBrandShades in src/utils/helpers.js). */
:root[data-theme="dark"] {
  --ink: #e7eaf0;
  --ink-soft: #b8c0cd;
  --muted: #838d9c;
  --border: #333c4a;
  --bg: #12161d;
  --surface: #1b212b;
  --success: #3ecb8d;
  --success-soft: rgba(62, 203, 141, 0.16);
  --danger: #e5686b;
  --danger-soft: rgba(229, 104, 107, 0.16);
  --warn: #e0a83f;
  --warn-soft: rgba(224, 168, 63, 0.16);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 8px rgba(0, 0, 0, 0.2);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 12px; font-weight: 650; color: var(--ink); }
h1 { font-size: 24px; }
h2 { font-size: 19px; }
h3 { font-size: 15px; }
h4 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }

p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.mt { margin-top: 20px; }

/* --- App shell --- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
}

.sidebar-brand { display: flex; align-items: center; gap: 8px; padding: 4px 8px 20px; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--brand); color: #fff; font-weight: 700; font-size: 14px;
  flex-shrink: 0;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-name { font-weight: 700; font-size: 15px; }
.brand-tagline {
  font-size: 9.5px; font-weight: 700; letter-spacing: 0.06em; color: var(--muted);
  display: flex; align-items: center; gap: 5px;
}
.brand-version {
  font-weight: 650; background: var(--brand-soft); color: var(--brand-dark);
  border-radius: 20px; padding: 1px 6px; letter-spacing: 0;
}

.side-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  display: block; padding: 9px 12px; border-radius: 8px;
  color: var(--ink-soft); font-weight: 500; font-size: 13.5px;
}
.nav-link:hover { background: var(--bg); text-decoration: none; }
.nav-link.active { background: var(--brand-soft); color: var(--brand-dark); }
.nav-group-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700;
  color: var(--muted); padding: 16px 12px 6px;
}

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 28px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.topbar-title { font-weight: 650; font-size: 17px; }
.topbar-user { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.user-name { font-weight: 600; }

.content { padding: 26px 28px 60px; max-width: 1100px; }

/* --- Buttons & links --- */
.btn {
  display: inline-block; padding: 9px 16px; border-radius: 8px; font-size: 13.5px;
  font-weight: 600; border: 1px solid transparent; cursor: pointer; text-decoration: none;
  line-height: 1.2;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { background: var(--brand-soft); color: var(--brand-dark); }
.btn-secondary:hover { background: #dde7ff; }
.btn-ghost { background: transparent; color: var(--ink-soft); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger-ghost { background: transparent; color: var(--danger); border-color: var(--danger-soft); }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.btn-block { display: block; width: 100%; text-align: center; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }

.link-btn {
  background: none; border: none; color: var(--brand); cursor: pointer;
  padding: 0; font-size: inherit; font-weight: 500;
}
.link-btn:hover { text-decoration: underline; }

/* --- Cards & layout --- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px 22px; margin-bottom: 20px; box-shadow: var(--shadow);
}
.card-narrow { max-width: 560px; }

.page-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 18px; gap: 14px; flex-wrap: wrap; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 820px) { .two-col { grid-template-columns: 1fr; } }

.quick-actions { display: flex; gap: 10px; margin-bottom: 22px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 22px; }
@media (max-width: 900px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat-value { font-size: 26px; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 12.5px; margin-top: 2px; }

/* --- Tables --- */
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border);
}
.table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: none; }
.row-muted { opacity: 0.55; }

/* --- Forms --- */
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 7px;
  font-size: 13.5px; font-family: inherit; color: var(--ink); background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.field-row { display: flex; gap: 14px; }
.field-row .field { flex: 1; }
.form-actions { display: flex; gap: 10px; margin-top: 6px; }
.search-form { display: flex; gap: 8px; }
.search-form input { padding: 9px 11px; border: 1px solid var(--border); border-radius: 7px; min-width: 240px; }
.inline-reset { display: flex; gap: 6px; margin-top: 8px; }
.inline-reset input { padding: 6px 9px; border: 1px solid var(--border); border-radius: 6px; }

/* --- Badges --- */
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11px;
  font-weight: 650; text-transform: capitalize; background: var(--bg); color: var(--ink-soft);
}
.badge-lg { font-size: 12.5px; padding: 5px 12px; }
.badge-role { background: var(--brand-soft); color: var(--brand-dark); }
.badge-draft { background: var(--bg); color: var(--ink-soft); }
.badge-sent, .badge-unpaid, .badge-pending { background: var(--warn-soft); color: var(--warn); }
.badge-accepted, .badge-paid, .badge-delivered { background: var(--success-soft); color: var(--success); }
.badge-rejected, .badge-cancelled { background: var(--danger-soft); color: var(--danger); }
.badge-so-pending { background: var(--warn-soft); color: var(--warn); }
.badge-so-in_progress { background: var(--brand-soft); color: var(--brand-dark); }
.badge-so-delivered { background: var(--success-soft); color: var(--success); }
.badge-so-cancelled { background: var(--danger-soft); color: var(--danger); }
.badge-po-draft { background: var(--bg); color: var(--ink-soft); }
.badge-po-ordered { background: var(--warn-soft); color: var(--warn); }
.badge-po-partially_received { background: var(--brand-soft); color: var(--brand-dark); }
.badge-po-received { background: var(--success-soft); color: var(--success); }
.badge-po-cancelled { background: var(--danger-soft); color: var(--danger); }
.badge-planning { background: var(--bg); color: var(--ink-soft); }
.badge-in_progress { background: var(--brand-soft); color: var(--brand-dark); }
.badge-uat { background: var(--warn-soft); color: var(--warn); }
.badge-completed { background: var(--success-soft); color: var(--success); }
.badge-todo { background: var(--bg); color: var(--ink-soft); }
.badge-done { background: var(--success-soft); color: var(--success); }

/* --- Notifications --- */
.notif-bell { position: relative; display: inline-flex; align-items: center; padding: 4px 8px; border-radius: 8px; color: var(--ink-soft); font-weight: 600; font-size: 13px; }
.notif-bell:hover { background: var(--bg); text-decoration: none; }
.notif-count { background: var(--danger); color: #fff; border-radius: 20px; padding: 1px 7px; font-size: 11px; font-weight: 700; margin-left: 5px; }
.notif-item { padding: 10px 0; border-bottom: 1px solid var(--border); }
.notif-item:last-child { border-bottom: none; }
.notif-item.unread { background: var(--brand-soft); border-radius: 8px; padding: 10px 12px; margin-bottom: 4px; border-bottom: none; }

/* --- Detail list --- */
.detail-list { display: grid; grid-template-columns: 110px 1fr; row-gap: 8px; column-gap: 10px; margin: 0 0 16px; }
.detail-list dt { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.detail-list dd { margin: 0; }

/* --- Proposal item builder --- */
.item-table th, .item-table td { padding: 6px 8px; }
.item-table input, .item-table select { padding: 6px 8px; font-size: 13px; }
.row-total { font-weight: 600; white-space: nowrap; }

.totals-box {
  display: flex; gap: 28px; justify-content: flex-end; padding: 14px 0 4px; margin-top: 8px;
  border-top: 1px solid var(--border);
}
.totals-box > div { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.totals-box span { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.totals-box strong { font-size: 16px; }

/* --- Alerts --- */
.alert { padding: 11px 14px; border-radius: 8px; font-size: 13.5px; margin-bottom: 16px; }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-success { background: var(--success-soft); color: var(--success); }

/* --- Auth --- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 34px; width: 100%; max-width: 380px; }
.auth-brand { display: flex; align-items: center; gap: 8px; margin-bottom: 18px; }
.auth-title { font-size: 19px; margin-bottom: 18px; }

/* --- Link box (share link) --- */
.link-box { display: flex; gap: 8px; align-items: center; }
.link-box input { flex: 1; padding: 9px 11px; border: 1px solid var(--border); border-radius: 7px; font-size: 13px; color: var(--ink-soft); background: var(--bg); }

/* --- Signature --- */
.signature-preview { max-width: 320px; border: 1px solid var(--border); border-radius: 8px; padding: 8px; background: #fff; }
.sig-canvas { width: 100%; max-width: 600px; height: 180px; border: 1.5px dashed var(--border); border-radius: 8px; background: #fff; touch-action: none; cursor: crosshair; display: block; margin-bottom: 6px; }

/* --- Public client-facing page --- */
.public-body { background: var(--bg); }
.public-shell { max-width: 780px; margin: 0 auto; padding: 30px 20px 60px; }
.public-header { display: flex; align-items: center; gap: 8px; margin-bottom: 22px; }
.public-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 30px 34px; }
.public-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 6px; }
.public-footer { text-align: center; color: var(--muted); font-size: 12px; margin-top: 24px; }

hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }

/* --- Document header (invoices) --- */
.doc-header { display: flex; align-items: flex-start; justify-content: space-between; }
.doc-header-right { text-align: right; }

/* --- Print --- */
@media print {
  .no-print, .sidebar, .topbar { display: none !important; }
  .app-shell { display: block; }
  .content { padding: 0; max-width: none; }
  .printable { box-shadow: none; border: none; }
  body { background: #fff; }
}
