/* ============================================================
   TASK ENVIRONMENT — Global Design System
   ============================================================ */

/* --- Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* --- CSS Variables --- */
:root {
  /* Colors */
  --bg:            #0B0D10;
  --surface:       #151A21;
  --surface-2:     #1C2330;
  --surface-3:     #242D3A;
  --border:        #1F2937;
  --border-hover:  #2D3748;

  --accent-blue:   #3A86FF;
  --accent-blue-hover: #5A9FFF;
  --accent-blue-dim:   rgba(58, 134, 255, 0.12);
  --accent-teal:   #00C2A8;
  --accent-teal-hover: #00DBC0;
  --accent-teal-dim:   rgba(0, 194, 168, 0.12);

  --text:          #E6EDF3;
  --text-muted:    #8B949E;
  --text-faint:    #4A5568;

  --red:           #FF4D4F;
  --red-dim:       rgba(255, 77, 79, 0.12);
  --yellow:        #F5A623;
  --yellow-dim:    rgba(245, 166, 35, 0.12);
  --green:         #00C2A8;

  /* Typography */
  --font-sans:     'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono:     'JetBrains Mono', monospace;

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

  /* Radii */
  --r-sm:  6px;
  --r-md:  10px;
  --r-lg:  14px;
  --r-xl:  20px;
  --r-full: 9999px;

  /* Shadows */
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.4);
  --shadow-md:  0 4px 16px rgba(0,0,0,0.5);
  --shadow-lg:  0 8px 32px rgba(0,0,0,0.6);
  --shadow-blue: 0 0 0 3px rgba(58, 134, 255, 0.25);
  --shadow-teal: 0 0 0 3px rgba(0, 194, 168, 0.25);

  /* Transitions */
  --t-fast:   0.1s ease;
  --t-base:   0.18s ease;
  --t-slow:   0.3s ease;

  /* Layout */
  --nav-h:    60px;
  --sidebar-w: 220px;

  /* Topbar blur bg (changes in light mode) */
  --topbar-bg: rgba(11, 13, 16, 0.95);
}

/* ============================================================
   LIGHT MODE
   ============================================================ */
:root[data-theme="light"] {
  --bg:            #F0F2F5;
  --surface:       #FFFFFF;
  --surface-2:     #F1F3F5;
  --surface-3:     #E4E7EB;
  --border:        #DEE2E6;
  --border-hover:  #ADB5BD;

  --text:          #111318;
  --text-muted:    #495057;
  --text-faint:    #868E96;

  --shadow-sm:  0 1px 3px rgba(0,0,0,0.08);
  --shadow-md:  0 4px 16px rgba(0,0,0,0.12);
  --shadow-lg:  0 8px 32px rgba(0,0,0,0.16);

  --topbar-bg: rgba(240, 242, 245, 0.95);

  /* Accent dims adjusted for light bg */
  --accent-blue-dim:  rgba(58, 134, 255, 0.1);
  --accent-teal-dim:  rgba(0, 194, 168, 0.1);
  --red-dim:          rgba(255, 77, 79, 0.08);
  --yellow-dim:       rgba(245, 166, 35, 0.08);
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a {
  color: var(--accent-blue);
  text-decoration: none;
  transition: color var(--t-base);
}
a:hover { color: var(--accent-blue-hover); }

img, video { display: block; max-width: 100%; }

ul, ol { list-style: none; }

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

/* --- Typography --- */
h1 { font-size: clamp(2rem, 4vw, 3.5rem); font-weight: 700; line-height: 1.15; letter-spacing: -0.03em; }
h2 { font-size: clamp(1.5rem, 3vw, 2.25rem); font-weight: 700; line-height: 1.2; letter-spacing: -0.02em; }
h3 { font-size: 1.25rem; font-weight: 600; line-height: 1.3; }
h4 { font-size: 1rem; font-weight: 600; }
p  { color: var(--text-muted); line-height: 1.7; }

.text-muted   { color: var(--text-muted); }
.text-faint   { color: var(--text-faint); }
.text-accent  { color: var(--accent-blue); }
.text-teal    { color: var(--accent-teal); }
.text-sm      { font-size: 0.875rem; }
.text-xs      { font-size: 0.75rem; }
.text-mono    { font-family: var(--font-mono); }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 10px var(--sp-5);
  border-radius: var(--r-md);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all var(--t-base);
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--accent-blue);
  color: #fff;
}
.btn-primary:hover {
  background: var(--accent-blue-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(58, 134, 255, 0.35);
}
.btn-primary:active { transform: translateY(0); }

.btn-teal {
  background: var(--accent-teal);
  color: #000;
}
.btn-teal:hover {
  background: var(--accent-teal-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(0, 194, 168, 0.35);
}

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

.btn-surface {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-surface:hover {
  background: var(--surface-3);
}

.btn-danger {
  background: var(--red-dim);
  color: var(--red);
  border: 1px solid rgba(255,77,79,0.2);
}
.btn-danger:hover {
  background: var(--red);
  color: #fff;
}

.btn-sm {
  padding: 6px var(--sp-3);
  font-size: 0.8125rem;
  border-radius: var(--r-sm);
}

.btn-lg {
  padding: 13px var(--sp-8);
  font-size: 1rem;
  border-radius: var(--r-lg);
}

.btn-icon {
  padding: 8px;
  width: 36px;
  height: 36px;
  border-radius: var(--r-sm);
}

/* --- Form Elements --- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.form-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.form-input {
  width: 100%;
  padding: 11px var(--sp-4);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text);
  font-size: 0.9375rem;
  transition: all var(--t-base);
  outline: none;
}

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

.form-input:focus {
  border-color: var(--accent-blue);
  box-shadow: var(--shadow-blue);
  background: var(--surface-3);
}

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

.form-textarea {
  resize: vertical;
  min-height: 100px;
}

.form-select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238B949E' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* --- Cards / Surfaces --- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-6);
}

.card-sm {
  padding: var(--sp-4);
  border-radius: var(--r-md);
}

.card-hover {
  transition: all var(--t-base);
  cursor: pointer;
}
.card-hover:hover {
  border-color: var(--border-hover);
  background: var(--surface-2);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

/* --- Badges --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--r-full);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.03em;
}

.badge-blue    { background: var(--accent-blue-dim); color: var(--accent-blue); }
.badge-teal    { background: var(--accent-teal-dim); color: var(--accent-teal); }
.badge-red     { background: var(--red-dim); color: var(--red); }
.badge-yellow  { background: var(--yellow-dim); color: var(--yellow); }
.badge-muted   { background: var(--surface-3); color: var(--text-muted); }

/* --- Divider --- */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--sp-6) 0;
}

/* --- Avatar --- */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--accent-blue-dim);
  color: var(--accent-blue);
  font-weight: 600;
  font-size: 0.875rem;
  flex-shrink: 0;
  border: 2px solid var(--border);
}
.avatar-sm  { width: 28px; height: 28px; font-size: 0.7rem; }
.avatar-md  { width: 36px; height: 36px; }
.avatar-lg  { width: 48px; height: 48px; font-size: 1.1rem; }
.avatar-xl  { width: 64px; height: 64px; font-size: 1.4rem; }

/* --- 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(--surface-3);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.75rem;
  padding: 4px 8px;
  border-radius: var(--r-sm);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--t-fast);
  z-index: 1000;
}
[data-tooltip]:hover::after { opacity: 1; }

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }

/* --- Loading / Spinner --- */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Toast Notifications --- */
#toast-container {
  position: fixed;
  bottom: var(--sp-6);
  right: var(--sp-6);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  z-index: 9999;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 12px var(--sp-5);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
  min-width: 280px;
  animation: slideInRight 0.2s ease;
}

.toast-success { border-left: 3px solid var(--accent-teal); }
.toast-error   { border-left: 3px solid var(--red); }
.toast-info    { border-left: 3px solid var(--accent-blue); }

@keyframes slideInRight {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* --- Utility --- */
.flex          { display: flex; }
.flex-col      { flex-direction: column; }
.items-center  { align-items: center; }
.justify-center{ justify-content: center; }
.justify-between{ justify-content: space-between; }
.gap-1         { gap: var(--sp-1); }
.gap-2         { gap: var(--sp-2); }
.gap-3         { gap: var(--sp-3); }
.gap-4         { gap: var(--sp-4); }
.gap-6         { gap: var(--sp-6); }
.w-full        { width: 100%; }
.mt-auto       { margin-top: auto; }
.sr-only       { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-base);
}
.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: var(--sp-8);
  width: 90%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
  transform: scale(0.96) translateY(8px);
  transition: transform var(--t-base);
}
.modal-overlay.active .modal {
  transform: scale(1) translateY(0);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-6);
}
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 4px;
  border-radius: var(--r-sm);
  transition: all var(--t-fast);
}
.modal-close:hover { color: var(--text); background: var(--surface-2); }

/* --- Dropdown --- */
.dropdown {
  position: relative;
}
.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-2);
  min-width: 180px;
  box-shadow: var(--shadow-lg);
  z-index: 500;
  display: none;
}
.dropdown-menu.open { display: block; }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 8px var(--sp-3);
  border-radius: var(--r-sm);
  font-size: 0.875rem;
  color: var(--text);
  cursor: pointer;
  transition: background var(--t-fast);
  background: none;
  border: none;
  width: 100%;
  text-align: left;
}
.dropdown-item:hover { background: var(--surface-3); }
.dropdown-item.danger { color: var(--red); }
.dropdown-divider {
  border-top: 1px solid var(--border);
  margin: var(--sp-2) 0;
}

/* ============================================================
   MOBILE RESPONSIVE — Global
   ============================================================ */
@media (max-width: 768px) {
  #toast-container {
    left: var(--sp-4);
    right: var(--sp-4);
    bottom: var(--sp-4);
  }
  .toast {
    min-width: unset;
    width: 100%;
  }
  .modal {
    width: 95%;
    padding: var(--sp-6);
  }
  .search-bar { display: none; }
  .content { padding: var(--sp-5); }
}
