/* =====================================================================
   Tensor - dashboard.css (app shell: content area, topbar, stats, panels)
   Sidebar rules live in sidebar-mobile.css.
   ===================================================================== */

.app-shell { display: flex; min-height: 100vh; min-height: 100dvh; position: relative; z-index: 2; }

.content {
  flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; z-index: 2;
  padding: 1.6rem clamp(1rem, 3vw, 2.4rem) 3rem;
  gap: 1.6rem;                       /* one spacing rhythm for every section */
}
.content > * { margin-bottom: 0; }

/* ========== TOPBAR ========== */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.topbar h1 { font-size: clamp(1.4rem, 3vw, 1.9rem); font-weight: 700; margin: 0; }
.topbar .sub { color: var(--text-dim); font-size: .92rem; margin: .2rem 0 0; }
.topbar .btn { transition: transform .2s ease, box-shadow .2s ease; }
.topbar .btn:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(109, 123, 255, .4); }
.topbar .btn:active { transform: scale(.97); }

.sidebar-toggle {
  display: none; background: var(--glass); border: 1px solid var(--border); color: var(--text);
  width: 42px; height: 42px; border-radius: 12px; cursor: pointer; font-size: 1.1rem;
  align-items: center; justify-content: center; flex-shrink: 0; transition: background .2s, transform .2s;
}
.sidebar-toggle:hover { background: var(--glass-strong); }
.sidebar-toggle:active { transform: scale(.95); }

/* ========== LAUNCHER HINT ========== */
.ll-hint {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  margin: .7rem 0 0; font-size: .88rem; color: var(--text-dim);
}
.ll-hint[hidden] { display: none; }
.ll-clear {
  background: none; border: 0; padding: 0; font: inherit; color: var(--accent);
  text-decoration: underline; cursor: pointer;
}
.learn-launcher .kbd {
  display: inline-block; padding: 0 .4rem; border-radius: 6px; border: 1px solid var(--border); font-size: .8rem;
}

/* ========== STAT CARDS ========== */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.1rem; }

.stat-card {
  padding: 1.4rem; display: flex; flex-direction: column; gap: .4rem;
  color: inherit; text-decoration: none;
  transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}
a.stat-card:hover { transform: translateY(-4px); border-color: rgba(109, 123, 255, .45); }
a.stat-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.stat-card .ic {
  width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center;
  font-size: 1.15rem; color: #fff; background: var(--grad); margin-bottom: .4rem;
}
.stat-card b { font-size: 1.9rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-card span { color: var(--text-dim); font-size: .88rem; }

/* skeleton sizing (moved out of inline styles) */
.stat-card .ic.skeleton { width: 46px; height: 46px; }
.stat-card b.skeleton { height: 28px; width: 60%; }
.stat-card span.skeleton { height: 14px; width: 80%; }
.recent-list .recent-item.skeleton { height: 54px; }
.achievements .ach-card.skeleton { height: 96px; }

.skeleton {
  background: linear-gradient(90deg, rgba(255,255,255,.04) 25%, rgba(255,255,255,.12) 37%, rgba(255,255,255,.04) 63%);
  background-size: 1200px 100%; animation: shimmerSweep 1.6s linear infinite; border-radius: 10px; display: block;
}

/* error state */
.load-error {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; padding: 1.2rem 1.4rem;
}
.load-error > i { font-size: 1.5rem; color: #f59e0b; }
.load-error > div { flex: 1; min-width: 200px; }
.load-error p { margin: .2rem 0 0; color: var(--text-dim); font-size: .9rem; }

/* ========== PANELS ========== */
.panel { padding: 1.5rem; }
.panel h3 { margin-bottom: 1rem; display: flex; align-items: center; gap: .6rem; font-size: 1.1rem; }
.panel h3 i { color: var(--accent); }

.recent-list { display: flex; flex-direction: column; gap: .7rem; }
.recent-item {
  display: flex; align-items: center; justify-content: space-between; gap: .8rem;
  padding: .85rem 1rem; border-radius: 12px; background: var(--glass); border: 1px solid var(--border);
  color: inherit; text-decoration: none; transition: transform .2s, border-color .2s;
}
a.recent-item:hover { transform: translateX(4px); border-color: rgba(109, 123, 255, .5); }
a.recent-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.recent-item .ttl { display: flex; align-items: center; gap: .7rem; overflow: hidden; }
.recent-item .ttl i { color: var(--accent); }
.recent-item .ttl b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-item small { color: var(--text-dim); flex-shrink: 0; }

/* ========== NOTES ========== */
.note-item {
  display: flex; align-items: center; gap: .6rem; padding: .7rem .9rem; border-radius: 12px;
  background: var(--glass); border: 1px solid var(--border);
  transition: opacity .2s, transform .2s, border-color .2s;
}
.note-item:hover, .note-item:focus-within { border-color: rgba(109, 123, 255, .5); }
.note-item.removing { opacity: 0; transform: translateX(24px); }
.note-item .ni-main {
  flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .1rem; color: inherit; text-decoration: none;
}
.note-item .ni-main b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note-item .ni-main small { color: var(--text-dim); }
.ni-flags { color: var(--accent); display: flex; gap: .3rem; font-size: .8rem; }
.note-actions { display: flex; gap: .2rem; }
.note-actions button {
  width: 34px; height: 34px; border-radius: 8px; border: 0; background: transparent;
  color: var(--text-dim); cursor: pointer; transition: background .15s, color .15s;
}
.note-actions button:hover { background: var(--glass-strong); color: var(--text); }
.note-actions button.danger:hover { color: #ef4444; }
.note-actions button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
/* Hover devices: reveal actions on hover/focus. Touch devices: always visible. */
@media (hover: hover) and (pointer: fine) {
  .note-actions { opacity: 0; transition: opacity .15s; }
  .note-item:hover .note-actions, .note-item:focus-within .note-actions { opacity: 1; }
}

/* ========== CHART ========== */
.chart-wrap { position: relative; height: 220px; }
.chart-empty {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  padding: 1rem; margin: 0; color: var(--text-dim); font-size: .9rem; pointer-events: none;
}
.chart-empty[hidden] { display: none; }

/* ========== PROGRESS META ========== */
.progress-meta { display: flex; flex-direction: column; gap: .5rem; margin-top: 1rem; }
.pm-row { display: flex; justify-content: space-between; gap: 1rem; font-size: .9rem; }
.pm-row span { color: var(--text-dim); }
.pm-row i { color: var(--accent); margin-right: .35rem; }

/* ========== ACHIEVEMENTS ========== */
.ach-card .ach-body { display: flex; flex-direction: column; gap: .15rem; min-width: 0; flex: 1; }
.ach-card .ach-body small { color: var(--text-dim); font-size: .75rem; }
.ach-bar { height: 5px; border-radius: 99px; background: var(--border); overflow: hidden; margin-top: .35rem; }
.ach-bar > span { display: block; height: 100%; border-radius: inherit; background: var(--grad); }
.ach-card.locked .ach-ic { opacity: .65; }

/* ========== SETTINGS (shared with profile page) ========== */
.settings-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.1rem; }
.settings-card { padding: 1.6rem; }
.settings-card h3 { margin-bottom: 1.1rem; }
.settings-card .field input { padding-left: 1rem; }
.settings-card .field input.with-icon { padding-left: 2.8rem; }


/* ========== FOCUS (keyboard) ========== */
.sidebar-toggle:focus-visible,
.ws-card:focus-visible,
.trend-card:focus-visible,
.topic-card:focus-visible,
.ni-main:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ========== TABLET ========== */
@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .settings-grid { grid-template-columns: 1fr; }
  .stat-card b { font-size: 1.6rem; }
}

/* ========== MOBILE ========== */
@media (max-width: 880px) {
  .app-shell { flex-direction: column; }
  .content { width: 100%; padding: calc(64px + 1rem + env(safe-area-inset-top, 0px)) 1rem 2rem; gap: 1.2rem; }

  .topbar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 120; height: calc(64px + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) 1rem 0; background: var(--nav-bg); backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border); flex-wrap: nowrap; gap: .75rem;
  }
  .topbar > div:first-child { min-width: 0; flex: 1 1 auto; overflow: hidden; }
  .topbar h1 { font-size: 1.25rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar .sub { font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sidebar-toggle { display: grid !important; place-items: center; order: 99; margin-left: auto; }
  .topbar > div:last-child { display: flex; align-items: center; gap: .5rem; flex: 0 0 auto; }

  .stats-grid { gap: .8rem; }
  .stat-card { padding: 1rem; }
  .continue-card, .first-run { grid-template-columns: auto 1fr; }
  .continue-card .btn, .first-run > .btn { grid-column: 1 / -1; width: 100%; }
  .first-run-steps { grid-column: 1 / -1; grid-template-columns: 1fr; }
  .mobile-quick-action { display: inline-flex; position: sticky; bottom: calc(.8rem + env(safe-area-inset-bottom, 0px)); z-index: 30; align-self: center; width: min(100%, 22rem); box-shadow: 0 12px 30px rgba(0,0,0,.35); }
  .text-button { min-height: 40px; }
  .first-run-steps li { min-height: 44px; }
  .stat-card b { font-size: 1.4rem; }
  .stat-card span { font-size: .8rem; }
  .panel { padding: 1.2rem; }
  .panel h3 { font-size: 1rem; margin-bottom: .8rem; }
  .recent-item { padding: .7rem .8rem; }
}

/* ========== SMALL MOBILE ========== */
@media (max-width: 480px) {
  .content { padding: calc(60px + .9rem + env(safe-area-inset-top, 0px)) .8rem 2rem; }
  .topbar { height: calc(60px + env(safe-area-inset-top, 0px)); padding-left: .8rem; padding-right: .8rem; }
  .topbar h1 { font-size: 1.1rem; }
  .topbar .sub { display: none; }
  .topbar .btn { padding: .55rem .8rem; font-size: .82rem; }
  .sidebar-toggle { width: 44px; height: 44px; }   /* 44px minimum touch target */
  .stats-grid { gap: .7rem; }
  .stat-card { padding: .9rem; }
  .stat-card .ic { width: 40px; height: 40px; font-size: 1rem; }
  .stat-card b { font-size: 1.2rem; }
  .panel { padding: 1rem; }
  .chart-wrap { height: 180px; }
  .note-actions button { width: 38px; height: 38px; }
  .note-item { flex-wrap: wrap; }
  .note-actions { width: 100%; justify-content: flex-end; }
}

/* ========== FIRST-RUN + CONTINUE ========== */
.continue-card, .first-run {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 1rem;
  padding: 1.25rem 1.4rem; border-color: color-mix(in srgb, var(--accent) 32%, var(--border));
}
.continue-card[hidden], .first-run[hidden], .first-run-secondary { display: none; }
.continue-icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); }
.continue-copy h2, .first-run h2 { margin: 0; font: 600 1.2rem var(--rd-display, inherit); letter-spacing: -.03em; }
.continue-copy p:last-child, .first-run > div > p:last-child { margin: .25rem 0 0; color: var(--text-dim); font-size: .9rem; }
.first-run { grid-template-columns: 1.1fr 1.5fr auto; }
.first-run-steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: .7rem; list-style: none; padding: 0; margin: 0; }
.first-run-steps li { display: flex; gap: .55rem; align-items: center; min-width: 0; padding: .6rem; border: 1px solid var(--border); border-radius: 10px; color: var(--text-dim); }
.first-run-steps li > span { display: grid; place-items: center; width: 24px; height: 24px; flex: 0 0 24px; border-radius: 50%; background: var(--glass-strong); color: var(--text); font-size: .75rem; }
.first-run-steps li.complete { border-color: color-mix(in srgb, var(--success) 45%, var(--border)); color: var(--text); }
.first-run-steps li.complete > span { background: var(--success); color: #fbfaf7; }
.first-run-steps b, .first-run-steps small { display: block; }
.first-run-steps b { font-size: .82rem; }
.first-run-steps small { margin-top: .15rem; font-size: .75rem; color: inherit; }
.mobile-quick-action { display: none; }
.text-button { border: 0; background: transparent; color: var(--accent-light, var(--accent)); text-decoration: underline; cursor: pointer; font: inherit; padding: .25rem; }

/* ========== REDUCED MOTION ========== */
@media (prefers-reduced-motion: reduce) {
  .stat-card, .recent-item, .note-item, .topbar .btn, .skeleton { transition: none !important; animation: none !important; }
}
