:root {
  --paper: #f7f3ea;
  --paper-strong: #fffdf8;
  --ink: #17212b;
  --muted: #52606d;
  --line: rgba(23, 33, 43, 0.12);
  --line-strong: rgba(23, 33, 43, 0.22);
  --accent: #b45309;
  --accent-soft: rgba(180, 83, 9, 0.14);
  --teal: #0f766e;
  --teal-soft: rgba(15, 118, 110, 0.14);
  --danger: #b91c1c;
  --danger-soft: rgba(185, 28, 28, 0.12);
  --shadow: 0 24px 60px rgba(23, 33, 43, 0.12);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --navbar-top-offset: 16px;
  --header-stack-gap: 40px;
  --app-navbar-shell-offset: 122px;
  --app-navbar-hide-offset: 160px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(15, 118, 110, 0.14), transparent 28%),
    radial-gradient(circle at top right, rgba(180, 83, 9, 0.16), transparent 24%),
    linear-gradient(180deg, #f4efe5 0%, #f8f6f1 100%);
  color: var(--ink);
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.shell {
  width: min(1380px, calc(100% - 40px));
  margin: 0 auto;
  padding: var(--app-navbar-shell-offset) 0 52px;
}

.app-navbar {
  position: fixed;
  top: var(--navbar-top-offset);
  left: 50%;
  width: min(1380px, calc(100% - 40px));
  margin-top: 0;
  display: flex;
  align-items: center;
  gap: 0;
  padding: 8px 18px;
  border: 1px solid var(--line);
  border-radius: 26px;
  background:
    linear-gradient(135deg, rgba(255, 253, 248, 0.94), rgba(255, 249, 240, 0.9)),
    var(--paper-strong);
  box-shadow:
    0 14px 34px rgba(23, 33, 43, 0.08);
  backdrop-filter: blur(18px);
  transform: translateX(-50%) translateY(0);
  transition:
    transform 280ms cubic-bezier(0.22, 1, 0.36, 1),
    opacity 220ms ease,
    box-shadow 220ms ease;
  z-index: 1100;
}

.app-navbar.is-hidden {
  transform: translateX(-50%) translateY(calc(-1 * var(--app-navbar-hide-offset)));
  opacity: 0;
  pointer-events: none;
}

.app-navbar__brand {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  min-width: 0;
  padding-left: 0;
  padding-right: 0;
}

.app-navbar__brand-mark {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: radial-gradient(circle at 35% 35%, #6dd3f5, #1191c7 68%, #0b3f5d 100%);
  box-shadow: 0 0 0 8px rgba(17, 145, 199, 0.12);
}

.app-navbar__brand-copy {
  display: flex;
  align-items: center;
  min-width: 0;
}

.app-navbar__brand-text {
  color: var(--ink);
  font-family: "Fraunces", Georgia, serif;
  font-size: clamp(1.05rem, 1.45vw, 1.3rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-navbar__brand-subtitle {
  display: none;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-navbar__cluster {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex: 1 1 auto;
  min-width: 0;
  margin-left: clamp(20px, 3vw, 72px);
}

.app-navbar__tab-rail {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 3px;
  flex: 0 1 auto;
  min-width: 0;
  width: fit-content;
  max-width: 100%;
  padding: 3px;
  margin-right: 0;
  border: 1px solid rgba(23, 33, 43, 0.08);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.72);
  overflow-x: auto;
  scrollbar-width: none;
}

.app-navbar__tab-rail::-webkit-scrollbar {
  display: none;
}

.app-navbar__meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  justify-content: flex-end;
  white-space: nowrap;
}

.app-navbar__meta-pill {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 13px;
  border-radius: 999px;
  border: 1px solid rgba(23, 33, 43, 0.08);
  background: rgba(255, 253, 248, 0.72);
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
}

.app-navbar__logout {
  min-height: 36px;
  padding: 0 13px;
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.72);
  border-color: rgba(23, 33, 43, 0.08);
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(400px, 0.92fr);
  gap: 16px;
  padding: 20px 24px;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background:
    linear-gradient(135deg, rgba(255, 253, 248, 0.94), rgba(255, 249, 240, 0.9)),
    var(--paper-strong);
  box-shadow: var(--shadow);
}

.hero-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  padding-right: 0;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.hero h1,
.section-head h2 {
  margin: 0;
  font-family: "Fraunces", Georgia, serif;
  font-weight: 700;
  line-height: 1.04;
}

.hero h1 {
  font-size: clamp(1.95rem, 3.2vw, 3.2rem);
  max-width: 14ch;
}

.lead {
  max-width: 54ch;
  margin: 0;
  color: var(--muted);
  font-size: 0.96rem;
  line-height: 1.58;
}

.lead:empty {
  display: none;
}

.hero-panel,
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: rgba(255, 253, 248, 0.92);
  box-shadow: 0 12px 36px rgba(23, 33, 43, 0.08);
}

.hero-panel {
  width: 100%;
  max-width: 460px;
  justify-self: end;
  min-width: 0;
  padding: 2px 0 2px 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  border: 0;
  border-left: 1px solid rgba(23, 33, 43, 0.08);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.hero-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--ink);
  color: white;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  flex: 0 0 auto;
}

.hero-panel .field {
  gap: 8px;
}

.hero-panel .field span {
  font-size: 0.86rem;
}

.hero-panel .field input,
.hero-panel .field select {
  min-height: 42px;
}

.hero-panel .hero-actions {
  gap: 10px;
}

.hero-panel .primary-btn,
.hero-panel .ghost-btn {
  min-height: 40px;
  padding: 0 14px;
}

.hero-panel .storage-status {
  font-size: 0.88rem;
  line-height: 1.5;
}

.chip-alt {
  background: var(--teal);
}

.chip-soft {
  background: rgba(23, 33, 43, 0.08);
  color: var(--ink);
}

.hero-actions,
.form-actions,
.line-toolbar,
.toolbar-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.toolbar-inline-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.storage-status,
.section-note {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.page-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 22px;
}

.page-tab {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid rgba(23, 33, 43, 0.12);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.85);
  color: var(--ink);
  font-weight: 600;
  cursor: pointer;
}

.page-tab-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.page-tab.is-active {
  background: var(--ink);
  color: white;
}

.app-navbar .page-tab {
  min-height: 36px;
  padding: 0 11px;
  border: 0;
  background: transparent;
  color: rgba(23, 33, 43, 0.68);
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  transition:
    color 180ms ease,
    background 180ms ease,
    box-shadow 180ms ease;
}

.app-navbar .page-tab:hover {
  transform: none;
  background: rgba(23, 33, 43, 0.06);
  color: var(--ink);
}

.app-navbar .page-tab.is-active {
  background: var(--ink);
  color: white;
  box-shadow: 0 8px 18px rgba(23, 33, 43, 0.16);
}

.page-stack {
  margin-top: var(--header-stack-gap);
}

.page-panel {
  display: none;
}

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

.main-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 22px;
  margin-top: 26px;
}

.panel {
  grid-column: span 4;
  padding: 22px;
}

.panel > * + * {
  margin-top: 18px;
}

.panel-collapse-content > * + * {
  margin-top: 18px;
}

.panel-wide {
  grid-column: span 12;
}

.panel-half {
  grid-column: span 6;
}

.form-panel {
  padding-bottom: 28px;
}

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.section-head > :first-child {
  display: grid;
  gap: 9px;
}

.section-head-compact {
  margin-bottom: 12px;
}

.section-head-compact > :first-child {
  gap: 6px;
}

.section-head-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  margin-left: auto;
  flex: 0 0 auto;
}

.section-head h2 {
  font-size: clamp(1.2rem, 1.9vw, 1.72rem);
}

.legend-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 12px;
}

.legend-item {
  font-size: 0.92rem;
  font-weight: 600;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
  align-items: stretch;
}

.kpi-grid-result {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.kpi-card {
  display: grid;
  grid-template-rows: minmax(2.4rem, auto) minmax(2.6rem, auto) minmax(2.2rem, auto);
  gap: 8px;
  min-width: 0;
  height: 100%;
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(249, 245, 236, 0.9));
}

.kpi-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.35;
  text-wrap: balance;
}

.kpi-value {
  display: block;
  margin: 0;
  max-width: 100%;
  min-width: 0;
  font-size: clamp(1.2rem, 1.55vw, 1.85rem);
  line-height: 1.05;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums lining-nums;
  overflow-wrap: anywhere;
}

.kpi-note {
  display: block;
  margin-top: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
  text-wrap: pretty;
}

.insight-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  align-items: stretch;
}

.insight-card {
  height: 100%;
  padding: 15px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.98);
}

.insight-card strong {
  display: block;
  margin-bottom: 6px;
  font-size: 1rem;
}

.insight-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.table-shell {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(255, 253, 248, 0.95);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.data-table th,
.data-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.data-table thead th {
  position: sticky;
  top: 0;
  background: #f3ede2;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.data-table tbody tr:hover {
  background: rgba(180, 83, 9, 0.05);
}

.management-table input,
.management-table select {
  min-height: 40px;
  width: 100%;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: white;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(23, 33, 43, 0.08);
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  flex: 0 0 auto;
}

.tag.is-success {
  background: var(--teal-soft);
  color: var(--teal);
}

.tag.is-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.form-grid,
.company-card-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field span,
.mini-title {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
}

.field-wide {
  grid-column: span 2;
}

.field input,
.field select {
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: white;
  color: var(--ink);
}

.field input:focus,
.field select:focus,
.management-table input:focus,
.management-table select:focus {
  outline: 2px solid rgba(15, 118, 110, 0.2);
  border-color: rgba(15, 118, 110, 0.48);
}

.preset-conversion-box {
  margin-top: 20px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(23, 33, 43, 0.03);
}

#quick-account-form {
  margin: 18px 0 20px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.78);
}

.quick-account-help,
.cell-note {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.5;
}

.cell-note {
  margin-top: 6px;
}

.line-list {
  display: grid;
  gap: 12px;
}

#entry-form .line-toolbar {
  margin-bottom: 16px;
  padding-right: 4px;
}

#entry-form .form-actions {
  margin-top: 18px;
  padding-top: 4px;
  padding-right: 4px;
}

.entry-line-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1.4fr auto;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.82);
}

.mini-field {
  min-width: 0;
}

.entry-balance-box {
  margin-top: 18px;
  padding: 15px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: #f6efe3;
  color: var(--ink);
  font-weight: 600;
}

.entry-balance-box.is-valid {
  background: rgba(15, 118, 110, 0.08);
  border-color: rgba(15, 118, 110, 0.25);
  color: var(--teal);
}

.entry-balance-box.is-invalid {
  background: rgba(185, 28, 28, 0.08);
  border-color: rgba(185, 28, 28, 0.22);
  color: var(--danger);
}

.company-list {
  display: grid;
  gap: 16px;
}

.company-card {
  padding: 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.96);
}

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

.company-card-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.company-card-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.equal-action-group {
  display: grid;
  grid-template-columns: minmax(132px, 1fr);
  width: 100%;
}

.equal-action-group > .primary-btn,
.equal-action-group > .ghost-btn,
.equal-action-group > .secondary-btn,
.equal-action-group > .danger-btn,
.equal-action-group > .line-remove-btn {
  width: 100%;
  justify-content: center;
}

.primary-btn,
.ghost-btn,
.line-remove-btn,
.danger-btn,
.secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.icon-toggle-btn {
  width: 36px;
  min-width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid rgba(23, 33, 43, 0.14);
  background: rgba(255, 253, 248, 0.72);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  align-self: flex-start;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22);
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.icon-toggle-btn__glyph {
  width: 10px;
  height: 10px;
  background: currentColor;
  clip-path: polygon(24% 18%, 24% 82%, 82% 50%);
  transform: rotate(90deg);
  transition: transform 180ms ease;
}

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

.ghost-btn,
.line-remove-btn,
.secondary-btn {
  background: rgba(23, 33, 43, 0.05);
  border-color: rgba(23, 33, 43, 0.12);
  color: var(--ink);
}

.danger-btn {
  background: rgba(185, 28, 28, 0.08);
  border-color: rgba(185, 28, 28, 0.18);
  color: var(--danger);
}

.line-remove-btn {
  align-self: end;
}

.app-navbar .ghost-btn.app-navbar__logout {
  min-height: 36px;
  padding: 0 13px;
  border-radius: 999px;
  border-color: rgba(23, 33, 43, 0.08);
  background: rgba(255, 253, 248, 0.72);
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  flex: 0 0 auto;
}

.primary-btn:hover,
.ghost-btn:hover,
.icon-toggle-btn:hover,
.line-remove-btn:hover,
.danger-btn:hover,
.secondary-btn:hover,
.page-tab:hover {
  transform: translateY(-1px);
}

.icon-toggle-btn:hover {
  background: rgba(23, 33, 43, 0.06);
  border-color: rgba(23, 33, 43, 0.24);
}

.app-navbar .ghost-btn.app-navbar__logout:hover {
  transform: none;
  background: rgba(23, 33, 43, 0.06);
  border-color: rgba(23, 33, 43, 0.12);
}

.icon-toggle-btn:focus-visible {
  outline: 2px solid rgba(0, 125, 142, 0.32);
  outline-offset: 3px;
}

.icon-toggle-btn[aria-expanded="false"] .icon-toggle-btn__glyph {
  transform: rotate(0deg);
}

.panel.is-collapsed .section-head {
  margin-bottom: 0;
}

.primary-btn:disabled,
.ghost-btn:disabled,
.danger-btn:disabled,
.secondary-btn:disabled,
.line-remove-btn:disabled,
.icon-toggle-btn:disabled {
  opacity: 0.56;
  cursor: not-allowed;
  transform: none;
}

.number-negative {
  color: var(--danger);
}

.number-positive {
  color: var(--teal);
}

@media (max-width: 1160px) {
  .app-navbar {
    padding: 8px 14px;
  }

  .app-navbar__cluster {
    gap: 9px;
    margin-left: clamp(14px, 2vw, 32px);
  }

  .app-navbar .page-tab {
    padding: 0 10px;
    font-size: 0.86rem;
  }

  .kpi-grid,
  .kpi-grid-result,
  .form-grid,
  .company-card-grid,
  .insight-list {
    grid-template-columns: 1fr 1fr;
  }

  .hero {
    grid-template-columns: minmax(0, 1fr) minmax(340px, 0.95fr);
  }

  .panel,
  .panel-half {
    grid-column: span 12;
  }

  .entry-line-row {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 760px) {
  :root {
    --navbar-top-offset: 12px;
  }

  .shell {
    width: min(100% - 24px, 1380px);
  }

  .app-navbar {
    width: min(1380px, calc(100% - 24px));
    padding: 7px 12px;
    border-radius: 20px;
  }

  .app-navbar.is-hidden {
    transform: translateX(-50%) translateY(calc(-1 * var(--app-navbar-hide-offset)));
  }

  .app-navbar__brand {
    gap: 8px;
    padding-left: 2px;
    padding-right: 0;
  }

  .app-navbar__cluster {
    gap: 5px;
    margin-left: 8px;
  }

  .app-navbar__tab-rail {
    width: fit-content;
    max-width: 100%;
  }

  .app-navbar__meta-pill {
    min-height: 34px;
    padding: 0 12px;
    font-size: 0.84rem;
  }

  .app-navbar .ghost-btn.app-navbar__logout {
    min-height: 34px;
    padding: 0 12px;
    font-size: 0.84rem;
  }

  .app-navbar__brand-text {
    font-size: 1.02rem;
  }

  .hero,
  .kpi-grid,
  .kpi-grid-result,
  .form-grid,
  .company-card-grid,
  .entry-line-row,
  .insight-list {
    grid-template-columns: 1fr;
  }

  .hero-copy {
    padding-right: 0;
  }

  .hero-panel {
    max-width: none;
    justify-self: stretch;
    padding: 16px 0 0;
    border-left: 0;
    border-top: 1px solid rgba(23, 33, 43, 0.08);
  }

  .field-wide {
    grid-column: auto;
  }

  .section-head,
  .hero-actions,
  .line-toolbar,
  .form-actions,
  .toolbar-inline {
    align-items: stretch;
  }

  .section-head-actions {
    width: 100%;
    justify-content: flex-end;
    margin-left: 0;
  }

  .data-table {
    min-width: 680px;
  }
}
