/* Mz Expense — plain CSS, theme via data-theme + data-accent on <html> */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root { --radius: 12px; }

html[data-accent="blue"]   { --accent: #4f7cff; }
html[data-accent="green"]  { --accent: #2bb673; }
html[data-accent="purple"] { --accent: #9b5cff; }
html[data-accent="orange"] { --accent: #ff9f43; }
html[data-accent="pink"]   { --accent: #ff5c8a; }
html[data-accent="teal"]   { --accent: #19b8c2; }

html[data-theme="dark"] {
  --bg: #16161f; --bg2: #1e1e2c; --card: #232334; --text: #e9e9f2;
  --muted: #9aa0b4; --border: #34344e; --input: #1b1b28;
  --danger: #e63946; --ok: #2bb673;
}
html[data-theme="light"] {
  --bg: #f2f4f9; --bg2: #ffffff; --card: #ffffff; --text: #1d1d2a;
  --muted: #66708a; --border: #dcdfe8; --input: #f7f8fc;
  --danger: #d62839; --ok: #1f9d63;
}

body {
  font-family: "Segoe UI", "Noto Sans Thai", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ---------- layout ---------- */

#topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 18px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 1.05rem; }
#menuBtn { display: none; }
#nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
#nav a {
  color: var(--muted); text-decoration: none;
  padding: 6px 12px; border-radius: 8px; font-size: 0.95rem;
}
#nav a:hover { color: var(--text); background: rgba(128,128,160,.12); }
#nav a.active { color: var(--accent); background: rgba(128,128,160,.15); }
.userbox { color: var(--muted); font-size: 0.9rem; }

main { max-width: 860px; margin: 0 auto; padding: 18px 14px 60px; }
main > * + * { margin-top: 16px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.card h1 { font-size: 1.4rem; margin-bottom: 8px; }
.card h2 { font-size: 1.05rem; margin-bottom: 12px; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.spread { justify-content: space-between; }

/* ---------- forms ---------- */

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > label { font-size: 0.85rem; color: var(--muted); }
input, select, textarea {
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  padding: 9px 11px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; width: 100%; }
.check { display: flex; align-items: center; gap: 8px; margin: 8px 0 14px; font-size: 0.95rem; }

.btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  padding: 9px 16px;
  transition: background .15s ease, transform .1s ease;
}
.btn:hover { background: rgba(128,128,160,.12); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.ghost { border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); }
.btn.sm { padding: 4px 10px; font-size: .85rem; }
.btn.icon { padding: 6px 10px; color: var(--muted); }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.seg .segbtn { border: none; border-radius: 0; padding: 7px 16px; }
.seg .segbtn.active { background: var(--accent); color: #fff; }

.pill {
  background: rgba(128,128,160,.14);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  padding: 7px 18px;
}
.pill:hover { background: rgba(128,128,160,.25); }

/* ---------- voice input ---------- */

.voicecard { display: flex; flex-direction: column; align-items: center; gap: 16px; text-align: center; }
#micBtn {
  width: 110px; height: 110px; border-radius: 50%;
  border: none; cursor: pointer;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 20px rgba(0,0,0,.35);
  transition: transform .15s ease, background .2s ease;
}
#micBtn:hover { transform: scale(1.06); }
#micBtn:disabled { opacity: .4; cursor: default; }
#micBtn svg { width: 48px; height: 48px; fill: currentColor; }
#micBtn.listening {
  background: var(--danger);
  animation: pulse 1.2s infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(230,57,70,.5); }
  70%  { box-shadow: 0 0 0 25px rgba(230,57,70,0); }
  100% { box-shadow: 0 0 0 0 rgba(230,57,70,0); }
}
#micStatus { min-height: 1.4em; color: var(--muted); font-size: .95rem; }

#transcript {
  width: min(700px, 100%);
  min-height: 110px;
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  font-size: 1.1rem;
  line-height: 1.6;
  text-align: left;
  white-space: pre-wrap;
}
#transcript:focus { outline: none; border-color: var(--accent); }
#transcript:empty::before { content: attr(data-ph); color: var(--muted); }
#transcript .interim { color: var(--muted); }
textarea#transcript { font: inherit; }

/* ---------- tables ---------- */

.tbl { width: 100%; border-collapse: collapse; font-size: .95rem; }
.tbl th, .tbl td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.tbl th { color: var(--muted); font-weight: 600; font-size: .85rem; }
.tbl tfoot td { font-weight: 700; border-bottom: none; }
.tbl .actions { white-space: nowrap; text-align: right; }
.tbl .more { display: none; }          /* mobile-only row expander indicator */
.tbl .recactions { display: none; }    /* mobile-only expanded action strip */

.chip {
  display: inline-block;
  background: rgba(128,128,160,.16);
  border-radius: 12px;
  padding: 2px 10px;
  font-size: .8rem;
  color: var(--muted);
}

/* ---------- charts ---------- */

.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 150px 1fr 90px; gap: 10px; align-items: center; font-size: .9rem; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: rgba(128,128,160,.15); border-radius: 7px; height: 14px; }
.bar { background: var(--accent); border-radius: 7px; height: 14px; min-width: 4px; }
.bar-val { text-align: right; font-variant-numeric: tabular-nums; }

.mchart { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 10px; }
.mcol { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.mbar { width: 100%; max-width: 44px; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.mlabel { color: var(--muted); font-size: .75rem; }

.pie-wrap { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.pie { width: 190px; height: 190px; flex: 0 0 auto; }
.pie path { stroke: var(--card); }
.legend { list-style: none; font-size: .9rem; }
.legend li { padding: 3px 0; display: flex; align-items: center; gap: 8px; }
.legend .dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }

/* ---------- search ---------- */

.searchgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.searchgrid .field { margin-bottom: 0; }

/* ---------- settings ---------- */

.swatches { display: flex; gap: 10px; }
.sw { width: 34px; height: 34px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.sw.active { border-color: var(--text); }
.sw-blue   { background: #4f7cff; } .sw-green  { background: #2bb673; }
.sw-purple { background: #9b5cff; } .sw-orange { background: #ff9f43; }
.sw-pink   { background: #ff5c8a; } .sw-teal   { background: #19b8c2; }

.userlist { list-style: none; margin-bottom: 12px; }
.userlist li { padding: 6px 0; border-bottom: 1px solid var(--border); }

/* ---------- auth ---------- */

.authcard { max-width: 420px; margin: 8vh auto 0; }

/* ---------- modal & toast ---------- */

.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal { width: min(440px, 100%); }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(80px);
  background: var(--card); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 20px; font-size: .95rem;
  opacity: 0; pointer-events: none;
  transition: transform .25s ease, opacity .25s ease;
  z-index: 100; max-width: 90vw;
}
#toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
#toast.ok  { border-color: var(--ok); }
#toast.err { border-color: var(--danger); }

/* ---------- responsive ---------- */

@media (max-width: 640px) {
  .bar-row { grid-template-columns: 110px 1fr 70px; }
  #topbar { flex-wrap: nowrap; gap: 8px; padding: 8px 10px; }
  #menuBtn { display: inline-flex; align-items: center; justify-content: center; }
  .brand { font-size: .95rem; white-space: nowrap; }
  #nav {
    display: none;
    position: absolute; top: 100%; left: 0; right: 0;
    flex-direction: column; gap: 2px; flex: none;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 10px 24px rgba(0,0,0,.35);
    padding: 8px 10px 12px;
  }
  #topbar.open #nav { display: flex; }
  #nav a { padding: 11px 12px; white-space: nowrap; font-size: 1rem; }
  .userbox { margin-left: auto; }
  main { padding: 12px 8px 50px; }
  .card { padding: 14px; }
  .tbl { font-size: .85rem; }
  .tbl th, .tbl td { padding: 6px 5px; }
  .tbl .by { display: none; }
  .tbl .actions { display: none; }
  .tbl .more { display: table-cell; color: var(--muted); text-align: right; width: 1ch; }
  .tbl tbody tr.recrow { cursor: pointer; }
  .tbl tr.recrow.open + .recactions { display: table-row; }
  .recactions td { text-align: right; }
  .recactions td .btn { margin-left: 8px; }
  .chip { padding: 2px 8px; font-size: .75rem; }
  .btn.sm { padding: 4px 8px; font-size: .8rem; }
  #micBtn { width: 92px; height: 92px; }
  #micBtn svg { width: 40px; height: 40px; }
  #transcript { min-height: 90px; font-size: 1rem; }
  .pie { width: 150px; height: 150px; }
  .pie-wrap { gap: 14px; }
  .legend { font-size: .8rem; }
}
