:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #059669;
  --warning: #d97706;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 6px 16px rgba(15, 23, 42, 0.04);
  font-synthesis: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  background: #0f172a;
  color: #e2e8f0;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  align-self: start;
  min-height: 100vh;
}
.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 4px 8px;
}
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #10b981);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.5px;
}
.brand-name { font-weight: 700; color: #fff; font-size: 16px; }
.brand-sub { font-size: 12px; color: #94a3b8; margin-top: 2px; }

.nav { display: flex; flex-direction: column; gap: 6px; }
.nav-item {
  background: transparent;
  border: 0;
  color: #cbd5e1;
  padding: 11px 12px;
  border-radius: 10px;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: #1e293b; color: #fff; font-weight: 600; }
.nav-icon { width: 18px; display: inline-block; text-align: center; color: #93c5fd; }

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  border-top: 1px solid rgba(255,255,255,0.08);
  padding-top: 20px;
}
.sidebar-footer .btn-ghost { color: #cbd5e1; justify-content: flex-start; }
.sidebar-footer .btn-ghost:hover { background: rgba(255,255,255,0.06); color: #fff; }
.small { font-size: 12px; }
.muted { color: var(--muted); }
.sidebar .muted { color: #94a3b8; }

/* Main */
.main { padding: 28px; min-width: 0; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 24px;
}
.topbar h1 { margin: 0; font-size: 28px; line-height: 1.2; }
.topbar p { margin: 6px 0 0; }

/* Buttons */
.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--text); border-color: transparent; }
.btn-ghost:hover { background: #f1f5f9; }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fee2e2; }
.btn-small { padding: 7px 10px; font-size: 13px; }
.import-label { cursor: pointer; }

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 13px; color: var(--muted); margin-bottom: 8px; font-weight: 500; }
.stat-value { font-size: 30px; font-weight: 700; line-height: 1; }

/* Panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  overflow: hidden;
}
.panel-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.panel-header h2 { margin: 0; font-size: 18px; }
.panel-header p { margin: 4px 0 0; }

/* Table */
.table-wrap { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.table th, .table td {
  padding: 13px 16px;
  text-align: left;
  border-bottom: 1px solid #edf2f7;
  vertical-align: middle;
}
.table th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 700;
  background: #fbfcfe;
}
.table tbody tr:hover { background: #f8fafc; }
.table tbody tr:last-child td { border-bottom: 0; }
.empty { text-align: center; color: var(--muted); padding: 28px 16px !important; }
.link-btn {
  background: none;
  border: 0;
  color: var(--primary);
  font-weight: 600;
  padding: 4px;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: #f1f5f9;
  color: #475569;
  white-space: nowrap;
}
.badge-blue { background: #eff6ff; color: #1d4ed8; }
.badge-green { background: #ecfdf5; color: #047857; }
.badge-amber { background: #fffbeb; color: #b45309; }
.badge-red { background: #fef2f2; color: #b91c1c; }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-purple { background: #f5f3ff; color: #6d28d9; }

/* Forms */
.filters { display: flex; gap: 10px; flex-wrap: wrap; width: 100%; }
.filters .input { width: auto; min-width: 180px; }
.filters .input[type="search"] { flex: 1; min-width: 220px; }

.form-layout { display: flex; flex-direction: column; gap: 0; }
.form-grid {
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 13px; font-weight: 600; color: #334155; }
.field-full { grid-column: 1 / -1; }
.req { color: #dc2626; }
.input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  font-size: 14px;
  min-height: 42px;
}
.input:focus {
  outline: 2px solid #bfdbfe;
  border-color: #60a5fa;
}
textarea.input { min-height: auto; resize: vertical; }
select.input { cursor: pointer; }

.form-actions {
  padding: 16px 20px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  align-items: center;
  background: #fbfcfe;
}
.form-actions .btn-danger { margin-right: auto; }

/* Detail */
.detail-header { align-items: flex-start; }
.detail-actions { display: flex; gap: 8px; }
.detail-grid {
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}
.detail-section {
  padding: 16px;
  background: #f8fafc;
  border: 1px solid #edf2f7;
  border-radius: 10px;
}
.detail-section h3 {
  margin: 0 0 14px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0;
  border-bottom: 1px dashed #e5e7eb;
  font-size: 14px;
}
.detail-row:last-child { border-bottom: 0; padding-bottom: 0; }
.detail-row .label { color: var(--muted); flex: 0 0 160px; }
.detail-row .value { text-align: right; font-weight: 500; word-break: break-word; }
.detail-section.full { grid-column: 1 / -1; }
.prewrap { white-space: pre-wrap; text-align: left; }

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #0f172a;
  color: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  box-shadow: 0 10px 24px rgba(0,0,0,0.2);
  font-size: 14px;
  z-index: 100;
  max-width: 320px;
}

.hidden { display: none !important; }

@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    min-height: auto;
    padding: 16px;
  }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav-item { flex: 1; justify-content: center; }
  .main { padding: 16px; }
  .topbar { flex-direction: column; align-items: stretch; }
  .form-grid { grid-template-columns: 1fr; }
  .field-full { grid-column: auto; }
  .filters .input, .filters .input[type="search"] { min-width: 0; width: 100%; flex: none; }
  .detail-row { flex-direction: column; }
  .detail-row .label { flex: none; }
  .detail-row .value { text-align: left; }
}
