:root {
  color-scheme: light;
  --bg: #f6f7f2;
  --surface: #ffffff;
  --surface-strong: #eef3ed;
  --ink: #16201b;
  --muted: #66726c;
  --line: #dce4dc;
  --primary: #1d4638;
  --primary-2: #2f6b55;
  --accent: #d99b2b;
  --danger: #a43f35;
  --good: #2c7751;
  --info: #326e91;
  --shadow: 0 16px 40px rgba(20, 35, 29, 0.08);
  --radius: 8px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100%;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(238, 243, 237, 0.9), rgba(246, 247, 242, 0.78) 42%, var(--bg)),
    var(--bg);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(100%, 420px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--primary);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.brand-mark img {
  width: 44px;
  height: 44px;
  display: block;
}

.brand-title {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.1;
  letter-spacing: 0;
}

.brand-subtitle {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.layout {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(246, 247, 242, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.topbar-inner {
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: 12px 16px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}

.top-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.top-title img {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  flex: 0 0 auto;
}

.top-title h1 {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.1;
  letter-spacing: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-line {
  margin-top: 2px;
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 0.78rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 99px;
  background: var(--accent);
  display: inline-block;
}

.status-dot.cloud {
  background: var(--good);
}

.date-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

.date-control input {
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 0 10px;
  max-width: 145px;
}

.content {
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: 16px 16px 92px;
}

.view-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin: 8px 0 16px;
}

.view-head h2 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.1;
  letter-spacing: 0;
}

.view-head p {
  margin: 5px 0 0;
  color: var(--muted);
}

.grid {
  display: grid;
  gap: 12px;
}

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

.metric,
.panel,
.list-item,
.form-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 22px rgba(20, 35, 29, 0.04);
}

.metric {
  min-height: 104px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
}

.metric-label {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.metric-value {
  font-size: clamp(1.28rem, 6vw, 2rem);
  font-weight: 760;
  line-height: 1;
  letter-spacing: 0;
}

.metric-note {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.25;
}

.metric.good .metric-value {
  color: var(--good);
}

.metric.bad .metric-value {
  color: var(--danger);
}

.panel {
  padding: 16px;
}

.panel + .panel,
.grid + .panel,
.panel + .grid {
  margin-top: 12px;
}

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

.panel-head h3 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0;
}

.pill {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--primary);
  padding: 0 10px;
  font-weight: 700;
  font-size: 0.78rem;
  white-space: nowrap;
}

.progress-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5e8de;
}

.progress-fill {
  height: 100%;
  min-width: 2px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary-2), var(--accent));
}

.split-row,
.detail-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}

.detail-row {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.detail-row:last-child {
  border-bottom: 0;
}

.detail-row strong {
  display: block;
  font-size: 0.95rem;
}

.detail-row span {
  display: block;
  color: var(--muted);
  font-size: 0.84rem;
  margin-top: 3px;
}

.detail-value {
  font-weight: 760;
  white-space: nowrap;
}

.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  overflow-x: auto;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.segmented button {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 0 12px;
  white-space: nowrap;
}

.segmented button.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 4px 14px rgba(20, 35, 29, 0.08);
  font-weight: 750;
}

.form-box {
  padding: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 11px;
  outline: none;
}

.field textarea {
  min-height: 82px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--primary-2);
  box-shadow: 0 0 0 3px rgba(47, 107, 85, 0.12);
}

.actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 14px;
}

.btn {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  font-weight: 750;
  text-decoration: none;
}

.btn.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
}

.btn.danger {
  border-color: rgba(164, 63, 53, 0.22);
  color: var(--danger);
}

.btn.icon-only {
  width: 42px;
  padding: 0;
}

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

.list-item {
  padding: 14px;
}

.list-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.list-title {
  margin: 0;
  font-size: 0.98rem;
  line-height: 1.2;
}

.list-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
}

.list-amount {
  font-weight: 800;
  white-space: nowrap;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 28px 16px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.5);
}

.chart {
  display: grid;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(84px, 140px) 1fr auto;
  gap: 10px;
  align-items: center;
  font-size: 0.86rem;
}

.bar-track {
  height: 10px;
  background: #e5e8de;
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--info);
  border-radius: 999px;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  background: rgba(255, 255, 255, 0.95);
  border-top: 1px solid var(--line);
  padding: 8px max(8px, env(safe-area-inset-left)) calc(8px + var(--safe-bottom)) max(8px, env(safe-area-inset-right));
  backdrop-filter: blur(16px);
}

.bottom-nav-inner {
  width: min(720px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
}

.nav-btn {
  min-height: 52px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  gap: 2px;
  padding: 4px;
  font-size: 0.72rem;
  font-weight: 750;
}

.nav-btn svg {
  width: 20px;
  height: 20px;
  stroke-width: 2.2;
}

.nav-btn.active {
  color: var(--primary);
  background: var(--surface-strong);
}

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(78px + var(--safe-bottom));
  z-index: 50;
  width: min(520px, calc(100% - 32px));
  margin: 0 auto;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--ink);
  color: white;
  box-shadow: var(--shadow);
}

.hidden {
  display: none !important;
}

@media (min-width: 720px) {
  .content {
    padding-bottom: 34px;
  }

  .bottom-nav {
    position: sticky;
    bottom: auto;
    top: 59px;
    padding: 8px 16px;
    border-top: 0;
    border-bottom: 1px solid var(--line);
  }

  .bottom-nav-inner {
    width: min(1200px, 100%);
    grid-template-columns: repeat(5, max-content);
    justify-content: start;
  }

  .nav-btn {
    min-height: 42px;
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    padding: 0 12px;
  }

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

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

  .field.full {
    grid-column: 1 / -1;
  }

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

@media (min-width: 980px) {
  .dashboard-grid {
    grid-template-columns: 1.35fr 0.9fr;
    align-items: start;
  }

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