:root {
  --sidebar-bg: #151a2e;
  --sidebar-bg-alt: #1b2140;
  --sidebar-border: #262c4a;
  --sidebar-text: #9aa3c4;
  --sidebar-text-active: #ffffff;
  --sidebar-active-bg: rgba(255, 255, 255, 0.08);

  --bg: #f4f5f9;
  --card: #ffffff;
  --border: #e3e5ef;
  --border-soft: #edeef5;
  --text: #14172a;
  --muted: #6b7080;
  --accent: #4a5cf0;
  --accent-hover: #3a49d6;
  --accent-soft: #eef0fe;
  --error: #c0281c;
  --error-soft: #fdecea;
  --success: #157a3f;
  --success-soft: #e6f6ec;
  --warn: #92600a;
  --warn-soft: #fdf1dc;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 23, 42, 0.04), 0 8px 24px rgba(20, 23, 42, 0.04);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

/* ---------- App shell ---------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 22px;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #7a5cf0);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.brand-name {
  color: var(--sidebar-text-active);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
}

.nav-label {
  color: #5c6491;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 6px 10px;
  margin-top: 6px;
}

.app-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--sidebar-text);
  font-size: 0.88rem;
  font-weight: 500;
}

.nav-item:hover { background: var(--sidebar-bg-alt); color: var(--sidebar-text-active); }

.nav-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-text-active);
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: flex;
}
.nav-icon svg { width: 100%; height: 100%; stroke: currentColor; stroke-width: 1.6; fill: none; }

.nav-item.disabled {
  color: #4b5178;
  cursor: default;
}
.nav-item.disabled .nav-icon svg { stroke: #4b5178; }

.sidebar-spacer { flex: 1; }

.sidebar-footer {
  border-top: 1px solid var(--sidebar-border);
  padding-top: 12px;
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 12px;
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--sidebar-bg-alt);
  color: var(--sidebar-text-active);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.78rem;
  flex-shrink: 0;
  border: 1px solid var(--sidebar-border);
}

.user-name { color: var(--sidebar-text-active); font-size: 0.85rem; font-weight: 600; line-height: 1.3; }
.user-role { font-size: 0.75rem; color: var(--sidebar-text); }

.sidebar-link {
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.85rem;
  text-align: left;
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}
.sidebar-link:hover { background: var(--sidebar-bg-alt); color: var(--sidebar-text-active); }

/* ---------- Content area ---------- */

.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.content {
  flex: 1;
  padding: 32px 40px 60px;
  max-width: 1080px;
  width: 100%;
  margin: 0 auto;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.page-header h1 { margin: 0 0 4px; }
.page-header .eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  margin: 0 0 6px;
}

h1 { font-size: 1.5rem; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 1rem; margin-top: 26px; margin-bottom: 10px; }
.muted { color: var(--muted); }

/* ---------- Buttons ---------- */

.btn, button {
  background: var(--accent);
  color: white;
  border: none;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 0.87rem;
  cursor: pointer;
  font-weight: 600;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  transition: background 0.12s ease;
}
.btn:hover, button:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg); }

/* ---------- Cards ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}
.card.narrow { max-width: 400px; margin: 8vh auto; }

.auth-main {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  margin-bottom: 18px;
}

/* ---------- Forms ---------- */

label {
  display: block;
  margin-bottom: 16px;
  font-size: 0.85rem;
  font-weight: 600;
}

input, select, textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

input[type="file"] {
  padding: 8px;
  background: var(--bg);
  border-style: dashed;
}

.error {
  color: var(--error);
  background: var(--error-soft);
  border-radius: 7px;
  padding: 9px 12px;
  font-size: 0.85rem;
  margin-bottom: 16px;
}

/* ---------- Stat cards ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow);
  transition: border-color 0.12s ease;
}
.stat-card:hover { border-color: var(--accent); }
.stat-card.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.stat-card .stat-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.stat-card .stat-value { font-size: 1.5rem; font-weight: 700; margin-top: 4px; }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot-loaded { background: var(--accent); }
.dot-approved { background: #b8790a; }
.dot-released { background: #1c9150; }
.dot-confirmed_paid { background: #0f6b38; }
.dot-all { background: var(--muted); }

/* ---------- Tabs (secondary filter, used on top of table) ---------- */

.tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.tab {
  padding: 6px 12px;
  border-radius: 20px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  font-size: 0.82rem;
  text-transform: capitalize;
}
.tab.active { background: var(--accent); color: white; border-color: var(--accent); }
.tab .count { opacity: 0.7; margin-left: 4px; }

/* ---------- Table ---------- */

.table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  overflow-x: auto; /* wide tables scroll sideways instead of clipping */
  box-shadow: var(--shadow);
}

table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border-soft); font-size: 0.87rem; }
table.list th { color: var(--muted); font-weight: 600; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; background: #fafbfd; }
table.list tbody tr:hover { background: #fafbff; }
table.list tr:last-child td { border-bottom: none; }
table.list td.amount { font-variant-numeric: tabular-nums; font-weight: 600; }
table.list a.row-link { text-decoration: none; color: var(--accent); font-weight: 600; }

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

table.detail { margin: 14px 0; }
table.detail th { text-align: left; color: var(--muted); font-weight: 600; padding: 6px 16px 6px 0; vertical-align: top; white-space: nowrap; }
table.detail td { padding: 6px 0; }

/* ---------- Badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.76rem;
  font-weight: 600;
  text-transform: capitalize;
}
.status-loaded { background: var(--accent-soft); color: var(--accent); }
.status-approved { background: var(--warn-soft); color: var(--warn); }
.status-released { background: var(--success-soft); color: var(--success); }
.status-confirmed_paid { background: var(--success-soft); color: var(--success); }

/* ---------- Timeline ---------- */

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li {
  padding: 10px 0 10px 22px;
  position: relative;
  font-size: 0.87rem;
  border-left: 2px solid var(--border);
  margin-left: 4px;
}
.timeline li::before {
  content: "";
  position: absolute;
  left: -7px;
  top: 14px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--card);
}
.timeline li:last-child { border-left-color: transparent; }

.actions-row { display: flex; gap: 8px; margin-top: 20px; }

/* ---------- Misc ---------- */

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
  margin-bottom: 16px;
}
.back-link:hover { color: var(--text); }

/* ---------- Responsive ---------- */

@media (max-width: 820px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    padding: 10px 14px;
    gap: 10px;
    overflow-x: auto;
  }
  .sidebar-brand { padding: 0; margin-right: 8px; }
  .nav-label { display: none; }
  .app-nav { flex-direction: row; }
  .sidebar-spacer { display: none; }
  .sidebar-footer { flex-direction: row; align-items: center; border-top: none; margin: 0 0 0 auto; padding: 0; }
  .user-chip { padding: 0 8px 0 0; }
  .user-role { display: none; }
  .content { padding: 20px 16px 40px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  table.list { font-size: 0.82rem; }
}

/* ---------- Dashboard: category groups, rands, urgency ---------- */

.summary-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  font-size: 0.85rem;
  color: var(--muted);
}
.summary-bar strong { color: var(--text); }
.summary-total { font-variant-numeric: tabular-nums; }

table.list tr.group-row td {
  background: #f7f8fc;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border-soft);
  padding: 9px 16px;
}
table.list tr.group-row:first-child td { border-top: none; }
table.list tr.group-row:hover td { background: #f7f8fc; }
.group-name { font-weight: 700; font-size: 0.8rem; letter-spacing: 0.02em; }
.group-meta { color: var(--muted); font-size: 0.78rem; margin-left: 10px; font-variant-numeric: tabular-nums; }

table.list td.zar { color: var(--muted); font-weight: 500; white-space: nowrap; }
table.list td.amount { white-space: nowrap; }
.doc-name {
  display: inline-block;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}
table.list td.row-actions { white-space: nowrap; text-align: right; }

.badge-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.badge-urgent {
  background: var(--error-soft);
  color: var(--error);
  text-transform: uppercase;
  font-size: 0.66rem;
  letter-spacing: 0.05em;
  padding: 3px 8px;
  margin-left: 6px;
  vertical-align: middle;
}
.badge-row .badge-urgent, .badge-row .badge-overdue { margin-left: 0; }
.badge-overdue {
  background: var(--warn-soft);
  color: var(--warn);
  text-transform: uppercase;
  font-size: 0.66rem;
  letter-spacing: 0.05em;
  padding: 3px 8px;
}
table.list tr.row-urgent td:first-child { box-shadow: inset 3px 0 0 var(--error); }
.due-overdue { color: var(--error); font-weight: 600; }
.dot-urgent { background: var(--error); }
.stat-card.stat-urgent:hover { border-color: var(--error); }
.stat-card.stat-urgent.active { border-color: var(--error); box-shadow: 0 0 0 3px var(--error-soft); }

.comment-count {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 600;
  margin-right: 12px;
  vertical-align: middle;
}
.comment-count svg { width: 14px; height: 14px; }
.comment-count:hover { color: var(--accent); }

.rates-note { color: var(--muted); font-size: 0.78rem; margin: 10px 2px 0; }
.zar-hint { color: var(--muted); font-size: 0.95rem; font-weight: 500; margin-left: 6px; white-space: nowrap; }

/* ---------- Forms: rows, checkboxes, hints ---------- */

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.hint { margin: -10px 0 16px; font-size: 0.78rem; }
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  align-self: end;
  padding-bottom: 10px;
}
.checkbox-label input {
  width: 16px;
  height: 16px;
  margin: 0;
  display: inline-block;
  accent-color: var(--accent);
}
.btn-sm { padding: 7px 13px; font-size: 0.8rem; }

/* ---------- Request detail: edit, documents, discussion ---------- */

.edit-details {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0;
  margin: 4px 0 8px;
  background: #fafbfd;
}
.edit-details summary {
  cursor: pointer;
  padding: 10px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  list-style: none;
}
.edit-details summary::-webkit-details-marker { display: none; }
.edit-details summary::before { content: "\25B8"; display: inline-block; margin-right: 6px; transition: transform 0.12s ease; }
.edit-details[open] summary::before { transform: rotate(90deg); }
.edit-form { padding: 4px 14px 14px; }
.edit-form .checkbox-label { align-self: auto; padding: 0 0 14px; }

.doc-list { list-style: none; padding: 0; margin: 0 0 14px; }
.doc-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border-soft);
  font-size: 0.87rem;
  min-width: 0;
}
.doc-list li:last-child { border-bottom: none; }
.doc-list a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-icon { width: 18px; height: 18px; color: var(--muted); flex-shrink: 0; display: flex; }
.doc-icon svg { width: 100%; height: 100%; }
.doc-meta { color: var(--muted); font-size: 0.76rem; margin-left: auto; white-space: nowrap; }

.inline-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.inline-form label { margin-bottom: 0; flex: 1; min-width: 220px; }
.inline-form button { margin-bottom: 1px; }
.inline-form + .hint { margin-top: 8px; }

.discussion { margin-top: 20px; }
.comments { list-style: none; padding: 0; margin: 0 0 18px; }
.comment {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-soft);
}
.comment:last-child { border-bottom: none; }
.comment .avatar { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.comment-body { flex: 1; min-width: 0; }
.comment-head { display: flex; align-items: baseline; gap: 8px; font-size: 0.85rem; }
.comment-author { font-weight: 600; }
.comment-time { color: var(--muted); font-size: 0.76rem; }
.comment-delete { margin-left: auto; }
.comment-text { margin: 4px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.88rem; line-height: 1.45; }
.btn-link {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 500;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
}
.btn-link:hover { background: none; color: var(--error); }

@media (max-width: 820px) {
  .form-row { grid-template-columns: 1fr; }
  .checkbox-label { padding-bottom: 0; }
  .doc-meta { display: none; }
}

table.list th:first-child, table.list td:first-child { white-space: nowrap; }

/* ---------- Dashboard rows open the request ---------- */

table.list tr.request-row { cursor: pointer; }
a.row-title { font-weight: 600; color: var(--text); text-decoration: none; }
a.row-title:hover { color: var(--accent); text-decoration: underline; }
.doc-name { max-width: 150px; }
@media (max-width: 1200px) {
  .col-submitter { display: none; }
}
