/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-w: 220px;
  --sidebar-bg: #162032;
  --sidebar-hover: #1e2d42;
  --sidebar-active: #2d7dd2;
  --sidebar-text: #9ab0c8;
  --sidebar-text-active: #ffffff;
  --bg: #f0f4f8;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --accent: #2d7dd2;
  --accent-hover: #2467b5;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
}

html { font-size: 15px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

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

/* ── App shell ────────────────────────────────────────────────────────────── */
.shell { display: flex; min-height: 100vh; }

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}

.logo-icon { font-size: 22px; color: var(--accent); }
.logo-text { font-size: 16px; font-weight: 700; color: #fff; }

.nav-links {
  list-style: none;
  padding: 10px 0;
  flex: 1;
}

.nav-section {
  padding: 14px 18px 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgba(154,176,200,.45);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 18px;
  color: var(--sidebar-text);
  font-size: 13.5px;
  border-radius: 0;
  transition: background .15s, color .15s;
  text-decoration: none;
}

.nav-link svg {
  width: 16px; height: 16px;
  fill: currentColor;
  flex-shrink: 0;
  opacity: .7;
}

.nav-link:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.nav-link:hover svg { opacity: 1; }
.nav-link.active { background: var(--sidebar-active); color: #fff; }
.nav-link.active svg { opacity: 1; }

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid rgba(255,255,255,.07);
}

.sidebar-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
  flex-shrink: 0;
}

.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { font-size: 13px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: 11px; color: var(--sidebar-text); }

.sidebar-logout {
  color: var(--sidebar-text);
  display: flex;
  align-items: center;
  padding: 4px;
  border-radius: 4px;
  transition: color .15s;
  text-decoration: none;
}
.sidebar-logout:hover { color: #fff; text-decoration: none; }
.sidebar-logout svg { width: 16px; height: 16px; fill: currentColor; }

/* ── Main content ─────────────────────────────────────────────────────────── */
.main { flex: 1; min-width: 0; }
.main-inner { padding: 28px 32px; max-width: 1100px; }

/* ── Page header ──────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.page-title { font-size: 22px; font-weight: 700; color: var(--text); }
.page-sub { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card + .card { margin-top: 16px; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}

.card-title { font-size: 14px; font-weight: 600; }
.card-form { padding: 24px; }
.card-form .card-title { margin-bottom: 20px; }

/* ── Stat cards ───────────────────────────────────────────────────────────── */
.stat-row { display: flex; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  min-width: 140px;
  box-shadow: var(--shadow);
}

.stat-value { font-size: 32px; font-weight: 700; color: var(--text); line-height: 1; }
.stat-label { font-size: 12px; font-weight: 500; color: var(--text-muted); margin-top: 4px; }

/* ── Tables ───────────────────────────────────────────────────────────────── */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table thead th {
  padding: 10px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}
.table tbody td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: #f8fafc; }
.td-actions { display: flex; gap: 6px; justify-content: flex-end; }
.text-muted { color: var(--text-muted); }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}

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

.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg); }

.btn-danger-ghost { background: transparent; color: var(--danger); border-color: #fca5a5; }
.btn-danger-ghost:hover { background: #fef2f2; }

.btn-full { width: 100%; justify-content: center; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}

.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-orange { background: #fef3c7; color: #b45309; }
.badge-gray   { background: #f1f5f9; color: #475569; }
.badge-green  { background: #dcfce7; color: #15803d; }
.badge-purple { background: #ede9fe; color: #6d28d9; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-stack { display: flex; flex-direction: column; gap: 18px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-row { display: flex; gap: 16px; flex-wrap: wrap; }
.field-grow { flex: 1; min-width: 180px; }
.field-narrow { width: 100px; }

label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

input[type="text"], input[type="email"], input[type="password"],
input[type="url"], input[type="number"], select, textarea {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(45,125,210,.12);
}

input.input-readonly { background: #f8fafc; color: var(--text-muted); }
textarea { resize: vertical; min-height: 80px; }

.checkbox-label { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.checkbox-label input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }

.required { color: var(--danger); }
.field-hint { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.field-hint-inline { font-size: 12px; color: var(--text-muted); font-weight: 400; }
.field-hint code { background: var(--bg); padding: 1px 4px; border-radius: 3px; font-family: monospace; font-size: 11px; }

.form-actions { display: flex; gap: 10px; padding-top: 4px; }

fieldset.fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

fieldset.fieldset legend {
  padding: 0 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: .04em;
  text-transform: uppercase;
}

/* ── Flash messages ───────────────────────────────────────────────────────── */
.flash {
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13.5px;
  margin-bottom: 18px;
  border: 1px solid transparent;
}

.flash-success { background: #f0fdf4; color: var(--success); border-color: #bbf7d0; }
.flash-error   { background: #fef2f2; color: var(--danger);  border-color: #fecaca; }
.flash-info    { background: #eff6ff; color: var(--accent);  border-color: #bfdbfe; }

/* ── Filters ──────────────────────────────────────────────────────────────── */
.filters {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
}

.filter-form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.filter-form select { width: auto; min-width: 140px; }
.filter-count { font-size: 12px; color: var(--text-muted); white-space: nowrap; }

/* ── Tabs ─────────────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.tab {
  padding: 10px 18px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  text-decoration: none;
  transition: color .15s, border-color .15s;
  margin-bottom: -1px;
}

.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Detail list ──────────────────────────────────────────────────────────── */
.detail-list {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 0;
  padding: 8px 20px;
}

.detail-list-wide { grid-template-columns: 200px 1fr; }

.detail-list dt {
  padding: 10px 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  padding-right: 16px;
}

.detail-list dd {
  padding: 10px 0;
  font-size: 13.5px;
  border-bottom: 1px solid var(--border);
}

.detail-list dt:last-of-type,
.detail-list dd:last-child { border-bottom: none; }

/* ── Files grid ───────────────────────────────────────────────────────────── */
.files-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  padding: 20px;
}

.file-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.file-thumb-wrap { display: block; aspect-ratio: 4/3; overflow: hidden; background: #f8fafc; }
.file-thumb { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .2s; }
.file-thumb-wrap:hover .file-thumb { transform: scale(1.04); }

.file-doc-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 4/3;
  background: #f8fafc;
  color: var(--text-muted);
  text-decoration: none;
}
.file-doc-icon svg { width: 40px; height: 40px; fill: currentColor; }
.file-doc-icon:hover { background: var(--bg); }

.file-meta { padding: 10px 12px; }
.file-name { font-size: 12px; font-weight: 500; word-break: break-all; }
.file-size { font-size: 11px; margin-top: 2px; }

/* ── Auth layout ──────────────────────────────────────────────────────────── */
.auth-body { background: var(--sidebar-bg); }

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

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

.auth-brand .logo-text { font-size: 20px; font-weight: 700; color: #fff; }

.auth-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
}

.auth-title { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.auth-subtitle { color: var(--text-muted); font-size: 13px; margin-bottom: 24px; }

/* ── Two column layout ────────────────────────────────────────────────────── */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 768px) { .two-col { grid-template-columns: 1fr; } }

/* ── Status select ────────────────────────────────────────────────────────── */
.status-select { width: auto; min-width: 110px; }
.inline-form { display: inline; }

/* ── Misc ─────────────────────────────────────────────────────────────────── */
.link { color: var(--accent); font-weight: 500; }
.link:hover { text-decoration: underline; }
.code-sm { font-family: 'SF Mono', 'Cascadia Code', Consolas, monospace; font-size: 12px; background: var(--bg); padding: 2px 5px; border-radius: 3px; color: var(--text); }
.break-all { word-break: break-all; }

.empty-state { padding: 40px; text-align: center; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 36px; font-weight: 800; margin-bottom: 12px; }
.empty-state h2 { font-size: 18px; margin-bottom: 8px; color: var(--text); }
.empty-state p { font-size: 14px; }

.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; }

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 2px; }
