:root {
  --content-max: 1180px;
  --focus-ring: rgba(0, 169, 165, .34);
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --text-xs: 12px;
  --text-sm: 13px;
  --text-md: 14px;
  --text-base: 15px;
  --text-lg: 18px;
  --text-xl: 20px;
  --control-h: 44px;
  --control-h-lg: 48px;
  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-card: 0 10px 26px rgba(16, 42, 67, .08);
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

body {
  font-size: var(--text-base);
  line-height: 1.45;
}

.shell {
  max-width: var(--content-max);
  padding: 16px 16px 40px;
}

.hero {
  min-height: 84px;
  margin-bottom: var(--space-4);
  padding: 16px 20px;
  border-radius: var(--radius-lg);
}

.hero:before {
  border-radius: 12px;
}

.hero-top {
  margin-bottom: var(--space-2);
  gap: var(--space-3);
}

.hero-title-wrap {
  gap: 2px;
}

.hero-kicker {
  font-size: 11px;
  line-height: 1.2;
  font-weight: 800;
  letter-spacing: .09em;
}

.hero h1 {
  font-size: var(--text-xl);
  line-height: 1.2;
  font-weight: 750;
}

.hero-logo {
  height: 26px;
  max-width: 118px;
  padding: 4px 8px;
}

.hero-greet {
  min-height: 38px;
  margin-top: var(--space-1);
  padding: 6px 10px;
  gap: var(--space-2);
}

.hello-avatar {
  width: 28px;
  height: 28px;
  flex-basis: 28px;
}

.hello-line {
  font-size: var(--text-sm);
  line-height: 1.3;
  font-weight: 750;
}

.bottom-nav {
  position: sticky;
  top: 10px;
  left: auto;
  right: auto;
  bottom: auto;
  width: 100%;
  height: auto;
  min-height: 56px;
  margin: 0 0 var(--space-4);
  padding: 6px;
  border-radius: var(--radius-lg);
}

.nav-btn {
  min-height: var(--control-h);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  line-height: 1.2;
  font-weight: 700;
}

.nav-btn .ic {
  font-size: 16px;
}

.nav-btn.active,
.nav-btn[aria-current="page"] {
  border-radius: var(--radius-md);
  color: #0f7775;
}

.stack {
  gap: var(--space-4);
}

.upload-form-column {
  display: grid;
  gap: var(--space-4);
  align-content: start;
  min-width: 0;
}

.card {
  padding: var(--space-5);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

h2 {
  margin: 0 0 var(--space-3);
  font-size: var(--text-lg);
  line-height: 1.3;
  font-weight: 750;
  letter-spacing: 0;
}

.section-head {
  align-items: center;
  margin-bottom: var(--space-2);
}

.section-head h2 {
  margin: 0;
}

.page-intro {
  margin: 0 0 var(--space-4);
  color: var(--muted);
  font-size: var(--text-md);
  line-height: 1.5;
}

.required-mark {
  color: #b33b3b;
  font-weight: 800;
}

.field {
  margin-bottom: var(--space-3);
}

label,
.setting-item .label {
  margin-bottom: 6px;
  color: #33566e;
  font-size: var(--text-sm);
  line-height: 1.35;
  font-weight: 650;
}

input,
select,
textarea {
  min-height: var(--control-h);
  padding: 9px 12px;
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  line-height: 1.35;
}

textarea {
  min-height: 96px;
}

input[readonly] {
  background: #f2f6f9;
  color: #536b7d;
}

.two,
.three,
.settings-grid-2,
.settings-inline,
.setup-mode-row {
  gap: var(--space-3);
}

.field-note {
  margin: -4px 0 var(--space-3);
  font-size: var(--text-sm);
  line-height: 1.4;
}

.tiny,
.settings-sub,
.fx-source-line,
.preview-fallback,
.native-pdf-status {
  font-size: var(--text-xs);
  line-height: 1.45;
}

.btn {
  min-height: var(--control-h);
  padding: 9px 14px;
  border-radius: var(--radius-md);
  font-size: var(--text-md);
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: 0;
}

.btn.mini {
  min-height: 38px;
  padding: 7px 11px;
  font-size: var(--text-sm);
}

.save-inner {
  max-width: none;
}

.save-actions {
  grid-template-columns: 1fr;
}

.save-wrap {
  margin-top: 0;
}

.save-btn {
  min-height: var(--control-h-lg);
  padding: 11px 16px;
  border-radius: 12px;
  font-size: var(--text-base);
  line-height: 1.2;
  font-weight: 750;
}

.result,
.hint {
  margin-top: var(--space-3);
  padding: 10px 12px;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  line-height: 1.45;
}

.result.notice {
  background: var(--warnBg);
  border-color: var(--warnLine);
  color: #71501b;
}

.sheet-table tr.travel-import-highlight td {
  background: #e8f7ef;
  box-shadow: inset 0 2px 0 #11875d, inset 0 -2px 0 #11875d;
}

.sheet-table tr.travel-import-highlight td:first-child {
  box-shadow: inset 2px 2px 0 #11875d, inset 0 -2px 0 #11875d;
}

.sheet-table tr.travel-import-highlight td:last-child {
  box-shadow: inset -2px 2px 0 #11875d, inset 0 -2px 0 #11875d;
}

.country-checks {
  min-height: var(--control-h);
  padding: 8px 10px;
  gap: 8px 12px;
  border-radius: var(--radius-md);
}

.country-checks label {
  margin: 0;
  font-size: var(--text-sm);
  font-weight: 650;
}

.workflow-strip {
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.flow-step {
  min-height: 56px;
  padding: 8px;
  gap: var(--space-1);
  border-radius: var(--radius-sm);
}

.flow-step .n {
  width: 22px;
  height: 22px;
  font-size: var(--text-xs);
}

.flow-step .t {
  font-size: var(--text-xs);
  line-height: 1.25;
  font-weight: 750;
}

.sub-panel,
.fx-panel,
.summary-panel {
  padding: var(--space-3);
  margin: var(--space-3) 0;
  border-radius: var(--radius-md);
  gap: var(--space-3);
}

.summary-grid,
.metric-grid {
  gap: var(--space-3);
}

.summary-item,
.metric {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
}

.summary-item .k,
.metric .k {
  margin-bottom: var(--space-1);
  font-size: var(--text-xs);
}

.summary-item .v,
.metric .v {
  font-size: var(--text-md);
}

.list-toolbar {
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.list-toolbar .btn {
  min-height: var(--control-h);
  padding: 9px 14px;
  font-size: var(--text-sm);
}

.sheet-table {
  max-height: 620px;
  border-radius: var(--radius-md);
}

.sheet-table table {
  font-size: var(--text-sm);
  line-height: 1.35;
}

.sheet-table th,
.sheet-table td {
  padding: 10px;
}

.sheet-table th:nth-child(3),
.sheet-table td:nth-child(3) {
  min-width: 250px;
}

.cell-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.icon-btn {
  width: auto;
  min-width: 72px;
  height: 38px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  line-height: 1;
  font-weight: 700;
}

.icon-btn .action-icon {
  font-size: 14px;
}

.preview-summary {
  margin-top: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-md);
}

.list-swipe-hint {
  display: none;
}

.explorer-toolbar {
  grid-template-columns: auto auto minmax(140px, 1fr);
  gap: var(--space-2);
  align-items: center;
  margin-bottom: var(--space-3);
}

.explorer-toolbar .btn {
  width: auto;
  min-height: var(--control-h);
}

.explorer-meta {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, 260px);
  gap: var(--space-3);
  align-items: end;
  margin: var(--space-3) 0;
}

.tree {
  max-height: 600px;
  padding: var(--space-2);
  border-radius: var(--radius-md);
}

.tree-item {
  width: 100%;
  min-height: var(--control-h);
  padding: 9px 10px;
  gap: var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: var(--text-md);
  line-height: 1.35;
  text-align: left;
}

.tree-item:hover {
  border-color: #d8e6f0;
}

.tree-name {
  font-size: var(--text-md);
}

.file-preview {
  padding: var(--space-3);
  border-radius: var(--radius-md);
}

.preview-actions,
.pdf-page-controls {
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.preview-actions .btn,
.pdf-page-controls .btn {
  min-height: 40px;
  padding: 8px 12px;
  font-size: var(--text-sm);
}

.settings-shell {
  gap: var(--space-4);
  align-items: start;
}

.settings-block {
  gap: var(--space-3);
  border-radius: var(--radius-lg);
}

.settings-summary {
  min-height: 52px;
  padding: 13px 16px;
  font-size: var(--text-base);
  line-height: 1.3;
  font-weight: 750;
}

.settings-content {
  padding: var(--space-4);
  gap: var(--space-3);
}

.settings-content .btn {
  min-height: 42px;
  padding: 9px 13px;
  font-size: var(--text-sm);
  line-height: 1.2;
  font-weight: 700;
}

.settings-content .btn.main {
  border-color: transparent;
  background: linear-gradient(145deg, #10b2ae, #0f8a88);
  color: #fff;
  box-shadow: 0 7px 16px rgba(15, 138, 136, .18);
}

.settings-content .btn.main:hover {
  background: linear-gradient(145deg, #0fa5a2, #0c7f7d);
  color: #fff;
}

.settings-content .btn.soft {
  border-color: #c8d8e6;
  background: #f3f7fb;
  color: #2a4f6d;
  box-shadow: none;
}

.settings-content .btn.soft:hover {
  background: #e9f0f6;
  color: #23475f;
}

.settings-sub {
  font-size: var(--text-sm);
  line-height: 1.45;
}

.settings-status-row,
.setting-value-row {
  gap: var(--space-2);
}

.settings-chip,
.setup-mode-pill {
  min-height: 36px;
  padding: 7px 11px;
  font-size: var(--text-sm);
  line-height: 1.25;
}

.setting-value {
  min-height: var(--control-h);
  padding: 9px 11px;
  border-radius: var(--radius-md);
  font-size: var(--text-md);
  line-height: 1.35;
}

.x-btn {
  min-width: 64px;
  height: 40px;
  padding: 0 10px;
  font-size: var(--text-sm);
}

.app-download-grid {
  gap: var(--space-3);
}

.app-download-card {
  padding: var(--space-3);
  gap: var(--space-2);
}

.app-download-title {
  font-size: var(--text-md);
}

.app-download-btn,
.app-download-status {
  min-height: var(--control-h);
  font-size: var(--text-sm);
  font-weight: 750;
}

.settings-note {
  grid-column: 1 / -1;
  padding: 10px 12px;
  border: 1px solid #dce9f3;
  border-radius: var(--radius-md);
  background: #f7fbff;
}

.login-wrap {
  padding-top: 10vh;
}

.login-card {
  padding: var(--space-6);
  gap: var(--space-3);
  border-radius: var(--radius-lg);
}

.login-card h2 {
  margin-bottom: 0;
  font-size: var(--text-xl);
}

.login-card .picker-actions {
  grid-template-columns: 1fr;
  gap: var(--space-3);
}

#prepareEmailBtn {
  width: 100%;
}

.choice-btn {
  min-height: var(--control-h-lg);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: var(--text-md);
  line-height: 1.3;
}

.sheet-panel {
  padding: var(--space-4);
  gap: var(--space-3);
  border-radius: var(--radius-lg);
}

.sheet-title {
  font-size: var(--text-lg);
  line-height: 1.3;
  font-weight: 750;
}

.sheet-sub {
  font-size: var(--text-md);
  line-height: 1.45;
}

.btn:focus-visible,
.save-btn:focus-visible,
.nav-btn:focus-visible,
.icon-btn:focus-visible,
.choice-btn:focus-visible,
.settings-summary:focus-visible,
.tree-item:focus-visible,
.x-btn:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

html[data-theme="dark"] .result.notice {
  background: #3a2d15;
  border-color: #8a6a24;
  color: #ffe3a7;
}

html[data-theme="dark"] input[readonly] {
  background: #132534;
  color: #a9bdca;
}

html[data-theme="dark"] .tree-item {
  color: #e4eef6;
}

html[data-theme="dark"] .tree-item:hover,
html[data-theme="dark"] .settings-note {
  background: #122432;
  border-color: #2f4b60;
}

html[data-theme="dark"] .settings-content .btn.soft {
  background: #183246;
  color: #d7e8f3;
  border-color: #2f4b60;
}

html[data-theme="dark"] .settings-content .btn.main {
  background: linear-gradient(145deg, #11aaa7, #0d7f7d);
  color: #fff;
  border-color: transparent;
}

@media (min-width: 761px) {
  #loginPage .login-card {
    width: 100%;
    max-width: 520px;
    margin: 0 auto;
  }

  #uploadPage > .stack {
    grid-template-columns: minmax(370px, .84fr) minmax(0, 1.46fr);
    gap: var(--space-5);
    align-items: start;
  }

  #uploadPage > .stack > .upload-form-column {
    grid-column: 2;
  }

  #listPage > .stack {
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: var(--space-5);
    align-items: start;
  }

  #listPage > .stack > .card:last-child {
    position: sticky;
    top: 82px;
  }

  #explorerPage > .stack {
    grid-template-columns: minmax(370px, .76fr) minmax(0, 1.24fr);
    gap: var(--space-5);
    align-items: start;
  }

  #settingsPage > .stack > .card {
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
  }

  #settingsPage .settings-shell {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #settingsResult,
  #storageInfo {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  :root {
    --control-h: 48px;
    --control-h-lg: 52px;
  }

  body {
    font-size: var(--text-base);
    line-height: 1.45;
  }

  .shell {
    max-width: 520px;
    padding:
      calc(10px + env(safe-area-inset-top))
      max(10px, env(safe-area-inset-right))
      calc(var(--navH) + 24px + env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-left));
  }

  .hero {
    min-height: 68px;
    margin-bottom: var(--space-3);
    padding: 13px 15px;
    border-radius: var(--radius-lg);
  }

  .hero-top {
    flex-direction: row;
    align-items: center;
    margin-bottom: 0;
  }

  .hero h1 {
    font-size: var(--text-lg);
  }

  .hero-kicker {
    font-size: 10px;
  }

  .hero-logo {
    height: 25px;
    max-width: 104px;
  }

  .hero-greet {
    margin-top: var(--space-2);
  }

  .stack {
    gap: var(--space-3);
  }

  .upload-form-column {
    gap: var(--space-3);
  }

  .card {
    padding: var(--space-4);
  }

  h2 {
    margin-bottom: 10px;
    font-size: 17px;
  }

  .page-intro {
    margin-bottom: var(--space-3);
    font-size: var(--text-md);
  }

  label,
  .setting-item .label {
    font-size: var(--text-sm);
  }

  input,
  select,
  textarea {
    min-height: var(--control-h);
    padding: 10px 12px;
    font-size: 16px;
  }

  textarea {
    min-height: 84px;
  }

  .btn {
    min-height: var(--control-h);
    padding: 10px 14px;
    font-size: var(--text-md);
  }

  .bottom-nav {
    position: fixed;
    top: auto;
    left: 8px;
    right: 8px;
    bottom: 0;
    width: auto;
    height: calc(var(--navH) + env(safe-area-inset-bottom));
    min-height: 0;
    margin: 0;
    padding: 0 0 max(6px, env(safe-area-inset-bottom));
    border-radius: 16px 16px 0 0;
  }

  .nav-btn {
    min-height: 60px;
    display: grid;
    place-items: center;
    align-content: center;
    gap: var(--space-1);
    padding: 4px;
    font-size: 11.5px;
    line-height: 1.15;
  }

  .nav-btn .ic {
    font-size: 18px;
  }

  .workflow-strip {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    margin-bottom: var(--space-3);
  }

  .flow-step {
    min-height: 52px;
    padding: 6px;
  }

  .flow-step .n {
    width: 20px;
    height: 20px;
  }

  .flow-step .t {
    font-size: 11px;
  }

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

  .amount-grid .field:last-child {
    grid-column: 1 / -1;
  }

  .save-btn {
    min-height: var(--control-h-lg);
    font-size: var(--text-base);
  }

  .explorer-toolbar {
    grid-template-columns: 1fr 1fr;
  }

  .explorer-toolbar #pickerSelectBtn {
    grid-column: 1 / -1;
    width: 100%;
  }

  .explorer-toolbar .btn {
    width: 100%;
  }

  .explorer-meta {
    grid-template-columns: 1fr;
    gap: var(--space-2);
  }

  .sheet-table {
    max-height: none;
    overflow: visible;
    border: 0;
    background: transparent;
  }

  .sheet-table table {
    min-width: 0;
    font-size: var(--text-sm);
  }

  .sheet-table thead {
    display: none;
  }

  .sheet-table tbody {
    display: grid;
    gap: var(--space-3);
  }

  .sheet-table tr {
    display: grid;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: #fff;
  }

  .sheet-table tr.travel-import-highlight {
    border-color: #11875d;
    box-shadow: 0 0 0 2px rgba(17, 135, 93, .16);
  }

  .sheet-table tr.travel-import-highlight td,
  .sheet-table tr.travel-import-highlight td:first-child,
  .sheet-table tr.travel-import-highlight td:last-child {
    box-shadow: none;
  }

  .sheet-table td {
    min-width: 0 !important;
    display: grid;
    grid-template-columns: 96px minmax(0, 1fr);
    gap: var(--space-3);
    padding: 10px 12px;
    overflow-wrap: anywhere;
  }

  .sheet-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: var(--text-xs);
    line-height: 1.35;
    font-weight: 700;
  }

  .sheet-table td:not([data-label]) {
    display: block;
  }

  .sheet-table td:not([data-label])::before {
    display: none;
  }

  .sheet-table .money-cell {
    text-align: left;
  }

  .sheet-table .cell-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-2);
  }

  .sheet-table .icon-btn {
    width: 100%;
    min-width: 0;
    height: var(--control-h);
  }

  .settings-shell {
    grid-template-columns: 1fr;
  }

  .settings-summary {
    min-height: 52px;
    padding: 13px 14px;
  }

  .settings-content {
    padding: 14px;
  }

  .settings-content .btn,
  .app-download-btn,
  .app-download-status {
    min-height: var(--control-h);
  }

  .x-btn {
    height: var(--control-h);
    min-height: var(--control-h);
  }

  .settings-note {
    grid-column: auto;
  }

  .login-wrap {
    padding-top: 5vh;
  }

  .login-card {
    padding: var(--space-5);
  }

  .sheet-panel {
    padding: 14px;
  }

  html[data-theme="dark"] .sheet-table tr {
    background: #102030;
    border-color: #2b4357;
  }

  html[data-theme="dark"] .sheet-table tr.travel-import-highlight {
    border-color: #39c18f;
  }
}

@media (max-width: 360px) {
  .shell {
    padding-left: 8px;
    padding-right: 8px;
  }

  .card {
    padding: 14px;
  }

  .nav-btn span:last-child {
    font-size: 10.5px;
  }

  .expense-meta-grid,
  .amount-grid {
    grid-template-columns: 1fr;
  }

  .amount-grid .field:last-child {
    grid-column: auto;
  }

  .workflow-strip {
    gap: var(--space-1);
  }
}
