:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --chrome: #f7faf8;
  --surface: #ffffff;
  --surface-2: #eef5f2;
  --ink: #17211f;
  --muted: #66736f;
  --line: #dce5df;
  --teal: #5f8d82;
  --teal-2: #4f7f75;
  --gold: #d7ad66;
  --coral: #bf756e;
  --blue: #6b879f;
  --icon-line: #41645e;
  --bg-glow: rgba(95, 141, 130, 0.12);
  --accent-soft: rgba(95, 141, 130, 0.2);
  --focus-ring: rgba(95, 141, 130, 0.16);
  --seg-bg: #edf6f2;
  --seg-active: #ffffff;
  --seg-line: #d6e4dd;
  --button-bg: #78988e;
  --button-shadow: rgba(120, 152, 142, 0.2);
  --texture: radial-gradient(circle at 1px 1px, rgba(95, 141, 130, 0.14) 1px, transparent 0);
  --texture-size: 18px 18px;
  --texture-opacity: 0.18;
  --shadow: 0 10px 28px rgba(21, 42, 39, 0.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --sticky-brand-height: 62px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
}

html[data-theme="sea"] {
  --chrome: #f5f9fb;
  --bg: #f4f8fa;
  --surface-2: #edf5f8;
  --ink: #152129;
  --muted: #60737d;
  --line: #d9e5ea;
  --teal: #5f8595;
  --teal-2: #4f7b8d;
  --gold: #d5b06d;
  --coral: #bd7770;
  --blue: #617f9c;
  --icon-line: #435f68;
  --bg-glow: rgba(95, 133, 149, 0.12);
  --accent-soft: rgba(95, 133, 149, 0.2);
  --focus-ring: rgba(95, 133, 149, 0.16);
  --seg-bg: #edf5f8;
  --seg-active: #ffffff;
  --seg-line: #d4e4ea;
  --button-bg: #7893a5;
  --button-shadow: rgba(120, 147, 165, 0.2);
  --texture: linear-gradient(135deg, rgba(95, 133, 149, 0.1) 0 1px, transparent 1px 18px);
  --texture-size: 18px 18px;
  --texture-opacity: 0.44;
}

html[data-theme="sage"] {
  --chrome: #f7faf3;
  --bg: #f7f9f1;
  --surface-2: #eef4e8;
  --ink: #211f18;
  --muted: #687364;
  --line: #dde6d6;
  --teal: #6f8b68;
  --teal-2: #607f5d;
  --gold: #d2ae63;
  --coral: #bd7b6e;
  --blue: #71889b;
  --icon-line: #50684b;
  --bg-glow: rgba(111, 139, 104, 0.12);
  --accent-soft: rgba(111, 139, 104, 0.2);
  --focus-ring: rgba(111, 139, 104, 0.16);
  --seg-bg: #eff5e7;
  --seg-active: #ffffff;
  --seg-line: #dbe8cf;
  --button-bg: #82966f;
  --button-shadow: rgba(130, 150, 111, 0.2);
  --texture: radial-gradient(ellipse at 20% 10%, rgba(210, 174, 99, 0.14), transparent 35%), linear-gradient(0deg, rgba(111, 139, 104, 0.055) 1px, transparent 1px);
  --texture-size: auto, 100% 22px;
  --texture-opacity: 0.36;
}

html[data-theme="oat"] {
  --chrome: #fafaf5;
  --bg: #f7f7f2;
  --surface-2: #eff2ea;
  --ink: #20221d;
  --muted: #6f7368;
  --line: #e0e1d7;
  --teal: #838d78;
  --teal-2: #74806a;
  --gold: #d0ad72;
  --coral: #b8796f;
  --blue: #7a8796;
  --icon-line: #5d6856;
  --bg-glow: rgba(131, 141, 120, 0.12);
  --accent-soft: rgba(131, 141, 120, 0.2);
  --focus-ring: rgba(131, 141, 120, 0.16);
  --seg-bg: #eff1e9;
  --seg-active: #ffffff;
  --seg-line: #dfe3d7;
  --button-bg: #7f8975;
  --button-shadow: rgba(127, 137, 117, 0.2);
  --texture: radial-gradient(circle at 2px 2px, rgba(131, 141, 120, 0.11) 1px, transparent 0), linear-gradient(0deg, rgba(131, 141, 120, 0.055) 1px, transparent 1px);
  --texture-size: 20px 20px, 100% 24px;
  --texture-opacity: 0.34;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  position: relative;
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, var(--bg-glow), transparent 260px),
    var(--bg);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: var(--texture);
  background-size: var(--texture-size);
  opacity: var(--texture-opacity);
}

button,
input,
select {
  font: inherit;
  max-width: 100%;
  min-width: 0;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: calc(max(14px, var(--safe-top)) + 10px) 14px calc(92px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 6px 0 18px;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  flex: 1 1 auto;
  gap: 10px;
}

.brand-icon {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.brand-icon svg {
  width: 44px;
  height: 44px;
  display: block;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 1.16rem;
  line-height: 1.1;
  letter-spacing: 0;
}

.brand p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.78rem;
}

.month-control {
  flex: 0 1 238px;
  min-width: 0;
  max-width: 260px;
}

.month-picker {
  display: grid;
  grid-template-columns: 46px minmax(112px, 1fr) 46px;
  gap: 8px;
}

.month-step {
  display: grid;
  place-items: center;
  min-width: 46px;
  min-height: 52px;
  padding: 0;
  border: 1px solid var(--line);
  color: var(--teal);
  background: var(--surface);
  font-size: 1.15rem;
  font-weight: 700;
}

.month-display {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 52px;
  padding: 0 8px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: var(--surface);
  font-size: 0.96rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}

label {
  display: grid;
  min-width: 0;
  gap: 6px;
  color: var(--muted);
  font-size: 0.86rem;
}

input,
select {
  display: block;
  width: 100%;
  min-height: 50px;
  height: 50px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--ink);
  background: var(--surface);
  outline: none;
  font-size: 1rem;
  line-height: 50px;
  text-align: left;
}

input[type="date"],
input[type="time"],
input[type="month"] {
  -webkit-appearance: none;
  appearance: none;
  min-width: 0;
  display: flex;
  align-items: center;
  line-height: normal;
  padding-top: 0;
  padding-bottom: 0;
  text-align: center;
}

input[type="date"]::-webkit-date-and-time-value,
input[type="time"]::-webkit-date-and-time-value,
input[type="month"]::-webkit-date-and-time-value {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  line-height: normal;
  margin: 0;
  text-align: center;
}

select {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 42px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--teal) 50%),
    linear-gradient(135deg, var(--teal) 50%, transparent 50%);
  background-position:
    calc(100% - 20px) 50%,
    calc(100% - 14px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

input:focus,
select:focus {
  border-color: var(--teal-2);
  box-shadow: 0 0 0 3px rgba(31, 129, 116, 0.14);
}

select:disabled {
  color: var(--muted);
  background: #f0f3f1;
}

.tab-panel {
  display: none;
}

.tab-panel.is-active {
  display: block;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 12px 0 10px;
}

.section-title h2,
.panel-heading h2 {
  font-size: 1rem;
  letter-spacing: 0;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.metric-card {
  min-height: 104px;
  display: grid;
  align-content: space-between;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-card span,
.metric-card small {
  color: var(--muted);
  font-size: 0.78rem;
}

.metric-card strong {
  font-size: clamp(1.28rem, 8vw, 1.82rem);
  line-height: 1.05;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.metric-card:nth-child(2) {
  border-color: color-mix(in srgb, var(--blue) 22%, var(--line));
}

.metric-card:nth-child(3) {
  border-color: color-mix(in srgb, var(--gold) 28%, var(--line));
}

.metric-card.danger strong,
.metric-card.danger small {
  color: var(--coral);
}

.tool-panel {
  margin: 16px 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.compact-panel {
  box-shadow: none;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  min-width: 0;
}

.form-grid label:nth-child(5),
.form-grid label:nth-child(6) {
  grid-column: span 1;
}

.two-col {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.split-box {
  margin-top: 14px;
  display: grid;
  gap: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 3px;
  border: 1px solid var(--seg-line);
  border-radius: 8px;
  background: var(--seg-bg);
}

.segmented label {
  display: block;
  color: var(--muted);
  font-size: 0.86rem;
}

.segmented input {
  position: absolute;
  width: 1px;
  min-height: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: grid;
  min-height: 46px;
  place-items: center;
  border-radius: 6px;
}

.segmented input:checked + span {
  color: var(--ink);
  background: var(--seg-active);
  box-shadow: 0 1px 4px rgba(21, 42, 39, 0.12);
}

.split-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 0.86rem;
}

.split-preview span,
.split-tags span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--teal);
  white-space: nowrap;
}

.manual-fields {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  align-items: end;
  gap: 10px;
  min-width: 0;
}

.form-actions,
.backup-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.primary-button {
  color: #fff;
  background: var(--teal);
}

.secondary-button {
  color: #fff;
  background: var(--button-bg);
  box-shadow: 0 8px 18px var(--button-shadow);
}

.ghost-button {
  border: 1px solid var(--line);
  color: var(--teal);
  background: var(--surface);
}

.danger-button {
  color: #fff;
  background: var(--coral);
}

.icon-button {
  width: 40px;
  min-width: 40px;
  padding: 0;
  color: var(--teal);
  background: #eef5f2;
}

.danger-icon {
  color: var(--coral);
  background: #fbefed;
}

.record-list {
  display: grid;
  gap: 10px;
}

.record-item {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.record-main {
  min-width: 0;
  display: grid;
  gap: 7px;
}

.record-title,
.record-meta,
.split-tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
}

.record-title strong {
  font-size: 1.12rem;
}

.record-title span,
.record-meta,
.record-warning {
  color: var(--muted);
  font-size: 0.82rem;
}

.record-meta span {
  overflow-wrap: anywhere;
}

.record-warning {
  color: var(--coral);
}

.record-actions {
  display: grid;
  align-content: start;
  gap: 8px;
}

.filters,
.import-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 4px 0 14px;
  min-width: 0;
}

.import-row {
  grid-template-columns: 160px 1fr;
  align-items: end;
  margin: 12px 0 0;
}

.file-picker input {
  padding-top: 9px;
}

.advice-panel {
  margin-top: 12px;
}

.advice-card {
  padding: 14px;
  border: 1px solid var(--accent-soft);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.advice-card.warning {
  border-color: rgba(212, 155, 55, 0.42);
}

.advice-card.danger {
  border-color: rgba(201, 93, 75, 0.44);
}

.advice-card.ok {
  border-color: rgba(31, 129, 116, 0.28);
}

.advice-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.advice-heading h2 {
  font-size: 1rem;
}

.advice-heading p,
.advice-note,
.advice-grid small,
.advice-grid span {
  color: var(--muted);
}

.advice-heading p {
  margin-top: 5px;
  font-size: 0.82rem;
  line-height: 1.45;
}

.advice-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.advice-grid div {
  min-width: 0;
  display: grid;
  gap: 5px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.advice-grid span,
.advice-grid small {
  font-size: 0.76rem;
}

.advice-grid strong {
  font-size: 1.04rem;
  line-height: 1.1;
}

.advice-note {
  margin-top: 12px;
  font-size: 0.82rem;
  line-height: 1.45;
}

.stats-layout {
  display: grid;
  gap: 18px;
  margin-top: 16px;
}

.stats-layout h3 {
  margin-bottom: 10px;
  font-size: 0.94rem;
}

.stat-table {
  display: grid;
  gap: 8px;
}

.stat-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

.stat-row small {
  grid-column: 1 / -1;
  color: var(--muted);
}

.close-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.close-grid div {
  display: grid;
  gap: 4px;
}

.close-grid span {
  color: var(--muted);
  font-size: 0.78rem;
}

.close-grid strong {
  font-size: 1rem;
}

.danger-zone {
  margin: 18px 0 4px;
  display: flex;
  justify-content: flex-end;
}

.app-version {
  margin: 6px 0 18px;
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
}

.theme-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.theme-choice {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 62px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
  text-align: left;
}

.theme-choice.is-active {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.theme-swatch {
  display: flex;
  width: 48px;
  height: 34px;
  overflow: hidden;
  border: 1px solid rgba(23, 33, 31, 0.08);
  border-radius: 8px;
  background: var(--surface-2);
}

.theme-swatch i {
  flex: 1 1 0;
}

.theme-choice strong,
.theme-choice small {
  display: block;
}

.theme-choice small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.25;
}

.empty-state {
  min-height: 88px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.58);
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(18px);
}

.bottom-nav button {
  min-width: 0;
  min-height: 44px;
  padding: 0 4px;
  color: var(--muted);
  background: transparent;
  font-size: 0.82rem;
}

.bottom-nav button.is-active {
  color: #fff;
  background: var(--teal);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(78px + env(safe-area-inset-bottom));
  z-index: 20;
  max-width: min(340px, calc(100vw - 28px));
  transform: translateX(-50%) translateY(16px);
  opacity: 0;
  pointer-events: none;
  padding: 10px 14px;
  border-radius: 8px;
  color: #fff;
  background: rgba(23, 33, 31, 0.92);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.hidden {
  display: none !important;
}

@media (max-width: 520px) {
  .app-shell {
    padding-top: 0;
  }

  .topbar {
    align-items: center;
    gap: 16px;
    padding-top: calc(var(--sticky-brand-height) + 12px);
  }

  .brand {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 12;
    flex: 1 1 100%;
    width: 100%;
    height: var(--sticky-brand-height);
    padding: 8px 14px 10px;
    border-radius: 0;
    background: var(--chrome);
    box-shadow: 0 1px 0 rgba(220, 229, 223, 0.64);
  }

  h1 {
    font-size: 1.12rem;
  }

  .month-control {
    flex: 1 1 100%;
    min-width: 0;
    max-width: 100%;
  }

  .month-picker {
    grid-template-columns: 56px minmax(0, 1fr) 56px;
    gap: 10px;
  }

  .month-step,
  .month-display {
    min-height: 56px;
  }

  .month-display {
    font-size: 1.05rem;
  }

  .form-grid,
  .filters,
  .manual-fields,
  .import-row {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .form-grid > label,
  .filters > label,
  .import-row > label,
  .manual-fields > label {
    min-width: 0;
  }

  input,
  select {
    min-height: 56px;
    height: 56px;
    border-radius: 10px;
    padding-left: 16px;
    padding-right: 16px;
    line-height: 56px;
  }

  select {
    padding-right: 46px;
  }

  .metric-card {
    min-height: 112px;
    padding: 12px;
  }

  .manual-fields .ghost-button {
    width: 100%;
    min-height: 52px;
  }

  .tool-panel {
    padding: 14px 12px;
  }

  .advice-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .advice-heading .ghost-button {
    width: 100%;
    min-height: 48px;
  }

  .advice-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .theme-options {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 860px) {
  .app-shell {
    padding-bottom: 110px;
  }

  #tab-overview.is-active {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 400px;
    gap: 18px;
    align-items: start;
  }

  #tab-overview .section-title:first-child,
  #tab-overview .metric-grid,
  #tab-overview .section-title:last-of-type,
  #tab-overview #recentList {
    grid-column: 1;
  }

  #tab-overview .tool-panel {
    grid-column: 2;
    grid-row: 1 / span 4;
    margin-top: 0;
    position: sticky;
    top: 12px;
  }

  .stats-layout {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .close-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .bottom-nav {
    width: min(680px, calc(100% - 32px));
    left: 50%;
    right: auto;
    bottom: 14px;
    transform: translateX(-50%);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow);
  }
}
