/* ─── Design tokens ─────────────────────────────────────────────── */
:root {
  --sidebar-width: 240px;
  --topbar-height: 60px;

  --color-bg:          #f0f3f7;
  --color-surface:     #ffffff;
  --color-surface-subtle: #f8fafc;
  --color-surface-hover:  #fafbfc;
  --color-border:      #c8d2de;

  --color-sidebar-bg:  #ffffff;
  --color-sidebar-text:#374151;
  --color-sidebar-hover-bg: #edf2f7;
  --color-sidebar-hover-text: #0f172a;
  --color-sidebar-active-bg: #dbeafe;
  --color-sidebar-active-text: #1d4ed8;
  --color-sidebar-active-accent: #1d4ed8;

  --color-topbar-bg:   #ffffff;
  --color-topbar-border: #c8d2de;

  /* Text — all pass WCAG AA (4.5:1) on white and on --color-bg */
  --color-text-primary:   #0f172a;   /* was #1e293b — near-black  */
  --color-text-secondary: #374151;   /* was #64748b — dark slate  */
  --color-text-muted:     #64748b;   /* was #94a3b8 — medium slate */

  --color-accent:      #1d4ed8;
  --color-accent-light:#dbeafe;

  --color-danger:       #ef4444;
  --color-danger-light: #fee2e2;
  --color-danger-bg:    #fff8f8;

  --radius-sm: 6px;
  --radius-md: 10px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.09), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,.11);

  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

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

body {
  font-family: var(--font);
  font-size: 14.5px;
  color: var(--color-text-primary);
  background: var(--color-bg);
  display: flex;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }

/* ─── Sidebar ───────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--color-sidebar-bg);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  transition: transform .25s ease;
}

.sidebar__brand {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.sidebar__brand-icon {
  width: 32px;
  height: 32px;
  background: var(--color-accent);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar__brand-icon svg {
  width: 18px;
  height: 18px;
  stroke: #fff;
  fill: none;
}

.sidebar__brand-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--color-text-primary);
  letter-spacing: -.3px;
}

.sidebar__brand-name span {
  color: var(--color-accent);
}

/* Nav */
.sidebar__nav {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-section {
  margin-bottom: 8px;
}

.nav-section__label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--color-text-muted);
  padding: 8px 8px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--color-sidebar-text);
  font-size: 13.5px;
  font-weight: 500;
  transition: background .15s, color .15s;
  white-space: nowrap;
  position: relative;
}

.nav-item:hover {
  background: var(--color-sidebar-hover-bg);
  color: var(--color-sidebar-hover-text);
}

.nav-item.active {
  background: var(--color-sidebar-active-bg);
  color: var(--color-sidebar-active-text);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 20%;
  height: 60%;
  width: 3px;
  background: var(--color-sidebar-active-accent);
  border-radius: 0 3px 3px 0;
}

.nav-item__icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: .85;
}

.nav-item.active .nav-item__icon,
.nav-item:hover .nav-item__icon {
  opacity: 1;
}

.nav-item__badge {
  margin-left: auto;
  background: var(--color-accent-light);
  color: var(--color-accent);
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 20px;
}

/* Sidebar footer */
.sidebar__footer {
  padding: 12px;
  border-top: 1px solid var(--color-border);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s;
}

.sidebar-user:hover { background: var(--color-sidebar-hover-bg); }

.sidebar-user__avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #60a5fa, #2563eb);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-user__info { flex: 1; min-width: 0; }

.sidebar-user__name {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-primary);
  truncate: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-user__role {
  font-size: 11px;
  color: var(--color-text-muted);
}

/* ─── Main wrapper ──────────────────────────────────────────────── */
.main-wrapper {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ─── Topbar ────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-height);
  background: var(--color-topbar-bg);
  border-bottom: 1px solid var(--color-topbar-border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.topbar__page-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text-primary);
  flex: 1;
}


.topbar__actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.topbar__btn {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-secondary);
  transition: background .15s, color .15s;
  position: relative;
}

.topbar__btn:hover {
  background: var(--color-bg);
  color: var(--color-text-primary);
}

.topbar__btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
}

.topbar__btn--notify .badge {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-danger);
  border: 1.5px solid #fff;
}

.topbar__divider {
  width: 1px;
  height: 24px;
  background: var(--color-border);
  margin: 0 4px;
}

.topbar__avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #60a5fa, #2563eb);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  transition: opacity .15s;
  flex-shrink: 0;
}

.topbar__avatar:hover { opacity: .85; }

/* ─── Page content ──────────────────────────────────────────────── */
.page-content {
  flex: 1;
  padding: 28px 28px;
  overflow-y: auto;
}

/* ─── Scrollbar ─────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-text-muted); }

/* ─── List page ─────────────────────────────────────────────────── */
.list-page { display: flex; flex-direction: column; gap: 20px; }

.list-page__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.list-page__title {
  font-size: 20px;
  font-weight: 700;
  color: var(--color-text-primary);
  letter-spacing: -.3px;
}

.list-page__subtitle {
  font-size: 13.5px;
  color: var(--color-text-secondary);
  margin-top: 2px;
}

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

/* ─── Data table ────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table thead {
  background: #eef2f7;
  border-bottom: 1px solid var(--color-border);
}

.data-table th {
  padding: 11px 20px;
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.data-table td {
  padding: 13px 20px;
  font-size: 14px;
  color: var(--color-text-primary);
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

.data-table tbody tr:last-child td { border-bottom: none; }

.data-table tbody tr:hover td { background: #eef2f7; }

.text-secondary { color: var(--color-text-secondary) !important; }

.text-mono {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--color-text-secondary);
}

.code-badge {
  display: inline-flex;
  align-items: center;
  background: var(--color-accent-light);
  color: var(--color-accent);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
}

.code-badge--link:hover {
  background: #dbeafe;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ─── Button ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: opacity .15s, box-shadow .15s;
  font-family: var(--font);
}

.btn--primary {
  background: var(--color-accent);
  color: #fff;
  box-shadow: 0 1px 3px rgba(37,99,235,.3);
}

.btn--primary:hover { opacity: .9; box-shadow: 0 3px 8px rgba(37,99,235,.35); }

/* ─── Empty state ───────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 60px 24px;
  color: var(--color-text-muted);
}

.empty-state__title {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-top: 4px;
}

.empty-state__sub { font-size: 13px; }

/* ─── Form page ─────────────────────────────────────────────────── */
.form-page { display: flex; flex-direction: column; gap: 20px; max-width: 720px; }

.form-page__header { display: flex; flex-direction: column; gap: 4px; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-muted);
  margin-bottom: 8px;
  transition: color .15s;
}

.back-link:hover { color: var(--color-accent); }

.form-card { overflow: visible; }

.form-section {
  padding: 24px 24px 0;
}

.form-section__label {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--color-text-muted);
  margin-bottom: 16px;
}

.form-fields {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding-bottom: 24px;
}

.form-fields--two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.form-divider {
  height: 1px;
  background: var(--color-border);
  margin: 0 24px;
}

.form-field { display: flex; flex-direction: column; gap: 5px; }

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

.form-label__required { color: var(--color-danger); margin-left: 2px; }

.form-field input {
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-family: var(--font);
  color: var(--color-text-primary);
  background: var(--color-surface);
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  width: 100%;
}

.form-field input:focus,
.form-field select:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

.form-field input::placeholder { color: var(--color-text-muted); }

.form-field select {
  height: 38px;
  padding: 0 32px 0 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-family: var(--font);
  color: var(--color-text-primary);
  background: var(--color-surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") no-repeat right 10px center;
  appearance: none;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  width: 100%;
  cursor: pointer;
}

.form-field--error input,
.form-field--error select {
  border-color: var(--color-danger);
  background-color: var(--color-danger-bg);
}

.form-field--error input:focus,
.form-field--error select:focus {
  box-shadow: 0 0 0 3px rgba(239,68,68,.1);
}

.form-hint {
  font-size: 12px;
  color: var(--color-text-muted);
}

.form-error {
  font-size: 12px;
  color: var(--color-danger);
}

/* ── Inline tag widget (chip + dropdown) ─────────────────── */
#tags-hidden-inputs { display: contents; }

.tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 0;
}

.tag-chips:not(:empty) { margin-bottom: 10px; }

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 12px;
  background: var(--color-accent-light);
  color: var(--color-accent);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
}

.tag-chip__remove {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  color: inherit;
  opacity: 0.55;
  border-radius: 50%;
  transition: opacity .15s, background .15s;
}

.tag-chip__remove:hover {
  opacity: 1;
  background: rgba(37,99,235,.15);
}

.tag-add-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.tag-add-select {
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font);
  color: var(--color-text-primary);
  background: var(--color-surface);
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}

.tag-add-select:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

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

.form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--color-border);
  background: #eef2f7;
}

.btn--ghost {
  background: transparent;
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
}

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