:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --ink: #111111;
  --muted: #6c6c6c;
  --line: #dddddd;
  --soft: #f1f1f1;
  --danger: #a93d34;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; }
button, summary, a { -webkit-tap-highlight-color: transparent; }

.page {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 0 clamp(24px, 4vw, 72px);
}

.topbar {
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.brand {
  color: var(--ink);
  text-decoration: none;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: .02em;
}

.more-menu { position: relative; }
.more-menu summary {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
  letter-spacing: 2px;
  border-radius: 50%;
}
.more-menu summary::-webkit-details-marker { display: none; }
.more-menu summary:hover { background: var(--soft); color: var(--ink); }
.menu-popover {
  position: absolute;
  z-index: 5;
  top: 48px;
  right: 0;
  width: 190px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 16px 45px rgba(0,0,0,.1);
}
.menu-popover a {
  display: block;
  padding: 10px 12px;
  color: var(--ink);
  text-decoration: none;
  border-radius: 6px;
  font-size: 13px;
}
.menu-popover a:hover { background: var(--soft); }

.balance {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 48px 0 70px;
}

.overline {
  margin: 0 0 22px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .2em;
  font-size: 11px;
  font-weight: 650;
}

.balance-value {
  display: flex;
  align-items: baseline;
  justify-content: center;
  line-height: .82;
}

.balance-value strong {
  font-size: clamp(120px, 20vw, 250px);
  font-weight: 300;
  letter-spacing: -.085em;
}

.balance-value > span {
  margin-left: 18px;
  color: var(--muted);
  font-size: clamp(28px, 4vw, 54px);
  font-weight: 350;
}

.balance-days {
  margin: 40px 0 0;
  color: var(--muted);
  font-size: 15px;
}

.category-balances {
  display: flex;
  gap: 24px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 12px;
}
.category-balances > span { display: flex; align-items: center; gap: 7px; }
.category-balances strong { margin-left: 2px; color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.category-dot { width: 7px; height: 7px; display: inline-block; flex: 0 0 auto; border-radius: 50%; }
.category-dot.unofficial { background: #9a9a9a; }
.category-dot.official { background: #4677c8; }

.main-actions {
  display: flex;
  align-items: center;
  gap: 38px;
  margin-top: 54px;
}

.round-action,
.text-action,
.dark-action,
.secondary-action,
.danger-action {
  border: 0;
  background: none;
  color: var(--ink);
  cursor: pointer;
  font-weight: 550;
}

.round-action {
  width: 58px;
  height: 58px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  font-size: 22px;
  font-weight: 350;
}
.round-action:hover { border-color: var(--ink); background: var(--surface); }
.text-action { margin-left: 12px; padding: 14px 20px; border: 1px solid var(--line); border-radius: 99px; color: var(--ink); }
.text-action:hover { color: var(--ink); }
.text-action span { font-variant-numeric: tabular-nums; }

.page-footer {
  min-height: 58px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  border-top: 1px solid var(--line);
  color: #999;
  font-size: 11px;
}

dialog {
  border: 0;
  padding: 0;
  color: var(--ink);
  background: transparent;
}
dialog::backdrop { background: rgba(0,0,0,.28); backdrop-filter: blur(2px); }

.panel-dialog {
  width: min(440px, calc(100vw - 24px));
  max-height: calc(100vh - 32px);
  margin: auto;
  border-radius: 14px;
  box-shadow: 0 25px 80px rgba(0,0,0,.16);
}

.history-dialog { width: min(720px, calc(100vw - 32px)); }

.panel {
  width: 100%;
  padding: 22px;
  background: var(--surface);
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.panel-head .overline { margin-bottom: 8px; }
h2 {
  margin: 0;
  font-size: 23px;
  line-height: 1.1;
  font-weight: 500;
  letter-spacing: -.025em;
}

.close-button {
  width: 32px;
  height: 32px;
  margin: -5px -5px 0 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 22px;
  font-weight: 300;
}
.close-button:hover { color: var(--ink); background: var(--soft); }

.type-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin: 18px 0 14px;
  padding: 2px;
  border: 0;
  border-radius: 9px;
  background: var(--soft);
}
.type-switch label { cursor: pointer; }
.type-switch input { position: absolute; opacity: 0; pointer-events: none; }
.type-switch span {
  display: block;
  padding: 8px;
  border-radius: 7px;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
  font-weight: 550;
}
.type-switch input:checked + span {
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(0,0,0,.09);
}

fieldset.category-switch {
  display: block;
  min-width: 0;
  margin: 0 0 14px;
  padding: 0;
  border: none;
}
.category-switch legend { display: block; width: 100%; margin: 0 0 6px; padding: 0; color: var(--muted); font-size: 10px; font-weight: 550; }
.category-options { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.category-switch label { min-width: 0; cursor: pointer; }
.category-switch input { position: absolute; opacity: 0; pointer-events: none; }
.category-switch span { display: flex; min-width: 0; align-items: center; justify-content: center; gap: 6px; padding: 7px 6px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); background: var(--surface); font-size: 10px; white-space: nowrap; }
.category-switch input:checked + span { border-color: #9d9d9d; color: var(--ink); background: var(--soft); box-shadow: inset 0 0 0 1px var(--surface); }

.form-grid { display: grid; grid-template-columns: 132px minmax(0, 1fr); gap: 12px; align-items: start; }
.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 550;
}
.field > span small, .field > small { color: #aaa; font-weight: 400; }
.time-hint { display: grid; gap: 2px; min-height: 25px; line-height: 1.2; }
.time-hint span:first-child { color: var(--ink); font-weight: 550; }
.time-hint span:last-child { color: #999; font-size: 10px; }
.time-parts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.time-part { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; height: 36px; padding-right: 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.time-part:focus-within { border-color: #888; }
.time-part input { min-width: 0; height: 34px; padding: 0 4px 0 9px; border: 0 !important; border-radius: 6px; }
.time-part > span { color: #999; font-size: 10px; font-weight: 400; }
.time-part input::-webkit-outer-spin-button,
.time-part input::-webkit-inner-spin-button { margin: 0; appearance: none; }
.time-part input[type=number] { appearance: textfield; }
.field input, .field textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: none;
  color: var(--ink);
  background: transparent;
}
.field input { height: 36px; resize: none; }
.field input[type="date"] { min-height: 36px; padding-block: 0; line-height: 34px; appearance: none; -webkit-appearance: none; }
.field textarea { min-height: 54px; resize: vertical; }
.field input:focus, .field textarea:focus { border-color: #888; }
.form-error { min-height: 15px; margin: 0; color: var(--danger); font-size: 11px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; padding-top: 14px; border-top: 1px solid var(--line); }
.dark-action, .secondary-action, .danger-action { padding: 9px 14px; border-radius: 6px; font-size: 12px; }
.dark-action { color: white; background: var(--ink); }
.secondary-action { border: 1px solid var(--line); }
.danger-action { color: white; background: var(--danger); }

.history { max-height: calc(100vh - 32px); overflow: auto; }
.history-list { margin-top: 25px; }
.history-row {
  display: grid;
  grid-template-columns: 92px 32px minmax(0, 1fr) auto 68px;
  align-items: center;
  gap: 12px;
  padding: 17px 0;
  border-top: 1px solid var(--line);
}
.history-row:first-child { border-top: 0; }
.entry-date { color: var(--muted); font-size: 12px; }
.entry-icon {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--soft);
  font-size: 16px;
}
.entry-copy { min-width: 0; }
.entry-copy strong { display: block; font-size: 13px; font-weight: 600; }
.category-label { display: inline-block; margin-left: 6px; padding: 3px 6px; border-radius: 99px; color: #666; background: #ededed; font-size: 9px; font-weight: 600; vertical-align: 1px; }
.category-label.official { color: #315f9f; background: #e7eef9; }
.entry-note { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-hours { font-size: 17px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.history-row.spent .entry-hours { color: var(--danger); }
.row-actions { display: flex; justify-content: flex-end; gap: 2px; }
.icon-button {
  width: 31px;
  height: 31px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 16px;
}
.icon-button:hover { color: var(--ink); background: var(--soft); }
.empty { padding: 52px 10px; color: var(--muted); text-align: center; font-size: 13px; }
.empty strong { display: block; margin-bottom: 7px; color: var(--ink); font-size: 18px; font-weight: 500; }

.confirm-dialog {
  width: min(400px, calc(100vw - 32px));
  margin: auto;
  border-radius: 14px;
  box-shadow: 0 25px 80px rgba(0,0,0,.16);
}
.confirm-card { padding: 28px; background: var(--surface); }
.confirm-card .overline { margin-bottom: 10px; }
.confirm-card > p:not(.overline) { margin: 14px 0 25px; color: var(--muted); font-size: 13px; }

.toast {
  position: fixed;
  z-index: 20;
  bottom: 24px;
  left: 50%;
  padding: 11px 16px;
  border-radius: 7px;
  color: white;
  background: var(--ink);
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: .2s;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

button:focus-visible, summary:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 600px) {
  .page { padding: 0 20px; }
  .topbar { height: 70px; }
  .balance { padding: 30px 0 45px; }
  .balance-value strong { font-size: clamp(105px, 38vw, 165px); }
  .balance-value > span { margin-left: 10px; font-size: 28px; }
  .balance-days { margin-top: 30px; font-size: 13px; }
  .category-balances { flex-direction: column; gap: 8px; align-items: flex-start; }
  .main-actions { gap: 12px; margin-top: 40px; }
  .text-action { margin-left: 4px; }
  .page-footer { justify-content: center; }
  .page-footer span:last-child { display: none; }
  .panel { padding: 20px 16px; }
  .form-grid { grid-template-columns: 1fr; gap: 0; }
  .category-options { grid-template-columns: 1fr; }
  .history-row { grid-template-columns: 66px 28px minmax(0,1fr) auto; gap: 8px; }
  .entry-date { font-size: 10px; }
  .row-actions { grid-column: 3 / -1; justify-content: flex-start; }
}
