/* Fonts loaded via <link> in index.html for non-blocking loading */

/* ── Color Tokens ─────────────────────────────────────────── */
:root {
  --bg-darkest:    #1e1f22;
  --bg-primary:    #313338;
  --bg-secondary:  #2b2d31;
  --bg-tertiary:   #232428;
  --bg-input:      #383a40;
  --bg-hover:      #404249;
  --bg-modal:      #2b2d31;

  --text-primary:   #f2f3f5;
  --text-secondary: #b5bac1;
  --text-muted:     #949ba4;
  --text-link:      #00a8fc;

  --accent:         #5865f2;
  --accent-hover:   #4752c4;
  --accent-light:   rgba(88,101,242,0.15);
  --accent-glow:    rgba(88,101,242,0.3);

  --success:        #23a559;
  --success-light:  rgba(35,165,89,0.15);
  --danger:         #da373c;
  --danger-light:   rgba(218,55,60,0.15);
  --warning:        #f0b232;
  --warning-light:  rgba(240,178,50,0.15);

  --border:         #3f4147;
  --glass-bg:       rgba(43,45,49,0.7);
  --glass-border:   rgba(255,255,255,0.08);
  --glass-blur:     12px;

  --shadow-sm:   0 1px 3px rgba(0,0,0,0.3);
  --shadow-md:   0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg:   0 8px 24px rgba(0,0,0,0.5);
  --shadow-xl:   0 16px 48px rgba(0,0,0,0.6);

  --space-1:4px; --space-2:8px; --space-3:12px; --space-4:16px;
  --space-5:20px; --space-6:24px; --space-8:32px; --space-10:40px;
  --space-12:48px; --space-16:64px;

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

  --text-xs:11px; --text-sm:13px; --text-base:15px; --text-md:16px;
  --text-lg:18px; --text-xl:20px; --text-2xl:24px; --text-3xl:30px;

  --radius-sm:4px; --radius-md:8px; --radius-lg:12px;
  --radius-xl:16px; --radius-full:9999px;

  --transition-fast:   150ms cubic-bezier(0.4,0,0.2,1);
  --transition-base:   200ms cubic-bezier(0.4,0,0.2,1);
  --transition-slow:   300ms cubic-bezier(0.4,0,0.2,1);
  --transition-spring: 300ms cubic-bezier(0.34,1.56,0.64,1);

  --z-card:10; --z-sticky:20; --z-sidebar:30;
  --z-modal:40; --z-toast:50; --z-palette:60;

  --sidebar-width:240px;
  --sidebar-collapsed-width:60px;
  --bottom-nav-height:60px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --focus-ring: 0 0 0 3px rgba(88,101,242,0.35);
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-primary);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  text-size-adjust: 100%;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-sm); }
a:focus-visible,
button:focus-visible,
[role="button"]:focus-visible,
.btn:focus-visible,
.btn-icon:focus-visible,
.input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  box-shadow: var(--focus-ring);
}

h1,h2,h3,h4,h5,h6 { font-weight: 600; line-height: 1.25; color: var(--text-primary); }
a { color: var(--text-link); text-decoration: none; }
a:hover { opacity: 0.8; }
code, pre { font-family: var(--font-mono); font-size: 0.9em; }

/* ── App Shell ───────────────────────────────────────────── */
#app { display: none; min-height: 100dvh; }
/* App visibility is controlled via inline style in auth.js (display:flex / none) */

.app-sidebar {
  flex-shrink: 0;
  width: var(--sidebar-width);
  background: var(--bg-darkest);
  border-right: 1px solid var(--border);
  position: fixed; top: 0; left: 0;
  height: 100dvh;
  z-index: var(--z-sidebar);
  display: flex; flex-direction: column;
  transition: width var(--transition-base);
  overflow: hidden;
}
.app-sidebar.collapsed { width: var(--sidebar-collapsed-width); overflow: visible; }

.app-main {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100dvh;
  min-width: 0;             /* flex items need this to not overflow their parent */
  display: flex; flex-direction: column;
  transition: margin-left var(--transition-base);
}
.app-sidebar.collapsed ~ .app-main { margin-left: var(--sidebar-collapsed-width); }

.page-content { flex: 1; padding: var(--space-6); overflow-x: hidden; }

/* ── Glass Card ──────────────────────────────────────────── */
.glass-card {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-family: var(--font-sans); font-size: var(--text-sm); font-weight: 500;
  border: none; border-radius: var(--radius-md); cursor: pointer;
  transition: background var(--transition-fast), transform var(--transition-fast);
  white-space: nowrap; min-height: 38px; touch-action: manipulation;
  text-decoration: none; line-height: 1;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-hover); color: var(--text-primary); }
.btn-secondary:hover { background: #484b53; }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-danger { background: var(--danger-light); color: var(--danger); border: 1px solid rgba(218,55,60,0.3); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: var(--space-1) var(--space-3); font-size: var(--text-xs); min-height: 32px; border-radius: var(--radius-sm); }
.btn-lg { padding: var(--space-3) var(--space-6); font-size: var(--text-md); min-height: 44px; border-radius: var(--radius-lg); }
.btn-icon { padding: var(--space-2); min-width: 38px; min-height: 38px; justify-content: center; }
.btn-icon.btn-sm { min-width: 34px; min-height: 34px; padding: var(--space-1); }

/* ── Inputs ──────────────────────────────────────────────── */
.input {
  width: 100%; padding: var(--space-2) var(--space-3);
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-md); color: var(--text-primary);
  font-family: var(--font-sans); font-size: var(--text-sm);
  min-height: 38px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  touch-action: manipulation;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.input::placeholder { color: var(--text-muted); }
.input-lg { padding: var(--space-3) var(--space-4); min-height: 44px; font-size: var(--text-base); border-radius: var(--radius-lg); }

select.input {
  appearance: none;
  background-image: 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='%23949ba4' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: var(--space-8); cursor: pointer;
}

textarea.input { resize: vertical; min-height: 80px; line-height: 1.6; }

.form-field { display: flex; flex-direction: column; gap: var(--space-2); }
.form-label { font-size: var(--text-xs); font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; }
.form-hint { font-size: var(--text-xs); color: var(--text-muted); }
.form-error { font-size: var(--text-xs); color: var(--danger); }

.input-group { position: relative; display: flex; align-items: center; }
.input-group .input { padding-left: 36px; }
.input-group-icon { position: absolute; left: var(--space-3); color: var(--text-muted); pointer-events: none; display: flex; align-items: center; }

/* ── Tags / Badges ───────────────────────────────────────── */
.tag {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 2px var(--space-2); border-radius: var(--radius-full);
  font-size: var(--text-xs); font-weight: 500; line-height: 1.4;
}
.tag-accent  { background: var(--accent-light); color: #8b97ff; }
.tag-success { background: var(--success-light); color: #3ec17a; }
.tag-danger  { background: var(--danger-light);  color: #e35d61; }
.tag-warning { background: var(--warning-light); color: var(--warning); }
.tag-muted   { background: var(--bg-hover); color: var(--text-secondary); }

/* ── Modal ───────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  z-index: var(--z-modal); display: flex; align-items: center; justify-content: center;
  padding: max(var(--space-4), var(--safe-top)) max(var(--space-4), var(--safe-right)) max(var(--space-4), var(--safe-bottom)) max(var(--space-4), var(--safe-left));
  opacity: 0; pointer-events: none;
  transition: opacity var(--transition-base);
}
.modal-backdrop.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--bg-modal); border: 1px solid var(--border);
  border-radius: var(--radius-xl); width: 100%; max-width: 520px;
  display: flex; flex-direction: column;
  max-height: min(90dvh, 760px); overflow: hidden; box-shadow: var(--shadow-xl);
  transform: scale(0.95) translateY(8px);
  transition: transform var(--transition-spring);
}
.modal-backdrop.open .modal { transform: scale(1) translateY(0); }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-5) var(--space-6); border-bottom: 1px solid var(--border); }
.modal-title { font-size: var(--text-lg); font-weight: 600; }
.modal-body { padding: var(--space-6); display: flex; flex-direction: column; gap: var(--space-5); overflow-y: auto; min-height: 0; }
.modal-footer { display: flex; align-items: center; justify-content: flex-end; gap: var(--space-3); padding: var(--space-4) var(--space-6); border-top: 1px solid var(--border); flex-wrap: wrap; }

/* ── Confirm Dialog ─────────────────────────────────────── */
.confirm-modal { max-width: 400px; }
.confirm-modal .modal-header .modal-title { display: flex; align-items: center; gap: var(--space-2); }
.confirm-message { font-size: var(--text-base); color: var(--text-secondary); line-height: 1.6; }

/* ── Toasts ──────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: calc(var(--space-6) + var(--safe-bottom)); right: calc(var(--space-6) + var(--safe-right));
  z-index: var(--z-toast); display: flex; flex-direction: column;
  gap: var(--space-2); pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  font-size: var(--text-sm); color: var(--text-primary);
  pointer-events: all; max-width: 320px;
  animation: toastIn 0.25s ease forwards;
}
.toast.removing { animation: toastOut 0.2s ease forwards; }
.toast-success { border-left: 3px solid var(--success); }
.toast-error   { border-left: 3px solid var(--danger); }
.toast-info    { border-left: 3px solid var(--accent); }

/* ── Page Layout ─────────────────────────────────────────── */
.page-header { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-6); flex-wrap: wrap; min-width: 0; }
.page-header-left { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.page-title { font-size: var(--text-2xl); font-weight: 700; }
.page-subtitle { font-size: var(--text-sm); color: var(--text-muted); margin-top: 2px; }
.page-actions { display: flex; flex-direction: row-reverse; align-items: center; justify-content: flex-end; gap: var(--space-2); flex-wrap: wrap; min-width: 0; }

/* ── Empty State ─────────────────────────────────────────── */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-4); padding: var(--space-12) var(--space-6); text-align: center; color: var(--text-muted); min-width: 0; }
.empty-state svg { opacity: 0.4; }
.empty-state h3 { color: var(--text-secondary); font-size: var(--text-lg); }
.empty-state p  { font-size: var(--text-sm); max-width: 300px; }

/* ── Pinned Bar ──────────────────────────────────────────── */
.pinned-bar { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-6); background: var(--bg-secondary); border-bottom: 1px solid var(--border); overflow-x: auto; min-height: 44px; scrollbar-width: none; }
.pinned-bar::-webkit-scrollbar { display: none; }
.pinned-bar-label { font-size: var(--text-xs); font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; flex-shrink: 0; }
.pinned-item { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-1) var(--space-3); background: var(--bg-hover); border: 1px solid var(--border); border-radius: var(--radius-full); font-size: var(--text-xs); color: var(--text-secondary); white-space: nowrap; cursor: pointer; transition: background var(--transition-fast), color var(--transition-fast); text-decoration: none; }
.pinned-item:hover { background: var(--accent-light); color: var(--text-primary); }
.pinned-item img { width: 14px; height: 14px; border-radius: 2px; }

/* ── View Toggle ─────────────────────────────────────────── */
.view-toggle { display: flex; background: var(--bg-input); border-radius: var(--radius-md); padding: 2px; gap: 2px; }
.view-toggle-btn { display: flex; align-items: center; justify-content: center; width: 30px; height: 28px; border-radius: var(--radius-sm); border: none; background: transparent; color: var(--text-muted); cursor: pointer; transition: background var(--transition-fast), color var(--transition-fast); }
.view-toggle-btn.active { background: var(--bg-hover); color: var(--text-primary); }

/* ── Skeleton ────────────────────────────────────────────── */
.skeleton { background: linear-gradient(90deg, var(--bg-secondary) 25%, var(--bg-hover) 50%, var(--bg-secondary) 75%); background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: var(--radius-md); }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; flex-shrink: 0; }

/* ── Checkbox ────────────────────────────────────────────── */
.checkbox { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; flex-shrink: 0; }

/* ── Divider ─────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border); border: none; margin: var(--space-4) 0; }

/* ── Utilities ───────────────────────────────────────────── */
.flex { display: flex; } .flex-col { flex-direction: column; }
.items-center { align-items: center; } .justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); } .gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); } .gap-6 { gap: var(--space-6); }
.flex-1 { flex: 1; } .w-full { width: 100%; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-muted { color: var(--text-muted); } .text-sm { font-size: var(--text-sm); }
.font-mono { font-family: var(--font-mono); }

/* ── Tooltip ─────────────────────────────────────────────── */
[data-tooltip] { position: relative; }
[data-tooltip]::after { content: attr(data-tooltip); position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%); background: var(--bg-tertiary); color: var(--text-primary); font-size: var(--text-xs); padding: 4px 8px; border-radius: var(--radius-sm); white-space: nowrap; pointer-events: none; opacity: 0; transition: opacity var(--transition-fast); z-index: var(--z-toast); border: 1px solid var(--border); }
[data-tooltip]:hover::after { opacity: 1; }

/* ── Keyframes ───────────────────────────────────────────── */
@keyframes fadeIn   { from{opacity:0} to{opacity:1} }
@keyframes slideUp  { from{opacity:0;transform:translateY(12px)} to{opacity:1;transform:translateY(0)} }
@keyframes scaleIn  { from{opacity:0;transform:scale(0.95)} to{opacity:1;transform:scale(1)} }
@keyframes toastIn  { from{opacity:0;transform:translateX(20px)} to{opacity:1;transform:translateX(0)} }
@keyframes toastOut { from{opacity:1;transform:translateX(0)} to{opacity:0;transform:translateX(20px)} }
@keyframes shimmer  { 0%{background-position:-200% 0} 100%{background-position:200% 0} }
@keyframes pulse    { 0%,100%{opacity:1} 50%{opacity:0.5} }
@keyframes spin     { to{transform:rotate(360deg)} }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .app-sidebar { display: none; }
  .app-main { margin-left: 0; padding-bottom: calc(var(--bottom-nav-height) + var(--safe-bottom)); }
  .page-content { padding: var(--space-4) max(var(--space-4), var(--safe-right)) var(--space-4) max(var(--space-4), var(--safe-left)); }
  .modal { max-width: 100%; border-bottom-left-radius: 0; border-bottom-right-radius: 0; position: fixed; bottom: 0; left: 0; right: 0; max-height: calc(92dvh - var(--safe-bottom)); }
  .modal-backdrop { align-items: flex-end; }
  .modal-body { padding: var(--space-4); }
  .modal-header,
  .modal-footer { padding-left: var(--space-4); padding-right: var(--space-4); }
  #toast-container { bottom: calc(var(--bottom-nav-height) + var(--space-4) + var(--safe-bottom)); right: max(var(--space-4), var(--safe-right)); left: max(var(--space-4), var(--safe-left)); }
  .page-title { font-size: var(--text-xl); }
  .pinned-bar { padding: var(--space-2) var(--space-4); }
  .page-header { flex-direction: column; align-items: stretch; gap: var(--space-3); }
  .page-actions { justify-content: flex-start; }
  .page-actions .btn-primary { flex: 1 1 auto; justify-content: center; }
  .page-actions .btn:not(.btn-primary) span { display: none; }
  .page-actions .btn:not(.btn-primary) { min-width: 40px; justify-content: center; }
}

@media (hover: none), (pointer: coarse) {
  .btn,
  .input,
  .filter-pill,
  .view-toggle-btn,
  .toolbar-btn,
  .context-item,
  .combobox-option,
  .tag-suggestion-item {
    min-height: 44px;
  }
  [data-tooltip]::after { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
