:root {
  --navy: #3a3a3a; --navy-dark: #262626; --navy-light: #c1121f; --red-brand: #c1121f; --orange: #f28c28; --orange-light: #fdebd9;
  --gold: #f6a623; --green: #1f8a5b; --green-bg: #e6f4ec; --red: #c0392b; --red-bg: #fbeae8; --amber: #b7791f; --amber-bg: #fff4e0;
  --bg: #f3f5f8; --surface: #ffffff; --border: #dde3ea; --text: #1a1f2b; --muted: #5f6b7a; --muted-light: #8a95a3;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px; --sidebar-w: 250px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; font-size: 14px; line-height: 1.45; }
a { color: var(--navy-light); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 650; color: var(--navy); }
h1 { font-size: 22px; } h2 { font-size: 16px; } h3 { font-size: 14px; }
p { margin: 0 0 8px; }
[hidden] { display: none !important; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); } .small { font-size: 12px; } .bold { font-weight: 650; }
.pos { color: var(--green); } .neg { color: var(--red); } .warn { color: var(--amber); }
.mt { margin-top: 16px; } .mb { margin-bottom: 16px; } .mt-sm { margin-top: 8px; }
.nowrap { white-space: nowrap; }

/* ---------- Login ---------- */
.login-view { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--navy-dark), var(--navy-light)); padding: 20px; }
.login-card { background: var(--surface); border-radius: 14px; padding: 32px; width: 100%; max-width: 400px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.login-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 24px; }
.login-foot { margin-top: 18px; color: var(--muted); font-size: 12px; text-align: center; }
.brand-mark { width: 42px; height: 42px; border-radius: 9px; background: var(--navy); color: var(--gold); font-weight: 800; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
.brand-name { font-weight: 750; letter-spacing: .5px; color: var(--navy); font-size: 14px; }
.brand-sub { font-size: 12px; color: var(--muted); }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); background: var(--navy-dark); color: #dfe8f0; display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; left: 0; z-index: 30; transition: transform .2s ease; }
.sidebar-brand { display: flex; gap: 10px; align-items: center; padding: 16px 16px 12px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar-brand .brand-name { color: #fff; } .sidebar-brand .brand-sub { color: #9fb3c4; }
.sidebar-close { display: none; margin-left: auto; color: #fff; }
.nav { flex: 1; overflow-y: auto; padding: 10px 0; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 18px; color: #c9d6e2; font-size: 13.5px; border-left: 3px solid transparent; }
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav a.active { background: rgba(255,255,255,.1); color: #fff; border-left-color: var(--gold); }
.nav .nav-group { padding: 12px 18px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: #8aa0b4; }
.nav .nav-sub a { padding-left: 34px; font-size: 13px; }
.nav-icon { width: 18px; text-align: center; opacity: .9; }
.sidebar-foot { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.08); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.nav-user { font-size: 12px; line-height: 1.3; } .nav-user b { color: #fff; display: block; } .nav-user span { color: #9fb3c4; }
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 25; }
.main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar-search { display: flex; gap: 6px; flex: 1; max-width: 520px; }
.topbar-search input { flex: 1; }
#menu-btn { display: none; }
.demo-badge { margin-left: auto; background: var(--gold); color: #4a3a00; font-weight: 700; font-size: 11px; padding: 4px 10px; border-radius: 999px; letter-spacing: .5px; cursor: help; }
.content { padding: 22px 24px; flex: 1; }
.app-foot { padding: 12px 24px; color: var(--muted-light); font-size: 12px; text-align: center; }

/* ---------- Page header ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); border-top: 3px solid var(--navy); }
.stat.green { border-top-color: var(--green); } .stat.red { border-top-color: var(--red); } .stat.gold { border-top-color: var(--gold); } .stat.grey { border-top-color: var(--muted-light); }
.stat .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 4px; color: var(--text); font-variant-numeric: tabular-nums; }
.stat .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.tbl th { background: #f6f8fa; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .3px; white-space: nowrap; }
.tbl tbody tr:hover { background: #f9fbfd; }
.tbl tfoot td { font-weight: 700; background: #f0f4f8; }
.tbl tr.row-link { cursor: pointer; }
.tbl .empty { text-align: center; color: var(--muted); padding: 28px; font-style: italic; }
.tbl th.sortable { cursor: pointer; user-select: none; } .tbl th.sortable:hover { color: var(--navy); }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 12px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 650; white-space: nowrap; background: #e8eef5; color: var(--navy); }
.badge.green { background: var(--green-bg); color: var(--green); } .badge.red { background: var(--red-bg); color: var(--red); }
.badge.amber { background: var(--amber-bg); color: var(--amber); } .badge.grey { background: #eceff3; color: var(--muted); } .badge.demo { background: var(--gold); color: #4a3a00; }
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; border: 1px solid; }
.alert.warning { background: var(--amber-bg); border-color: #f0d49a; color: #6b4600; }
.alert.danger { background: var(--red-bg); border-color: #f1b7b1; color: #7a231a; }
.alert.info { background: #e8f0f8; border-color: #bcd3e8; color: var(--navy); }
.alert.success { background: var(--green-bg); border-color: #b5dfc7; color: #145c3b; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: 13px; }
.field > span { color: var(--muted); font-weight: 600; font-size: 12px; }
.field .req::after { content: " *"; color: var(--red); }
input, select, textarea { font: inherit; color: var(--text); background: #fff; border: 1px solid #c7cfd8; border-radius: 7px; padding: 8px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(20,90,133,.25); border-color: var(--navy-light); }
input[type="checkbox"], input[type="radio"] { width: auto; }
textarea { min-height: 70px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-error { background: var(--red-bg); color: var(--red); padding: 8px 12px; border-radius: 7px; margin-bottom: 12px; font-size: 13px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.filters .field { margin-bottom: 0; min-width: 140px; flex: 1 1 140px; max-width: 260px; }
.filters .field.wide { max-width: 360px; flex: 2 1 220px; }
.inline-total { font-size: 13px; color: var(--muted); }
.total-box { background: #f0f4f8; border-radius: 8px; padding: 10px 14px; display: flex; justify-content: space-between; gap: 12px; font-weight: 650; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn { font: inherit; font-weight: 600; border: 1px solid #c7cfd8; background: #fff; color: var(--text); padding: 8px 14px; border-radius: 7px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { background: #f4f6f9; } .btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--navy); border-color: var(--navy); color: #fff; } .btn-primary:hover { background: var(--navy-light); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; } .btn-danger:hover { background: #a93226; }
.btn-ghost { background: transparent; border-color: rgba(255,255,255,.3); color: #fff; } .btn-ghost:hover { background: rgba(255,255,255,.1); }
.btn-sm { padding: 5px 10px; font-size: 12px; } .btn-block { width: 100%; justify-content: center; }
.icon-btn { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--navy); padding: 4px 8px; }
.btn-link { background: none; border: none; color: var(--navy-light); cursor: pointer; padding: 0; font: inherit; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10,20,30,.5); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 30px 12px; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 760px; box-shadow: 0 25px 60px rgba(0,0,0,.35); animation: pop .15s ease; }
.modal.narrow { max-width: 460px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 18px 20px; }
.modal-foot { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Toast ---------- */
.toast-root { position: fixed; bottom: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--navy-dark); color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 8px 20px rgba(0,0,0,.25); font-size: 13px; max-width: 360px; animation: pop .2s ease; }
.toast.success { background: var(--green); } .toast.error { background: var(--red); }

/* ---------- Charts ---------- */
.chart { width: 100%; height: auto; display: block; font-family: inherit; }
.chart text { font-size: 11px; fill: var(--muted); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
.hbar-row { display: grid; grid-template-columns: minmax(110px, 40%) 1fr auto; gap: 8px; align-items: center; font-size: 13px; padding: 4px 0; }
.hbar-row .bar { height: 12px; background: #e6ecf2; border-radius: 6px; overflow: hidden; }
.hbar-row .bar i { display: block; height: 100%; background: var(--navy-light); border-radius: 6px; }
.hbar-row .bar i.over { background: var(--red); } .hbar-row .bar i.near { background: var(--amber); }
.hbar-row .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Detail lists ---------- */
.dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13px; }
.dl dt { color: var(--muted); } .dl dd { margin: 0; }
.attachment { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; flex-wrap: wrap; }
.history { font-size: 12px; } .history li { margin-bottom: 6px; } .history code { background: #f0f4f8; padding: 1px 4px; border-radius: 3px; font-size: 11px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { background: none; border: none; border-bottom: 2px solid transparent; padding: 8px 12px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.tabs button.active { color: var(--navy); border-bottom-color: var(--gold); }
.statement { max-width: 820px; }
.statement .line { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed var(--border); }
.statement .line.total { font-weight: 700; border-bottom: 2px solid var(--navy); border-top: 1px solid var(--navy); background: #f0f4f8; padding: 8px 6px; }
.statement .line.muted { color: var(--muted); font-style: italic; font-size: 13px; }
.statement h3 { margin: 16px 0 6px; text-transform: uppercase; letter-spacing: .5px; border-bottom: 1px solid var(--navy); padding-bottom: 3px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.spinner { display: inline-block; width: 22px; height: 22px; border: 3px solid #d7dee6; border-top-color: var(--navy); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: middle; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; }
  .sidebar.open ~ .sidebar-backdrop { display: block; }
  .sidebar-close { display: block; }
  .main { margin-left: 0; }
  #menu-btn { display: block; }
  .content { padding: 16px 14px; }
  .topbar { padding: 8px 14px; }
  .topbar-search input { min-width: 0; }
}
@media (max-width: 600px) {
  .stat .value { font-size: 19px; }
  .topbar-search button { display: none; }
  .demo-badge { font-size: 10px; padding: 3px 8px; }
  .modal-backdrop { padding: 10px 6px; }
  .modal-body { padding: 14px; }
  .page-head h1 { font-size: 19px; }
  .filters .field { max-width: none; }
  .dl { grid-template-columns: 1fr; gap: 2px; } .dl dt { margin-top: 6px; }
}
@media print {
  .sidebar, .topbar, .app-foot, .actions, .filters, .btn { display: none !important; }
  .main { margin: 0; } .content { padding: 0; } .card { box-shadow: none; border: none; }
}
.page-head form.filters { margin: 0; align-items: center; }
.page-head form.filters input, .page-head form.filters select { width: auto; }

/* ---------- Brand theme (Grand Georick Energy: charcoal, red, orange) ---------- */
.login-view { background: linear-gradient(135deg, #2b2b2b 0%, #4a1a1a 55%, #c1121f 100%); }
.login-brand { justify-content: center; }
.login-logo { max-width: 260px; width: 100%; height: auto; display: block; margin: 0 auto; }
.btn-primary { background: var(--red-brand); border-color: var(--red-brand); } .btn-primary:hover { background: #a30f1a; }
.sidebar { background: #ffffff; color: var(--text); border-right: 1px solid var(--border); }
.sidebar-brand { padding: 14px 14px 10px; border-bottom: 1px solid var(--border); }
.sidebar-logo { width: 100%; max-width: 200px; height: auto; display: block; }
.sidebar-brand .brand-sub { color: var(--muted); }
.nav a { color: #444; }
.nav a:hover { background: var(--orange-light); color: var(--text); }
.nav a.active { background: #fdecea; color: var(--red-brand); border-left-color: var(--red-brand); font-weight: 600; }
.nav .nav-group { color: var(--orange); font-weight: 700; }
.sidebar-foot { border-top: 1px solid var(--border); }
.nav-user b { color: var(--text); } .nav-user span { color: var(--muted); }
.sidebar-foot .btn-ghost { border-color: var(--border); color: var(--text); } .sidebar-foot .btn-ghost:hover { background: #f4f6f9; }
.sidebar-close { color: var(--text); }
.stat { border-top-color: var(--orange); }
.tbl th { background: #f7f3ef; }
.tbl tfoot td { background: #fdf3ea; }
.statement .line.total { border-color: var(--red-brand); background: #fdf3ea; }
.statement h3 { border-bottom-color: var(--orange); color: var(--red-brand); }
.tabs button.active { color: var(--red-brand); border-bottom-color: var(--orange); }
.hbar-row .bar i { background: linear-gradient(90deg, var(--orange), var(--red-brand)); }
.demo-badge { background: var(--gold); }
.badge { background: #f3efe9; color: #5a4a3a; }
.topbar { border-bottom: 3px solid var(--orange); }
.icon-btn { color: var(--red-brand); }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(242,140,40,.3); border-color: var(--orange); }
.toast { background: #333; }
.alert.info { background: var(--orange-light); border-color: #f5c99a; color: #6b3d0f; }
h1, h2, h3 { color: var(--navy); }
.page-head h1 { color: var(--red-brand); }
