:root {
  --pri: #1f4e79; --pri2: #2e75b6; --bg: #f2f4f7; --card: #fff; --line: #c9d1db;
  --txt: #1d2733; --mut: #66748a; --red: #c0392b; --grn: #1e8449; --org: #d68910;
  --hdr: #dde7f2;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--txt); font-size: 15px; }
.hidden { display: none !important; }

/* login */
.login { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(160deg, var(--pri), var(--pri2)); }
.login-card { background: #fff; border-radius: 16px; padding: 28px 22px; width: 100%; max-width: 340px; text-align: center; box-shadow: 0 10px 30px #0003; }
.login-card h1 { font-size: 18px; margin: 8px 0 18px; }
.logo { width: 64px; height: 64px; border-radius: 16px; background: var(--pri); color: #fff; font-weight: 800; font-size: 22px; display: flex; align-items: center; justify-content: center; margin: 0 auto; }
.err { color: var(--red); min-height: 1em; }

/* layout */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--pri); color: #fff; display: flex; align-items: center; gap: 6px; padding: 10px 10px; padding-top: max(10px, env(safe-area-inset-top)); }
.topbar h1 { font-size: 18px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { background: none; border: 0; color: inherit; font-size: 22px; width: 38px; height: 38px; border-radius: 8px; cursor: pointer; }
.icon-btn:active { background: #fff3; }
.subtabs { position: sticky; top: 58px; z-index: 19; display: flex; overflow-x: auto; background: #fff; border-bottom: 1px solid var(--line); scrollbar-width: none; }
.subtabs a { flex: 0 0 auto; padding: 11px 14px; text-decoration: none; color: var(--mut); font-weight: 600; font-size: 14px; border-bottom: 3px solid transparent; }
.subtabs a.on { color: var(--pri); border-color: var(--pri); }
main { padding: 10px 10px 100px; max-width: 1100px; margin: 0 auto; }
.bottomnav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: flex; background: #fff; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.bottomnav a { flex: 1; text-align: center; padding: 6px 0 7px; font-size: 11px; color: var(--mut); text-decoration: none; display: flex; flex-direction: column; align-items: center; gap: 1px; }
.bottomnav a span { font-size: 20px; }
.bottomnav a.on { color: var(--pri); font-weight: 700; }
.fab { position: fixed; right: 16px; bottom: calc(72px + env(safe-area-inset-bottom)); z-index: 31; width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--pri2); color: #fff; font-size: 30px; box-shadow: 0 4px 14px #0004; cursor: pointer; }

/* dashboard */
.sec-title { font-size: 13px; font-weight: 700; color: var(--mut); text-transform: uppercase; letter-spacing: .5px; margin: 14px 2px 8px; }
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 700px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { background: var(--card); border-radius: 12px; padding: 12px; box-shadow: 0 1px 3px #0001; border-left: 4px solid var(--pri2); cursor: pointer; text-decoration: none; color: inherit; display: block; }
.tile:active { transform: scale(.98); }
.tile .lbl { font-size: 12px; color: var(--mut); }
.tile .val { font-size: 21px; font-weight: 800; margin-top: 4px; }
.tile .sub { font-size: 11px; color: var(--mut); margin-top: 2px; }
.tile.red { border-color: var(--red); } .tile.red .val { color: var(--red); }
.tile.grn { border-color: var(--grn); } .tile.grn .val { color: var(--grn); }
.tile.org { border-color: var(--org); } .tile.org .val { color: var(--org); }

/* excel-like grid */
.toolbar { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; flex-wrap: wrap; }
.toolbar input, .toolbar select { flex: 1; min-width: 120px; }
.grid-wrap { overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: 6px; max-height: calc(100vh - 230px); }
table.grid { border-collapse: collapse; width: 100%; font-size: 13px; }
.grid th, .grid td { border: 1px solid var(--line); padding: 7px 8px; white-space: nowrap; text-align: left; }
.grid th { position: sticky; top: 0; background: var(--hdr); z-index: 2; font-weight: 700; cursor: pointer; user-select: none; }
.grid th.rn, .grid td.rn { position: sticky; left: 0; background: #eef1f5; color: var(--mut); text-align: center; width: 34px; z-index: 1; font-size: 11px; }
.grid th.rn { z-index: 3; background: var(--hdr); }
.grid tbody tr:nth-child(even) td { background: #f8fafc; }
.grid tbody tr:nth-child(even) td.rn { background: #e8ecf1; }
.grid tbody tr { cursor: pointer; }
.grid tbody tr:active td { background: #dbeafe; }
.grid td.num, .grid th.num { text-align: right; }
.grid tfoot td { font-weight: 800; background: #fff8e1; position: sticky; bottom: 0; }
.grid .empty { text-align: center; color: var(--mut); padding: 24px; cursor: default; }
.count { font-size: 12px; color: var(--mut); margin: 6px 2px; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11px; font-weight: 700; background: #e5e7eb; }
.badge.red { background: #fde2e0; color: var(--red); } .badge.grn { background: #d5f5e3; color: var(--grn); } .badge.org { background: #fdebd0; color: var(--org); }
.red { color: var(--red); } .grn { color: var(--grn); } .org { color: var(--org); }

/* forms */
input, select, textarea { width: 100%; font: inherit; padding: 10px 11px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--txt); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--pri2); border-color: transparent; }
label.f { display: block; margin-bottom: 11px; }
label.f > span { display: block; font-size: 12px; font-weight: 700; color: var(--mut); margin-bottom: 4px; }
.hint { font-size: 12px; color: var(--mut); margin-top: 3px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn { font: inherit; font-weight: 700; padding: 10px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--txt); cursor: pointer; text-decoration: none; display: inline-block; text-align: center; }
.btn.primary { background: var(--pri2); border-color: var(--pri2); color: #fff; }
.btn.danger { background: #fff; border-color: var(--red); color: var(--red); }
.btn.grn { background: var(--grn); border-color: var(--grn); color: #fff; }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn.block { width: 100%; margin-top: 8px; }
.btns { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.btns .btn { flex: 1; }
.card { background: #fff; border-radius: 10px; padding: 12px; margin-bottom: 10px; box-shadow: 0 1px 3px #0001; }
.card h3 { margin: 0 0 8px; font-size: 15px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.kv b { text-align: right; }
.calc { background: #eef6ff; border: 1px dashed var(--pri2); border-radius: 8px; padding: 9px 11px; font-size: 13px; margin-bottom: 11px; }

/* modal */
.modal { position: fixed; inset: 0; z-index: 50; background: #0006; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 560px; max-height: 92vh; border-radius: 16px 16px 0 0; display: flex; flex-direction: column; }
@media (min-width: 700px) { .modal { align-items: center; } .sheet { border-radius: 16px; } }
.sheet-head { display: flex; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fff; border-radius: 16px 16px 0 0; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 17px; }
.sheet-body { padding: 14px; overflow-y: auto; padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: #222d; color: #fff; padding: 10px 16px; border-radius: 20px; z-index: 60; font-size: 14px; max-width: 90%; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 5px 6px 5px 11px; font-size: 13px; display: inline-flex; align-items: center; gap: 4px; }
.chip button { border: 0; background: #eee; border-radius: 50%; width: 22px; height: 22px; cursor: pointer; color: var(--red); }
@media print {
  .topbar, .bottomnav, .fab, .subtabs, .toolbar, .noprint { display: none !important; }
  .grid-wrap { max-height: none; overflow: visible; border: 0; }
  main { padding: 0; }
}

.plan-banner { background: #fff3cd; color: #8a6d00; text-align: center; font-size: 12px; font-weight: 700; padding: 5px; border-bottom: 1px solid #f0d78a; }
.login-card input + input { margin-top: 0; }
