:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #1d2624;
  --muted: #68736f;
  --line: #dce3df;
  --accent: #1f6f68;
  --accent-dark: #174f4a;
  --amber: #b46916;
  --danger: #ad343e;
  --blue: #315f9d;
  --shadow: 0 14px 32px rgba(19, 34, 31, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #163532;
  color: #f5fbf8;
  padding: 24px 18px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  min-height: 48px;
  margin-bottom: 28px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  overflow: hidden;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: #bed3ce;
  margin-top: 2px;
}

.app-refresh-button {
  display: grid;
  place-items: center;
  margin-left: auto;
  margin-right: 40px;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: #f5fbf8;
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1;
}

.app-refresh-button:disabled {
  opacity: 0.62;
}

.quick-save-button {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.36);
  border-radius: 6px;
  background: #1f7d73;
  color: #ffffff;
  font-weight: 800;
  text-align: center;
}

.quick-save-button:disabled {
  opacity: 0.62;
}

.quick-save-button[hidden] {
  display: none;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 6px;
  padding: 12px 14px;
  text-align: left;
  color: #dbe8e4;
  background: transparent;
  text-decoration: none;
}

.nav-item.is-active,
.nav-item:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

.main {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.86rem;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 1.85rem;
}

h2 {
  margin-bottom: 0;
  font-size: 1.08rem;
}

h3 {
  font-size: 0.95rem;
}

.panel-subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.top-actions,
.button-row,
.filter-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.primary-button,
.secondary-button,
.danger-button {
  border: 1px solid transparent;
  border-radius: 6px;
  min-height: 40px;
  padding: 9px 14px;
  font-weight: 700;
}

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

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

.secondary-button {
  background: #ffffff;
  color: var(--ink);
  border-color: var(--line);
}

.danger-button {
  background: #ffffff;
  color: #a33d3d;
  border-color: #efc8c8;
}

.link-button {
  border: 0;
  padding: 0;
  color: var(--accent);
  background: transparent;
  font-weight: 800;
  text-align: left;
}

.expense-row-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.mini-action-button,
.mini-danger-button,
.mini-icon-button {
  min-height: 28px;
  border-radius: 6px;
  padding: 4px 7px;
  font-size: 0.78rem;
  font-weight: 800;
}

.mini-action-button {
  min-width: 44px;
}

.mini-action-button {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--accent-dark);
}

.mini-danger-button {
  min-width: 34px;
  border: 1px solid #e0b8bc;
  background: #fff7f8;
  color: var(--danger);
}

.mini-icon-button {
  width: 28px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--muted);
}

.mini-icon-button:disabled {
  opacity: 0.32;
}

.full {
  width: 100%;
}

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

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

.metric {
  padding: 16px;
}

.metric span,
label,
.ai-suggestion span,
.status-pill {
  color: var(--muted);
  font-size: 0.86rem;
}

.metric strong {
  display: block;
  margin-top: 6px;
  font-size: 1.35rem;
}

.view {
  display: none;
}

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

.capture-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 18px;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(340px, 0.78fr) minmax(620px, 1.22fr);
  gap: 18px;
  align-items: start;
}

.panel {
  padding: 18px;
}

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

.status-pill {
  border-radius: 999px;
  padding: 5px 10px;
  background: #edf4f2;
  color: var(--accent);
  white-space: nowrap;
}

.status-pill.warning {
  background: #fff4df;
  color: var(--amber);
}

.form-panel {
  display: grid;
  gap: 14px;
}

.entry-step {
  display: grid;
  gap: 14px;
}

.entry-step[hidden],
.receipt-action-row[hidden],
.receipt-reference[hidden] {
  display: none;
}

.receipt-action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.receipt-reference {
  border: 1px solid #9fc9be;
  border-radius: 6px;
  padding: 10px 12px;
  background: #edf8f5;
  color: var(--accent);
  font-weight: 800;
  text-align: center;
}

.ocr-tools {
  display: grid;
  gap: 10px;
}

.upload-box {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 116px;
  border: 1px dashed #8ca7a0;
  border-radius: 8px;
  background: #f8fbfa;
  color: var(--ink);
  text-align: center;
}

.upload-box input {
  display: none;
}

.upload-box span,
.upload-box small {
  display: block;
}

.upload-box small {
  color: var(--muted);
}

.upload-icon {
  position: relative;
  width: 54px;
  height: 40px;
  border: 3px solid var(--accent);
  border-radius: 10px;
  background: #ffffff;
}

.upload-icon::before {
  content: "";
  position: absolute;
  top: -10px;
  left: 12px;
  width: 22px;
  height: 10px;
  border: 3px solid var(--accent);
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  background: #ffffff;
}

.upload-icon::after {
  content: "";
  position: absolute;
  top: 9px;
  left: 16px;
  width: 16px;
  height: 16px;
  border: 4px solid var(--accent);
  border-radius: 50%;
  background: #edf8f5;
}

.demo-receipt-tools {
  display: grid;
  gap: 6px;
  margin-top: -4px;
}

.demo-receipt-tools[hidden] {
  display: none;
}

.demo-receipt-tools strong {
  color: var(--accent);
  font-size: 0.94rem;
}

.demo-sample-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
.demo-receipt-tools .secondary-button {
  min-height: 44px;
  border-color: #9fc9be;
  background: #edf8f5;
  color: var(--accent);
  font-weight: 900;
}

.demo-receipt-tools small {
  color: var(--muted);
  text-align: center;
}
.camera-tools {
  display: grid;
  gap: 10px;
}

.camera-frame {
  display: none;
  place-items: center;
  min-height: 220px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111917;
  color: #dbe8e4;
}

.camera-frame.is-active {
  display: grid;
}

.camera-frame video {
  width: 100%;
  max-height: 360px;
  object-fit: contain;
}

.camera-frame.has-video span {
  display: none;
}

.secondary-button:disabled,
.primary-button:disabled,
.danger-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.preview-frame {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 180px;
  max-height: 320px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f2f4f1;
  color: var(--muted);
}

.preview-frame img {
  display: none;
  width: 100%;
  height: 100%;
  max-height: 320px;
  object-fit: contain;
}

.preview-frame.has-image span {
  display: none;
}

.preview-frame.has-image img {
  display: block;
}

.preview-receipt-badge {
  position: absolute;
  left: 10px;
  top: 10px;
  z-index: 1;
  border-radius: 999px;
  padding: 6px 10px;
  background: rgba(22, 53, 50, 0.88);
  color: #ffffff;
  font-size: 0.84rem;
  font-weight: 900;
}

.preview-receipt-badge[hidden] {
  display: none;
}

.upload-status {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: #fbfcfb;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.upload-status.is-ok {
  border-color: #9fc9be;
  background: #edf8f5;
  color: var(--accent);
}

.upload-status.is-error {
  border-color: #e7a6ab;
  background: #fff3f4;
  color: var(--danger);
}

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

.choice-field {
  align-content: start;
  order: 2;
}

.priority-field {
  grid-column: 1 / -1;
  order: 1;
}

.choice-field.priority-field {
  order: 1;
}

.memo-field {
  grid-column: 1 / -1;
  order: 4;
}

.tax-category-field {
  grid-column: 1 / -1;
  order: 5;
}

.tax-breakdown-field {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
  order: 6;
}

.tax-field {
  order: 6;
}

.tax-breakdown-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(84px, 0.45fr);
  gap: 8px;
  align-items: end;
}

.tax-breakdown-row label {
  min-width: 0;
}

.tax-breakdown-row input {
  min-height: 42px;
  padding: 9px 10px;
  text-align: center;
  font-weight: 800;
}

.tax-out-row {
  grid-template-columns: minmax(0, 1fr);
}

.ocr-confirm-field {
  grid-column: 1 / -1;
  margin-top: 4px;
  order: 10;
}

.vendor-field {
  order: 10;
}

.invoice-field {
  order: 11;
}

.receipt-date-field {
  order: 12;
}

.ocr-confirm-field input {
  background: #fbfcfb;
  color: var(--muted);
}

.priority-field input {
  min-height: 52px;
  font-size: 1.5rem;
  font-weight: 900;
}

.choice-field-wide {
  grid-column: 1 / -1;
}

.native-choice {
  display: none;
}

.choice-grid {
  display: grid;
  gap: 9px;
}

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

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

.account-choice-grid {
  grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
}

.choice-button {
  min-height: 48px;
  border: 1px solid #d3ddd9;
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, #f6f8f7);
  color: #53625d;
  padding: 9px 8px;
  font-weight: 800;
  text-align: center;
  box-shadow: 0 1px 0 rgba(19, 34, 31, 0.04);
}

.choice-button.is-selected {
  border-color: var(--accent-dark);
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 5px 12px rgba(31, 111, 104, 0.22);
}

.tax-field.is-hidden {
  display: none;
}

label {
  display: grid;
  gap: 6px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  padding: 10px 11px;
}

textarea {
  resize: vertical;
}

.ai-suggestion,
.check-item,
.approval-item,
.master-list li {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.ai-suggestion {
  display: grid;
  gap: 4px;
  padding: 12px;
}

.check-list,
.approval-list,
.master-list {
  display: grid;
  gap: 10px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.check-item,
.approval-item,
.master-list li {
  padding: 8px 10px;
}

.master-list li {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  min-width: 0;
}

.master-item-main {
  display: grid;
  gap: 2px;
  min-width: 0;
  flex: 1 1 auto;
}

.master-item-main strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.master-item-main span {
  color: var(--muted);
}

.master-item-actions {
  display: flex;
  flex-shrink: 0;
  gap: 4px;
}

.check-item.is-warning {
  border-color: #e5bb72;
  background: #fff8ec;
}

.check-item.is-error {
  border-color: #e7a6ab;
  background: #fff3f4;
}

.audit-box {
  margin-top: 22px;
}

.audit-box ul {
  display: grid;
  gap: 8px;
  padding-left: 18px;
  color: var(--muted);
}

.table-heading {
  align-items: flex-end;
}

.receipt-panel {
  margin-bottom: 18px;
}

.receipt-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.receipt-card {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 12px;
  min-width: 0;
  contain: layout paint;
  content-visibility: auto;
  contain-intrinsic-size: 360px;
}

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

.receipt-actions .primary-button,
.receipt-actions .secondary-button,
.receipt-actions .danger-button {
  width: 100%;
  min-height: 40px;
  padding: 8px 6px;
}

.receipt-thumb {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f2f4f1;
  color: var(--muted);
}

.receipt-number {
  position: absolute;
  left: 8px;
  top: 8px;
  z-index: 1;
  border-radius: 999px;
  padding: 4px 8px;
  background: rgba(22, 53, 50, 0.88);
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 900;
}

.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  grid-template-rows: auto 1fr;
  background: #ffffff;
}

.image-viewer[hidden] {
  display: none;
}

.image-viewer-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  background: #ffffff;
}

.image-viewer-bar .secondary-button {
  width: auto;
  min-width: 72px;
}

.image-viewer-bar strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-viewer-body {
  display: grid;
  place-items: start center;
  overflow: auto;
  background: #f6f7f4;
}

.image-viewer-body img {
  display: block;
  width: min(100%, 900px);
  height: auto;
}

body.has-image-viewer {
  overflow: hidden;
}

.receipt-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.receipt-meta {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.receipt-meta strong,
.receipt-meta span {
  overflow-wrap: anywhere;
}

.receipt-meta span {
  color: var(--muted);
  font-size: 0.84rem;
}

.table-wrap {
  overflow-x: auto;
}

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

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

th {
  color: var(--muted);
  font-size: 0.82rem;
}

td {
  font-size: 0.92rem;
}

.row-check {
  width: 20px;
  height: 20px;
}

.amount {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.inline-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  gap: 10px;
  margin-bottom: 16px;
}

.master-columns {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.settings-grid .panel {
  overflow: hidden;
}

.settings-grid .inline-form {
  grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(72px, auto);
}

.settings-grid #masterForm {
  grid-template-columns: minmax(120px, 0.7fr) minmax(180px, 1fr) minmax(72px, auto);
}

.master-columns h3 {
  margin-bottom: 8px;
}

.pill-draft {
  color: var(--muted);
}

.pill-submitted {
  color: var(--blue);
}

.pill-approved,
.pill-checked {
  color: var(--accent);
}

.pill-review {
  color: var(--amber);
  font-weight: 700;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 4;
    padding: 14px 14px 10px;
  }

  .brand {
    margin-bottom: 10px;
    min-height: 42px;
  }

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

  .nav-item,
  .quick-save-button {
    text-align: center;
    padding: 10px 6px;
    min-height: 40px;
  }

  .admin-nav-link {
    display: none;
  }

  .main {
    padding: 8px 18px 18px;
  }

  .topbar {
    gap: 10px;
    margin-bottom: 14px;
  }

  .topbar .top-actions,
  .summary-grid {
    display: none;
  }

  .summary-grid,
  .capture-layout,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .capture-layout {
    gap: 12px;
  }

  .advanced-field,
  #captureView > .capture-layout > .panel:not(.form-panel) {
    display: none;
  }

  .form-panel {
    gap: 12px;
  }

  .topbar,
  .form-panel > .panel-heading,
  .upload-status,
  .receipt-reference {
    display: none;
  }
}

@media (max-width: 680px) {
  .panel-heading,
  .table-heading,
  .top-actions,
  .button-row,
  .filter-row {
    align-items: stretch;
    flex-direction: column;
  }

  .summary-grid,
  .form-grid,
  .inline-form,
  .master-columns {
    grid-template-columns: 1fr;
  }

  .nav {
    overflow-x: auto;
    grid-template-columns: repeat(4, minmax(78px, 1fr));
  }

  .main {
    padding: 8px 14px 14px;
  }

  .form-panel {
    padding: 14px;
  }

  .upload-box {
    min-height: 112px;
  }

  .preview-frame {
    min-height: 220px;
    max-height: 360px;
  }

  .preview-frame img {
    max-height: 360px;
  }

  .ai-suggestion {
    padding: 10px;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
  }

  .receipt-action-row {
    grid-template-columns: 1fr;
  }

  .account-choice-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

  .choice-button {
    min-height: 44px;
    padding: 8px 6px;
  }

  .master-list li {
    align-items: center;
    flex-direction: row;
  }
}
