/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --sidebar-w:       260px;
  --sidebar-bg:      #1e293b;
  --sidebar-border:  #334155;
  --sidebar-hover:   #334155;
  --sidebar-active:  #4f46e5;

  --primary:         #4f46e5;
  --primary-hover:   #4338ca;
  --primary-light:   #eef2ff;

  --success:         #10b981;
  --success-light:   #ecfdf5;
  --error:           #ef4444;
  --error-light:     #fef2f2;
  --warning:         #f59e0b;
  --warning-light:   #fffbeb;

  --bg:              #f1f5f9;
  --surface:         #ffffff;
  --border:          #e2e8f0;
  --border-focus:    #4f46e5;

  --text:            #1e293b;
  --text-muted:      #64748b;
  --text-light:      #94a3b8;

  --radius-sm:       4px;
  --radius:          8px;
  --radius-lg:       12px;

  --shadow-sm:       0 1px 2px rgba(0,0,0,.06);
  --shadow:          0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:       0 4px 6px -1px rgba(0,0,0,.10), 0 2px 4px -1px rgba(0,0,0,.06);

  --font:            -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --topbar-h:        60px;
  --transition:      0.18s ease;
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body { font-family: var(--font); color: var(--text); background: var(--bg); line-height: 1.6; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { display: block; }
button { cursor: pointer; font-family: inherit; }
ul { list-style: none; }
input, textarea, select, button { font-family: inherit; font-size: 0.9rem; }

/* ── Layout ────────────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ───────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  transition: transform var(--transition);
  overflow-y: auto;
}
.sidebar__top    { flex: 1; padding: 0 0 1rem; }
.sidebar__bottom { padding: 1rem; border-top: 1px solid var(--sidebar-border); }

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1.25rem 1.25rem 1rem;
  font-weight: 700;
  font-size: 1.05rem;
  color: #fff;
  letter-spacing: -0.01em;
}
.sidebar__brand svg { width: 24px; height: 24px; color: var(--primary); flex-shrink: 0; }

.sidebar__nav { padding: 0 0.75rem; display: flex; flex-direction: column; gap: 2px; }

.sidebar__link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius);
  color: #94a3b8;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
  text-decoration: none;
}
.sidebar__link svg   { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar__link:hover { background: var(--sidebar-hover); color: #e2e8f0; text-decoration: none; }
.sidebar__link.active { background: var(--sidebar-active); color: #fff; }

.sidebar__user {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex: 1;
  min-width: 0;
}
.sidebar__bottom { display: flex; align-items: center; gap: 0.5rem; }

.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
}
.sidebar__user-info { min-width: 0; }
.sidebar__user-name {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: #e2e8f0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar__user-role { font-size: 0.75rem; color: #64748b; }

.sidebar__logout {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  color: #64748b;
  flex-shrink: 0;
  transition: background var(--transition), color var(--transition);
  text-decoration: none;
}
.sidebar__logout svg { width: 18px; height: 18px; }
.sidebar__logout:hover { background: var(--sidebar-hover); color: #e2e8f0; }

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

/* ── Topbar ────────────────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar__toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0.4rem;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.topbar__toggle:hover { background: var(--bg); }
.topbar__toggle svg { width: 22px; height: 22px; }
.topbar__title { font-size: 1rem; font-weight: 600; color: var(--text); }

/* ── Main content ──────────────────────────────────────────────────────────── */
.main-content { flex: 1; padding: 1.75rem; max-width: 1200px; width: 100%; }

/* ── Page header ───────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.page-title    { font-size: 1.4rem; font-weight: 700; color: var(--text); line-height: 1.2; }
.page-subtitle { font-size: 0.875rem; color: var(--text-muted); margin-top: 2px; }

/* ── Card ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.25rem;
  overflow: hidden;
}
.card__header {
  padding: 0.875rem 1.25rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  background: var(--bg);
}
.card__header--flex {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card__body    { padding: 1.25rem; }
.card__toolbar { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); background: var(--bg); }

/* ── Search ────────────────────────────────────────────────────────────────── */
.search-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.search-input-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
}
.search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}
.search-input { padding-left: 2.25rem !important; }

/* ── Table ─────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.table thead { background: var(--bg); }
.table th {
  text-align: left;
  padding: 0.65rem 1rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
.table td {
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #f8fafc; }

.td-id   { color: var(--text-muted); font-size: 0.8rem; width: 48px; }
.td-name { min-width: 160px; }
.td-date { white-space: nowrap; color: var(--text-muted); font-size: 0.8rem; }
.td-actions { white-space: nowrap; text-align: right; }
.th-actions { text-align: right; }

.form-inline { display: inline; }

/* ── Empty state ───────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
  text-align: center;
  gap: 0.75rem;
}
.empty-state svg { width: 48px; height: 48px; color: var(--text-light); }
.empty-state p   { font-size: 0.9rem; }

/* ── Pagination ────────────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: center;
  padding: 1rem;
  border-top: 1px solid var(--border);
}
.page-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 0.6rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  border: 1px solid var(--border);
  background: var(--surface);
  text-decoration: none;
  transition: all var(--transition);
}
.page-btn:hover  { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── Forms ─────────────────────────────────────────────────────────────────── */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.form-group          { margin-bottom: 1rem; }
.form-group--required .form-label::after { content: ' *'; color: var(--error); }

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.35rem;
}
.form-control {
  display: block;
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.form-control::placeholder { color: var(--text-light); }
.form-control:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}
.form-control.is-invalid { border-color: var(--error); }
textarea.form-control     { resize: vertical; min-height: 100px; }

/* Extra fields */
.extra-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.6rem;
  animation: slideDown 0.15s ease;
}
.extra-row .form-control:first-child { max-width: 220px; }

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Form actions ──────────────────────────────────────────────────────────── */
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.5rem;
  margin-bottom: 1.5rem;
}

/* ── Meta info ─────────────────────────────────────────────────────────────── */
.meta-info {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: right;
  margin-bottom: 0.75rem;
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition),
              color var(--transition), box-shadow var(--transition);
  text-decoration: none;
  white-space: nowrap;
  line-height: 1;
}
.btn svg { width: 15px; height: 15px; flex-shrink: 0; }

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

.btn--secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn--secondary:hover { background: var(--bg); text-decoration: none; color: var(--text); }

.btn--danger {
  background: var(--error);
  color: #fff;
  border-color: var(--error);
}
.btn--danger:hover { background: #dc2626; border-color: #dc2626; text-decoration: none; color: #fff; }

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

.btn--sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }
.btn--sm svg { width: 13px; height: 13px; }

.btn--icon { padding: 0.35rem; }
.btn--icon svg { width: 15px; height: 15px; }

.btn--full { width: 100%; justify-content: center; }

/* ── Alerts ────────────────────────────────────────────────────────────────── */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  border: 1px solid transparent;
  margin-bottom: 1rem;
}
.alert--success { background: var(--success-light); color: #065f46; border-color: #a7f3d0; }
.alert--error   { background: var(--error-light);   color: #991b1b; border-color: #fecaca; }
.alert--warning { background: var(--warning-light); color: #92400e; border-color: #fde68a; }

.alert--dismissible { position: relative; padding-right: 2.5rem; }
.alert__close {
  position: absolute; top: 0.5rem; right: 0.75rem;
  background: none; border: none;
  font-size: 1.1rem; line-height: 1;
  color: currentColor; opacity: 0.6;
  padding: 0.2rem;
}
.alert__close:hover { opacity: 1; }

.alert__list { padding-left: 1.25rem; list-style: disc; }
.alert__list li { margin-bottom: 2px; }

/* ── Overlay (mobile) ──────────────────────────────────────────────────────── */
.overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 150;
}

/* ── Text utilities ────────────────────────────────────────────────────────── */
.text-muted { color: var(--text-muted); }
.text-sm    { font-size: 0.85rem; }

/* ── Login page ────────────────────────────────────────────────────────────── */
body.login-page {
  background: linear-gradient(135deg, #1e293b 0%, #334155 50%, #1e293b 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}
.login-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 1.25rem;
}
.login-logo svg {
  width: 48px; height: 48px;
  color: var(--primary);
}
.login-title {
  text-align: center;
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
}
.login-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-bottom: 1.5rem;
}
.login-hint {
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-light);
  margin-top: 1.25rem;
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(calc(-1 * var(--sidebar-w)));
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-md);
  }
  .overlay.open { display: block; }

  .main-wrapper { margin-left: 0; }
  .topbar__toggle { display: flex; }
  .main-content   { padding: 1rem; }

  .form-row { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; gap: 0.75rem; }
  .page-header .btn { align-self: flex-start; }

  .table th:nth-child(5),
  .table td:nth-child(5) { display: none; }

  .login-card { padding: 2rem 1.5rem; }
}

@media (max-width: 480px) {
  .search-form { flex-direction: column; align-items: stretch; }
  .search-input-wrap { min-width: unset; }
  .form-actions { flex-direction: column-reverse; }
  .btn--full-mobile { width: 100%; justify-content: center; }
}
