/* ===================== Design tokens ===================== */
:root,
[data-theme="light"] {
  --bg: #F5F1E8;
  --surface: #FBF8F2;
  --surface-2: #F0EBDD;
  --text: #2B2621;
  --text-muted: #7A7266;
  --border: #E3DCCB;
  --accent: #C2673E;
  --accent-bg: rgba(194, 103, 62, 0.13);
  --closed: #6B7A4F;
  --closed-bg: rgba(107, 122, 79, 0.13);
  --danger: #96392A;
  --danger-bg: rgba(150, 57, 42, 0.12);
  --shadow: 0 1px 2px rgba(43, 38, 33, 0.06), 0 4px 12px rgba(43, 38, 33, 0.05);
}

[data-theme="dark"] {
  --bg: #211E1A;
  --surface: #2C2823;
  --surface-2: #362F28;
  --text: #F0EAE0;
  --text-muted: #A79C8A;
  --border: #453D34;
  --accent: #D97A4E;
  --accent-bg: rgba(217, 122, 78, 0.16);
  --closed: #8AA06A;
  --closed-bg: rgba(138, 160, 106, 0.16);
  --danger: #C2604A;
  --danger-bg: rgba(194, 96, 74, 0.15);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 4px 14px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }

/* The app toggles visibility via the hidden attribute/property on
   elements whose own selectors also set display (flex/grid/etc).
   Without !important here, [hidden]'s (0,1,0) specificity just ties
   or loses against those, so this must always win regardless of what
   else targets the element. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

.font-serif { font-family: 'Source Serif 4', Georgia, serif; }
.font-mono { font-family: 'IBM Plex Mono', ui-monospace, monospace; }

/* ===================== Layout shells ===================== */
.screen { min-height: 100vh; }

#loginScreen {
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  width: 320px;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-title {
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 24px;
  margin: 0;
}

.login-sub {
  margin: -10px 0 6px;
  color: var(--text-muted);
  font-size: 13px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.topbar-title {
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 18px;
}
.topbar-sub {
  color: var(--text-muted);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 400;
  margin-left: 6px;
}

.topbar-nav { display: flex; gap: 4px; }

.topbar-right { display: flex; align-items: center; gap: 14px; }

.whoami {
  font-size: 13px;
  color: var(--text-muted);
}

.view { padding: 24px 28px 60px; max-width: 1200px; margin: 0 auto; }
.view-heading { font-family: 'Source Serif 4', Georgia, serif; font-size: 20px; margin: 0; }
.muted { color: var(--text-muted); font-size: 13px; font-weight: 400; }

/* ===================== Toolbar ===================== */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 16px;
  flex-wrap: wrap;
}

.toolbar-stats { display: flex; gap: 28px; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat-label { font-size: 12px; color: var(--text-muted); }
.stat-value { font-family: 'IBM Plex Mono', monospace; font-size: 15px; font-weight: 500; }
.toolbar-actions { display: flex; gap: 8px; }

/* ===================== Buttons & inputs ===================== */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .job-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.05); }
.btn-accent { color: var(--accent); border-color: var(--accent); }
.btn-accent:hover { background: var(--accent-bg); }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); }

kbd {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 4px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 6px;
  font-family: inherit;
}
.link-btn:hover { color: var(--text); background: var(--surface-2); }
.link-btn.active { color: var(--accent); font-weight: 600; }

.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  border-radius: 6px;
}
.icon-btn:hover { color: var(--accent); background: var(--surface-2); }

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
}
.field span { color: var(--text-muted); }

input, select, textarea {
  font-family: inherit;
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }

.error-text { color: var(--danger); font-size: 13px; margin: 0; }

/* ===================== Card columns ===================== */
.columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
.column-heading {
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  text-transform: uppercase;
  margin: 0 0 10px;
}
.card-list { display: flex; flex-direction: column; gap: 14px; }

/* ===================== Job card (ticket stub) ===================== */
.job-card {
  position: relative;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 16px 18px;
  border-left: 4px solid var(--accent);
  cursor: pointer;
}
.job-card[data-status="closed"] {
  border-left-color: var(--closed);
  opacity: 0.9;
}
.job-card-status {
  position: absolute;
  top: 12px;
  right: 14px;
  font-size: 11px;
  padding: 2px 10px;
  border-radius: 20px;
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 500;
}
.job-card[data-status="closed"] .job-card-status {
  background: var(--closed-bg);
  color: var(--closed);
}
.job-card-title {
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 16px;
  margin-bottom: 2px;
  padding-right: 70px;
}
.job-card-sub { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.job-card-body { margin-top: 14px; cursor: default; }

.section-label {
  font-size: 12px;
  color: var(--text-muted);
  margin: 12px 0 6px;
}
.materials-label { border-top: 1px solid var(--border); padding-top: 10px; }

.sessions-list { display: flex; flex-direction: column; gap: 6px; }
.session-row {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
}
.session-row-top { display: flex; justify-content: space-between; color: var(--text-muted); font-size: 11px; margin-bottom: 3px; }
.session-row-times { display: flex; flex-direction: column; gap: 2px; }
.session-row-times div { display: flex; justify-content: space-between; }
.session-row-times span:first-child { color: var(--text-muted); }
.session-del { float: right; background: none; border: none; color: var(--danger); cursor: pointer; font-size: 11px; }

.session-add-form, .material-add-form {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.session-add-label { font-size: 11px; color: var(--text-muted); width: 100%; }
.session-add-form input, .material-add-form input { flex: 1; min-width: 70px; padding: 6px 8px; }

.materials-list { display: flex; flex-direction: column; }
.material-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--border);
  padding: 7px 0;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
}
.material-row input[type="number"] {
  width: 70px;
  text-align: right;
  padding: 4px 6px;
}
.material-row .material-remove { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 11px; }

.job-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-top: 12px;
}
.job-card-total { font-family: 'IBM Plex Mono', monospace; font-size: 13px; color: var(--text-muted); }
.job-card-total strong { color: var(--text); font-weight: 500; }
.job-card-footer-actions { display: flex; gap: 8px; }

/* ===================== Archive ===================== */
.archive-filters { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.archive-filters input, .archive-filters select { min-width: 160px; }
.archive-list .job-card { cursor: default; border-left-color: var(--text-muted); }

/* ===================== Admin ===================== */
.admin-section { margin-bottom: 32px; }
.admin-section h3 { font-family: 'Source Serif 4', Georgia, serif; font-size: 16px; margin: 0 0 12px; }
.user-list, .bug-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.user-row, .bug-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-radius: 8px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  gap: 10px;
  flex-wrap: wrap;
}
.user-row-name { font-family: 'IBM Plex Mono', monospace; font-size: 13px; }
.role-badge {
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text-muted);
  margin-left: 8px;
}
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }

.bug-row { align-items: flex-start; }
.bug-desc { flex: 1; min-width: 220px; font-size: 13px; }
.bug-meta { font-size: 11px; color: var(--text-muted); margin-top: 3px; }
.bug-screenshot-link { font-size: 12px; color: var(--accent); }
.bug-row[data-status="resolved"] { opacity: 0.6; }

/* ===================== Modals ===================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal {
  width: 380px;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal h2 { font-family: 'Source Serif 4', Georgia, serif; font-size: 18px; margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

@media (max-width: 720px) {
  .columns { grid-template-columns: 1fr; }
  .topbar { padding: 12px 16px; flex-wrap: wrap; gap: 10px; }
  .view { padding: 18px 16px 50px; }
}
