:root {
  --bg: #f3f3f3;
  --panel: #ffffff;
  --line: #cfcfcf;
  --line-strong: #b8b8b8;
  --head: #efefef;
  --text: #111111;
  --muted: #666666;
  --accent: #0f5fcb;
  --accent-weak: #e8f0ff;
  --income: #f2faf5;
  --expense: #fff3ee;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  font-size: 13px;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
}

.page-shell {
  max-width: 1700px;
  margin: 0 auto;
  padding: 8px 10px 14px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 8px;
}

.brand-block h1,
.panel-header h2,
.report-title-row h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.1;
}

.eyebrow,
.section-eyebrow {
  margin: 0 0 2px;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.subtitle {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.header-actions,
.toolbar-actions,
.quick-actions,
.row-actions,
.entry-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.header-actions {
  justify-content: flex-end;
}

.button,
.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 4px 10px;
  border: 1px solid var(--line-strong);
  background: #f7f7f7;
  color: var(--text);
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  line-height: 1.1;
}

.button.primary {
  background: var(--accent);
  border-color: #0c54b6;
  color: #ffffff;
}

.button.ghost {
  background: #fafafa;
}

.button.subtle {
  background: #ffffff;
}

.button.wide,
.wide-cell-button {
  width: 100%;
}

.panel,
.metric-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
}

.panel {
  padding: 8px;
  margin-bottom: 8px;
}

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

.narrow-panel {
  max-width: 420px;
  margin: 50px auto 0;
}

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

.sheet-mini-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 700;
}

.inline-link {
  color: var(--accent);
  font-weight: 600;
}

.status-panel {
  padding: 6px 8px;
}

.status-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
}

.status-item {
  padding: 2px 10px;
  border-right: 1px solid var(--line);
}

.status-item:last-child {
  border-right: 0;
}

.status-label {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.status-value {
  display: block;
  margin-top: 2px;
  font-size: 15px;
  font-weight: 700;
}

.toolbar-grid-excel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.toolbar-inline,
.login-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  align-items: end;
}

.toolbar-inline-small {
  grid-template-columns: 1fr auto;
}

.toolbar-inline-pin {
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
}

.pin-menu {
  position: relative;
}

.pin-menu-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 30;
  width: min(360px, calc(100vw - 24px));
  padding: 8px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--panel);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.08);
}

.pin-menu-panel[hidden] {
  display: none;
}

.pin-menu-title {
  margin-bottom: 8px;
}

.pin-menu-divider {
  height: 1px;
  margin: 10px 0;
  background: var(--line);
}

.pin-note {
  margin: -2px 0 8px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.pin-popup-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.pin-setting-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
}

.mobile-entry-panel,
.mobile-ledger-panel,
.mobile-filter-panel,
.mobile-summary-panel {
  display: none;
}

.login-form {
  grid-template-columns: 1fr;
}

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

.field span {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
}

input,
select {
  width: 100%;
  min-height: 30px;
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #ffffff;
  color: var(--text);
  font-size: 12px;
}

.entry-sheet-panel {
  padding: 8px;
}

.mobile-entry-form {
  display: grid;
  gap: 10px;
}

.mobile-disclosure summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.mobile-disclosure[open] summary {
  margin-bottom: 10px;
}

.mobile-filter-form {
  display: grid;
  gap: 10px;
}

.mobile-filter-row,
.mobile-entry-top-row,
.mobile-entry-meta-row {
  display: grid;
  gap: 10px;
}

.mobile-filter-row,
.mobile-entry-meta-row {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.mobile-entry-top-row {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
  align-items: end;
}

.mobile-quick-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.mobile-type-field {
  margin: 0;
  padding: 0;
  border: 0;
}

.mobile-type-field legend {
  margin-bottom: 6px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
}

.mobile-type-toggle {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.mobile-type-option {
  position: relative;
  display: block;
}

.mobile-type-option input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.mobile-type-option span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: #ffffff;
  font-weight: 700;
}

.type-income input:checked + span {
  border-color: #8dc39b;
  background: var(--income);
  color: #215b35;
}

.type-expense input:checked + span {
  border-color: #d6a089;
  background: var(--expense);
  color: #8d4222;
}

.mobile-entry-field input,
.mobile-entry-field select {
  min-height: 46px;
  font-size: 16px;
}

.mobile-amount-input {
  font-size: 24px;
  font-weight: 700;
}

.mobile-entry-actions {
  display: grid;
  gap: 8px;
}

.entry-table-wrap {
  border-radius: 4px;
}

.entry-grid {
  width: 100%;
  min-width: 1200px;
  border-collapse: collapse;
  table-layout: fixed;
}

.entry-grid .entry-col-date,
.entry-grid .entry-col-type {
  width: 10.7%;
}

.entry-grid .entry-col-record {
  width: 25%;
}

.entry-grid .entry-col-category {
  width: 15.4%;
}

.entry-grid .entry-col-amount {
  width: 9.6%;
}

.entry-grid .entry-col-memo,
.entry-grid .entry-col-action {
  width: 14.3%;
}

.entry-grid th,
.entry-grid td {
  border: 1px solid var(--line);
}

.entry-grid th {
  background: var(--head);
  padding: 5px 6px;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
}

.entry-grid td {
  padding: 2px;
  background: #ffffff;
}

.entry-grid input,
.entry-grid select {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 0;
  font-size: 13px;
  padding: 8px;
}

.entry-grid input:focus,
.entry-grid select:focus {
  outline: none;
  border-color: #5b9cff;
  box-shadow: inset 0 0 0 1px #5b9cff;
}

.entry-actions-cell {
  padding: 4px !important;
  vertical-align: middle;
  background: #fafafa !important;
}

.entry-actions-cell .button {
  min-height: 34px;
  margin-bottom: 4px;
}

.entry-actions-cell .button:last-child {
  margin-bottom: 0;
}

.num-input,
.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #ffffff;
}

.pagination-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 8px 0;
}

.pagination-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  min-height: 30px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #ffffff;
  color: var(--text);
  font-size: 12px;
  line-height: 1;
}

.pagination-link.is-current {
  border-color: var(--accent);
  background: var(--accent-weak);
  color: var(--accent);
  font-weight: 700;
}

.pagination-link.is-disabled {
  color: #9a9a9a;
  background: #f4f4f4;
}

.sheet-caption,
.table-note,
.record-meta,
.flash {
  color: var(--muted);
}

.sheet-caption {
  margin: 0 0 6px;
  font-size: 11px;
}

.sheet-table {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;
  table-layout: fixed;
}

.sheet-table th,
.sheet-table td {
  border: 1px solid var(--line);
  padding: 6px 7px;
  vertical-align: top;
  background: #ffffff;
}

.sheet-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--head);
  text-align: left;
  font-size: 11px;
  font-weight: 700;
}

.sheet-table tfoot td {
  background: #f7f7f7;
  font-weight: 700;
}

.ledger-table-wrap {
  height: calc(100vh - 360px);
  min-height: 320px;
}

.summary-table-wrap {
  max-height: 180px;
}

.compact-table {
  min-width: 760px;
}

.date-cell {
  white-space: nowrap;
}

.record-cell {
  min-width: 360px;
}

.record-title {
  font-weight: 700;
  line-height: 1.2;
}

.record-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 3px;
  font-size: 11px;
}

.row-actions {
  margin-top: 4px;
  font-size: 11px;
}

.mobile-ledger-list {
  display: grid;
  gap: 8px;
}

.mobile-summary-list {
  display: grid;
  gap: 8px;
}

.mobile-ledger-card {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
}

.mobile-summary-card {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
}

.mobile-ledger-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 6px;
}

.mobile-summary-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.mobile-summary-top span {
  color: var(--muted);
  font-size: 11px;
}

.mobile-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 10px;
  font-size: 12px;
}

.mobile-ledger-date {
  font-size: 12px;
  color: var(--muted);
}

.mobile-ledger-kind {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.mobile-ledger-kind.income {
  background: var(--income);
  color: #215b35;
}

.mobile-ledger-kind.expense {
  background: var(--expense);
  color: #8d4222;
}

.mobile-ledger-figure {
  display: grid;
  gap: 2px;
  text-align: right;
}

.mobile-ledger-figure strong {
  font-size: 18px;
  line-height: 1.1;
}

.mobile-ledger-figure span {
  font-size: 11px;
  color: var(--muted);
}

.link-button {
  min-height: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: #b42318;
}

.strong {
  font-weight: 700;
}

.entry-income td {
  background: var(--income);
}

.entry-expense td {
  background: var(--expense);
}

.empty-state {
  text-align: center;
  padding: 18px !important;
  color: var(--muted);
}

.table-note {
  margin: 6px 0 0;
  font-size: 11px;
}

.flash-stack {
  display: grid;
  gap: 6px;
  margin-bottom: 8px;
}

.flash {
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #ffffff;
  font-size: 12px;
}

.flash-success {
  border-color: #b7dac0;
  color: #1f6a34;
  background: #f2fbf5;
}

.flash-error {
  border-color: #edc3c3;
  color: #a11d1d;
  background: #fff5f5;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 8px;
}

.metric-card {
  padding: 8px 10px;
}

.metric-card strong {
  display: block;
  margin-top: 2px;
  font-size: 16px;
}

.accent-card {
  background: var(--accent-weak);
}

.report-title-row,
.print-summary {
  display: grid;
  gap: 8px;
}

.print-panel {
  break-inside: avoid;
}

@media print {
  body {
    background: #ffffff;
  }

  .page-shell {
    max-width: none;
    padding: 0;
  }

  .page-header,
  .flash-stack,
  .button,
  .row-actions {
    display: none !important;
  }

  .panel,
  .metric-card,
  .table-wrap {
    border-color: #d0d0d0;
    box-shadow: none;
  }

  .ledger-table-wrap,
  .summary-table-wrap {
    height: auto;
    max-height: none;
  }
}

@media (max-width: 1180px) {
  .toolbar-grid-excel {
    grid-template-columns: 1fr;
  }

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

  .toolbar-inline,
  .toolbar-inline-small,
  .toolbar-inline-pin {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .ledger-table-wrap,
  .summary-table-wrap {
    height: auto;
    max-height: none;
  }
}

@media (max-width: 760px) {
  .page-shell {
    padding: 6px 6px 12px;
  }

  .page-header,
  .toolbar-inline,
  .toolbar-inline-small,
  .toolbar-inline-pin,
  .metrics-grid,
  .login-form {
    grid-template-columns: 1fr;
    display: grid;
  }

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

  .status-item {
    padding: 6px 8px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .status-balance {
    grid-column: 1 / -1;
    background: #fafafa;
  }

  .status-balance .status-value {
    font-size: 22px;
  }

  .header-actions {
    display: none;
  }

  .pin-menu {
    width: 100%;
  }

  .pin-menu-panel {
    position: static;
    width: 100%;
    margin-top: 6px;
  }

  .pin-setting-form {
    grid-template-columns: 1fr;
  }

  .header-actions form,
  .header-actions a,
  .header-actions button,
  .button {
    width: 100%;
  }

  .toolbar-grid-excel,
  .entry-sheet-panel,
  .ledger-panel,
  .summary-panel {
    display: none;
  }

  .mobile-entry-panel,
  .mobile-ledger-panel,
  .mobile-filter-panel,
  .mobile-summary-panel {
    display: block;
  }

  .mobile-entry-panel {
    margin-top: -2px;
  }

  .mobile-entry-top-row,
  .mobile-entry-meta-row {
    grid-template-columns: 1fr;
  }
}
