/* ============================================================
   DASHBOARD COMPONENTS
   Header nav, cards, stat tiles, tables, forms, auth screens.
   Loaded after style.css, which defines the design tokens.
   ============================================================ */

/* ---------- Header nav ---------- */

.main-nav {
  display: flex;
  gap: 4px;
  margin-left: auto;
  margin-right: 14px;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 15px;
  border-radius: var(--r-pill);
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-muted);
  transition: background 0.2s var(--ease-out), color 0.2s var(--ease-out);
}

.nav-link:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}

.nav-link.active {
  background: linear-gradient(120deg, rgba(139, 92, 246, 0.28), rgba(217, 70, 176, 0.28));
  color: var(--text);
  border: 1px solid var(--border-hi);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 6px 6px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.user-avatar {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--violet), var(--magenta));
  color: #fff;
  font-weight: 800;
  font-size: 0.92rem;
  flex-shrink: 0;
}

.user-meta { display: flex; flex-direction: column; line-height: 1.15; }
.user-name { font-size: 0.87rem; font-weight: 700; }
.user-role { font-size: 0.72rem; color: var(--text-dim); }

.logout {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  color: var(--text-dim);
  font-size: 1rem;
}

.logout:hover { background: var(--wrong-bg); color: var(--wrong); text-decoration: none; }

/* ---------- Cards ---------- */

.card {
  padding: 24px;
  border-radius: var(--r-lg);
  background: linear-gradient(160deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
}

.card-tight { padding: 18px; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 34px 0 16px;
}

.section-head:first-child { margin-top: 0; }
.section-head .section-label { margin: 0; }

.section-action {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--magenta-hi);
  white-space: nowrap;
}

/* ---------- Stat tiles ---------- */

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}

.stat-tile {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  border-radius: var(--r);
  background: linear-gradient(150deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}

.stat-tile::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent, var(--magenta));
}

.stat-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  font-size: 1.25rem;
  background: color-mix(in srgb, var(--accent, var(--magenta)) 16%, transparent);
  flex-shrink: 0;
}

.stat-value {
  font-size: 1.65rem;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* ---------- Mini progress ring ---------- */

.mini-ring { position: relative; flex-shrink: 0; }

.mini-ring-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  font-size: 0.78rem;
  font-weight: 800;
}

/* ---------- Progress bars ---------- */

.bar {
  height: 8px;
  border-radius: var(--r-pill);
  background: var(--surface-hi);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: var(--r-pill);
  background: linear-gradient(90deg, var(--violet), var(--magenta));
  transition: width 0.6s var(--ease-out);
}

.bar-fill.good { background: linear-gradient(90deg, #34d399, #10b981); }
.bar-fill.mid  { background: linear-gradient(90deg, #fbbf24, #f59e0b); }
.bar-fill.low  { background: linear-gradient(90deg, #fb7185, #ef4444); }

/* ---------- List rows ---------- */

.row-list { display: grid; gap: 10px; }

.row-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 15px 18px;
  border-radius: var(--r);
  background: var(--surface);
  border: 1px solid var(--border);
  color: inherit;
  transition: border-color 0.2s var(--ease-out), transform 0.2s var(--ease-out);
}

a.row-item:hover {
  border-color: var(--border-hi);
  transform: translateX(3px);
  text-decoration: none;
}

.row-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 11px;
  font-size: 1.15rem;
  background: color-mix(in srgb, var(--accent, var(--magenta)) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent, var(--magenta)) 32%, transparent);
  flex-shrink: 0;
}

.row-main  { flex: 1; min-width: 0; }
.row-title { font-weight: 700; font-size: 0.97rem; margin: 0 0 3px; }
.row-sub   { font-size: 0.82rem; color: var(--text-muted); margin: 0; }

.row-end   { text-align: right; flex-shrink: 0; }
.row-value { font-weight: 800; font-size: 1.05rem; }
.row-note  { font-size: 0.76rem; color: var(--text-dim); }

/* ---------- Tables ---------- */

.table-wrap {
  overflow-x: auto;
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: var(--surface);
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  min-width: 620px;
}

table.data th {
  text-align: left;
  padding: 13px 16px;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-dim);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.data td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

table.data tr:last-child td { border-bottom: none; }
table.data tbody tr { transition: background 0.16s var(--ease-out); }
table.data tbody tr:hover { background: var(--surface-2); }

/* ---------- Pills ---------- */

.pill {
  display: inline-block;
  padding: 3px 11px;
  border-radius: var(--r-pill);
  font-size: 0.75rem;
  font-weight: 700;
}

.pill-good { background: var(--correct-bg); color: var(--correct); }
.pill-mid  { background: rgba(251, 191, 36, 0.16); color: var(--gold); }
.pill-low  { background: var(--wrong-bg); color: var(--wrong); }
.pill-info { background: var(--accent-soft); color: var(--violet-hi); }
.pill-mute { background: rgba(255, 255, 255, 0.06); color: var(--text-muted); }

/* ---------- Forms ---------- */

.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 7px;
}

.input, .select, .textarea {
  width: 100%;
  padding: 13px 16px;
  border-radius: var(--r);
  background: var(--surface-hi);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.2s var(--ease-out), box-shadow 0.2s var(--ease-out);
}

.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--magenta);
  box-shadow: 0 0 0 3px rgba(217, 70, 176, 0.18);
}

.textarea { resize: vertical; min-height: 84px; line-height: 1.5; }
.select { cursor: pointer; }
.select option { background: var(--surface-2); color: var(--text); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.hint { font-size: 0.8rem; color: var(--text-dim); margin: 6px 0 0; }

/* ---------- Alerts ---------- */

.alert {
  padding: 14px 18px;
  border-radius: var(--r);
  margin-bottom: 20px;
  font-size: 0.93rem;
  border: 1px solid;
}

.alert-error { background: var(--wrong-bg);   border-color: rgba(251, 113, 133, 0.4); color: #ffd5dc; }
.alert-ok    { background: var(--correct-bg); border-color: rgba(52, 211, 153, 0.4);  color: #c9f7e5; }
.alert-info  { background: rgba(139, 92, 246, 0.12); border-color: rgba(139, 92, 246, 0.35); color: #ddd3ff; }

/* ---------- Auth screens ---------- */

.auth-wrap {
  min-height: calc(100vh - 68px);
  display: grid;
  place-items: center;
  padding: 40px 20px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 34px;
  border-radius: var(--r-lg);
  background: linear-gradient(160deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
}

.auth-card h1 { font-size: 1.7rem; text-align: center; margin-bottom: 6px; }

.auth-card .sub {
  text-align: center;
  color: var(--text-muted);
  margin: 0 0 26px;
  font-size: 0.95rem;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 22px 0;
  color: var(--text-dim);
  font-size: 0.82rem;
}

.auth-divider::before, .auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.demo-accounts { display: grid; gap: 8px; }

.demo-btn {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 14px;
  border-radius: var(--r);
  background: var(--surface-hi);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.88rem;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: border-color 0.2s var(--ease-out), transform 0.2s var(--ease-out);
}

.demo-btn:hover { border-color: var(--magenta); transform: translateX(3px); }
.demo-btn .d-role { font-weight: 700; }
.demo-btn .d-mail { color: var(--text-dim); font-size: 0.78rem; }

/* ---------- Layout helpers ---------- */

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.split  { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; align-items: start; }
/* Grid items default to min-width:auto, which refuses to shrink below the
   min-content width of wide children (e.g. table.data's min-width:620px in
   .table-wrap) -- that pushes the whole grid track open past its fr share
   instead of letting the child scroll internally. min-width:0 here lets the
   track's own width win, same pattern as .mode-card in shell.css. */
.split > * { min-width: 0; }

.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.stack { display: grid; gap: 12px; }

.muted { color: var(--text-muted); }
.dim   { color: var(--text-dim); }
.mt-0  { margin-top: 0; }
.mb-0  { margin-bottom: 0; }
.mb-2  { margin-bottom: 18px; }
.text-c { text-align: center; }

.badge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 11px;
}

.badge-item {
  text-align: center;
  padding: 14px 8px;
  border-radius: var(--r);
  background: var(--surface);
  border: 1px solid var(--border);
}

.badge-item.locked { opacity: 0.32; filter: grayscale(1); }
.badge-icon { font-size: 1.7rem; display: block; margin-bottom: 5px; }
.badge-name { font-size: 0.74rem; font-weight: 700; line-height: 1.25; }

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .split, .grid-2 { grid-template-columns: 1fr; }
  .nav-label { display: none; }
  .nav-link { padding: 9px 12px; }
}

@media (max-width: 640px) {
  .app-header .wrap {
    height: auto;
    padding-top: 10px;
    padding-bottom: 10px;
    flex-wrap: wrap;
  }
  .main-nav { order: 3; width: 100%; margin: 4px 0 0; justify-content: space-around; }
  .nav-label { display: inline; }
  .user-meta { display: none; }
  .form-row { grid-template-columns: 1fr; }
  .stat-row { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 1.35rem; }
}
