:root {
  --green-900: #143823;
  --green-800: #1f5236;
  --green-700: #276843;
  --green-600: #2f7d50;
  --green-100: #e3f0e6;
  --green-50: #f1f7f2;
  --bg: #f5f6f1;
  --card: #ffffff;
  --ink: #17241b;
  --muted: #66756a;
  --line: #e2e7df;
  --amber: #a8650b;
  --amber-bg: #fdf3e1;
  --red: #b3402f;
  --yellow: #f2c14e;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(20, 40, 25, .06), 0 6px 20px rgba(20, 40, 25, .06);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }

/* Header */
.top {
  position: sticky; top: 0; z-index: 10;
  background: var(--green-800); color: #fff;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 10px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .12);
}
.brand { display: flex; align-items: center; gap: 10px; max-width: 980px; margin: 0 auto; }
.logo { width: 34px; height: 34px; color: #fff; flex: none; }
.brand-name { font-weight: 700; font-size: 18px; letter-spacing: .2px; }
.brand-sub { font-size: 12.5px; opacity: .75; }
.user-switch {
  display: block; width: 100%; max-width: 980px; margin: 10px auto 0; padding: 7px 10px; border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, .3); background: rgba(255, 255, 255, .12); color: #fff; font-size: 14px;
}
.user-switch option { color: #17241b; }
.roles {
  display: flex; gap: 8px; overflow-x: auto; margin: 12px auto 0; max-width: 980px;
  scrollbar-width: none; padding-bottom: 2px;
}
.roles::-webkit-scrollbar { display: none; }
.role {
  flex: none; border: 1px solid rgba(255, 255, 255, .25); background: transparent; color: #fff;
  border-radius: 999px; padding: 6px 12px; font-size: 14px; display: flex; align-items: center; gap: 6px; cursor: pointer;
}
.role.on { background: #fff; color: var(--green-800); border-color: #fff; font-weight: 600; }
.badge {
  min-width: 20px; height: 20px; border-radius: 10px; background: var(--yellow); color: var(--green-900);
  font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; padding: 0 6px;
}

/* Layout */
.view { max-width: 560px; margin: 0 auto; padding: 16px 16px 120px; }
.view.wide { max-width: 980px; }
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 26px 4px 10px; font-weight: 650; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }

/* Hero */
.hero {
  background: linear-gradient(150deg, var(--green-700), var(--green-900)); color: #fff;
  border-radius: 22px; padding: 22px 20px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.hero::after {
  content: ""; position: absolute; right: -40px; top: -40px; width: 160px; height: 160px; border-radius: 50%;
  background: radial-gradient(circle, rgba(242, 193, 78, .35), transparent 70%);
}
.hero h1 { margin: 0 0 6px; font-size: 24px; }
.hero p { margin: 0 0 18px; opacity: .85; }
.hero-actions { display: grid; grid-template-columns: 1fr; gap: 10px; position: relative; z-index: 1; }

/* Buttons */
.btn {
  border: 0; border-radius: 14px; padding: 14px 16px; font-weight: 650; font-size: 16px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
  transition: transform .08s ease, filter .15s ease;
}
.btn:active { transform: scale(.98); }
.btn svg { width: 20px; height: 20px; }
.btn-camera { background: var(--yellow); color: var(--green-900); font-size: 17px; padding: 17px; }
.btn-ghost { background: rgba(255, 255, 255, .12); color: #fff; }
.btn-primary { background: var(--green-700); color: #fff; }
.btn-primary:disabled { filter: grayscale(.7); opacity: .55; }
.btn-outline { background: #fff; color: var(--ink); border: 1.5px solid var(--line); }
.btn-danger { background: #fff; color: var(--red); border: 1.5px solid #e9c3bb; }
.btn-sm { padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.file-input { display: none; }

/* Expense list */
.exp { display: flex; gap: 12px; align-items: center; cursor: pointer; }
.thumb { width: 56px; height: 56px; border-radius: 12px; object-fit: cover; background: var(--green-50); flex: none; border: 1px solid var(--line); }
.thumb.pdf { display: flex; align-items: center; justify-content: center; color: var(--green-700); font-weight: 700; font-size: 13px; }
.exp-main { flex: 1; min-width: 0; }
.exp-title { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.exp-meta { font-size: 13.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.exp-amount { font-weight: 700; white-space: nowrap; text-align: right; }
.pill { display: inline-block; border-radius: 999px; font-size: 12px; font-weight: 650; padding: 2px 9px; margin-top: 4px; }
.pill.wait { background: var(--amber-bg); color: var(--amber); }
.pill.ok { background: var(--green-100); color: var(--green-700); }
.pill.no { background: #fbe9e5; color: var(--red); }
.pill.acc { background: #e6eefb; color: #2d5ba8; }

/* Progress steps */
.steps { display: flex; align-items: center; gap: 4px; margin-top: 12px; }
.step { flex: 1; height: 5px; border-radius: 3px; background: var(--line); }
.step.done { background: var(--green-600); }
.step.fail { background: var(--red); }
.step-labels { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--muted); margin-top: 5px; gap: 4px; }

/* Scan */
.scan { position: relative; border-radius: var(--radius); overflow: hidden; background: #0e1d14; box-shadow: var(--shadow); }
.scan img { display: block; width: 100%; max-height: 340px; object-fit: contain; }
.scan .pdfbox { height: 200px; display: flex; align-items: center; justify-content: center; color: #cfe3d4; font-weight: 600; }
.scan.reading img, .scan.reading .pdfbox { filter: brightness(.65); }
.scan.reading::after {
  content: ""; position: absolute; left: 0; right: 0; height: 90px; top: -90px;
  background: linear-gradient(180deg, transparent, rgba(242, 193, 78, .55), transparent);
  animation: sweep 1.6s ease-in-out infinite;
}
@keyframes sweep { to { top: 100%; } }
.scan-status {
  position: absolute; left: 12px; bottom: 12px; right: 12px; background: rgba(15, 30, 20, .78); color: #fff;
  border-radius: 12px; padding: 10px 12px; font-size: 14.5px; display: flex; align-items: center; gap: 10px; backdrop-filter: blur(6px);
}
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid rgba(255, 255, 255, .3); border-top-color: var(--yellow); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Forms */
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 8px; }
.card-title { font-weight: 700; font-size: 16.5px; }
.ai {
  display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; color: var(--green-700);
  background: var(--green-100); border-radius: 999px; padding: 3px 9px;
}
.ai svg { width: 13px; height: 13px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: block; margin-bottom: 10px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin: 0 0 4px 2px; font-weight: 550; }
.field input, .field select, .field textarea {
  width: 100%; border: 1.5px solid var(--line); border-radius: 12px; padding: 11px 12px; background: #fff;
  font-size: 16px; outline: none; transition: border-color .15s ease, background .6s ease;
}
.field textarea { min-height: 88px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--green-600); }
.field.filled input, .field.filled select, .field.filled textarea { background: var(--green-50); border-color: #cfe3d4; }
.amount input { font-size: 22px; font-weight: 700; }
.warn {
  background: var(--amber-bg); color: #7a4a06; border-radius: 12px; padding: 10px 12px; margin-bottom: 8px;
  font-size: 14.5px; display: flex; gap: 8px;
}
.warn svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.error { background: #fbe9e5; color: var(--red); border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; font-size: 14.5px; }
details.items summary { cursor: pointer; color: var(--green-700); font-weight: 600; font-size: 14.5px; padding: 4px 2px; }
.items ul { list-style: none; padding: 0; margin: 8px 0 0; }
.items li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 2px; border-bottom: 1px dashed var(--line); font-size: 14.5px; }
.items li:last-child { border-bottom: 0; }

.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; }
.toggle input { display: none; }
.switch { width: 50px; height: 30px; border-radius: 15px; background: var(--line); position: relative; flex: none; transition: background .2s ease; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); transition: transform .2s ease; }
.toggle input:checked + .switch { background: var(--green-600); }
.toggle input:checked + .switch::after { transform: translateX(20px); }

.path { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 14px; }
.path .node { background: var(--green-50); border: 1px solid #cfe3d4; color: var(--green-800); border-radius: 999px; padding: 4px 10px; font-weight: 600; }
.path .arrow { color: var(--muted); }

.sticky-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9; padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px);
  background: rgba(245, 246, 241, .92); backdrop-filter: blur(10px); border-top: 1px solid var(--line);
}
.sticky-bar .inner { max-width: 560px; margin: 0 auto; display: flex; gap: 10px; }
.sticky-bar .btn { flex: 1; }

.back { background: none; border: 0; color: var(--green-700); font-weight: 650; padding: 4px 0 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }

/* Detail */
.big-amount { font-size: 34px; font-weight: 800; letter-spacing: -.5px; margin: 2px 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 15px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 550; overflow-wrap: anywhere; }
.doc-img { width: 100%; border-radius: 14px; border: 1px solid var(--line); display: block; max-height: 420px; object-fit: contain; background: #fafbf8; cursor: zoom-in; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 22px; font-size: 14.5px; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--green-600); }
.timeline li::after { content: ""; position: absolute; left: 8.5px; top: 18px; bottom: 0; width: 1.5px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.timeline li.no::before { background: var(--red); }
.timeline .when { color: var(--muted); font-size: 13px; }
.comment-box textarea { min-height: 70px; }

/* Success */
.success { text-align: center; padding: 40px 12px 20px; }
.check { width: 92px; height: 92px; border-radius: 50%; background: var(--green-600); margin: 0 auto 18px; display: flex; align-items: center; justify-content: center; animation: pop .45s cubic-bezier(.2, 1.4, .4, 1); }
.check svg { width: 48px; height: 48px; stroke: #fff; stroke-width: 3.2; fill: none; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 40; stroke-dashoffset: 40; animation: draw .45s .25s ease forwards; }
@keyframes pop { from { transform: scale(.3); opacity: 0; } }
@keyframes draw { to { stroke-dashoffset: 0; } }
.success h1 { margin: 0 0 6px; font-size: 24px; }

/* Accounting */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 4px; }
.tile .label { font-size: 13.5px; color: var(--muted); }
.tile .value { font-size: 26px; font-weight: 800; margin-top: 2px; }
.tile .sub { font-size: 13.5px; color: var(--muted); }
.acc-row { display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; align-items: center; }
.field.mt { margin-top: 16px; }
.offline { background: #fdf6e3; color: #6b4e00; border-bottom: 1px solid #e0b44c; padding: 10px 16px; font-size: 14px; text-align: center; }
.archive { margin: 12px 0 4px; text-align: center; }
.log { max-height: 360px; overflow-y: auto; }
.log-row { padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.inline-input { flex: 1 1 180px; min-width: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font: inherit; }
.batch .acc-actions { margin-top: 8px; }
.acc-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.note { font-size: 13.5px; color: var(--muted); text-align: center; margin-top: 18px; }

.new-flash { animation: flash 1.6s ease; }
@keyframes flash { 0% { box-shadow: 0 0 0 3px var(--yellow); } 100% { box-shadow: var(--shadow); } }

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translate(-50%, 20px); background: var(--green-900); color: #fff;
  padding: 10px 16px; border-radius: 12px; font-size: 14.5px; opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 20;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.lightbox { position: fixed; inset: 0; background: rgba(8, 16, 10, .92); z-index: 30; display: flex; align-items: center; justify-content: center; padding: 16px; cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

@media (min-width: 720px) {
  .hero-actions { grid-template-columns: 1fr 1fr; }
}
.user-switch[hidden] { display: none; }
.brand { position: relative; }
.logout {
  margin-left: auto; background: transparent; color: #fff; border: 1px solid rgba(255, 255, 255, .3);
  border-radius: 999px; padding: 5px 12px; font-size: 13.5px; cursor: pointer;
}
.logout[hidden] { display: none; }
.login { padding-top: 24px; }
.login h1 { margin: 0 0 6px; font-size: 24px; }
.login p { color: var(--muted); margin: 0 0 16px; }
.login .btn { width: 100%; }
.mail { font-size: 13.5px; border-top: 1px dashed var(--line); padding: 8px 0; overflow-wrap: anywhere; }
.mail a { color: var(--green-700); font-weight: 600; }
.choices { display: grid; gap: 8px; margin-bottom: 4px; }
.choice {
  display: flex; align-items: center; gap: 10px; border: 1.5px solid var(--line); border-radius: 12px;
  padding: 11px 12px; cursor: pointer; font-size: 15px; background: #fff;
}
.choice input { accent-color: var(--green-700); width: 18px; height: 18px; margin: 0; }
.choice.on { border-color: var(--green-600); background: var(--green-50); font-weight: 600; }
#settle .field:first-child { margin-top: 12px; }
.scan-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 10px 2px 0; }
.crop { position: relative; user-select: none; touch-action: none; border-radius: 12px; overflow: hidden; background: #0e1d14; }
.crop img { display: block; width: 100%; pointer-events: none; }
.crop-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.crop-svg polygon { fill: rgba(242, 193, 78, .18); stroke: var(--yellow); stroke-width: 2; vector-effect: non-scaling-stroke; }
.handle {
  position: absolute; width: 30px; height: 30px; margin: -15px 0 0 -15px; border-radius: 50%;
  background: rgba(242, 193, 78, .35); border: 3px solid var(--yellow); box-shadow: 0 2px 8px rgba(0, 0, 0, .4);
  touch-action: none; cursor: grab;
}
.grid3 { display: grid; grid-template-columns: 1fr; gap: 0 10px; }
@media (min-width: 720px) { .grid3 { grid-template-columns: 1fr 1fr 1fr; } }
.admin-row { padding: 10px 2px; border-bottom: 1px dashed var(--line); }
.admin-row:last-of-type { border-bottom: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--green-50); border: 1px solid #cfe3d4; color: var(--green-800);
  border-radius: 999px; padding: 2px 4px 2px 10px; font-size: 13px; }
.chip-x { border: 0; background: transparent; color: var(--muted); font-size: 16px; line-height: 1; cursor: pointer; padding: 0 4px; }
code { background: var(--green-50); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
