:root {
  color-scheme: light;
  --bg: #f5efe3;
  --grid: rgba(24, 33, 47, 0.04);
  --panel: #fffaf1;
  --panel-strong: #ffffff;
  --panel-soft: #fff3da;
  --line: #dfd4c1;
  --text: #18212f;
  --muted: #697386;
  --accent: #0f766e;
  --accent-strong: #0d9488;
  --accent-soft: #d8f3ed;
  --blue: #1f7ee6;
  --cyan: #0ea5e9;
  --green: #16a34a;
  --orange: #ea580c;
  --red: #dc2626;
  --shadow: 0 24px 70px rgba(72, 55, 38, 0.16);
  --soft-shadow: 0 14px 42px rgba(72, 55, 38, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, var(--grid) 1px, transparent 1px),
    linear-gradient(180deg, var(--grid) 1px, transparent 1px),
    radial-gradient(circle at 12% 0%, rgba(255, 255, 255, 0.92), transparent 30rem),
    radial-gradient(circle at 86% 8%, rgba(216, 243, 237, 0.68), transparent 24rem),
    var(--bg);
  background-size: 28px 28px, 28px 28px, auto, auto;
  color: var(--text);
  font-family: Inter, Manrope, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.65rem 0.75rem;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  outline: none;
}

button,
.mode-select {
  min-height: 36px;
  border: 1px solid rgba(15, 118, 110, 0.22);
  border-radius: 999px;
  padding: 0.5rem 0.82rem;
  background: linear-gradient(135deg, #00a889, #007d8a);
  color: #ffffff;
  cursor: pointer;
  font-weight: 900;
  box-shadow: 0 10px 24px rgba(0, 128, 128, 0.14);
}

button:hover {
  background: linear-gradient(135deg, #0d9488, #0284c7);
}

.hidden {
  display: none !important;
}

.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    linear-gradient(90deg, rgba(24, 33, 47, 0.045) 1px, transparent 1px),
    linear-gradient(180deg, rgba(24, 33, 47, 0.045) 1px, transparent 1px),
    radial-gradient(circle at 50% 34%, rgba(255, 255, 255, 0.96), rgba(245, 239, 227, 0.9) 28rem),
    var(--bg);
  background-size: 30px 30px, 30px 30px, auto, auto;
}

.loading-card {
  display: grid;
  width: min(520px, 100%);
  min-height: 390px;
  justify-items: center;
  align-content: center;
  gap: 0.82rem;
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: clamp(1.6rem, 4vw, 2.35rem);
  background: rgba(255, 250, 241, 0.94);
  box-shadow: var(--shadow);
  text-align: center;
}

.loading-card h1 {
  display: grid;
  min-width: min(360px, 100%);
  min-height: 2.2em;
  place-items: center;
  margin: 0;
  font-size: clamp(1.55rem, 3vw, 2.25rem);
  line-height: 1.06;
}

.loading-tubes {
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 0.42rem;
  width: min(360px, 100%);
  height: 120px;
  padding-top: 0.5rem;
}

.loading-tubes span {
  display: grid;
  width: clamp(38px, 9vw, 54px);
  height: 108px;
  align-items: end;
  overflow: hidden;
  border: 1px solid hsl(var(--hue) 56% 70%);
  border-radius: 999px 999px 12px 12px;
  background: hsl(var(--hue) 72% 94%);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.76),
    0 14px 28px hsl(var(--hue) 62% 46% / 0.14);
}

.loading-tubes span::before {
  content: "";
  display: block;
  width: 100%;
  height: 48%;
  border-radius: 999px 999px 10px 10px;
  background: linear-gradient(180deg, hsl(var(--hue) 88% 64%), hsl(var(--hue) 78% 46%));
  animation: tubeLoad 1.25s ease-in-out infinite;
  animation-delay: calc(var(--hue) * -0.006s);
}

.loading-progress {
  width: min(340px, 100%);
  height: 0.7rem;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(104, 115, 134, 0.16);
}

.loading-progress span {
  display: block;
  width: var(--progress, 0%);
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #22c55e, #0ea5e9, #d946ef);
  transition: width 0.28s ease;
}

.loading-percent {
  color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.18rem;
  font-weight: 950;
}

.loading-message {
  max-width: min(390px, 100%);
  min-height: 1.35em;
  margin: 0;
  color: var(--muted);
  font-weight: 850;
  line-height: 1.35;
}

.loading-message.is-error {
  color: var(--red);
}

.loading-close {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.55rem 1.2rem;
  background: rgba(255, 255, 255, 0.86);
  color: var(--text);
  font-weight: 900;
  box-shadow: 0 10px 24px rgba(72, 55, 38, 0.1);
}

.loading-close:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

@keyframes tubeLoad {
  0%, 100% {
    height: 30%;
  }
  50% {
    height: 92%;
  }
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.login-card {
  display: grid;
  width: min(420px, 100%);
  gap: 0.72rem;
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 1.65rem;
  background: rgba(255, 250, 241, 0.94);
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0 0 0.4rem;
  font-size: 2rem;
}

.login-card label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.login-card button {
  margin-top: 0.3rem;
}

.error-text {
  min-height: 1.2em;
  margin: 0;
  color: var(--red);
  font-weight: 850;
}

.shell {
  width: min(1780px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 18px 0 36px;
}

.topbar {
  display: grid;
  grid-template-columns: auto auto minmax(360px, 1fr) auto auto auto;
  gap: 0.72rem;
  align-items: center;
  margin-bottom: 0.8rem;
  border: 1px solid rgba(223, 212, 193, 0.72);
  border-radius: 22px;
  padding: 0.62rem 0.72rem;
  background: rgba(255, 250, 241, 0.82);
  box-shadow: 0 12px 34px rgba(72, 55, 38, 0.08);
  backdrop-filter: blur(10px);
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.55rem, 2.4vw, 2.35rem);
  letter-spacing: 0;
}

.years,
.months {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.36rem;
}

.year-btn,
.month-btn,
.ghost-btn {
  min-height: 34px;
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.82);
  color: var(--text);
  font-size: 0.84rem;
  box-shadow: none;
}

.year-btn.is-active,
.month-btn.is-active {
  border-color: transparent;
  background: linear-gradient(135deg, #00a889, #007d8a);
  color: #ffffff;
  box-shadow: 0 8px 18px rgba(0, 128, 128, 0.16);
}

.month-btn.is-off {
  opacity: 0.42;
  filter: grayscale(1);
  text-decoration: line-through;
}

.month-btn {
  min-width: 3.1rem;
  padding-inline: 0.64rem;
}

.mode-select {
  min-width: 11.5rem;
  background: rgba(255, 255, 255, 0.88);
  color: var(--accent);
  box-shadow: 0 8px 20px rgba(72, 55, 38, 0.08);
}

.notice {
  margin: 0 0 0.8rem;
  border: 1px solid rgba(15, 118, 110, 0.24);
  border-radius: 18px;
  padding: 0.75rem 0.9rem;
  background: rgba(216, 243, 237, 0.8);
  color: var(--accent);
  font-weight: 850;
}

.notice.is-error {
  border-color: rgba(220, 38, 38, 0.22);
  background: #fee2e2;
  color: var(--red);
}

.summary {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 0.58rem;
  margin-bottom: 0.8rem;
}

.kpi {
  min-height: 106px;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0.86rem;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.84), rgba(255, 250, 241, 0.96)),
    var(--panel);
  box-shadow: var(--soft-shadow);
}

.kpi:nth-child(1) {
  border-color: rgba(14, 165, 233, 0.24);
}

.kpi:nth-child(1) strong {
  color: #0369a1;
}

.kpi:nth-child(2) {
  border-color: rgba(15, 118, 110, 0.26);
}

.kpi:nth-child(2) strong {
  color: var(--accent);
}

.kpi:nth-child(3) {
  border-color: rgba(234, 88, 12, 0.2);
}

.kpi:nth-child(3) strong {
  color: var(--orange);
}

.kpi span {
  display: block;
  margin-bottom: 0.42rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.kpi strong {
  display: block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(1.35rem, 2vw, 2.05rem);
  line-height: 1.02;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(480px, 0.9fr) minmax(560px, 1.1fr);
  gap: 0.8rem;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0.9rem;
  background: rgba(255, 250, 241, 0.92);
  box-shadow: var(--soft-shadow);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.72rem;
}

.panel-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.muted {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.chart-empty,
.empty {
  display: grid;
  min-height: 420px;
  place-items: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.46);
}

.chart {
  display: block;
  width: 100%;
  height: 420px;
}

.chart-grid {
  stroke: rgba(105, 115, 134, 0.22);
  stroke-width: 1;
}

.chart-axis {
  stroke: rgba(23, 32, 51, 0.5);
  stroke-width: 1.5;
}

.chart-line {
  fill: none;
  stroke: var(--cyan);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-dot {
  fill: var(--cyan);
}

.chart-label,
.chart-y {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.table-root {
  overflow: auto;
  max-height: 640px;
}

table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  border: 1px solid rgba(223, 212, 193, 0.72);
  border-radius: 16px;
}

th,
td {
  border-bottom: 1px solid rgba(216, 223, 210, 0.82);
  padding: 0.64rem 0.58rem;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 950;
}

tbody tr:hover td {
  background: rgba(216, 243, 237, 0.26);
}

tbody tr:last-child td {
  border-bottom: 0;
}

td strong,
.money {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 950;
  white-space: nowrap;
}

.detail-btn {
  min-height: 0;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  color: var(--accent);
  text-align: left;
  font-weight: 950;
}

.detail-btn:hover {
  background: transparent;
  color: var(--blue);
}

.danger-mini {
  min-height: 30px;
  border: 1px solid rgba(220, 38, 38, 0.2);
  padding: 0.36rem 0.58rem;
  background: #ffe2e6;
  color: #b42335;
  box-shadow: none;
  white-space: nowrap;
}

.danger-mini:hover {
  background: #fecdd3;
  color: #991b1b;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(23, 32, 51, 0.34);
  backdrop-filter: blur(7px);
}

.modal-card {
  width: min(980px, calc(100vw - 2rem));
  max-height: min(720px, calc(100vh - 2rem));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 1.2rem;
  background: rgba(255, 250, 241, 0.98);
  box-shadow: var(--shadow);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.modal-head h2 {
  margin: 0;
}

.eyebrow {
  display: inline-block;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 950;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

@media (max-width: 1180px) {
  .topbar,
  .summary,
  .workspace {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 640px) {
  .shell {
    width: 100%;
    padding: 12px 10px 28px;
  }

  .summary {
    grid-template-columns: 1fr;
  }

  .months {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .month-btn {
    min-width: 0;
  }
}
