:root {
  --bg: #050505;
  --panel: #111111;
  --panel-2: #1c1c1c;
  --line: rgba(255, 255, 255, 0.12);
  --text: #f7f7f2;
  --muted: #a8a8a8;
  --accent: #f7f7f2;
  --danger: #e8a0a0;
  --ok: #b8d4b8;
  --warn: #e6d4a0;
  --radius: 10px;
  --sidebar: 240px;
  --font: "Inter", system-ui, sans-serif;
  --display: "Playfair Display", Georgia, serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; }

.crm-shell { display: flex; min-height: 100vh; }
.crm-sidebar {
  width: var(--sidebar);
  flex-shrink: 0;
  background: #0a0a0a;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 1.1rem 0.85rem;
  position: sticky;
  top: 0;
  height: 100vh;
}
.crm-brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  font-family: var(--display);
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0 0.4rem 1.4rem;
}
.crm-brand img { width: 36px; height: 36px; object-fit: contain; }
.crm-nav { display: flex; flex-direction: column; gap: 0.25rem; flex: 1; }
.crm-nav-link {
  display: block;
  padding: 0.7rem 0.85rem;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.92rem;
}
.crm-nav-link:hover, .crm-nav-link.is-active {
  background: rgba(255,255,255,0.06);
  color: var(--text);
}
.crm-sidebar-foot { border-top: 1px solid var(--line); padding-top: 0.85rem; margin-top: 0.85rem; }
.crm-user { margin: 0 0.85rem 0.5rem; color: var(--muted); font-size: 0.8rem; }

.crm-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.crm-topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.4rem;
  border-bottom: 1px solid var(--line);
  background: rgba(5,5,5,0.92);
  position: sticky;
  top: 0;
  z-index: 10;
}
.crm-page-title {
  margin: 0;
  font-family: var(--display);
  font-size: 1.35rem;
  font-weight: 600;
}
.crm-menu-btn {
  display: none;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 0.45rem 0.7rem;
  border-radius: 6px;
}
.crm-content { padding: 1.4rem; }

.card {
  background: linear-gradient(160deg, rgba(28,28,28,0.95), rgba(17,17,17,0.98));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  margin-bottom: 1rem;
}
.card-title {
  margin: 0 0 0.85rem;
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.2rem;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
.stat .label { color: var(--muted); font-size: 0.8rem; margin: 0 0 0.35rem; }
.stat .value { font-family: var(--display); font-size: 1.8rem; margin: 0; line-height: 1.1; }
.stat .sub { color: var(--muted); font-size: 0.8rem; margin: 0.4rem 0 0; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.toolbar-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.search-form { display: flex; gap: 0.5rem; flex-wrap: wrap; flex: 1; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 2.4rem;
  padding: 0.5rem 0.95rem;
  border-radius: 7px;
  font-weight: 600;
  font-size: 0.9rem;
  border: 1px solid transparent;
}
.btn-primary { background: var(--accent); color: #050505; }
.btn-primary:hover { background: #fff; }
.btn-secondary { background: transparent; border-color: var(--line); color: var(--text); }
.btn-secondary:hover { border-color: rgba(255,255,255,0.35); }
.btn-danger { background: rgba(232,160,160,0.12); border-color: rgba(232,160,160,0.35); color: var(--danger); }
.btn-sm { min-height: 2rem; padding: 0.3rem 0.7rem; font-size: 0.82rem; }

.table-wrap { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
table.data th, table.data td {
  text-align: left;
  padding: 0.7rem 0.65rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
table.data th {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
}
table.data tr:hover td { background: rgba(255,255,255,0.02); }
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.badge-new { background: rgba(230,212,160,0.15); color: var(--warn); }
.badge-read { background: rgba(184,212,184,0.12); color: var(--ok); }
.badge-archived { background: rgba(255,255,255,0.06); color: var(--muted); }
.badge-issued { background: rgba(184,212,184,0.12); color: var(--ok); }
.badge-void { background: rgba(232,160,160,0.12); color: var(--danger); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem 1rem;
}
.form-grid .full { grid-column: 1 / -1; }
.field label {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: #0a0a0a;
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: rgba(247,247,242,0.4);
}
.field textarea { min-height: 90px; resize: vertical; }
.check-row { display: flex; flex-wrap: wrap; gap: 0.75rem 1.1rem; padding-top: 0.35rem; }
.check-row label { display: inline-flex; align-items: center; gap: 0.4rem; color: var(--muted); font-weight: 500; margin: 0; }
.actions-row { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 1rem; }

.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.alert-success { background: rgba(184,212,184,0.12); color: var(--ok); border: 1px solid rgba(184,212,184,0.25); }
.alert-error { background: rgba(232,160,160,0.12); color: var(--danger); border: 1px solid rgba(232,160,160,0.25); }
.alert-info { background: rgba(255,255,255,0.05); color: var(--muted); border: 1px solid var(--line); }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 0.45rem 0.75rem; margin: 0.35rem 0; }
.kv .k { color: var(--muted); }
.muted { color: var(--muted); }
.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(ellipse 70% 50% at 50% -10%, rgba(255,255,255,0.06), transparent 55%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 400px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  padding: 1.75rem;
}
.login-card h1 {
  margin: 0 0 0.35rem;
  font-family: var(--display);
  font-size: 1.6rem;
}
.login-card .sub { margin: 0 0 1.25rem; color: var(--muted); font-size: 0.9rem; }

@media (max-width: 860px) {
  .crm-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 40;
    transform: translateX(-105%);
    transition: transform 0.25s ease;
  }
  body.nav-open .crm-sidebar { transform: translateX(0); }
  .crm-menu-btn { display: inline-flex; }
  .form-grid { grid-template-columns: 1fr; }
}
