:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --ink: #1e2a24;
  --ink-soft: #5c6b63;
  --line: #e3e1d9;
  --accent: #1f6f4a;
  --accent-dark: #175539;
  --accent-soft: #e7f2ec;
  --danger: #b3402e;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(30, 42, 36, 0.08), 0 8px 24px rgba(30, 42, 36, 0.06);
  font-size: 15px;
}

* { box-sizing: border-box; }

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

.hidden { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 14px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  background: var(--accent);
  color: #fff;
  font-weight: 700; font-size: 20px;
  border-radius: 9px;
}
.brand h1 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -0.01em; }
.subtitle { margin: 0; font-size: 12px; color: var(--ink-soft); }

.tabs { display: flex; gap: 4px; }
.tab {
  border: none; background: none;
  padding: 8px 14px;
  font-size: 14px; font-weight: 550;
  color: var(--ink-soft);
  border-radius: 8px;
  cursor: pointer;
}
.tab:hover { background: var(--bg); }
.tab.active { background: var(--accent-soft); color: var(--accent-dark); }

.topbar-actions { margin-left: auto; display: flex; gap: 10px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 15px;
  font-size: 14px; font-weight: 550;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s ease;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-secondary { background: var(--accent-soft); color: var(--accent-dark); }
.btn-secondary:hover { background: #d9e9e0; }
.btn-ghost { background: none; color: var(--ink-soft); border-color: var(--line); }
.btn-ghost:hover { background: var(--bg); }
.btn:disabled { opacity: 0.5; cursor: default; }

.linklike {
  border: none; background: none; padding: 0;
  color: var(--accent); text-decoration: underline;
  font: inherit; cursor: pointer;
}

/* ---------- main layout ---------- */
.tab-panel { max-width: 1180px; margin: 0 auto; padding: 22px 28px 60px; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar input[type="search"] {
  flex: 1 1 260px;
  max-width: 380px;
}
.toolbar-spacer { flex: 1; }

input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

/* ---------- summary cards ---------- */
.summary-row { display: flex; gap: 14px; align-items: center; margin-bottom: 18px; }
.summary-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 18px;
  display: flex; flex-direction: column;
  min-width: 120px;
}
.summary-label { font-size: 12px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.05em; }
.summary-value { font-size: 21px; font-weight: 650; font-variant-numeric: tabular-nums; }
.threshold-note { font-size: 13px; color: var(--ink-soft); }

/* ---------- table ---------- */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  font-weight: 600;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td {
  padding: 11px 14px;
  border-bottom: 1px solid #f0efe9;
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fbfaf7; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.center { text-align: center; }
td.expense-no { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; color: var(--ink-soft); white-space: nowrap; }
td.cost { font-weight: 600; }
.cat-pill {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 12px; font-weight: 550;
  border-radius: 20px;
  padding: 3px 10px;
  white-space: nowrap;
}
.receipt-link {
  border: none; background: none; cursor: pointer;
  font-size: 16px; padding: 2px 6px;
}
.row-actions { display: flex; gap: 2px; justify-content: flex-end; opacity: 0; transition: opacity 0.1s; }
tr:hover .row-actions { opacity: 1; }
.row-actions button {
  border: none; background: none; cursor: pointer;
  padding: 4px 7px; border-radius: 6px; font-size: 14px;
}
.row-actions button:hover { background: var(--bg); }

.empty-state { padding: 40px; text-align: center; color: var(--ink-soft); }

/* ---------- dialogs ---------- */
dialog {
  border: none;
  border-radius: 14px;
  box-shadow: 0 24px 70px rgba(30, 42, 36, 0.25);
  padding: 0;
  width: min(640px, 92vw);
}
dialog::backdrop { background: rgba(30, 42, 36, 0.35); }
dialog form, .import-body, .viewer-body { padding: 26px 28px; }
dialog h2 { margin: 0 0 4px; font-size: 19px; }

.form-expense-no { margin: 0 0 10px; font-size: 13px; color: var(--ink-soft); font-family: ui-monospace, Menlo, monospace; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 13px 16px;
  margin-top: 14px;
}
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 550; color: var(--ink-soft); }
.form-grid .span2 { grid-column: span 2; }
.form-grid input, .form-grid select, .form-grid textarea { font-weight: 400; color: var(--ink); }

.existing-receipts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.existing-receipts .chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 20px;
  font-size: 12.5px;
  padding: 4px 10px;
}
.existing-receipts .chip button { border: none; background: none; cursor: pointer; color: var(--danger); padding: 0; font-size: 13px; }
.existing-receipts .chip .chip-open { color: var(--accent); }

.form-error { color: var(--danger); font-size: 13.5px; margin: 10px 0 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* import dialog */
.import-body p { color: var(--ink-soft); font-size: 14px; }
.drop-zone {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 44px 20px;
  text-align: center;
  color: var(--ink-soft);
  transition: border-color 0.12s, background 0.12s;
}
.drop-zone.dragover { border-color: var(--accent); background: var(--accent-soft); }
.import-status { font-size: 14px; }
.import-status.working { color: var(--accent-dark); }
.import-status.error { color: var(--danger); }

/* viewer */
#viewer-dialog { width: min(860px, 94vw); }
.viewer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
#viewer-title { font-weight: 600; }
#viewer-content img { max-width: 100%; border-radius: 8px; border: 1px solid var(--line); }
#viewer-content iframe { width: 100%; height: 70vh; border: 1px solid var(--line); border-radius: 8px; }

/* ---------- auth screen ---------- */
.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: grid;
  place-items: center;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 34px 38px;
  width: min(400px, 92vw);
}
.auth-form { display: flex; flex-direction: column; gap: 13px; }
.auth-form h2 { margin: 0 0 2px; font-size: 17px; text-align: center; }
.auth-form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 550; color: var(--ink-soft); }
.auth-form button { margin-top: 6px; justify-content: center; }
.auth-note { font-size: 12.5px; color: var(--ink-soft); margin: 0; }

/* ---------- user chip ---------- */
.user-chip {
  display: flex; align-items: center; gap: 8px;
  border-left: 1px solid var(--line);
  padding-left: 14px; margin-left: 4px;
  font-size: 13px;
}
#user-name { font-weight: 600; }
.role-badge {
  font-size: 11px; font-weight: 650;
  text-transform: uppercase; letter-spacing: 0.05em;
  background: var(--accent-soft); color: var(--accent-dark);
  border-radius: 10px; padding: 2px 7px;
}
.user-chip .linklike { font-size: 12px; color: var(--ink-soft); text-decoration: none; }
.user-chip .linklike:hover { color: var(--accent); text-decoration: underline; }

/* ---------- users tab ---------- */
.users-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.user-inactive td { opacity: 0.45; }
.user-actions { display: flex; gap: 8px; justify-content: flex-end; }
.user-actions .linklike { font-size: 12.5px; text-decoration: none; }
.user-actions .linklike:hover { text-decoration: underline; }

/* ---------- SQL console ---------- */
.sql-hint { color: var(--ink-soft); font-size: 14px; }
.sql-example {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  margin-top: 8px;
  font-size: 13px;
  cursor: pointer;
}
.sql-example:hover { border-color: var(--accent); }
#sql-input {
  width: 100%;
  min-height: 120px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13.5px;
  margin-top: 6px;
  resize: vertical;
}
.sql-actions { display: flex; align-items: center; gap: 14px; margin: 12px 0 18px; }
.sql-status { font-size: 13.5px; color: var(--ink-soft); }
.sql-status.error { color: var(--danger); }
#sql-table td { font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; white-space: nowrap; max-width: 340px; overflow: hidden; text-overflow: ellipsis; }
