/* ── Reset & Base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --brand:   #185FA5;
  --brand-d: #0f4a87;
  --dark:    #1c1c1e;
  --grey:    #f2f2f7;
  --border:  #e0e0e0;
  --text:    #1a1a1a;
  --muted:   #888;
  --green:   #2e7d32;
  --red:     #c62828;
  --amber:   #e65100;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--grey);
  min-height: 100vh;
  padding-bottom: calc(70px + env(safe-area-inset-bottom));
}

/* ── Layout ───────────────────────────────────────────── */
.page { display: none; }
.page.active { display: block; }

.content {
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 12px 16px;
}

/* ── Bottom Nav ───────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: white;
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 4px 8px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  gap: 4px;
  transition: color .15s;
}

.nav-btn .nav-icon { font-size: 20px; line-height: 1; }
.nav-btn.active { color: var(--brand); font-weight: 600; }

/* ── Page Header ──────────────────────────────────────── */
.page-header {
  background: var(--dark);
  color: white;
  padding: 16px;
  margin: -12px -12px 14px;
}
.page-header h1 { font-size: 17px; font-weight: 600; }
.page-header p  { font-size: 11px; color: #888; margin-top: 3px; }

/* ── Section Card ─────────────────────────────────────── */
.section {
  background: white;
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.07);
}

.sec-title {
  font-size: 13px;
  font-weight: 600;
  color: #444;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid #f0f0f0;
}

/* ── Fields ───────────────────────────────────────────── */
.field { margin-bottom: 10px; }
.field label { font-size: 13px; color: #555; display: block; margin-bottom: 4px; }

.field input,
.field select,
.field textarea {
  width: 100%;
  font-size: 16px;
  padding: 9px 11px;
  border: 1px solid #ccc;
  border-radius: 8px;
  background: white;
  color: var(--text);
  outline: none;
  -webkit-appearance: none;
  font-family: inherit;
  transition: border-color .15s;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--dark);
  background: white;
}

.field input.err  { border-color: #d93025; background: #fff8f7; }
.field input.warn,
.field textarea.warn { border-color: #f29900; background: #fffbe6; }
.field textarea { resize: vertical; min-height: 64px; }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }

.sel-wrap { position: relative; }
.sel-wrap::after {
  content: '▾';
  position: absolute; right: 10px; top: 50%;
  transform: translateY(-50%);
  color: #999; pointer-events: none; font-size: 12px;
}

/* ── Tip Boxes ────────────────────────────────────────── */
.tip-box {
  display: none;
  margin-top: 5px;
  padding: 7px 10px;
  border-radius: 7px;
  font-size: 12px;
  gap: 8px;
  align-items: flex-start;
}
.tip-box.show { display: flex; }
.tip-box.typo  { background: #fff3cd; border: 1px solid #ffc107; color: #856404; }
.tip-box.malay { background: #e8f4fd; border: 1px solid #1a73e8; color: #1a4a7a; }
.tip-box .fix-btn {
  margin-left: auto; flex-shrink: 0;
  padding: 4px 10px; border: none; border-radius: 5px;
  font-size: 11px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.tip-box.typo  .fix-btn { background: #ffc107; color: #000; }
.tip-box.malay .fix-btn { background: #1a73e8; color: #fff; }

/* ── Machine Items ────────────────────────────────────── */
.machine-item {
  border: 1px solid #eee;
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 8px;
  background: #fafafa;
}
.machine-header { display: flex; align-items: center; justify-content: space-between; }
.machine-name   { font-size: 14px; font-weight: 500; color: var(--text); }

.tog-btn {
  font-size: 12px; padding: 5px 14px;
  border: 1px solid #ccc; border-radius: 20px;
  background: white; color: #666; cursor: pointer;
  transition: all .15s;
}
.tog-btn.active { background: var(--dark); color: white; border-color: var(--dark); }

.mfields { display: none; margin-top: 12px; padding-top: 10px; border-top: 1px solid #f0f0f0; }
.mfields.open { display: block; }

.rate-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.rate-label       { font-size: 12px; color: #777; margin-bottom: 4px; }
.rate-label.grn   { color: var(--green); font-weight: 500; }
.rate-label.amb   { color: var(--amber); font-weight: 500; }
.rate-row input   { width: 100%; font-size: 16px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: white; }
.rate-row input.gi { border-color: #a5d6a7; background: #f1f8e9; }
.rate-row input.ai { border-color: #ffcc80; background: #fff8e1; }

/* ── Addon Buttons ────────────────────────────────────── */
.addon-bar { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.addon-btn {
  font-size: 12px; padding: 5px 13px;
  border: 1px solid #ddd; border-radius: 20px;
  background: white; color: #666; cursor: pointer; transition: all .15s;
}
.addon-btn.active { background: #e8f5e9; color: var(--green); border-color: var(--green); font-weight: 500; }
.addon-block       { display: none; margin-top: 8px; padding: 10px; background: white; border: 1px solid #eee; border-radius: 8px; }
.addon-block.open  { display: block; }
.addon-block label { font-size: 12px; color: #777; display: block; margin-bottom: 4px; }
.addon-block input { width: 100%; font-size: 16px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: #fafafa; }

/* ── Diesel Mode Buttons ──────────────────────────────── */
.dm-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.dm-btn {
  padding: 10px 8px; font-size: 13px; font-weight: 500;
  border: 1px solid var(--border); border-radius: 10px;
  background: #fafafa; color: #666; cursor: pointer;
  text-align: center; line-height: 1.4; transition: all .15s;
}
.dm-btn .dms { font-size: 10px; font-weight: 400; color: #999; margin-top: 2px; }
.dm-btn.si { border-color: var(--green); background: #f1f8e9; color: var(--green); }
.dm-btn.se { border-color: var(--red);   background: #fff5f5; color: var(--red); }
.dm-btn.sc { border-color: var(--brand); background: #e8f4fd; color: var(--brand); }

/* ── Mobi Buttons ─────────────────────────────────────── */
.m3btn {
  font-size: 13px; font-weight: 500; padding: 10px 4px;
  border: 1px solid var(--border); border-radius: 10px;
  background: #fafafa; color: var(--text); cursor: pointer;
  text-align: center; line-height: 1.4; transition: all .15s;
}
.m3btn .m3s { font-size: 11px; font-weight: 400; color: #999; margin-top: 2px; }
.m3btn.sel  { background: var(--dark); border-color: var(--dark); color: white; }
.m3btn.sel .m3s { color: #aaa; }

/* ── T&C Items ────────────────────────────────────────── */
.tc-item {
  display: flex; align-items: flex-start; gap: 8px;
  margin-bottom: 8px; padding: 9px;
  border: 1px solid #eee; border-radius: 8px;
  cursor: pointer; background: #fafafa;
}
.tc-item.on { background: #f0f0f0; border-color: var(--dark); }
.tc-ck {
  width: 18px; height: 18px; border: 1.5px solid #ccc;
  border-radius: 4px; flex-shrink: 0; margin-top: 1px;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: white; background: white;
}
.tc-item.on .tc-ck  { background: var(--dark); border-color: var(--dark); }
.tc-txt             { font-size: 12px; color: #666; line-height: 1.5; }
.tc-item.on .tc-txt { color: var(--text); }

/* ── Diesel panels ────────────────────────────────────── */
.pb      { display: none; }
.pb.show { display: block; }
.cmp-note {
  font-size: 12px; padding: 9px 11px;
  background: #e8f4fd; border: 1px solid #1a73e8;
  border-radius: 8px; color: #1a4a7a; margin-bottom: 10px; line-height: 1.5;
}

/* ── Primary Button ───────────────────────────────────── */
.btn-primary {
  width: 100%; padding: 15px;
  font-size: 15px; font-weight: 600;
  background: var(--brand); color: white;
  border: none; border-radius: 12px; cursor: pointer;
  font-family: inherit;
}
.btn-primary:active { opacity: .8; }

.btn-brand {
  width: 100%; padding: 15px;
  font-size: 15px; font-weight: 600;
  background: var(--brand); color: white;
  border: none; border-radius: 12px; cursor: pointer;
  font-family: inherit;
}

.btn-sm {
  font-size: 12px; padding: 6px 14px;
  border: 1px solid var(--border); border-radius: 20px;
  background: white; cursor: pointer; color: #555;
  font-family: inherit;
}
.btn-sm.green { border-color: var(--green); color: var(--green); background: #f1f8e9; }
.btn-sm.red   { border-color: var(--red);   color: var(--red);   background: #fff5f5; }
.btn-sm.blue  { border-color: var(--brand); color: var(--brand); background: #e8f4fd; }

/* ── History / List Cards ─────────────────────────────── */
.list-card {
  padding: 14px;
  border-radius: 12px;
  margin-bottom: 10px;
  background: white;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.list-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 6px;
}
.list-card-title  { font-size: 15px; font-weight: 600; color: var(--text); }
.list-card-number { font-size: 12px; color: var(--brand); font-weight: 600; }
.list-card-meta   { font-size: 12px; color: var(--muted); margin-bottom: 10px; line-height: 1.6; }
.list-card-meta .creator {
  display: inline-block;
  background: #eef3fa; color: var(--brand);
  padding: 1px 6px; border-radius: 4px;
  font-size: 10px; font-weight: 500;
  margin-left: 4px;
}
.list-card-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── Status Badges ────────────────────────────────────── */
.badge {
  display: inline-block;
  font-size: 10px; font-weight: 600;
  padding: 2px 8px; border-radius: 20px;
  text-transform: uppercase; letter-spacing: .04em;
}
.badge.draft     { background: #f0f0f0; color: #888; }
.badge.sent      { background: #e8f4fd; color: var(--brand); }
.badge.converted { background: #e8f5e9; color: var(--green); }
.badge.unpaid    { background: #fff3e0; color: var(--amber); }
.badge.paid      { background: #e8f5e9; color: var(--green); }

/* ── Accounts Tab ─────────────────────────────────────── */
.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.stat-card {
  background: white; border-radius: 12px; padding: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,.07); text-align: center;
}
.stat-card .stat-val  { font-size: 20px; font-weight: 700; color: var(--text); margin-bottom: 2px; }
.stat-card .stat-lbl  { font-size: 11px; color: var(--muted); }

.usage-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid #f0f0f0;
}
.usage-row:last-child { border-bottom: none; }
.usage-name  { font-size: 13px; font-weight: 500; }
.usage-stats { font-size: 12px; color: var(--muted); text-align: right; }

/* ── Settings ─────────────────────────────────────────── */
.settings-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 11px 0; border-bottom: 1px solid #f0f0f0; cursor: pointer;
}
.settings-row:last-child { border-bottom: none; }
.settings-row-label { font-size: 14px; color: var(--text); }
.settings-row-value { font-size: 13px; color: var(--muted); max-width: 55%; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.settings-row-arrow { color: #ccc; font-size: 12px; margin-left: 6px; }

/* ── Modal / Overlay ──────────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.45); z-index: 200;
  align-items: flex-end; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal-sheet {
  background: white; border-radius: 20px 20px 0 0;
  width: 100%; max-width: 480px; max-height: 90vh;
  overflow-y: auto; padding: 20px 16px 32px;
}
.modal-handle {
  width: 36px; height: 4px; background: #ddd;
  border-radius: 2px; margin: 0 auto 16px;
}
.modal-title { font-size: 16px; font-weight: 600; margin-bottom: 16px; }
.modal-close { float: right; font-size: 20px; cursor: pointer; color: var(--muted); }

/* ── Empty State ──────────────────────────────────────── */
.empty {
  text-align: center; padding: 32px 20px;
  color: var(--muted); font-size: 13px; line-height: 1.7;
}
.empty-icon { font-size: 36px; margin-bottom: 8px; }

/* ── Filter Tabs ──────────────────────────────────────── */
.filter-bar {
  display: flex; background: white; border-radius: 10px;
  overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.08);
  margin-bottom: 12px;
}
.filter-tab {
  flex: 1; padding: 10px; font-size: 13px; text-align: center;
  cursor: pointer; background: transparent; border: none;
  color: var(--muted); font-weight: 500; font-family: inherit;
}
.filter-tab.active { background: var(--dark); color: white; }

/* ── Spacer ───────────────────────────────────────────── */
.spacer-24 { height: 24px; }

/* ── Invoice form components ──────────────────────────── */
.inv-section-label {
  font-size: 11px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em;
  margin: 12px 0 6px;
}
.inv-toggle {
  flex: 1; padding: 9px 6px; font-size: 13px; font-weight: 500;
  background: var(--grey); border: 1px solid var(--border);
  border-radius: 8px; cursor: pointer; font-family: inherit;
  color: var(--muted); transition: all .15s;
}
.inv-toggle.sel {
  background: var(--brand); color: white; border-color: var(--brand);
}
.inv-toggle-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-top: 1px solid #f0f0f0; margin-top: 4px;
  font-size: 14px; font-weight: 500; color: var(--text);
}
.inv-chip {
  font-size: 12px; padding: 5px 12px; border-radius: 20px;
  background: var(--grey); border: 1px solid var(--border);
  cursor: pointer; color: var(--brand); font-weight: 600;
  font-family: inherit;
}
.inv-total-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 0 4px; border-top: 2px solid var(--dark); margin-top: 8px;
  font-size: 15px; font-weight: 700;
}
.inv-total-val { color: var(--brand); font-size: 18px; }

/* ── Login Screen ─────────────────────────────────────── */
.login-screen {
  position: fixed; inset: 0;
  background: linear-gradient(180deg, #0f4a87 0%, #185FA5 100%);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  z-index: 200;
}
.login-card {
  background: white;
  border-radius: 18px;
  padding: 28px 24px 22px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 12px 36px rgba(0,0,0,.25);
}
.login-logo {
  width: 56px; height: 56px;
  background: var(--brand); color: white;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 700;
  margin: 0 auto 14px;
}
.login-title { font-size: 20px; font-weight: 700; text-align: center; color: var(--text); }
.login-sub   { font-size: 13px; color: var(--muted); text-align: center; margin: 4px 0 22px; }

/* ── Toasts ───────────────────────────────────────────── */
#toast-host {
  position: fixed;
  left: 50%;
  bottom: calc(80px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
}
.toast {
  background: rgba(28,28,30,.95);
  color: white;
  padding: 11px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s, transform .2s;
  max-width: 88vw;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: rgba(46,125,50,.97); }
.toast-error   { background: rgba(198,40,40,.97); }

/* ── Loading spinner ──────────────────────────────────── */
.loading { text-align: center; padding: 24px; color: var(--muted); font-size: 13px; }

/* ── Invoice form specifics ───────────────────────────── */
.inv-from-qt {
  background: #e8f4fd; border: 1px solid #1a73e8;
  border-radius: 8px; padding: 10px 12px;
  font-size: 12px; color: #1a4a7a; margin-bottom: 12px; line-height: 1.6;
}
