:root {
  --paper: #faf7f2;
  --surface: #ffffff;
  --ink: #1c1a17;
  --ink-soft: #58524a;
  --muted: #8a8377;
  --border: #e8e1d4;
  --accent: #0f6b4c;
  --accent-ink: #ffffff;
  --accent-soft: #e5f0ea;
  --error: #b3261e;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(28, 26, 23, 0.04), 0 8px 24px -12px rgba(28, 26, 23, 0.12);
  --font-display: "Bitter", Georgia, serif;
  --font-body: "Manrope", -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { background: var(--paper); }

body {
  font-family: var(--font-body);
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.container { max-width: 980px; margin: 0 auto; padding: 40px 28px 80px; }
.container.wide { max-width: 1320px; }

.center-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 0;
  padding-bottom: 0;
}

/* Top navigation */
.topbar {
  border-bottom: 1px solid var(--border);
  background: var(--paper);
}

.topbar-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 20px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}

.brand {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.15rem;
  color: var(--ink);
  letter-spacing: -0.01em;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.brand-icon {
  border-radius: 6px;
  display: block;
}

.brand:hover { text-decoration: none; }

.topnav {
  display: flex;
  align-items: center;
  gap: 28px;
}

.topnav a {
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 0.92rem;
}

.topnav a:hover { color: var(--accent); text-decoration: none; }

.topnav-logout { color: var(--muted) !important; font-weight: 500 !important; }

.account-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 500;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.role-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
}

.role-badge-user {
  color: var(--muted);
  background: var(--border);
}

/* Typography */
h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 2rem;
  letter-spacing: -0.01em;
  margin: 0 0 20px;
  color: var(--ink);
}

h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.25rem;
  margin: 40px 0 16px;
  color: var(--ink);
}

p { color: var(--ink-soft); }

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

/* Tables — precise, numeric, tabular */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  margin-bottom: 24px;
}

th, td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--paper);
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--accent-soft); }

td:not(:first-child), th:not(:first-child) { text-align: right; }
td:first-child, th:first-child { text-align: left; }

/* Summary tables (key figures) get more presence */
.summary td, .summary th { font-size: 1rem; padding: 16px 18px; }
.summary th { text-transform: none; letter-spacing: 0; font-weight: 600; color: var(--ink-soft); background: var(--surface); text-align: left; }
.summary td { font-weight: 700; font-family: var(--font-display); }

/* Forms */
.auth-form, form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 420px;
  background: var(--surface);
  padding: 24px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.92rem;
  color: var(--ink-soft);
}

input, select, button {
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--ink);
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

button {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  cursor: pointer;
  font-weight: 700;
  padding: 12px 16px;
  letter-spacing: 0.01em;
  transition: transform 0.1s ease, opacity 0.15s ease;
}

button:hover { opacity: 0.92; }
button:active { transform: scale(0.99); }

.error { color: var(--error); font-size: 0.9rem; }

.notice {
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  display: inline-block;
}

/* Loan list — cards, not bare bullets */
.loan-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.loan-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.loan-card:hover { border-color: var(--accent); }

.loan-card-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--ink);
}

.loan-card-meta { color: var(--muted); font-size: 0.88rem; }

.loan-card-type {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 9px;
  border-radius: 999px;
  margin-left: 10px;
}

.hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin: -8px 0 16px;
  max-width: 640px;
  white-space: normal;
}

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

/* Schedule table column proportions — table-layout: fixed makes the
   colgroup widths actually binding instead of shrinking to fit content
   or growing to fit a long header. */
.schedule-table {
  table-layout: fixed;
  min-width: 1180px;
}
.schedule-table .col-num { width: 4%; }
.schedule-table .col-date { width: 9%; }
.schedule-table .col-money { width: 11%; }
.schedule-table .col-actions { width: 9%; }

.schedule-table th {
  white-space: normal;
  line-height: 1.25;
}

.schedule-table td { white-space: nowrap; }

.fact-cell {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.section-heading { margin-top: 32px; }

.bare-form {
  display: inline-flex;
  background: none;
  border: none;
  box-shadow: none;
  padding: 0;
  margin: 0 0 20px;
}

.receipt-actions {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

[x-cloak] { display: none !important; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 26, 23, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  max-width: 440px;
  width: 100%;
}

.modal h3 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.1rem;
  margin: 0 0 12px;
}

.modal p { margin: 0 0 16px; }

.modal-form { gap: 16px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

.modal-actions form {
  margin: 0;
  padding: 0;
  background: none;
  border: none;
  box-shadow: none;
  display: block;
}

button.secondary {
  background: var(--surface);
  color: var(--ink-soft);
  border: 1px solid var(--border);
}

.dropzone {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 28px 16px;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.88rem;
  background: var(--paper);
}

.dropzone:hover { border-color: var(--accent); color: var(--accent); }
.dropzone.has-file { border-color: var(--accent); color: var(--ink); background: var(--accent-soft); }
.dropzone input[type="file"] { display: none; }

.modal-viewer { max-width: 720px; }
.modal-viewer-body {
  max-height: 70vh;
  overflow: auto;
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}
.modal-viewer-body img { max-width: 100%; height: auto; }
.modal-viewer-body embed { width: 100%; height: 65vh; border: none; }

.share-url {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.share-actions {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.icon-btn.copied { color: var(--accent) !important; }

.attach-form button {
  color: var(--accent) !important;
}

button.danger {
  background: var(--error);
}

.icon-btn {
  background: none !important;
  border: none;
  color: var(--muted) !important;
  padding: 4px !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  vertical-align: middle;
  margin-left: 4px;
}

.icon-btn:hover {
  color: var(--error) !important;
  background: rgba(179, 38, 30, 0.08) !important;
  opacity: 1;
}

.inline-form {
  display: inline-flex;
  background: none;
  border: none;
  box-shadow: none;
  padding: 0;
  margin: 0;
}

.inline-form button {
  background: none;
  color: var(--error);
  font-weight: 600;
  padding: 2px 8px;
  border: 1px solid transparent;
}

.inline-form button:hover { text-decoration: underline; opacity: 1; }

.share-list, .payment-list {
  list-style: none;
  padding: 0;
  margin: 0 0 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.share-list li, .payment-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin: 0;
}

.new-loan-link {
  display: inline-block;
  font-weight: 700;
  margin-bottom: 20px;
}

ul { padding-left: 20px; }
li { margin-bottom: 6px; }

code {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 0.85rem;
}
