:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #18212f;
  --subtle: #687386;
  --line: #d9e0e8;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --warn: #b45309;
  --ready: #166534;
  --shadow: 0 18px 45px rgba(19, 32, 49, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 28px clamp(18px, 4vw, 56px) 18px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.2;
}

h1 {
  font-size: clamp(24px, 3vw, 34px);
}

.company-name {
  margin: 6px 0 0;
  color: var(--subtle);
  font-size: 14px;
  font-weight: 700;
}

h2 {
  font-size: 20px;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.status-strip span,
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f9fbfc;
  color: var(--subtle);
  white-space: nowrap;
}

.identity-bar {
  display: grid;
  grid-template-columns: minmax(220px, 0.9fr) minmax(360px, 1.4fr) minmax(190px, auto);
  gap: 18px;
  align-items: end;
  padding: 18px clamp(18px, 4vw, 56px);
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.identity-bar strong {
  display: block;
  font-size: 22px;
  line-height: 1.2;
}

.identity-bar span {
  display: block;
  margin-top: 4px;
  color: var(--subtle);
  font-size: 14px;
  font-weight: 700;
}

.identity-controls {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 120px auto;
  gap: 10px;
  align-items: end;
}

#identityPinWrap {
  display: none;
}

#identityPinWrap.is-visible {
  display: grid;
}

#identityMessage {
  align-self: center;
  margin: 0;
  font-weight: 700;
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 12px clamp(18px, 4vw, 56px);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: #fff;
}

.flow-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 10px;
  padding: 14px clamp(18px, 4vw, 56px);
  background: #fff;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.flow-step {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 2px 10px;
  min-width: 130px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfc;
}

.flow-step span {
  display: grid;
  grid-row: span 2;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #e7f5f3;
  color: var(--accent-dark);
  font-weight: 800;
}

.flow-step strong {
  line-height: 1.2;
}

.flow-step small {
  color: var(--subtle);
}

.flow-step.is-current {
  border-color: var(--accent);
}

.tab,
.ghost-button,
.primary-button,
.icon-button,
.danger-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.tab {
  padding: 8px 14px;
}

.tab.is-active {
  border-color: var(--accent);
  background: #e7f5f3;
  color: var(--accent-dark);
  font-weight: 700;
}

main {
  padding: 24px clamp(18px, 4vw, 56px) 56px;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.workspace {
  max-width: 1180px;
  margin: 0 auto;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
  gap: 18px;
}

.panel,
.expense-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 22px;
}

.section-head,
.card-main,
.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.section-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

label {
  display: grid;
  gap: 8px;
  color: #344054;
  font-weight: 700;
}

.field-note {
  color: #9a3412;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.45;
}

.tax-note {
  grid-column: 1 / -1;
  margin: -6px 0 0;
  padding: 10px 12px;
  border: 1px solid #fed7aa;
  border-radius: 8px;
  background: #fff7ed;
}

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

textarea {
  resize: vertical;
}

.upload-box {
  width: 100%;
  place-items: center;
  min-height: 150px;
  margin: 22px 0 14px;
  border: 1px dashed #9aa7b6;
  border-radius: 8px;
  background: #f9fbfc;
  text-align: center;
  cursor: pointer;
  color: var(--ink);
  font: inherit;
  font-weight: 900;
}

.upload-box input {
  display: none;
}

.upload-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #dff3f0;
  color: var(--accent-dark);
  font-size: 26px;
}

.camera-panel {
  display: grid;
  gap: 12px;
  margin: 18px 0;
}

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

.camera-panel video {
  width: 100%;
  max-height: 420px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111827;
}

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

.muted {
  color: var(--subtle);
  font-size: 14px;
}

.form-grid,
.search-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.search-grid {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  margin: 18px 0;
}

.fx4-settings {
  margin: 0 0 18px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.fx4-settings summary {
  cursor: pointer;
  color: var(--accent-dark);
  font-weight: 800;
}

.fx4-settings .search-grid {
  margin-bottom: 0;
}

.inline-select {
  width: 100%;
  min-width: 92px;
  min-height: 34px;
  padding: 4px 8px;
  font-size: 14px;
}

.settlement-button {
  width: 100%;
  min-height: 34px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--subtle);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.25;
  white-space: nowrap;
}

.settlement-button.is-settled {
  border-color: #86efac;
  background: #f0fdf4;
  color: var(--ready);
}

.delete-button {
  min-height: 34px;
  padding: 4px 10px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  background: #fff5f5;
  color: #b91c1c;
  font-size: 13px;
  font-weight: 900;
}

.delete-button:hover {
  border-color: #f87171;
  background: #fee2e2;
}

.receipt-download-button {
  min-height: 34px;
  padding: 4px 10px;
  font-size: 13px;
  white-space: nowrap;
}

.purpose-tools {
  display: grid;
  grid-template-columns: 1fr 56px;
  gap: 10px;
}

.icon-button {
  align-self: stretch;
  min-width: 56px;
  color: var(--accent-dark);
  font-weight: 800;
}

.icon-button.is-recording {
  border-color: #dc2626;
  background: #fee2e2;
  color: #991b1b;
}

.primary-button {
  padding: 0 16px;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.danger-button {
  padding: 0 14px;
  border-color: #dc2626;
  background: #fff;
  color: #991b1b;
  font-weight: 700;
}

.danger-button:hover {
  background: #fee2e2;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

button:disabled:hover {
  background: inherit;
}

.ghost-button {
  padding: 0 14px;
}

.wide {
  width: 100%;
  margin-top: 18px;
}

.receipt-panel img {
  display: none;
  width: 100%;
  max-height: 430px;
  object-fit: contain;
  margin-top: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.list {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.returned-workspace {
  margin-top: 22px;
}

.permission-note {
  min-height: 24px;
  margin: 14px 0 0;
  padding: 10px 12px;
  border: 1px solid #f1d7aa;
  border-radius: 8px;
  background: #fff8ed;
  color: #92400e;
  font-size: 14px;
  font-weight: 700;
}

.permission-chip {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid #f1d7aa;
  border-radius: 8px;
  background: #fff8ed;
  color: #92400e;
  font-size: 14px;
  font-weight: 700;
}

.return-history {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}

.return-note {
  padding: 12px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  background: #fff1f2;
}

.return-note strong {
  display: block;
  color: #991b1b;
  font-size: 13px;
}

.return-note p {
  margin: 6px 0 0;
  color: #7f1d1d;
}

.approval-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-top: 18px;
}

.approval-lane {
  min-width: 0;
}

.lane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 46px;
  padding: 0 4px;
}

.lane-head h3 {
  margin: 0;
  font-size: 17px;
}

.lane-head span {
  color: var(--subtle);
  font-weight: 700;
}

.expense-card {
  padding: 18px;
}

.card-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
}

.card-meta,
.card-details {
  color: var(--subtle);
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 0;
}

.card-meta span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8fafc;
  color: var(--subtle);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
}

.card-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 230px;
  gap: 22px;
  align-items: start;
  margin: 16px 0;
}

.card-details {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 12px 16px;
  font-size: 14px;
}

.card-details strong {
  display: block;
  color: var(--ink);
  font-size: 12px;
}

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

.receipt-thumb-wrap {
  min-height: 220px;
  align-self: stretch;
}

.receipt-thumb,
.receipt-empty {
  width: 100%;
  min-height: 220px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.receipt-thumb {
  display: block;
  height: 220px;
  padding: 8px;
  object-fit: contain;
  cursor: zoom-in;
}

.receipt-empty {
  display: grid;
  place-items: center;
  color: var(--subtle);
  font-size: 13px;
  font-weight: 700;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

.search-table {
  table-layout: fixed;
  min-width: 2010px;
}

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

th {
  background: #f8fafc;
  font-size: 13px;
}

.search-table th,
.search-table td {
  padding: 12px 10px;
  font-size: 13px;
  line-height: 1.35;
  word-break: keep-all;
}

.search-table th {
  white-space: nowrap;
}

.search-table td {
  white-space: normal;
}

.search-table th:nth-child(1),
.search-table td:nth-child(1) {
  width: 78px;
}

.search-table th:nth-child(2),
.search-table td:nth-child(2) {
  width: 132px;
}

.search-table th:nth-child(3),
.search-table td:nth-child(3) {
  width: 112px;
}

.search-table th:nth-child(4),
.search-table td:nth-child(4) {
  width: 170px;
}

.search-table th:nth-child(5),
.search-table td:nth-child(5) {
  width: 100px;
}

.search-table th:nth-child(6),
.search-table td:nth-child(6) {
  width: 132px;
}

.search-table th:nth-child(7),
.search-table td:nth-child(7) {
  width: 130px;
}

.search-table th:nth-child(8),
.search-table td:nth-child(8) {
  width: 132px;
}

.search-table th:nth-child(9),
.search-table td:nth-child(9) {
  width: 170px;
}

.search-table th:nth-child(10),
.search-table td:nth-child(10) {
  width: 150px;
}

.search-table th:nth-child(11),
.search-table td:nth-child(11) {
  width: 136px;
}

.search-table th:nth-child(12),
.search-table td:nth-child(12) {
  width: 210px;
}

.search-table th:nth-child(13),
.search-table td:nth-child(13) {
  width: 112px;
}

.search-table th:nth-child(14),
.search-table td:nth-child(14),
.search-table th:nth-child(15),
.search-table td:nth-child(15),
.search-table th:nth-child(16),
.search-table td:nth-child(16) {
  width: 92px;
}

.search-table td:nth-child(1),
.search-table td:nth-child(5),
.search-table td:nth-child(7),
.search-table td:nth-child(9),
.search-table td:nth-child(13),
.search-table td:nth-child(14),
.search-table td:nth-child(15),
.search-table td:nth-child(16) {
  white-space: nowrap;
}

.empty {
  padding: 28px;
  color: var(--subtle);
  text-align: center;
}

.status-warn {
  color: var(--warn);
}

.status-ready {
  color: var(--ready);
}

@media (max-width: 900px) {
  .topbar,
  .identity-bar,
  .section-head,
  .card-main {
    align-items: flex-start;
  }

  .topbar,
  .section-head,
  .card-main {
    flex-direction: column;
  }

  .identity-bar,
  .identity-controls {
    grid-template-columns: 1fr;
  }

  .two-column,
  .form-grid,
  .search-grid,
  .card-body,
  .card-details,
  .approval-columns {
    grid-template-columns: 1fr;
  }

  .flow-strip {
    grid-template-columns: repeat(5, 180px);
  }

}

@media (max-width: 640px) {
  .topbar {
    gap: 14px;
    padding: 18px 16px 14px;
  }

  h1 {
    font-size: 28px;
  }

  h2 {
    font-size: 22px;
  }

  .company-name {
    font-size: 13px;
  }

  .status-strip {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .status-strip span,
  .badge {
    justify-content: center;
    min-height: 38px;
    padding: 7px 8px;
    font-size: 13px;
  }

  .identity-bar {
    gap: 14px;
    padding: 16px;
  }

  .identity-bar strong {
    font-size: 24px;
  }

  .identity-bar span,
  #identityMessage {
    font-size: 13px;
    line-height: 1.45;
  }

  .identity-controls {
    gap: 12px;
  }

  .identity-controls label {
    gap: 6px;
  }

  .tabs {
    position: sticky;
    top: 0;
    z-index: 20;
    gap: 8px;
    padding: 10px 16px;
  }

  .tab {
    flex: 0 0 auto;
    min-height: 44px;
    padding: 8px 16px;
    white-space: nowrap;
  }

  .flow-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 12px 16px;
    overflow-x: visible;
  }

  .flow-step {
    min-width: 0;
    padding: 9px;
  }

  main {
    padding: 16px 12px 40px;
  }

  .workspace {
    max-width: none;
  }

  .panel {
    padding: 16px;
  }

  .section-head {
    gap: 12px;
  }

  .section-actions,
  .form-actions,
  .camera-actions,
  .card-actions {
    width: 100%;
  }

  .section-actions > *,
  .form-actions > *,
  .camera-actions > *,
  .card-actions > * {
    flex: 1 1 auto;
  }

  .permission-note {
    margin-top: 14px;
    font-size: 13px;
    line-height: 1.6;
  }

  .upload-box {
    min-height: 128px;
    margin: 18px 0 14px;
    padding: 18px 12px;
  }

  .upload-icon {
    width: 50px;
    height: 50px;
    font-size: 30px;
  }

  .camera-panel video {
    max-height: 58vh;
    object-fit: cover;
  }

  .form-grid,
  .search-grid {
    gap: 12px;
  }

  label {
    gap: 7px;
    font-size: 15px;
  }

  input,
  select,
  textarea,
  .primary-button,
  .ghost-button,
  .danger-button,
  .icon-button {
    min-height: 48px;
    font-size: 16px;
  }

  input,
  select,
  textarea {
    padding: 11px 12px;
  }

  .tax-note {
    margin-top: -2px;
    padding: 9px 10px;
    font-size: 12px;
  }

  .purpose-tools {
    grid-template-columns: 1fr 58px;
  }

  .wide {
    margin-top: 14px;
  }

  .receipt-panel {
    order: 2;
  }

  .receipt-panel img {
    max-height: 58vh;
    margin-top: 14px;
  }

  .returned-workspace {
    margin-top: 16px;
  }

  .approval-columns {
    gap: 14px;
  }

  .lane-head {
    min-height: 38px;
  }

  .expense-card {
    padding: 16px;
  }

  .card-title {
    font-size: 20px;
  }

  .card-meta {
    gap: 8px;
  }

  .card-meta span {
    min-height: 30px;
    font-size: 12px;
  }

  .card-body {
    gap: 14px;
  }

  .card-details {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .receipt-thumb-wrap,
  .receipt-thumb,
  .receipt-empty {
    min-height: 280px;
  }

  .receipt-thumb {
    height: 280px;
  }

  .table-wrap {
    margin: 0 -4px;
  }

  .search-table th,
  .search-table td {
    padding: 10px 8px;
    font-size: 12px;
  }

  .inline-select,
  .settlement-button,
  .receipt-download-button,
  .delete-button {
    min-height: 40px;
    font-size: 12px;
  }
}

@media (max-width: 420px) {
  h1 {
    font-size: 24px;
  }

  h2 {
    font-size: 20px;
  }

  .status-strip {
    grid-template-columns: 1fr;
  }

  .card-details {
    grid-template-columns: 1fr;
  }

  .purpose-tools {
    grid-template-columns: 1fr;
  }

  .icon-button {
    min-width: 100%;
  }
}
