:root {
  font-family: "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #fff;
  --subtle: #f4f5f7;
  --line: #dfe2e8;
  --input-line: #b2bac7;
  --ink: #1b202b;
  --muted: #515b6c;
  --accent: #5739b9;
  --accent-hover: #452b9c;
  --accent-soft: #eee9fd;
  --focus: #7556df;
  --danger: #a1223e;
  --shadow: 0 12px 36px #2720460a;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}

:root[data-theme=dark] {
  color-scheme: dark;
  --bg: #15171b;
  --surface: #1e2127;
  --subtle: #262a32;
  --line: #373d48;
  --input-line: #626c7b;
  --ink: #f1f3f7;
  --muted: #b5bfcd;
  --accent: #c8b7ff;
  --accent-hover: #dfd4ff;
  --accent-soft: #332755;
  --focus: #b6a0ff;
  --danger: #ffb3c3;
  --shadow: 0 12px 34px #0002;
}

* { box-sizing: border-box; }
body, h1, h2, p, dl, dd { margin: 0; }
header { background: var(--surface); border-bottom: 1px solid var(--line); }
.wrap { width: min(1170px, calc(100% - 48px)); margin-inline: auto; }
.brand { display: flex; align-items: center; gap: 10px; min-height: 70px; font-size: 1.08rem; font-weight: 750; }
.clock { position: relative; display: inline-block; flex: none; width: 33px; height: 33px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); }
.clock::before { position: absolute; content: ""; inset: 7px; border: 1.8px solid; border-radius: 50%; }
.clock::after { position: absolute; content: ""; top: 11px; left: 16px; width: 4px; height: 6px; border-left: 1.8px solid; border-bottom: 1.8px solid; }
main { padding-block: 38px 52px; }
h1 { font-size: clamp(1.85rem, 4vw, 2.65rem); letter-spacing: -.045em; line-height: 1.12; }
.dashboard > h1 { margin-bottom: 22px; }
h2 { font-size: 1.16rem; letter-spacing: -.025em; margin-bottom: 18px; }
.layout { display: grid; grid-template-columns: minmax(300px, .83fr) minmax(0, 1.35fr); gap: 20px; align-items: start; }
.card { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 24px; box-shadow: var(--shadow); }

.month-summary {
  margin-bottom: 20px;
  padding: 22px 26px 25px;
  background: var(--surface);
  background: linear-gradient(115deg, var(--surface) 52%, color-mix(in srgb, var(--surface) 78%, var(--accent-soft)));
  border-top: 2px solid var(--accent);
}
.month-summary h2 { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-bottom: 16px; }
#summary-month { background: var(--accent-soft); color: var(--accent); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: .875rem; font-weight: 600; text-transform: capitalize; }
.month-summary dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.month-summary dl div { padding: 13px 16px; border: 1px solid var(--line); background: var(--surface); border-radius: 13px; }
.month-summary dt { font-size: .88rem; font-weight: 650; color: var(--muted); }
.month-summary dd { color: var(--ink); font-size: clamp(1.15rem, 3vw, 2rem); font-weight: 750; letter-spacing: -.035em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.month-summary .hint { color: var(--muted); font-weight: 500; letter-spacing: normal; }

form { display: grid; gap: 15px; }
label, legend { font-size: .875rem; font-weight: 650; }
input, select, button { font: inherit; }
input { accent-color: var(--accent); }
label > input:not([type=radio]), select {
  color: var(--ink);
  background: var(--subtle);
  border: 1px solid var(--input-line);
  border-radius: 9px;
  min-height: 42px;
}
label > input:not([type=radio]) { display: block; width: 100%; min-width: 0; margin-top: 5px; padding: 7px 10px; }
.pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 7px; }
.choices { display: flex; flex-wrap: wrap; gap: 7px; }
.choices label { display: flex; align-items: center; gap: 6px; border: 1px solid var(--input-line); border-radius: 9px; padding: 7px 9px; cursor: pointer; }
.choices label:has(:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.choices input { margin: 0; }
.duration, .history-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.duration { background: var(--subtle); border-radius: 9px; padding: 10px 13px; }
output { color: var(--accent); font-weight: 750; font-variant-numeric: tabular-nums; }
button { font-weight: 700; border: 1px solid transparent; border-radius: 9px; min-height: 44px; background: var(--accent); color: #fff; cursor: pointer; }
button:hover { background: var(--accent-hover); }
[data-theme=dark] button { color: #191b21; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

#theme { margin-left: auto; }
.brand button, #rates-close { background: var(--subtle); color: var(--ink); border-color: var(--line); min-height: 38px; padding: 4px 10px; font-size: .875rem; }
.brand button:hover, #rates-close:hover { background: var(--accent-soft); }
#rates-open { min-width: 38px; color: var(--accent); font-size: 1rem; }
.history-head h2 { margin: 0; }
#empty { margin-top: 15px; border: 1px dashed var(--input-line); border-radius: 13px; text-align: center; padding: 34px 12px; background: var(--subtle); }
#empty .clock { display: block; margin: 0 auto 9px; }
.hint, #notice, td small { font-size: .875rem; color: var(--muted); }
.storage-note { margin-top: 13px; }
#notice:empty { display: none; }
#notice.error, #rates-error, .login [role=alert] { color: var(--danger); }
.table-wrap { max-width: 100%; overflow-x: auto; margin-top: 15px; border: 1px solid var(--line); border-radius: 11px; }
table { border-collapse: collapse; width: 100%; font-size: .875rem; text-align: left; }
th, td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); background: var(--subtle); }
tr:last-child td { border-bottom: 0; }
td:first-child { overflow-wrap: anywhere; max-width: 145px; font-weight: 700; }
td:last-child { white-space: nowrap; font-variant-numeric: tabular-nums; }
td small { display: block; }

.login-wrap { padding-top: clamp(36px, 10vh, 110px); }
.login { max-width: 430px; margin-inline: auto; padding: 30px; }
.login-clock { margin-bottom: 12px; }
.login h1 { margin-bottom: 22px; font-size: 1.9rem; }
.login [role=alert] { margin-bottom: 14px; }
#rates-dialog { width: min(440px, calc(100% - 28px)); color: var(--ink); }
#rates-dialog::backdrop { background: #140d2baf; }
.rates-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

@media (max-width: 800px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  main { padding-block: 28px 40px; }
}
@media (max-width: 520px) {
  .wrap { width: calc(100% - 24px); }
  .brand { flex-wrap: wrap; gap: 6px; padding-block: 10px; min-height: 60px; }
  .brand button { padding-inline: 7px; }
  label > input:not([type=radio]), select { font-size: max(1rem, 16px); }
  .card { padding: 16px; }
  .month-summary dl { gap: 7px; }
  .month-summary dl div { padding: 9px; }
}

:root[data-palette=blue] {
  --accent: light-dark(#2359ab, #a8caff);
  --accent-hover: light-dark(#174587, #d2e3ff);
  --accent-soft: light-dark(#e7f0ff, #243859);
  --focus: light-dark(#3976ce, #a8caff);
}
:root[data-palette=green] {
  --accent: light-dark(#16634f, #9de5cd);
  --accent-hover: light-dark(#104d3d, #c0f5e3);
  --accent-soft: light-dark(#e0f5eb, #1d4036);
  --focus: light-dark(#218468, #9de5cd);
}
:root[data-palette=rose] {
  --accent: light-dark(#a23463, #ffb7d4);
  --accent-hover: light-dark(#84254e, #ffd3e5);
  --accent-soft: light-dark(#fbe8f0, #4b273c);
  --focus: light-dark(#bb4b7a, #ffb7d4);
}
:root[data-palette=amber] {
  --accent: light-dark(#8a4d12, #ffcb8c);
  --accent-hover: light-dark(#6a390b, #ffe0b6);
  --accent-soft: light-dark(#fff0dc, #4a3422);
  --focus: light-dark(#ac681e, #ffcb8c);
}
.palette-control { display: flex; align-items: center; gap: 7px; }
.palette-control select { min-height: 38px; padding: 4px 8px; border-color: var(--line); }



:root[data-background=violet] { --bg: light-dark(#efecf8, #1c1923); }
:root[data-background=blue] { --bg: light-dark(#eaf1f8, #161d27); }
:root[data-background=green] { --bg: light-dark(#eaf3ef, #161f1d); }
:root[data-background=rose] { --bg: light-dark(#f7edf1, #211a21); }
:root[data-background=amber] { --bg: light-dark(#f7f0e5, #211d18); }

.history-filters { display: flex; flex-wrap: wrap; gap: 8px; }
.period-filter { position: relative; }
.period-filter summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 7px 11px;
  font-size: .875rem;
  list-style: none;
  cursor: pointer;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--subtle);
}
.period-filter summary::-webkit-details-marker { display: none; }
.period-filter summary span { color: var(--muted); }
.period-filter summary strong, .period-options button { text-transform: capitalize; }
.period-filter summary::after {
  content: "";
  width: 6px;
  height: 6px;
  margin: 0 1px 3px 4px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
}
.period-filter[open] summary { border-color: var(--accent); }
.period-filter[open] summary::after { transform: rotate(225deg); margin-bottom: 0; }
.period-options {
  position: absolute;
  z-index: 2;
  inset: calc(100% + 6px) 0 auto auto;
  min-width: max(100%, 145px);
  max-height: 240px;
  overflow-y: auto;
  margin: 0;
  padding: 5px;
  list-style: none;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 12px 32px #0003;
}
.period-options button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 38px;
  padding: 5px 9px;
  text-align: left;
  color: var(--ink);
  background: transparent;
  font-size: .875rem;
}
.period-options button:hover, .period-options button[aria-pressed=true] {
  background: var(--accent-soft);
  color: var(--accent);
}
.period-options button[aria-pressed=true]::after { content: "✓"; }
#year-options { inset-inline: 0 auto; min-width: 100%; }
@media (max-width: 520px) {
  .history-filters { width: 100%; }
  .period-filter:nth-child(2) { flex: 1; min-width: 0; }
  .period-filter:nth-child(2) summary strong { flex: 1; }
}

.portal-name, .portal-preferences, .portal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.portal-name { white-space: nowrap; }
.portal-preferences { margin-left: auto; }
.portal-actions #theme { margin-left: 0; }
.portal-actions button, .portal-preferences select { height: 42px; }

@media (max-width: 760px) {
  .portal-bar { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; padding-block: 12px; }
  .portal-preferences, .portal-actions { display: grid; }
  .portal-preferences { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-left: 0; }
  .portal-preferences label { flex-direction: column; align-items: stretch; gap: 4px; }
  .portal-preferences select { width: 100%; min-width: 0; }
  .portal-actions { grid-template-columns: minmax(0, 1fr) 44px minmax(0, 1fr); }
  .portal-actions button { min-height: 44px; width: 100%; height: auto; }
}
