:root {
  --bg: #f7f6f1;
  --card: #ffffff;
  --ink: #1c2b27;
  --muted: #6b7c77;
  --line: #e6e3da;
  --primary: #0f766e;
  --primary-ink: #ffffff;
  --primary-soft: #d7ede9;
  --secondary: #eef0ea;
  --danger: #b3261e;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 8px 24px rgba(16,24,40,.06);
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --maxw: 480px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: "Fraunces", Georgia, serif; font-weight: 600; margin: 0; letter-spacing: -0.01em; }

.app-wrap { max-width: var(--maxw); margin: 0 auto; min-height: 100vh; position: relative; padding-bottom: 88px; }

/* Header */
.appbar {
  position: sticky; top: 0; z-index: 30;
  background: rgba(247,246,241,.85); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  padding: max(12px, env(safe-area-inset-top)) 18px 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.appbar .brand { display: flex; align-items: center; gap: 10px; }
.appbar .logo { width: 34px; height: 34px; border-radius: 10px; background: var(--primary); color: #fff; display: grid; place-items: center; }
.appbar .title { font-family: "Fraunces", serif; font-weight: 600; font-size: 18px; }
.appbar .sub { font-size: 12px; color: var(--muted); }

.content { padding: 18px; }

/* Bottom nav */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: var(--maxw); z-index: 40;
  background: rgba(255,255,255,.92); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 8px 8px max(8px, env(safe-area-inset-bottom));
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 600;
  padding: 6px 0; border-radius: 12px; transition: color .16s var(--ease-out);
}
.tabbar a.active { color: var(--primary); }
.tabbar a .ic { width: 24px; height: 24px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; cursor: pointer; font-family: inherit; font-weight: 700; font-size: 15px;
  background: var(--primary); color: var(--primary-ink);
  padding: 0 18px; height: 52px; border-radius: 14px; width: 100%;
  transition: transform .16s var(--ease-out), background .16s var(--ease-out), opacity .16s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: .6; }
.btn.secondary { background: var(--secondary); color: var(--ink); }
.btn.ghost { background: transparent; color: var(--primary); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.outline { background: #fff; border: 1px solid var(--line); color: var(--ink); }
.btn.sm { height: 44px; font-size: 14px; padding: 0 14px; width: auto; }
.btn.wa { background: #25D366; color: #06310f; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { width: 100%; }

.icon-btn {
  width: 44px; height: 44px; min-width: 44px; border-radius: 12px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); display: grid; place-items: center; cursor: pointer;
  transition: transform .16s var(--ease-out);
}
.icon-btn:active { transform: scale(0.94); }
.icon-btn.danger { color: var(--danger); border-color: #f0d7d5; }

/* Cards & lists */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.list { display: flex; flex-direction: column; gap: 12px; }
.row-card { display: flex; align-items: stretch; overflow: hidden; }
.row-card .main { flex: 1; padding: 16px; min-width: 0; cursor: pointer; }
.row-card .main .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-card .main .meta { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.row-card .side { display: flex; }
.row-card .side button { border: none; border-left: 1px solid var(--line); background: transparent; padding: 0 14px; color: var(--muted); cursor: pointer; display: grid; place-items: center; }
.row-card .side button:active { background: #f3f2ec; }
.row-card .side button.del { color: var(--danger); }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-head h1 { font-size: 26px; }
.page-head p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }

/* Forms */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--ink); }
.input, .textarea, .select {
  width: 100%; font-family: inherit; font-size: 16px; color: var(--ink);
  background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px;
  transition: border-color .16s var(--ease-out), box-shadow .16s var(--ease-out);
}
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.textarea { resize: vertical; min-height: 76px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 5px; }

/* Empty / loading */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; padding: 56px 16px; }
.empty .ico { width: 56px; height: 56px; border-radius: 16px; background: var(--secondary); display: grid; place-items: center; color: var(--muted); }
.empty .t { font-weight: 700; }
.empty .d { font-size: 13px; color: var(--muted); max-width: 240px; }
.skel { height: 76px; border-radius: var(--radius); background: linear-gradient(90deg,#eee,#f5f5f5,#eee); background-size: 200% 100%; animation: sh 1.2s infinite; }
@keyframes sh { 0%{background-position:200% 0} 100%{background-position:-200% 0} }

/* Dialog */
.overlay { position: fixed; inset: 0; background: rgba(20,28,25,.45); z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: var(--maxw); background: #fff; border-radius: 22px 22px 0 0;
  padding: 20px 18px max(20px, env(safe-area-inset-bottom)); animation: up .26s var(--ease-out);
  max-height: 92vh; overflow-y: auto;
}
@keyframes up { from { transform: translateY(24px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }
.sheet h2 { font-size: 20px; margin-bottom: 14px; }
.sheet .close { position: absolute; }

/* Dashboard tiles */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 8px; }
.tile { padding: 16px; border-radius: var(--radius); background: #fff; border: 1px solid var(--line); box-shadow: var(--shadow); text-decoration: none; color: inherit; transition: transform .16s var(--ease-out); }
.tile:active { transform: scale(0.98); }
.tile .ic { width: 40px; height: 40px; border-radius: 12px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; margin-bottom: 10px; }
.tile .n { font-family: "Fraunces", serif; font-size: 22px; font-weight: 600; }
.tile .l { font-size: 13px; color: var(--muted); }
.cta { margin-top: 8px; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; max-width: var(--maxw); margin: 0 auto; }
.login-card { width: 100%; text-align: center; }
.login-logo { width: 64px; height: 64px; border-radius: 18px; background: var(--primary); color: #fff; display: grid; place-items: center; margin: 0 auto 18px; }
.login-card h1 { font-size: 28px; }
.login-card .sub { color: var(--muted); font-size: 14px; margin: 6px 0 22px; }
.login-card .field { text-align: left; }
.err { background: #fdecea; color: var(--danger); border: 1px solid #f5c6c2; border-radius: 12px; padding: 10px 12px; font-size: 13.5px; margin-bottom: 14px; }

/* ---------- Invoice paper (mimics reference) ---------- */
.paper-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); }
.paper {
  width: 760px; background: #fff; color: #111; padding: 26px 28px;
  font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 1.3;
}
.paper .p-top { display: flex; justify-content: space-between; font-size: 12px; }
.paper .p-title { text-align: center; font-weight: bold; font-size: 22px; text-decoration: underline; margin: 2px 0 14px; font-family: Arial, sans-serif; }
.paper .p-head { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 14px; }
.paper .p-head .lbl { color: #333; display: inline-block; width: 74px; }
.paper .p-head .val { font-weight: bold; }
.paper table { width: 100%; border-collapse: collapse; }
.paper th, .paper td { padding: 5px 8px; text-align: left; }
.paper thead th { border-top: 1.5px solid #111; border-bottom: 1.5px solid #111; font-size: 12.5px; }
.paper tbody td { border-bottom: 1px dotted #cfcfcf; }
.paper .num { text-align: right; font-variant-numeric: tabular-nums; }
.paper .center { text-align: center; }
.paper .totals-row td { border-top: 1.5px solid #111; font-weight: bold; }
.paper .p-foot { margin-top: 4px; }
.paper .p-foot .grossbar { display: flex; justify-content: space-between; align-items: center; border: 1px solid #111; padding: 6px 8px; margin-top: 10px; font-weight: bold; }
.paper .p-words { margin-top: 8px; font-size: 12.5px; }
.paper .p-summary { margin-top: 10px; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.paper .p-summary .line { display: flex; gap: 14px; align-items: baseline; }
.paper .p-summary .line .k { color: #222; font-weight: bold; }
.paper .p-summary .line .v { min-width: 110px; text-align: right; font-weight: bold; border-bottom: 1px solid #111; padding-bottom: 1px; }

.toast { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 90; background: #1c2b27; color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow); animation: up .2s var(--ease-out); max-width: 90vw; }
.toast.err { background: var(--danger); }

.line-item { border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 12px; background: #fff; }
.line-item .li-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; margin-bottom: 10px; }
.line-item .li-top .d { font-weight: 700; }
.li-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.li-net { text-align: right; font-weight: 700; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }

.summary-card { padding: 16px; }
.summary-card .sl { display: flex; justify-content: space-between; padding: 7px 0; font-size: 14.5px; }
.summary-card .sl.total { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 12px; font-weight: 800; font-size: 17px; }
.summary-card .sl .muted { color: var(--muted); }

.muted { color: var(--muted); }
.mb12 { margin-bottom: 12px; }
.mt16 { margin-top: 16px; }
.center-text { text-align: center; }

/* Absolute strict sizing for ALL icons to prevent layout breaks */
#app svg, button svg, .tile svg, .btn svg, a svg {
    max-width: 28px !important;
    max-height: 28px !important;
    min-width: 16px;
    min-height: 16px;
    display: inline-block !important;
}