/* ============================================================
   Design tokens — shared across every page.
   Light palette lives on :root; dark overrides mirror it under
   prefers-color-scheme and the explicit [data-theme] toggle.
   ============================================================ */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #f3f4f9;
  --bg-elevated: #ffffff;
  --bg-subtle: #f8f9fc;
  --bg-hover: #eef0f8;

  --border: #e6e8f0;
  --border-strong: #d4d8e4;

  --text: #171a2b;
  --text-muted: #656b83;
  --text-faint: #9198b0;

  --primary: #5b5bf0;
  --primary-hover: #4a4ae0;
  --primary-soft: #eeeeff;
  --primary-text-on: #ffffff;

  --success: #16a34a;
  --success-soft: #ecfdf3;
  --danger: #e0393f;
  --danger-hover: #c62f35;
  --danger-soft: #fef2f2;
  --warning: #d97706;
  --warning-soft: #fffbeb;

  --focus-ring: #5b5bf0;

  --shadow-sm: 0 1px 2px rgba(23, 26, 43, 0.06);
  --shadow-md: 0 4px 16px rgba(23, 26, 43, 0.08);
  --shadow-lg: 0 16px 48px rgba(23, 26, 43, 0.16);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 999px;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    Helvetica, Arial, sans-serif;

  --ease: cubic-bezier(0.4, 0, 0.2, 1);

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #101120;
    --bg-elevated: #181a2e;
    --bg-subtle: #1e2036;
    --bg-hover: #23253d;

    --border: #2a2c46;
    --border-strong: #383a5c;

    --text: #eef0fb;
    --text-muted: #a2a6c4;
    --text-faint: #6c7093;

    --primary: #8382ff;
    --primary-hover: #9998ff;
    --primary-soft: #23234a;
    --primary-text-on: #101120;

    --success: #34d399;
    --success-soft: #103228;
    --danger: #f87171;
    --danger-hover: #fb9292;
    --danger-soft: #351c1f;
    --warning: #fbbf24;
    --warning-soft: #332608;

    --focus-ring: #8382ff;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.5);

    color-scheme: dark;
  }
}

:root[data-theme='dark'] {
  --bg: #101120;
  --bg-elevated: #181a2e;
  --bg-subtle: #1e2036;
  --bg-hover: #23253d;

  --border: #2a2c46;
  --border-strong: #383a5c;

  --text: #eef0fb;
  --text-muted: #a2a6c4;
  --text-faint: #6c7093;

  --primary: #8382ff;
  --primary-hover: #9998ff;
  --primary-soft: #23234a;
  --primary-text-on: #101120;

  --success: #34d399;
  --success-soft: #103228;
  --danger: #f87171;
  --danger-hover: #fb9292;
  --danger-soft: #351c1f;
  --warning: #fbbf24;
  --warning-soft: #332608;

  --focus-ring: #8382ff;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.5);

  color-scheme: dark;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}

::selection {
  background: var(--primary);
  color: var(--primary-text-on);
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-full);
  border: 2px solid var(--bg);
}

.icon {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 28px;
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), #9333ea);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(91, 91, 240, 0.35);
}

.brand-mark .icon {
  width: 18px;
  height: 18px;
  stroke: #fff;
}

.brand-name {
  font-size: 16px;
}

@media (max-width: 720px) {
  .brand-name {
    display: none;
  }
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-actions > * {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 38px;
  box-sizing: border-box;
}

.btn-label {
  display: inline;
}

@media (max-width: 860px) {
  .btn-label {
    display: none;
  }
  .btn-ghost.btn-sm {
    padding: 0 10px;
  }
}

@media (max-width: 480px) {
  .topbar {
    padding: 12px 16px;
  }
  .topbar-actions {
    gap: 6px;
  }
}

.avatar-chip {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #9333ea);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(91, 91, 240, 0.3);
}

/* ---------- Icon button (theme toggle etc.) ---------- */
.icon-btn-round {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s var(--ease), color 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.1s var(--ease);
}

.icon-btn-round:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.icon-btn-round:active {
  transform: scale(0.93);
}

.theme-toggle .icon-moon {
  display: none;
}
:root[data-theme='dark'] .theme-toggle .icon-sun {
  display: none;
}
:root[data-theme='dark'] .theme-toggle .icon-moon {
  display: inline-block;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .theme-toggle .icon-sun {
    display: none;
  }
  :root:not([data-theme='light']) .theme-toggle .icon-moon {
    display: inline-block;
  }
}

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 0 16px;
  height: 38px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background 0.15s var(--ease), color 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.1s var(--ease), box-shadow 0.15s var(--ease);
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.97);
}

.btn:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-text-on);
  box-shadow: 0 1px 2px rgba(91, 91, 240, 0.3);
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

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

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

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

.btn-danger:hover {
  background: var(--danger-soft);
}

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

.btn-sm {
  height: 32px;
  padding: 0 12px;
  font-size: 13px;
}

/* ---------- Cards ---------- */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-sm);
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease);
}

.card h2 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: 16px;
  color: var(--text);
}

/* ---------- Form controls ---------- */
label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

input,
select,
textarea {
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease), background 0.15s var(--ease);
  width: 100%;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-faint);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
  background: var(--bg-elevated);
}

textarea {
  resize: vertical;
  font-family: inherit;
}

.field-error {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--danger);
  min-height: 0;
}

.input-icon-wrap {
  position: relative;
}

.input-icon-wrap input {
  padding-left: 38px;
}

.input-icon-wrap:has(.field-toggle) input {
  padding-right: 40px;
}

.input-icon-wrap > .icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  pointer-events: none;
}

.input-icon-wrap .field-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  padding: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
}

.input-icon-wrap .field-toggle .icon {
  position: static;
  width: 16px;
  height: 16px;
  color: inherit;
  pointer-events: auto;
}

.input-icon-wrap .field-toggle:hover {
  color: var(--text-muted);
  background: var(--bg-hover);
}

/* ---------- Badge ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
  background: var(--primary-soft);
  color: var(--primary);
  white-space: nowrap;
}

/* ---------- Skeleton loaders ---------- */
.skel {
  background: linear-gradient(
    90deg,
    var(--bg-subtle) 25%,
    var(--bg-hover) 50%,
    var(--bg-subtle) 75%
  );
  background-size: 200% 100%;
  animation: skel-shine 1.4s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

@keyframes skel-shine {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 48px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.empty-state .icon {
  width: 40px;
  height: 40px;
  color: var(--text-faint);
  margin-bottom: 4px;
}

.empty-state strong {
  color: var(--text);
  font-size: 14px;
}

.empty-state span {
  font-size: 13px;
}

/* ---------- Toasts ---------- */
.toast-stack {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(360px, calc(100vw - 40px));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 13px 14px;
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  animation: toast-in 0.25s var(--ease);
}

.toast.leaving {
  animation: toast-out 0.2s var(--ease) forwards;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(24px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateX(24px) scale(0.96);
  }
}

.toast .icon {
  flex-shrink: 0;
  margin-top: 1px;
}

.toast-success .icon {
  color: var(--success);
}
.toast-error .icon {
  color: var(--danger);
}
.toast-info .icon {
  color: var(--primary);
}

/* ---------- Utility ---------- */
.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
