/* ============================================================
   Astorga Outdoor Living — Internal Dashboard
   Ledger-luxury: limestone paper, espresso ink, brass accents.
   Mobile-first; desktop enhances at 900px.
   ============================================================ */

@font-face {
  font-family: 'Fraunces';
  src: url('/fonts/fraunces-600.woff2') format('woff2');
  font-weight: 600; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Fraunces';
  src: url('/fonts/fraunces-700.woff2') format('woff2');
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Sans';
  src: url('/fonts/ibmplexsans-400.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Sans';
  src: url('/fonts/ibmplexsans-500.woff2') format('woff2');
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Sans';
  src: url('/fonts/ibmplexsans-600.woff2') format('woff2');
  font-weight: 600; font-style: normal; font-display: swap;
}

:root {
  --paper: #F5F1E8;
  --paper-deep: #EDE7D8;
  --card: #FFFFFF;
  --ink: #221C13;
  --ink-2: #6B6152;
  --ink-3: #99907F;
  --line: #E4DCCB;
  --line-soft: #EEE8DA;
  --brass: #8C6D2F;
  --brass-deep: #6F5623;
  --brass-wash: #F4EDDD;
  --green: #177245;
  --green-wash: #E7F2EB;
  --amber: #D07912;
  --amber-wash: #FBF0DF;
  --red: #A4432E;
  --red-wash: #F8E9E4;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(34, 28, 19, .05), 0 4px 16px rgba(34, 28, 19, .06);
  --sans: 'IBM Plex Sans', -apple-system, sans-serif;
  --serif: 'Fraunces', Georgia, serif;
  --tabbar-h: calc(62px + env(safe-area-inset-bottom));
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 85% -10%, rgba(140, 109, 47, .07), transparent 60%),
    var(--paper);
  min-height: 100vh;
  min-height: 100dvh;
}

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

::selection { background: var(--brass-wash); }

.skip {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--ink); color: #fff; padding: 8px 14px; border-radius: 0 0 8px 0;
}
.skip:focus { left: 0; }

/* ---------- Shell ---------- */

.shell { display: flex; min-height: 100vh; min-height: 100dvh; }

.main {
  flex: 1;
  min-width: 0;
  padding: 18px 16px calc(var(--tabbar-h) + 84px);
  max-width: 1120px;
  margin: 0 auto;
  width: 100%;
}

/* ---------- Sidebar (desktop) ---------- */

.sidebar {
  display: none;
  width: 232px;
  flex-shrink: 0;
  background: var(--ink);
  color: #D8D0C0;
  padding: 26px 18px calc(18px + env(safe-area-inset-bottom));
  position: sticky; top: 0; height: 100vh; height: 100dvh;
  flex-direction: column;
  gap: 4px;
}
.brand {
  font-family: var(--serif); font-weight: 700; font-size: 21px; letter-spacing: .04em;
  color: #F2ECDF; margin-bottom: 2px;
}
.brand small {
  display: block; font-family: var(--sans); font-weight: 500; font-size: 10.5px;
  letter-spacing: .22em; text-transform: uppercase; color: var(--brass);
  margin-top: 3px;
}
.sidebar nav { margin-top: 26px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a {
  display: flex; align-items: center; gap: 11px;
  color: #C9C0AC; padding: 9px 12px; border-radius: var(--radius-sm);
  font-weight: 500; font-size: 14px;
}
.sidebar nav a svg { width: 17px; height: 17px; opacity: .75; }
.sidebar nav a:hover { background: rgba(255, 255, 255, .06); color: #F2ECDF; text-decoration: none; }
.sidebar nav a.is-active { background: rgba(140, 109, 47, .28); color: #F2ECDF; }
.sidebar nav a.is-active svg { opacity: 1; }
.sidebar .nav-sep { height: 1px; background: rgba(255,255,255,.09); margin: 10px 8px; }
.sidebar form button {
  display: flex; align-items: center; gap: 11px; width: 100%;
  background: none; border: 0; color: #C9C0AC; padding: 9px 12px;
  border-radius: var(--radius-sm); font: 500 14px var(--sans); cursor: pointer;
}
.sidebar form button:hover { background: rgba(255,255,255,.06); color: #F2ECDF; }
.sidebar form button svg { width: 17px; height: 17px; opacity: .75; }

/* ---------- Top bar ---------- */

.topbar {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 12px; margin-bottom: 18px;
}
.topbar h1 {
  font-family: var(--serif); font-weight: 600; font-size: 26px; line-height: 1.15;
  letter-spacing: -.01em;
}
.topbar .sub { color: var(--ink-2); font-size: 13px; margin-top: 2px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font: 600 14.5px var(--sans); border: 0; cursor: pointer;
  border-radius: 10px; padding: 11px 17px; min-height: 44px;
  text-decoration: none; transition: background .12s ease, transform .06s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: scale(.98); }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--brass); color: #FFF9EC; box-shadow: var(--shadow); }
.btn-primary:hover { background: var(--brass-deep); }
.btn-ghost { background: transparent; color: var(--ink-2); border: 1px solid var(--line); }
.btn-ghost:hover { border-color: var(--ink-3); color: var(--ink); }
.btn-danger { background: transparent; color: var(--red); border: 1px solid var(--line); }
.btn-danger:hover { background: var(--red-wash); border-color: var(--red); }
.btn-sm { padding: 7px 12px; min-height: 36px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }

/* ---------- Cards & sections ---------- */

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px;
}
.section { margin-bottom: 26px; }
.section-title {
  font: 600 11.5px var(--sans); letter-spacing: .18em; text-transform: uppercase;
  color: var(--ink-2); margin-bottom: 10px;
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
}
.section-title a { font-size: 12px; letter-spacing: 0; text-transform: none; font-weight: 500; }

/* ---------- Stat tiles ---------- */

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat-grid-5 { grid-template-columns: repeat(2, 1fr); }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 11px 12px; box-shadow: var(--shadow); min-width: 0;
}
.stat .label {
  font-size: 10.5px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-2); line-height: 1.35;
}
.stat .value {
  /* Fluid size so full dollar amounts always fit 3-across on a 375px phone. */
  font-family: var(--serif); font-weight: 600; font-size: clamp(13.5px, 4vw, 21px);
  line-height: 1.2; margin-top: 4px; letter-spacing: -.02em; white-space: nowrap;
}
.stat .value.pos { color: var(--green); }
.stat .value.neg { color: var(--red); }
.stat .hint { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; }
.stat.stat-accent { background: linear-gradient(135deg, #2A2418, var(--ink)); border-color: var(--ink); }
.stat.stat-accent .label { color: #A89A7E; }
.stat.stat-accent .value { color: #F2ECDF; }

/* ---------- Row lists (ledger rows) ---------- */

.rows { display: flex; flex-direction: column; }
.row-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 2px; border-bottom: 1px solid var(--line-soft);
  color: inherit; min-height: 56px;
}
a.row-item:hover { text-decoration: none; background: var(--brass-wash); margin: 0 -8px; padding: 12px 10px; border-radius: 8px; }
.row-item:last-child { border-bottom: 0; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 12.5px; color: var(--ink-2); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-end { text-align: right; flex-shrink: 0; }
.row-amount { font-weight: 600; font-size: 15px; font-variant-numeric: tabular-nums; }
.row-amount.pos { color: var(--green); }
.row-date { font-size: 11.5px; color: var(--ink-3); margin-top: 1px; font-variant-numeric: tabular-nums; }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px;
  background: var(--paper-deep); color: var(--ink-2); white-space: nowrap;
  vertical-align: middle;
}
.chip svg { width: 11px; height: 11px; }
.chip-green { background: var(--green-wash); color: var(--green); }
.chip-amber { background: var(--amber-wash); color: #8A5410; }
.chip-red { background: var(--red-wash); color: var(--red); }
.chip-brass { background: var(--brass-wash); color: var(--brass-deep); }

.empty {
  text-align: center; color: var(--ink-3); padding: 34px 12px; font-size: 14px;
}
.empty a { font-weight: 600; }

/* ---------- Forms ---------- */

.form-grid { display: flex; flex-direction: column; gap: 14px; }
.field label {
  display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2);
  margin-bottom: 5px; letter-spacing: .02em;
}
.field label .req { color: var(--red); }
.field input[type="text"], .field input[type="date"], .field input[type="email"],
.field input[type="password"], .field input[type="number"], .field select, .field textarea {
  width: 100%; font: 400 16px var(--sans); color: var(--ink);
  background: var(--card); border: 1.5px solid var(--line); border-radius: 10px;
  padding: 12px 13px; min-height: 48px; appearance: none; -webkit-appearance: none;
}
.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236B6152' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 13px center; padding-right: 34px;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--brass); box-shadow: 0 0 0 3px rgba(140, 109, 47, .16);
}
.field textarea { min-height: 74px; resize: vertical; }
.field .help { font-size: 12px; color: var(--ink-3); margin-top: 4px; }
.field-error { font-size: 12.5px; color: var(--red); font-weight: 500; margin-top: 4px; }
.field input.has-error, .field select.has-error { border-color: var(--red); }

/* Must out-specify `.field input[type="text"]` above. */
.field.amount-field input[type="text"] {
  font-family: var(--serif); font-weight: 600; font-size: 27px; min-height: 60px;
  letter-spacing: -.01em;
}
/* minmax(0,…) lets date inputs — which carry a wide intrinsic min-width on
   iOS — shrink instead of pushing the page sideways. */
.field-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.field-row input { min-width: 0; }

.check { display: flex; gap: 9px; align-items: center; font-size: 14px; }
.check input { width: 19px; height: 19px; accent-color: var(--brass); flex-shrink: 0; }

/* Receipt / file upload */
.upload {
  display: flex; align-items: center; gap: 11px;
  border: 1.5px dashed var(--brass); border-radius: 10px;
  background: var(--brass-wash); padding: 13px 14px; cursor: pointer;
  font-weight: 600; font-size: 14.5px; color: var(--brass-deep); min-height: 52px;
}
.upload svg { width: 21px; height: 21px; flex-shrink: 0; }
.upload input { display: none; }
.upload .upload-name {
  font-weight: 400; color: var(--ink-2); font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.form-actions {
  display: flex; gap: 10px; margin-top: 6px;
  position: sticky; bottom: calc(var(--tabbar-h) + 10px); z-index: 5;
  background: linear-gradient(transparent, var(--paper) 30%);
  padding-top: 12px;
}
.form-actions .btn-primary { flex: 1; }

details.more-fields { border-top: 1px solid var(--line-soft); padding-top: 4px; }
details.more-fields summary {
  cursor: pointer; font-weight: 600; font-size: 13.5px; color: var(--brass-deep);
  padding: 8px 0; list-style: none; -webkit-tap-highlight-color: transparent;
}
details.more-fields summary::-webkit-details-marker { display: none; }
details.more-fields summary::after { content: ' +'; }
details.more-fields[open] summary::after { content: ' −'; }
details.more-fields .form-grid { margin-top: 8px; }

/* ---------- Filters ---------- */

details.filters { margin-bottom: 14px; }
details.filters summary {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  font: 600 13.5px var(--sans); color: var(--ink-2);
  border: 1px solid var(--line); border-radius: 99px; padding: 8px 15px;
  background: var(--card); list-style: none; -webkit-tap-highlight-color: transparent;
}
details.filters summary::-webkit-details-marker { display: none; }
details.filters summary svg { width: 14px; height: 14px; }
details.filters[open] summary { border-color: var(--brass); color: var(--brass-deep); }
.filters-body {
  margin-top: 10px; padding: 14px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.filters-body .field-full { grid-column: 1 / -1; }
.filters-body .btn { min-height: 44px; }

.searchbar { position: relative; margin-bottom: 12px; }
.searchbar input {
  width: 100%; font: 400 16px var(--sans);
  border: 1.5px solid var(--line); border-radius: 99px; background: var(--card);
  padding: 11px 16px 11px 40px; min-height: 46px;
}
.searchbar input:focus { outline: none; border-color: var(--brass); box-shadow: 0 0 0 3px rgba(140,109,47,.16); }
.searchbar svg {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--ink-3); pointer-events: none;
}

/* ---------- Charts ---------- */

.chart-card h3 { font: 600 13.5px var(--sans); margin-bottom: 2px; }
.chart-card .chart-sub { font-size: 12px; color: var(--ink-3); margin-bottom: 12px; }
.chart-grid { display: grid; gap: 10px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.hbar-row { display: grid; grid-template-columns: minmax(90px, 32%) 1fr auto; gap: 10px; align-items: center; padding: 5px 0; }
.hbar-label { font-size: 12.5px; font-weight: 500; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { background: var(--paper-deep); border-radius: 4px; height: 14px; overflow: hidden; }
.hbar-fill { background: var(--amber); height: 100%; border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar-value { font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; }

.svg-chart { width: 100%; height: auto; display: block; }
.svg-chart text { font-family: var(--sans); }

/* ---------- Tables (reports, settings) ---------- */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th {
  text-align: left; font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-2); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.data td { padding: 10px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data td.num { font-weight: 600; }

/* ---------- Flash & errors ---------- */

.flash {
  display: flex; align-items: center; gap: 9px;
  background: var(--green-wash); color: var(--green); border: 1px solid #BFDCCB;
  font-weight: 500; font-size: 14px; border-radius: 10px; padding: 11px 14px;
  margin-bottom: 14px; animation: flash-in .25s ease;
}
.flash svg { width: 16px; height: 16px; flex-shrink: 0; }
@keyframes flash-in { from { opacity: 0; transform: translateY(-6px); } }
.error-box {
  background: var(--red-wash); color: var(--red); border: 1px solid #E4C0B5;
  font-size: 13.5px; border-radius: 10px; padding: 11px 14px; margin-bottom: 14px;
}
.error-box ul { margin-left: 17px; }

/* ---------- Pagination ---------- */

.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 16px; }
.pager .pager-info { font-size: 12.5px; color: var(--ink-3); }

/* ---------- Bottom tab bar (mobile) ---------- */

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; align-items: stretch; justify-content: space-around;
  background: rgba(255, 255, 255, .92);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  height: var(--tabbar-h);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; font-size: 10px; font-weight: 600; letter-spacing: .02em;
  color: var(--ink-3); -webkit-tap-highlight-color: transparent;
}
.tabbar a:hover { text-decoration: none; }
.tabbar a svg { width: 21px; height: 21px; }
.tabbar a.is-active { color: var(--brass-deep); }
.tabbar .tab-fab {
  position: relative; flex: 0 0 74px;
}
.tabbar .tab-fab span {
  position: absolute; left: 50%; top: -18px; transform: translateX(-50%);
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--brass); color: #FFF9EC;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(111, 86, 35, .4);
  border: 3px solid var(--paper);
}
.tabbar .tab-fab span svg { width: 23px; height: 23px; }
.tabbar .tab-fab small {
  position: absolute; left: 0; right: 0; bottom: 7px; text-align: center;
  font-size: 10px; font-weight: 600; color: var(--brass-deep);
}

/* ---------- Login ---------- */

.login-wrap {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center; padding: 22px;
  background:
    radial-gradient(900px 420px at 15% -5%, rgba(140, 109, 47, .12), transparent 55%),
    radial-gradient(700px 380px at 100% 100%, rgba(23, 114, 69, .05), transparent 50%),
    var(--paper);
}
.login-card { width: 100%; max-width: 390px; }
.login-brand { text-align: center; margin-bottom: 26px; }
.login-brand .mark {
  font-family: var(--serif); font-weight: 700; font-size: 34px; letter-spacing: .02em;
}
.login-brand .mark em { font-style: normal; color: var(--brass); }
.login-brand p {
  font-size: 11px; font-weight: 600; letter-spacing: .28em; text-transform: uppercase;
  color: var(--ink-2); margin-top: 4px;
}
.login-card .card { padding: 22px; }

/* ---------- Detail blocks (project show, owner rows) ---------- */

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; font-size: 13.5px; }
.kv dt { color: var(--ink-2); }
.kv dd { font-weight: 500; text-align: right; font-variant-numeric: tabular-nums; }

details.row-expand { border-bottom: 1px solid var(--line-soft); }
details.row-expand:last-child { border-bottom: 0; }
details.row-expand summary { list-style: none; cursor: pointer; -webkit-tap-highlight-color: transparent; }
details.row-expand summary::-webkit-details-marker { display: none; }
details.row-expand .expand-body { padding: 4px 2px 16px; }

/* ---------- Settings ---------- */

.settings-list { display: flex; flex-direction: column; }
.settings-item {
  display: flex; gap: 8px; align-items: center; padding: 7px 0;
  border-bottom: 1px solid var(--line-soft); flex-wrap: wrap;
}
.settings-item input[type="text"] { flex: 1 1 130px; }
.settings-item .btn { flex-shrink: 0; }
.settings-item:last-child { border-bottom: 0; }
.settings-item input[type="text"] {
  flex: 1; min-width: 0; font: 400 14px var(--sans);
  border: 1px solid transparent; border-radius: 8px; padding: 8px 10px; background: transparent;
}
.settings-item input[type="text"]:hover { border-color: var(--line); }
.settings-item input[type="text"]:focus { outline: none; border-color: var(--brass); background: var(--card); }
.settings-item .check { font-size: 12.5px; color: var(--ink-2); }
.settings-add { display: flex; gap: 8px; margin-top: 10px; }
.settings-add input {
  flex: 1; min-width: 0; font: 400 14px var(--sans);
  border: 1.5px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
.settings-add input:focus { outline: none; border-color: var(--brass); }

/* ---------- Utilities ---------- */

.mt-2 { margin-top: 8px; } .mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; } .mb-4 { margin-bottom: 16px; }
.muted { color: var(--ink-3); font-size: 12.5px; }
.text-right { text-align: right; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 10px; }

/* ---------- Desktop ---------- */

@media (min-width: 900px) {
  body { font-size: 14.5px; }
  .sidebar { display: flex; }
  .tabbar { display: none; }
  .main { padding: 30px 34px 60px; }
  :root { --tabbar-h: 0px; }
  .form-actions { position: static; background: none; padding-top: 0; }
  .stat-grid-5 { grid-template-columns: repeat(5, 1fr); }
  .chart-grid { grid-template-columns: 1fr 1fr; }
  .chart-grid .chart-card-wide { grid-column: 1 / -1; }
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .filters-body { grid-template-columns: repeat(4, 1fr); }
  .topbar h1 { font-size: 30px; }
  .stat .value { font-size: 24px; }
  .form-card { max-width: 620px; }
  .login-card .card { padding: 30px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
