:root {
  --bg: #f2f3f5;
  --surface: #ffffff;
  --text: #1a1a1a;
  --muted: #707070;
  --border: #d5d8dc;
  /* #00b0f0 is the brand mark's cyan — too light for white-on-blue text, so it's
     reserved for decorative accents (borders, underlines). Buttons/links/active
     states use the darker, accessible shades below. */
  --accent: #00b0f0;
  --primary: #00688f;
  --primary-dark: #004c68;
  --secondary: #707070;
  --danger: #c0362c;
  --success: #1a7a4c;
  --radius: 0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 70px;
}

a { color: var(--primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 12px 14px 24px;
}

header.topbar {
  background: var(--surface);
  border-bottom: 3px solid var(--accent);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  position: sticky;
  top: 0;
  z-index: 10;
}

nav.tabs {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  padding: 6px 10px 8px;
  white-space: nowrap;
}

nav.tabs a {
  display: inline-block;
  padding: 8px 12px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  border-bottom: 2px solid transparent;
}

nav.tabs a.active {
  background: var(--bg);
  color: var(--primary);
  border-bottom: 2px solid var(--accent);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px 0;
}
.brand img { height: 28px; width: auto; display: block; }
.brand .brand-text {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.01em;
  color: var(--text);
}
.brand .brand-text span { color: var(--primary); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  padding: 14px;
  text-align: center;
}
.stat .value { font-size: 24px; font-weight: 700; }
.stat .label { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 0.03em; }

h1, h2, h3 { line-height: 1.25; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }

.muted { color: var(--muted); }
.right { text-align: right; }
.center { text-align: center; }

form .field {
  margin-bottom: 14px;
}
label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 14px;
}
input[type="text"],
input[type="number"],
input[type="date"],
input[type="password"],
input[type="file"],
select,
textarea {
  width: 100%;
  padding: 11px 12px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
}
textarea { resize: vertical; }

/* Browser-native controls render their own rounded chrome that border-radius
   on the wrapping element can't reach, so they need explicit resets. */
input[type="file"]::-webkit-file-upload-button {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--bg);
  color: var(--text);
  padding: 8px 14px;
  margin-right: 10px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
input[type="file"]::-webkit-file-upload-button:hover { background: var(--border); }

input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: #fff;
  display: inline-block;
  position: relative;
  vertical-align: middle;
  cursor: pointer;
  flex-shrink: 0;
}
input[type="checkbox"]:checked {
  background: var(--primary);
  border-color: var(--primary);
}
input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 1px;
  width: 5px;
  height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

select {
  appearance: none;
  -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) center, calc(100% - 13px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 32px;
}

.btn {
  display: inline-block;
  padding: 12px 18px;
  border-radius: var(--radius);
  /* Transparent border (not `none`) so primary, danger and bordered
     `.secondary` buttons are all the same height and line up in a row. */
  border: 1px solid transparent;
  background: var(--primary);
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  vertical-align: middle;
  cursor: pointer;
  text-align: center;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); }
.btn.block { width: 100%; }
.btn.small { padding: 6px 10px; font-size: 13px; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.btn:disabled { opacity: 0.65; cursor: default; }
.btn:disabled:hover { background: var(--primary); }
.btn.secondary:disabled:hover { background: var(--surface); }

/* Submit-in-flight: hide the label and spin a loader in its place. */
.btn.loading {
  position: relative;
  color: transparent;
  pointer-events: none;
}
.btn.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* Receipt auto-parse loader / status line (ledger form + promote page). */
.receipt-parsing {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 14px;
  color: var(--muted);
}
.receipt-parsing.done { color: var(--text); }
.receipt-parsing.loading::before {
  content: '';
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  flex-shrink: 0;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Inline preview of a just-picked receipt photo on the ledger form. */
.photo-preview {
  display: block;
  margin-top: 8px;
  max-width: 180px;
  width: 100%;
  border: 1px solid var(--border);
}

/* Several receipt thumbnails side by side when multiple photos are picked. */
.photo-preview-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.photo-preview-grid .photo-preview {
  margin-top: 0;
  max-width: 96px;
}

.btn.disabled { opacity: 0.5; cursor: default; pointer-events: none; }
.pagination { align-items: center; justify-content: space-between; margin-top: 16px; }
.page-indicator { font-size: 14px; color: var(--text-muted, var(--text)); }

.error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 10px 12px;
  border-radius: var(--radius);
  margin-bottom: 14px;
}
.warning {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
  padding: 10px 12px;
  border-radius: var(--radius);
  margin-bottom: 10px;
}
.success {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
  padding: 10px 12px;
  border-radius: var(--radius);
  margin-bottom: 14px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
}
th, td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
th { color: var(--muted); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
tr.total-row td { font-weight: 700; border-top: 2px solid var(--border); }

.table-scroll { overflow-x: auto; border-radius: var(--radius); }
.table-scroll table:not(.responsive-cards) { min-width: 600px; }

.receipt-thumb {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: block;
}
.receipt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
}
.receipt-tile { text-align: center; font-size: 12px; }

.pill {
  display: inline-block;
  padding: 3px 9px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

/* Card-style responsive table for the Daily Operations view */
@media (max-width: 640px) {
  table.responsive-cards thead { display: none; }
  table.responsive-cards, table.responsive-cards tbody, table.responsive-cards tr, table.responsive-cards td {
    display: block;
    width: 100%;
  }
  table.responsive-cards tr {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 10px;
    padding: 4px 10px;
  }
  table.responsive-cards td {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    border-bottom: 1px solid var(--bg);
    padding: 8px 0;
  }
  table.responsive-cards td:last-child { border-bottom: none; }
  table.responsive-cards td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--muted);
    flex-shrink: 0;
  }
}

.month-switcher {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 10px;
}
.month-switcher a {
  padding: 6px 10px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 13px;
  white-space: nowrap;
}
.month-switcher a.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.currency-switcher { display: flex; gap: 6px; margin-bottom: 10px; }
.currency-switcher a {
  padding: 6px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.currency-switcher a.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.checkbox-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.checkbox-row input[type="checkbox"] { flex-shrink: 0; }

.amount-credit { color: var(--success); }

.tx-list {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
}
.tx-row {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  align-items: flex-start;
}
.tx-row:last-child { border-bottom: none; }
.tx-row input.tx-checkbox { margin-top: 4px; flex-shrink: 0; }
.tx-row-body { flex: 1; min-width: 0; }
.tx-row-top {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 2px;
}
.tx-desc {
  font-size: 14px;
  margin-bottom: 6px;
  cursor: pointer;
  word-break: break-word;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 30px 10px;
}
