/* ==========================================================================
   IRM - Infinite Records Manager
   Design system: flat, professional, no gradients.
   Off-white / black / blue / green / red only.
   ========================================================================== */

:root {
  --c-bg: #f6f6f3;
  --c-surface: #ffffff;
  --c-surface-2: #f0f0ec;
  --c-border: #dcdcd4;
  --c-border-strong: #c2c2b8;
  --c-text: #14141a;
  --c-text-muted: #5c5c58;
  --c-text-faint: #8a8a82;

  --c-blue: #1d4ed8;
  --c-blue-dark: #1e3a8a;
  --c-blue-bg: #e8eefc;

  --c-green: #15803d;
  --c-green-bg: #e7f5ea;

  --c-red: #b91c1c;
  --c-red-bg: #fbe9e9;

  --c-black: #14141a;

  --radius: 6px;
  --radius-lg: 10px;
  --shadow-sm: 0 1px 2px rgba(20, 20, 26, 0.06);
  --shadow-md: 0 4px 16px rgba(20, 20, 26, 0.12);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--c-bg);
  color: var(--c-text);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, h5 { margin: 0 0 8px; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
p { margin: 0 0 8px; }
a { color: var(--c-blue); text-decoration: none; }
a:hover { text-decoration: underline; }
ul { margin: 0; padding: 0; list-style: none; }
button { font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ---------- App shell ---------- */
#app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 224px;
  flex-shrink: 0;
  background: var(--c-black);
  color: #f2f2ee;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
}
.sidebar__brand {
  padding: 20px 18px 16px;
  border-bottom: 1px solid #2a2a30;
}
.sidebar__brand-title { font-size: 16px; font-weight: 700; color: #fff; letter-spacing: -0.01em; }
.sidebar__brand-sub { font-size: 11px; color: #9a9a92; margin-top: 2px; }
.sidebar__nav { flex: 1; overflow-y: auto; padding: 10px 0; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  color: #c9c9c2;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: #1f1f24; color: #fff; }
.nav-item.active { background: #1f1f24; color: #fff; border-left-color: var(--c-blue); }
.nav-item__icon { width: 18px; text-align: center; opacity: 0.85; }
.sidebar__footer { padding: 12px 18px; font-size: 11px; color: #74746c; border-top: 1px solid #2a2a30; }

.main-area { margin-left: 224px; flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 56px;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar__title { font-size: 17px; font-weight: 650; }
.topbar__crumbs { font-size: 12px; color: var(--c-text-muted); }
.topbar__actions { display: flex; gap: 8px; align-items: center; }

#app-main { padding: 22px; flex: 1; }
#firebase-banner {
  background: var(--c-red-bg);
  border: 1px solid var(--c-red);
  color: var(--c-red);
  padding: 10px 16px;
  font-size: 13px;
  display: none;
}
#firebase-banner.show { display: block; }
#firebase-banner code { background: rgba(0,0,0,0.06); padding: 1px 5px; border-radius: 3px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius);
  border: 1px solid var(--c-border-strong);
  background: var(--c-surface);
  color: var(--c-text);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--c-surface-2); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn--primary { background: var(--c-blue); border-color: var(--c-blue); color: #fff; }
.btn--primary:hover { background: var(--c-blue-dark); }
.btn--danger { background: var(--c-red); border-color: var(--c-red); color: #fff; }
.btn--danger:hover { background: #8f1616; }
.btn--success { background: var(--c-green); border-color: var(--c-green); color: #fff; }
.btn--success:hover { background: #0f5c2c; }
.btn--ghost { background: transparent; border-color: transparent; }
.btn--ghost:hover { background: var(--c-surface-2); }
.btn--sm { padding: 5px 10px; font-size: 12px; }
.btn--icon { padding: 7px 9px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Cards ---------- */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}
.card--clickable { cursor: pointer; transition: border-color 0.12s, box-shadow 0.12s; }
.card--clickable:hover { border-color: var(--c-blue); box-shadow: var(--shadow-md); }

.grid { display: grid; gap: 14px; }
.grid--cards { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.grid--stats { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.grid--2 { grid-template-columns: 1fr 1fr; }
.grid--3 { grid-template-columns: 1fr 1fr 1fr; }

.stat-card { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius-lg); padding: 16px 18px; }
.stat-card__label { font-size: 12px; color: var(--c-text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-card__value { font-size: 26px; font-weight: 700; margin-top: 6px; }
.stat-card__sub { font-size: 12px; color: var(--c-text-faint); margin-top: 4px; }
.stat-card--blue { border-left: 3px solid var(--c-blue); }
.stat-card--green { border-left: 3px solid var(--c-green); }
.stat-card--red { border-left: 3px solid var(--c-red); }
.stat-card--black { border-left: 3px solid var(--c-black); }

/* ---------- Pills / badges ---------- */
.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.pill--blue { background: var(--c-blue-bg); color: var(--c-blue-dark); }
.pill--green { background: var(--c-green-bg); color: var(--c-green); }
.pill--red { background: var(--c-red-bg); color: var(--c-red); }
.pill--neutral { background: var(--c-surface-2); color: var(--c-text-muted); }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 650; margin-bottom: 5px; color: var(--c-text-muted); }
.field .hint { font-size: 11px; color: var(--c-text-faint); margin-top: 4px; }
.field .error { font-size: 11px; color: var(--c-red); margin-top: 4px; }
input[type=text], input[type=number], input[type=date], input[type=email],
input[type=tel], input[type=search], input[type=password], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--c-border-strong);
  border-radius: var(--radius);
  background: var(--c-surface);
  color: var(--c-text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--c-blue);
  box-shadow: 0 0 0 3px var(--c-blue-bg);
}
textarea { resize: vertical; min-height: 60px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }
.form-section {
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 16px;
  background: var(--c-surface);
}
.form-section__title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; color: var(--c-text-muted); margin-bottom: 12px; }
.toggle-group { display: flex; gap: 8px; }
.toggle-opt {
  flex: 1;
  text-align: center;
  padding: 9px;
  border: 1px solid var(--c-border-strong);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--c-text-muted);
}
.toggle-opt.active { background: var(--c-blue); border-color: var(--c-blue); color: #fff; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--c-border); border-radius: var(--radius-lg); background: var(--c-surface); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left;
  padding: 10px 12px;
  background: var(--c-surface-2);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--c-text-muted);
  border-bottom: 1px solid var(--c-border);
  white-space: nowrap;
}
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--c-border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.row--clickable { cursor: pointer; }
tbody tr.row--clickable:hover { background: var(--c-surface-2); }
.text-right { text-align: right; }
.text-muted { color: var(--c-text-muted); }
.text-faint { color: var(--c-text-faint); }
.text-green { color: var(--c-green); }
.text-red { color: var(--c-red); }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar__filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar__filters select, .toolbar__filters input { width: auto; min-width: 140px; }
.search-box { position: relative; }
.search-box input { padding-left: 30px; min-width: 220px; }
.search-box::before { content: '\1F50D'; position: absolute; left: 10px; top: 50%; transform: translateY(-50%); font-size: 12px; opacity: 0.5; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(20,20,26,0.5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto; z-index: 100;
}
.modal {
  background: var(--c-surface);
  border-radius: var(--radius-lg);
  width: 100%; max-width: 560px;
  box-shadow: var(--shadow-md);
  max-height: calc(100vh - 80px);
  display: flex; flex-direction: column;
}
.modal--sm { max-width: 420px; }
.modal--lg { max-width: 760px; }
.modal--xl { max-width: 980px; }
.modal__header { padding: 16px 20px; border-bottom: 1px solid var(--c-border); display: flex; align-items: center; justify-content: space-between; }
.modal__header h3 { margin: 0; }
.modal__close { cursor: pointer; font-size: 20px; color: var(--c-text-faint); background: none; border: none; line-height: 1; }
.modal__body { padding: 18px 20px; overflow-y: auto; }
.modal__footer { padding: 14px 20px; border-top: 1px solid var(--c-border); display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Wizard ---------- */
.wizard-steps { display: flex; gap: 6px; margin-bottom: 20px; }
.wizard-step {
  flex: 1; text-align: center; padding: 10px 8px; border-radius: var(--radius);
  background: var(--c-surface-2); font-size: 12px; font-weight: 700; color: var(--c-text-faint);
  border: 1px solid var(--c-border);
}
.wizard-step.active { background: var(--c-blue-bg); color: var(--c-blue-dark); border-color: var(--c-blue); }
.wizard-step.done { background: var(--c-green-bg); color: var(--c-green); border-color: var(--c-green); }

.group-card { border: 1px solid var(--c-border); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; background: var(--c-surface-2); position: relative; }
.group-card__remove { position: absolute; top: 8px; right: 8px; }

/* ---------- Detail page ---------- */
.detail-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; gap: 16px; flex-wrap: wrap; }
.detail-header__back { font-size: 12px; color: var(--c-text-muted); margin-bottom: 6px; cursor: pointer; display: inline-block; }
.kv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.kv { }
.kv__label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; color: var(--c-text-faint); margin-bottom: 3px; }
.kv__value { font-size: 14px; font-weight: 550; }

.tabs-strip { display: flex; gap: 4px; border-bottom: 1px solid var(--c-border); margin-bottom: 16px; }
.tabs-strip__item { padding: 9px 14px; font-size: 13px; font-weight: 600; color: var(--c-text-muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tabs-strip__item.active { color: var(--c-blue); border-bottom-color: var(--c-blue); }

.timeline { border-left: 2px solid var(--c-border); padding-left: 18px; margin-left: 6px; }
.timeline-item { position: relative; padding-bottom: 18px; }
.timeline-item::before { content: ''; position: absolute; left: -23px; top: 3px; width: 9px; height: 9px; border-radius: 50%; background: var(--c-blue); }
.timeline-item__time { font-size: 11px; color: var(--c-text-faint); }
.timeline-item__text { font-size: 13px; margin-top: 2px; }

.empty-state { text-align: center; padding: 50px 20px; color: var(--c-text-faint); }
.empty-state h3 { color: var(--c-text-muted); }

.section-title-row { display: flex; justify-content: space-between; align-items: center; margin: 22px 0 10px; }
.section-title-row h3 { margin: 0; }

/* ---------- Toast ---------- */
.irm-toast {
  position: fixed; bottom: 22px; right: 22px; background: var(--c-black); color: #fff;
  padding: 12px 18px; border-radius: var(--radius); font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow-md); opacity: 0; transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s; z-index: 999; max-width: 340px;
}
.irm-toast.show { opacity: 1; transform: translateY(0); }
.irm-toast--success { background: var(--c-green); }
.irm-toast--error { background: var(--c-red); }
.irm-toast--info { background: var(--c-black); }

/* ---------- Misc ---------- */
.divider { height: 1px; background: var(--c-border); margin: 16px 0; }
.chip { display: inline-flex; align-items: center; gap: 5px; background: var(--c-surface-2); border: 1px solid var(--c-border); padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-count { background: var(--c-blue); color: #fff; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 10px; margin-left: 6px; }
.warn-box { background: #fff4e5; border: 1px solid #e0a000; color: #8a5b00; padding: 10px 12px; border-radius: var(--radius); font-size: 12.5px; margin-bottom: 12px; }
.error-box { background: var(--c-red-bg); border: 1px solid var(--c-red); color: var(--c-red); padding: 10px 12px; border-radius: var(--radius); font-size: 12.5px; margin-bottom: 12px; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--c-border); border-top-color: var(--c-blue); border-radius: 50%; animation: spin 0.7s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Login screen ---------- */
#login-screen {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--c-bg);
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 28px 26px;
}
.login-card__brand { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; text-align: center; }
.login-card__sub { font-size: 12px; color: var(--c-text-muted); text-align: center; margin-bottom: 22px; }

/* ---------- Sidebar user footer ---------- */
.sidebar__user { padding: 10px 18px; border-top: 1px solid #2a2a30; font-size: 11px; color: #c9c9c2; }
.sidebar__user-email { color: #fff; font-weight: 600; margin-bottom: 6px; word-break: break-all; }
.sidebar__signout { background: none; border: 1px solid #3a3a40; color: #c9c9c2; padding: 5px 10px; border-radius: var(--radius); font-size: 11px; cursor: pointer; width: 100%; }
.sidebar__signout:hover { background: #1f1f24; color: #fff; }

@media (max-width: 860px) {
  .sidebar { width: 64px; }
  .sidebar__brand-title, .sidebar__brand-sub, .nav-item span.nav-label { display: none; }
  .main-area { margin-left: 64px; }
  .kv-grid { grid-template-columns: 1fr 1fr; }
}
