:root {
  --bg: #FFFFFF;
  --surface: #F4F7F6;
  --border: #DCE3E0;
  --ink: #1E2A27;
  --muted: #66756F;
  --accent: #2F7D6D;
  --accent-press: #276B5D;
  --accent-soft: #E3F0EC;
  --flag: #B4570A;
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1.5l5 5 5-5' stroke='%2366756F' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  --font: "Figtree", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 400 16px/1.45 var(--font); -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
h1 { font-size: 20px; font-weight: 600; margin: 0 0 16px; }
h2 { font-size: 20px; font-weight: 600; margin: 28px 0 12px; }
main { max-width: 560px; margin: 0 auto; padding: 20px 20px calc(88px + env(safe-area-inset-bottom)); }
.muted { color: var(--muted); }
.err { color: var(--flag); min-height: 1.4em; margin: 8px 0 0; font-size: 14px; }

/* focus */
:focus { outline: none; }
:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* tab bar */
#tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--bg); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
#tabs button { flex: 1; min-height: 52px; background: none; border: 0; font: 500 16px var(--font); color: var(--muted); }
#tabs button.active { color: var(--accent); font-weight: 600; }
@media (min-width: 700px) {
  #tabs { position: static; border-top: 0; border-bottom: 1px solid var(--border); max-width: 560px; margin: 0 auto; padding-bottom: 0; }
  main { padding-bottom: 40px; }
}

/* form */
label { display: block; font-size: 14px; color: var(--muted); margin: 0 0 6px; }
.row { display: flex; gap: 12px; margin-bottom: 16px; }
.row > div { flex: 1; min-width: 0; }
.field { margin-bottom: 16px; }
input, select, textarea {
  display: block; width: 100%; min-width: 0; margin: 0; font: 400 16px/1.2 var(--font); color: var(--ink);
  background-color: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 0 14px; height: 48px;
  -webkit-appearance: none; -moz-appearance: none; appearance: none; text-align: left;
}
textarea { height: auto; min-height: 110px; padding: 12px 14px; resize: vertical; line-height: 1.45; }
select {
  padding-right: 40px; background-image: var(--chevron); background-repeat: no-repeat;
  background-position: right 14px center; background-size: 12px 8px; text-overflow: ellipsis;
}
input[type="date"], input[type="time"] { min-height: 48px; line-height: 48px; }
input[type="date"]::-webkit-date-and-time-value, input[type="time"]::-webkit-date-and-time-value { text-align: left; margin: 0; min-height: 1.2em; }
input[type="date"]::-webkit-datetime-edit, input[type="time"]::-webkit-datetime-edit { padding: 0; }
input[type="date"]::-webkit-calendar-picker-indicator, input[type="time"]::-webkit-calendar-picker-indicator { opacity: .55; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }
.suffix { position: relative; }
.suffix input { padding-right: 52px; }
.suffix span { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }

button { font-family: var(--font); cursor: pointer; }
button.primary { display: block; width: 100%; height: 52px; margin-top: 8px; padding: 0 16px; border: 0; border-radius: 12px; background: var(--accent); color: #fff; font: 600 16px var(--font); }
button.primary:active { background: var(--accent-press); }
button.primary:disabled { opacity: .7; cursor: default; }
button.ghost { height: 44px; padding: 0 16px; border: 1px solid var(--border); border-radius: 10px; background: #fff; color: var(--ink); font: 500 16px var(--font); }
button.ghost:active { background: var(--surface); }
button.ghost:disabled { color: var(--muted); opacity: .5; cursor: default; }
button.danger { color: var(--flag); }
.block { display: block; width: 100%; }

/* login */
#login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
#login form { width: 100%; max-width: 320px; }
#login input { margin-bottom: 0; }

/* entry rows */
.card { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 48px; margin: 0 0 8px; padding: 12px 14px; text-align: left; background: var(--surface); border: 0; border-left: 3px solid transparent; border-radius: 10px; font: 400 16px var(--font); color: var(--ink); }
.card.flag { border-left-color: var(--flag); }
.card .t { font-weight: 600; font-variant-numeric: tabular-nums; }
.card .x { color: var(--muted); }
.empty-note { color: var(--muted); margin: 0 0 8px; }

/* toast (non-animated) */
#toast { position: fixed; left: 50%; bottom: calc(72px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 14px; display: none; z-index: 20; }
#toast.show { display: block; }

/* dialog */
dialog { width: min(520px, 92vw); max-height: 92vh; border: 0; border-radius: 14px; padding: 20px; color: var(--ink); font-family: var(--font); }
dialog::backdrop { background: rgba(30, 42, 39, .45); }
.dlg-actions { display: flex; gap: 10px; margin-top: 16px; }
.dlg-actions button { flex: 1; }
.dlg-actions .primary { margin-top: 0; height: 44px; }

/* calendar */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.cal-head strong { font-size: 20px; font-weight: 600; }
.cal-head button { min-width: 44px; padding: 0 12px; font-size: 20px; }
.grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.dow { text-align: center; font-size: 14px; color: var(--muted); padding: 4px 0; }
.day { position: relative; aspect-ratio: 1; border: 0; border-radius: 10px; background: var(--surface); color: var(--ink); padding: 0; font: 500 16px var(--font); }
.day.empty { visibility: hidden; }
.day.zero { color: var(--muted); font-weight: 400; }
.day.sel { background: var(--accent-soft); }
.day.today { outline: 2px solid var(--accent); outline-offset: -2px; }
.day.today:focus-visible { outline-offset: 2px; }
.day .badge { position: absolute; right: 4px; bottom: 4px; min-width: 18px; height: 18px; padding: 0 6px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); font-size: 14px; font-weight: 600; line-height: 18px; text-align: center; }
.day.sel .badge { background: #fff; }
.ate { padding: 14px; border-radius: 10px; background: var(--surface); white-space: pre-wrap; }
.ate.hl { background: #FCF1E6; border-left: 3px solid var(--flag); }
.ate.hl .alert { color: var(--flag); font-weight: 600; margin-bottom: 8px; }
.ate b { display: block; font-size: 14px; font-weight: 500; color: var(--muted); margin-top: 10px; }
.ate b:first-child, .ate .alert + b { margin-top: 0; }

/* stats */
.summary { padding: 20px; border-radius: 12px; background: var(--surface); font-size: 16px; }
.summary strong { font-size: 28px; font-weight: 600; line-height: 1.25; color: var(--accent); }
.summary .note { color: var(--muted); font-size: 14px; margin-top: 8px; }
.seg { display: flex; gap: 8px; margin: 20px 0 12px; }
.seg button { flex: 1; height: 44px; border: 1px solid var(--border); background: #fff; color: var(--ink); border-radius: 10px; font: 500 16px var(--font); }
.seg button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { padding: 12px 14px; border-radius: 10px; background: var(--surface); }
.stat .k { font-size: 14px; color: var(--muted); }
.stat .v { font-size: 16px; font-weight: 600; }
svg.chart { display: block; width: 100%; height: auto; }
svg.chart .bar { fill: var(--accent); }
svg.chart .bar.dim { opacity: .35; }
svg.chart .cnt { font: 500 10px var(--font); fill: var(--ink); text-anchor: middle; }
svg.chart .hr { font: 400 10px var(--font); fill: var(--muted); text-anchor: middle; }
svg.chart .axis { stroke: var(--border); }
.trend { margin-top: 16px; padding: 14px; border-radius: 10px; background: var(--surface); }
