/* ============================================================
   Qvisor Positions — Shared App Styles
   Based on Panel Brand Book design system
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Nunito+Sans:wght@300;400;500;600;700;800&display=swap');

/* ── Design Tokens ────────────────────────────────────────── */
:root {
  --ds-font:       'Nunito Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --ds-blue-50:    #eff6ff;
  --ds-blue-100:   #dbeafe;
  --ds-blue-500:   #3b82f6;
  --ds-blue-600:   #2563eb;
  --ds-blue-700:   #1d4ed8;
  --ds-gray-50:    #f9fafb;
  --ds-gray-100:   #f3f4f6;
  --ds-gray-200:   #e5e7eb;
  --ds-gray-300:   #d1d5db;
  --ds-gray-400:   #9ca3af;
  --ds-gray-500:   #6b7280;
  --ds-gray-600:   #4b5563;
  --ds-gray-700:   #374151;
  --ds-gray-800:   #1f2937;
  --ds-gray-900:   #111827;
  --ds-red-50:     #fef2f2;
  --ds-red-200:    #fecaca;
  --ds-red-600:    #dc2626;
  --ds-red-700:    #b91c1c;
  --ds-green-50:   #f0fdf4;
  --ds-green-200:  #bbf7d0;
  --ds-green-700:  #15803d;
  --ds-shadow-sm:  0 1px 2px 0 rgba(0,0,0,.05);
  --ds-shadow:     0 1px 3px 0 rgba(0,0,0,.1), 0 1px 2px -1px rgba(0,0,0,.1);
  --ds-shadow-md:  0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -2px rgba(0,0,0,.1);
  --ds-shadow-lg:  0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -4px rgba(0,0,0,.1);
  --ds-shadow-xl:  0 20px 25px -5px rgba(0,0,0,.1), 0 8px 10px -6px rgba(0,0,0,.1);
  --ds-r-lg:       0.5rem;
  --ds-r-xl:       0.75rem;
  --ds-r-2xl:      1rem;
  --ds-r-full:     9999px;
  --ds-transition: 150ms cubic-bezier(.4,0,.2,1);
  /* Semantic surface & status */
  --ds-surface:    #ffffff;
  --ds-positive:   #166534;
  --ds-negative:   #991b1b;
}

/* ── Dark theme ───────────────────────────────────────────── */
[data-theme="dark"] {
  color-scheme: dark;
  --ds-surface:    #1e2333;
  --ds-gray-50:    #111827;
  --ds-gray-100:   #1f2937;
  --ds-gray-200:   #374151;
  --ds-gray-300:   #4b5563;
  --ds-gray-400:   #6b7280;
  --ds-gray-500:   #9ca3af;
  --ds-gray-600:   #d1d5db;
  --ds-gray-700:   #e5e7eb;
  --ds-gray-800:   #f3f4f6;
  --ds-gray-900:   #f9fafb;
  --ds-blue-50:    rgba(37,99,235,.18);
  --ds-blue-100:   rgba(37,99,235,.28);
  --ds-red-50:     rgba(220,38,38,.12);
  --ds-red-200:    rgba(220,38,38,.3);
  --ds-green-50:   rgba(21,128,61,.12);
  --ds-green-200:  rgba(21,128,61,.3);
  --ds-positive:   #4ade80;
  --ds-negative:   #f87171;
  --ds-shadow-sm:  0 1px 2px 0 rgba(0,0,0,.4);
  --ds-shadow:     0 1px 3px 0 rgba(0,0,0,.5), 0 1px 2px -1px rgba(0,0,0,.4);
  --ds-shadow-md:  0 4px 6px -1px rgba(0,0,0,.5), 0 2px 4px -2px rgba(0,0,0,.4);
  --ds-shadow-lg:  0 10px 15px -3px rgba(0,0,0,.5), 0 4px 6px -4px rgba(0,0,0,.4);
  --ds-shadow-xl:  0 20px 25px -5px rgba(0,0,0,.5), 0 8px 10px -6px rgba(0,0,0,.4);
}

/* Popup/modal inner panels (inline bg:#fff overrides) */
[data-theme="dark"] #goals_settings_overlay > div,
[data-theme="dark"] #goal_detail_overlay > div {
  background: var(--ds-surface) !important;
  border: 1px solid var(--ds-gray-200);
}
[data-theme="dark"] .modal-backdrop { background: rgba(0,0,0,.7); }
[data-theme="dark"] .modal { background: var(--ds-surface); }

/* ── Reset ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--ds-font);
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--ds-gray-900);
  background: var(--ds-gray-50);
  -webkit-font-smoothing: antialiased;
}
a    { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; border: none; background: none; }
input  { font-family: inherit; }
svg    { display: block; flex-shrink: 0; }

/* ── Auth Page Layout ─────────────────────────────────────── */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: var(--ds-gray-50);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--ds-surface);
  border: 1px solid var(--ds-gray-200);
  border-radius: var(--ds-r-2xl);
  box-shadow: var(--ds-shadow-xl);
  overflow: hidden;
}

.auth-card-header {
  padding: 2rem 2rem 1.5rem;
  text-align: center;
  border-bottom: 1px solid var(--ds-gray-100);
}

.auth-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  background: var(--ds-blue-600);
  border-radius: var(--ds-r-xl);
  margin-bottom: 1rem;
}

.auth-logo svg { color: #fff; }

.auth-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ds-gray-900);
  margin-bottom: 0.25rem;
}

.auth-subtitle {
  font-size: 0.875rem;
  color: var(--ds-gray-500);
}

.auth-role-badge {
  display: inline-block;
  margin-top: 0.75rem;
  padding: 0.25rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--ds-r-full);
  background: var(--ds-blue-50);
  color: var(--ds-blue-600);
}

.auth-card-body { padding: 1.75rem 2rem 2rem; }

.auth-form { display: flex; flex-direction: column; gap: 1.25rem; }

.form-group { display: flex; flex-direction: column; gap: 0.375rem; }

.form-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--ds-gray-600);
}

.form-input {
  width: 100%;
  padding: 0.625rem 1rem;
  font-size: 0.875rem;
  font-family: var(--ds-font);
  background: var(--ds-surface);
  border: 1px solid var(--ds-gray-300);
  border-radius: var(--ds-r-lg);
  color: var(--ds-gray-900);
  outline: none;
  transition: border-color var(--ds-transition), box-shadow var(--ds-transition);
}
.form-input::placeholder { color: var(--ds-gray-400); }
.form-input:focus {
  border-color: var(--ds-blue-500);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}
.form-input.error { border-color: var(--ds-red-600); }
.form-input.error:focus { box-shadow: 0 0 0 3px rgba(220,38,38,.12); }

/* Password wrapper with toggle */
.input-wrap { position: relative; }
.input-wrap .form-input { padding-right: 2.75rem; }
.pw-toggle {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ds-gray-400);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  transition: color var(--ds-transition);
}
.pw-toggle:hover { color: var(--ds-gray-600); }

.btn-primary {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1.5rem;
  font-size: 0.875rem;
  font-weight: 700;
  font-family: var(--ds-font);
  color: #fff;
  background: var(--ds-blue-600);
  border: none;
  border-radius: var(--ds-r-lg);
  cursor: pointer;
  transition: background var(--ds-transition);
}
.btn-primary:hover { background: var(--ds-blue-700); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }

/* Alert */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  padding: 0.75rem 1rem;
  border-radius: var(--ds-r-lg);
  font-size: 0.875rem;
  line-height: 1.45;
}
.alert-error {
  background: var(--ds-red-50);
  border: 1px solid var(--ds-red-200);
  color: var(--ds-red-600);
}
.alert-success {
  background: var(--ds-green-50);
  border: 1px solid var(--ds-green-200);
  color: var(--ds-green-700);
}

/* Spinner */
.spinner {
  width: 1rem; height: 1rem;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Panel Layout (sidebar + content) ────────────────────── */
.panel-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: var(--ds-gray-50);
}

/* Sidebar */
.sidebar {
  flex-shrink: 0;
  width: 14rem; /* 224px */
  display: flex;
  flex-direction: column;
  background: var(--ds-gray-50);
  border-right: 1px solid var(--ds-gray-200);
  transition: width 300ms cubic-bezier(.4,0,.2,1);
}
.sidebar.collapsed { width: 5rem; }

.sidebar-logo {
  height: 4rem;
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  border-bottom: 1px solid var(--ds-gray-200);
  background: var(--ds-surface);
  overflow: hidden;
  gap: 0.625rem;
}
.sidebar-logo-icon {
  flex-shrink: 0;
  width: 2rem; height: 2rem;
  background: var(--ds-blue-600);
  border-radius: var(--ds-r-lg);
  display: flex; align-items: center; justify-content: center;
}
.sidebar-logo-icon svg { color: #fff; width: 1.125rem; height: 1.125rem; }
.sidebar-logo-text {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--ds-blue-600);
  white-space: nowrap;
  overflow: hidden;
  transition: opacity 200ms;
}
.sidebar.collapsed .sidebar-logo-text { opacity: 0; width: 0; }

.sidebar-nav {
  flex: 1;
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  padding: 0.625rem 0.75rem;
  border-radius: var(--ds-r-lg);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--ds-gray-600);
  transition: background var(--ds-transition), color var(--ds-transition);
  white-space: nowrap;
}
.nav-item:hover  { background: var(--ds-surface); color: var(--ds-gray-900); }
.nav-item.active { background: var(--ds-blue-50); color: var(--ds-blue-600); }
.nav-item svg    { width: 1.25rem; height: 1.25rem; flex-shrink: 0; }
.nav-item span   { margin-left: 0.75rem; overflow: hidden; transition: opacity 200ms, width 200ms; }
.sidebar.collapsed .nav-item span { opacity: 0; width: 0; margin: 0; }
.sidebar.collapsed .nav-item { justify-content: center; }

.sidebar-bottom {
  flex-shrink: 0;
  border-top: 1px solid var(--ds-gray-200);
  background: var(--ds-surface);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

/* Main column */
.main-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* Header */
.panel-header {
  flex-shrink: 0;
  height: 4rem;
  background: var(--ds-surface);
  border-bottom: 1px solid var(--ds-gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
}
.panel-header-left  { display: flex; align-items: center; gap: 0.75rem; }
.panel-header-right { display: flex; align-items: center; gap: 1rem; }
.page-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--ds-gray-900);
}

.btn-icon {
  display: flex; align-items: center; justify-content: center;
  width: 2.25rem; height: 2.25rem;
  border-radius: var(--ds-r-lg);
  color: var(--ds-gray-500);
  transition: background var(--ds-transition), color var(--ds-transition);
}
.btn-icon:hover { background: var(--ds-gray-100); color: var(--ds-gray-900); }
.btn-icon svg { width: 1.25rem; height: 1.25rem; }

.user-chip {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.375rem 0.75rem;
  border-radius: var(--ds-r-full);
  background: var(--ds-gray-100);
  font-size: 0.875rem; font-weight: 600;
  color: var(--ds-gray-700);
}
.user-chip .avatar {
  width: 1.75rem; height: 1.75rem;
  border-radius: 50%;
  background: var(--ds-blue-100);
  color: var(--ds-blue-600);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 700;
}

/* Panel content */
.panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.75rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Card */
.card {
  background: var(--ds-surface);
  border: 1px solid var(--ds-gray-200);
  border-radius: var(--ds-r-xl);
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--ds-gray-200);
}
.card-title { font-size: 0.9375rem; font-weight: 600; color: var(--ds-gray-900); }
.card-body  { padding: 1.5rem; }

/* Table */
.table-wrap { border: 1px solid var(--ds-gray-200); border-radius: var(--ds-r-xl); overflow: hidden; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
thead tr { background: var(--ds-gray-100); }
th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-size: 0.75rem; font-weight: 600;
  color: var(--ds-gray-500);
  text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--ds-gray-200);
  white-space: nowrap;
}
td {
  padding: 0.75rem 1rem;
  color: var(--ds-gray-600);
  border-bottom: 1px solid var(--ds-gray-200);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--ds-gray-50); }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 0.25rem;
  font-size: 0.75rem; font-weight: 600;
  padding: 0.125rem 0.5rem;
  border-radius: var(--ds-r-full);
}
.badge-green  { background: #dcfce7; color: #15803d; }
.badge-gray   { background: var(--ds-gray-100); color: var(--ds-gray-600); }
.badge-blue   { background: var(--ds-blue-50); color: var(--ds-blue-600); }
.badge-red    { background: #fee2e2; color: #b91c1c; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.375rem;
  font-size: 0.875rem; font-weight: 600; font-family: var(--ds-font);
  border-radius: var(--ds-r-lg);
  padding: 0.5rem 1rem;
  cursor: pointer; border: 1px solid transparent;
  transition: background var(--ds-transition), color var(--ds-transition), border-color var(--ds-transition);
  white-space: nowrap;
}
.btn svg { width: 1rem; height: 1rem; }
.btn-sm  { padding: 0.375rem 0.75rem; font-size: 0.8125rem; }

.btn-primary-sm { background: var(--ds-blue-600); color: #fff; }
.btn-primary-sm:hover { background: var(--ds-blue-700); }

.btn-secondary { background: var(--ds-surface); color: var(--ds-gray-600); border-color: var(--ds-gray-300); }
.btn-secondary:hover { background: var(--ds-gray-50); }

.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; }

.btn-ghost { background: transparent; color: var(--ds-gray-500); }
.btn-ghost:hover { background: var(--ds-gray-100); color: var(--ds-gray-900); }

/* Inputs (panel) */
.input {
  width: 100%;
  padding: 0.5rem 0.875rem;
  font-size: 0.875rem; font-family: var(--ds-font);
  background: var(--ds-surface);
  border: 1px solid var(--ds-gray-300);
  border-radius: var(--ds-r-lg);
  color: var(--ds-gray-900);
  outline: none;
  transition: border-color var(--ds-transition), box-shadow var(--ds-transition);
}
.input::placeholder { color: var(--ds-gray-400); }
.input:focus { border-color: var(--ds-blue-500); box-shadow: 0 0 0 3px rgba(59,130,246,.12); }
.input-label {
  display: block; font-size: 0.875rem; font-weight: 600;
  color: var(--ds-gray-600); margin-bottom: 0.375rem;
}

/* Select */
select.input { cursor: pointer; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(107,114,128,.6);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.modal {
  background: var(--ds-surface);
  border-radius: var(--ds-r-2xl);
  box-shadow: var(--ds-shadow-xl);
  width: 100%; max-width: 480px;
  border: 1px solid var(--ds-gray-200);
  display: flex; flex-direction: column;
  max-height: 90vh;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--ds-gray-200);
  flex-shrink: 0;
}
.modal-title { font-size: 1.125rem; font-weight: 600; color: var(--ds-gray-900); }
.modal > form { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow: hidden; }
.modal-body  { padding: 1.5rem; display: flex; flex-direction: column; gap: 1.25rem; overflow-y: auto; flex: 1; min-height: 0; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--ds-gray-200);
  flex-shrink: 0;
}

/* Toast */
.toast-container { position: fixed; top: 1rem; right: 1rem; z-index: 100; display: flex; flex-direction: column; gap: 0.5rem; }
.toast {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--ds-surface); border: 1px solid var(--ds-gray-200);
  border-radius: var(--ds-r-lg); box-shadow: var(--ds-shadow-lg);
  font-size: 0.875rem; min-width: 260px; max-width: 360px;
  animation: slideIn .2s ease;
}
.toast-success { border-left: 3px solid #22c55e; }
.toast-error   { border-left: 3px solid #dc2626; }
@keyframes slideIn { from { opacity:0; transform: translateX(1rem); } to { opacity:1; transform: translateX(0); } }

/* Stat cards */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px,1fr)); gap: 1rem; }
.stat-card {
  background: var(--ds-surface);
  border: 1px solid var(--ds-gray-200);
  border-radius: var(--ds-r-xl);
  padding: 1.25rem 1.5rem;
  display: flex; align-items: flex-start; gap: 1rem;
}
.stat-icon {
  width: 2.75rem; height: 2.75rem;
  border-radius: var(--ds-r-lg);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-icon svg { width: 1.375rem; height: 1.375rem; }
.stat-value { font-size: 1.75rem; font-weight: 800; color: var(--ds-gray-900); line-height: 1.2; }
.stat-label { font-size: 0.8125rem; color: var(--ds-gray-500); margin-top: 0.125rem; }

/* Footer */
.panel-footer {
  flex-shrink: 0; height: 3rem;
  background: var(--ds-surface); border-top: 1px solid var(--ds-gray-200);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.5rem;
  font-size: 0.8125rem; color: var(--ds-gray-400);
}

/* Utility */
.text-primary   { color: var(--ds-gray-900); }
.text-secondary { color: var(--ds-gray-600); }
.text-muted     { color: var(--ds-gray-400); }
.font-medium    { font-weight: 500; }
.font-semibold  { font-weight: 600; }
.font-bold      { font-weight: 700; }
.flex           { display: flex; }
.items-center   { align-items: center; }
.gap-2          { gap: 0.5rem; }
.gap-3          { gap: 0.75rem; }
.hidden         { display: none !important; }
