:root {
  --bg: #F5F2EA;
  --surface: #FFFFFF;
  --surface-alt: #EFEAE0;
  --ink: #23291D;
  --ink-muted: #6E7364;
  --line: #E1DACB;
  --forest: #2F4B3C;
  --forest-dark: #223629;
  --forest-light: #DCE8DF;
  --rust: #B5602A;
  --rust-light: #F3DFCB;
  --clay: #3A6EA5;
  --clay-light: #DCE7F2;
  --gold: #B08A1E;
  --gold-light: #F1E6C6;
  --danger: #A3392F;
  --danger-light: #F4DBD6;
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(35,41,29,0.06), 0 6px 20px rgba(35,41,29,0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.5;
}

h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; margin: 0; color: var(--forest-dark); }

a { color: var(--forest); text-decoration: none; }

.hidden { display: none !important; }

/* ---------- Auth screen ---------- */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(1200px 600px at 15% -10%, var(--forest-light) 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 10%, var(--rust-light) 0%, transparent 55%),
    var(--bg);
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 36px 32px;
  box-shadow: var(--shadow);
}
.auth-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 26px; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--forest); color: #F5F2EA;
  font-family: var(--font-display); font-weight: 700; font-size: 17px;
  flex-shrink: 0;
}
.auth-brand h1 { font-size: 21px; }
.auth-sub { margin: 2px 0 0; color: var(--ink-muted); font-size: 13px; }
.auth-tabs { display: flex; gap: 4px; background: var(--surface-alt); padding: 4px; border-radius: 10px; margin-bottom: 22px; }
.auth-tab { flex: 1; padding: 9px; border: none; background: transparent; border-radius: 8px; font-weight: 600; color: var(--ink-muted); cursor: pointer; font-family: var(--font-body); font-size: 13.5px; }
.auth-tab.active { background: var(--surface); color: var(--forest-dark); box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--ink-muted); }
.auth-form input {
  font-family: var(--font-body); font-size: 14.5px; padding: 10px 12px;
  border-radius: 8px; border: 1px solid var(--line); background: var(--bg);
  color: var(--ink);
}
.auth-form input:focus { outline: 2px solid var(--forest); outline-offset: 1px; }
.auth-error { color: var(--danger); font-size: 13px; margin: -4px 0 0; min-height: 0; }
.auth-error:empty { display: none; }
.auth-hint { font-size: 12px; color: var(--ink-muted); line-height: 1.5; margin-top: 4px; }
.auth-hint code { background: var(--surface-alt); padding: 1px 5px; border-radius: 4px; font-family: var(--font-mono); }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0; background: var(--forest-dark); color: #EAF0EA;
  display: flex; flex-direction: column; padding: 22px 16px; position: fixed; top: 0; bottom: 0; left: 0;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 0 6px 22px; border-bottom: 1px solid rgba(255,255,255,0.1); margin-bottom: 18px; }
.sidebar-brand .brand-mark { background: #EAF0EA; color: var(--forest-dark); }
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 15px; color: #fff; }
.brand-sub { font-size: 11px; color: #AEBBAD; margin-top: 1px; }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar-nav a {
  color: #C7D4C5; padding: 10px 12px; border-radius: 8px; font-size: 13.5px; font-weight: 500;
  transition: background .12s ease;
}
.sidebar-nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar-nav a.active { background: rgba(255,255,255,0.12); color: #fff; font-weight: 600; }
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 12px 6px 0; border-top: 1px solid rgba(255,255,255,0.1); margin-top: 12px; }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--rust); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.user-name { font-size: 13px; font-weight: 600; color: #fff; }
.sidebar-user a { font-size: 12px; color: #AEBBAD; }
.sidebar-user a:hover { color: #fff; }

.main-view { margin-left: 232px; flex: 1; min-width: 0; padding: 28px 34px 60px; max-width: 1320px; }
.view-root { display: flex; flex-direction: column; gap: 20px; }

/* ---------- Common layout bits ---------- */
.view-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.view-header h2 { font-size: 24px; }
.view-header .sub { color: var(--ink-muted); font-size: 13.5px; margin-top: 4px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card-flat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(2,1fr);} }

.stat-card { display: flex; flex-direction: column; gap: 6px; }
.stat-label { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-muted); font-weight: 600; }
.stat-value { font-family: var(--font-display); font-size: 22px; font-weight: 600; color: var(--forest-dark); white-space: nowrap; }
.stat-value.rust { color: var(--rust); }
.stat-sub { font-size: 12px; color: var(--ink-muted); }

.btn {
  font-family: var(--font-body); font-weight: 600; font-size: 13px; padding: 9px 16px;
  border-radius: 8px; border: 1px solid transparent; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  transition: transform .05s ease, background .12s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--forest); color: #fff; }
.btn-primary:hover { background: var(--forest-dark); }
.btn-outline { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-outline:hover { background: var(--surface-alt); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger-light); }
.btn-danger:hover { background: var(--danger-light); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }
.btn-icon { padding: 6px 8px; }

.tag {
  display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 99px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.tag-forest { background: var(--forest-light); color: var(--forest-dark); }
.tag-rust { background: var(--rust-light); color: var(--rust); }
.tag-clay { background: var(--clay-light); color: var(--clay); }
.tag-gold { background: var(--gold-light); color: var(--gold); }
.tag-danger { background: var(--danger-light); color: var(--danger); }
.tag-muted { background: var(--surface-alt); color: var(--ink-muted); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--ink-muted); font-weight: 700; padding: 8px 10px; border-bottom: 2px solid var(--line);
  white-space: nowrap;
}
tbody td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:hover { background: rgba(47,75,60,0.035); }
.table-wrap { overflow-x: auto; }

input, select, textarea {
  font-family: var(--font-body); font-size: 13.5px; padding: 8px 10px; border-radius: 7px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--forest); outline-offset: 0; }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--ink-muted); }
.field-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.field-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar select, .toolbar input { width: auto; min-width: 140px; }
.search-box { position: relative; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(35,41,29,0.45); display: flex; align-items: flex-start;
  justify-content: center; padding: 40px 20px; overflow-y: auto; z-index: 100;
}
.modal {
  background: var(--surface); border-radius: 14px; width: 100%; max-width: 640px; padding: 26px 28px 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.modal-wide { max-width: 820px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-header h3 { font-size: 18px; }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--ink-muted); }
.modal-body { display: flex; flex-direction: column; gap: 14px; max-height: 70vh; overflow-y: auto; padding-right: 4px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.attachment-list { display: flex; flex-direction: column; gap: 8px; }
.attachment-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--surface-alt); border-radius: 8px; padding: 8px 12px; font-size: 12.5px;
}
.attachment-item a { font-weight: 600; }
.attachment-meta { color: var(--ink-muted); font-size: 11.5px; }

.progress-bar { height: 8px; border-radius: 99px; background: var(--surface-alt); overflow: hidden; }
.progress-bar-fill { height: 100%; border-radius: 99px; background: var(--forest); }
.progress-bar-fill.over { background: var(--danger); }

.loading, .empty-state { color: var(--ink-muted); padding: 30px; text-align: center; font-size: 13.5px; }

.toast {
  position: fixed; bottom: 24px; right: 24px; background: var(--forest-dark); color: #fff;
  padding: 12px 18px; border-radius: 9px; font-size: 13.5px; box-shadow: var(--shadow); z-index: 200;
  max-width: 340px;
}
.toast.error { background: var(--danger); }

.tabs-row { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tabs-row button {
  background: none; border: none; padding: 10px 16px; font-size: 13.5px; font-weight: 600;
  color: var(--ink-muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs-row button.active { color: var(--forest-dark); border-bottom-color: var(--forest); }

.zone-pill-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* Timeline / gantt */
.gantt-scroll { overflow-x: auto; }
.gantt-grid { display: grid; }
.gantt-row-label { padding: 8px 10px; font-size: 12.5px; font-weight: 600; white-space: nowrap; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.gantt-track { position: relative; border-bottom: 1px solid var(--line); height: 38px; background-image: repeating-linear-gradient(to right, var(--line) 0, var(--line) 1px, transparent 1px, transparent var(--col-width, 26px)); }
.gantt-bar { position: absolute; top: 7px; height: 24px; border-radius: 6px; font-size: 11px; color: #fff; display: flex; align-items: center; padding: 0 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
.gantt-header-cell { font-size: 10.5px; text-align: center; color: var(--ink-muted); padding: 4px 0; border-bottom: 2px solid var(--line); font-weight: 700; }

.section-title { font-family: var(--font-display); font-size: 17px; font-weight: 600; color: var(--forest-dark); margin-bottom: 2px; }

.pill-btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 5px 12px;
  font-size: 12px; font-weight: 600; cursor: pointer; color: var(--ink-muted);
}
.pill-btn.active { background: var(--forest); color: #fff; border-color: var(--forest); }

.kv-list { display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.kv-list .row { display: flex; justify-content: space-between; gap: 10px; }
.kv-list .k { color: var(--ink-muted); }

.mini-note { font-size: 11.5px; color: var(--ink-muted); }

::-webkit-scrollbar { height: 8px; width: 8px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 99px; }

@media (max-width: 900px) {
  .sidebar { position: static; width: 100%; flex-direction: row; align-items: center; padding: 12px 16px; }
  .sidebar-nav { flex-direction: row; overflow-x: auto; }
  .sidebar-brand, .sidebar-user { display: none; }
  .main-view { margin-left: 0; padding: 20px; }
  .app-shell { flex-direction: column; }
}

/* Owner / Support name chips */
.chip-list { display: flex; flex-wrap: wrap; gap: 4px; }
.person-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2, #EFEBE0);
  border: 1px solid var(--border, #DDD6C4);
  font-size: 11.5px;
  white-space: nowrap;
}
.name-picker { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 0; }
.name-chip { display: inline-flex; cursor: pointer; }
.name-chip input { position: absolute; opacity: 0; pointer-events: none; }
.name-chip span {
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--border, #DDD6C4);
  background: var(--surface, #FFF);
  font-size: 12.5px;
  font-weight: 400;
  transition: all .12s ease;
}
.name-chip:hover span { border-color: var(--accent, #2F4B3C); }
.name-chip input:checked + span {
  background: var(--accent, #2F4B3C);
  border-color: var(--accent, #2F4B3C);
  color: #fff;
  font-weight: 600;
}

/* ---- Accounts / Invoices ---- */
.sidebar-heading { margin: 16px 6px 4px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,0.1); font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: #AEBBAD; }
.inv-pills { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.inv-pill { display: inline-flex; align-items: center; gap: 7px; padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line, #ddd); background: #fff; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--ink-muted, #555); }
.inv-pill.active { background: var(--forest-dark, #24352a); color: #fff; border-color: var(--forest-dark, #24352a); }
.inv-pill .inv-count { background: rgba(0,0,0,0.08); border-radius: 999px; padding: 1px 8px; font-size: 11.5px; }
.inv-pill.active .inv-count { background: rgba(255,255,255,0.2); }
.inv-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot-gold { background: #c98a00; } .dot-blue { background: #3a6ea5; } .dot-danger { background: #b23b3b; } .dot-forest { background: #4f7942; }
.inv-card { padding: 0; margin-bottom: 12px; overflow: hidden; }
.inv-card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; cursor: pointer; }
.inv-card-head:hover { background: rgba(0,0,0,0.02); }
.inv-head-left { display: flex; align-items: center; gap: 12px; }
.inv-title { font-weight: 700; font-size: 15.5px; }
.inv-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-muted, #666); margin-top: 3px; }
.inv-flag { color: #6b4fa0; font-weight: 600; } .inv-flag-paid { color: #2f7c4f; }
.inv-head-right { display: flex; align-items: center; gap: 10px; }
.inv-chevron { color: var(--ink-muted, #999); font-size: 11px; }
.inv-card-body { border-top: 1px solid var(--line, #eee); padding: 16px 18px 18px; }
.inv-section { margin-bottom: 10px; }
.inv-label { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-muted, #777); margin-bottom: 5px; }
.inv-doc-panel { flex: 1; background: rgba(0,0,0,0.03); border-radius: 10px; padding: 12px 14px; }
.inv-doc-panel-paid { background: #eef7ef; border: 1px solid #cfe6d2; }
.inv-doc { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 0; }
.inv-upload { display: flex; gap: 6px; margin-top: 8px; align-items: center; }
.inv-upload input[type="file"] { font-size: 12px; }
.inv-actions { display: flex; gap: 8px; margin-top: 14px; align-items: center; }
.inv-note-danger { background: #fbeeee; border: 1px solid #ecc9c9; color: #8f2f2f; border-radius: 8px; padding: 9px 12px; font-size: 13px; margin: 8px 0; }
.inv-hint { background: #fdf6e3; border: 1px solid #eadfb8; color: #7a6215; border-radius: 8px; padding: 9px 12px; font-size: 13px; }
