:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-soft: #f8f9fb;
  --surface-strong: #fff1eb;
  --ink: #111827;
  --muted: #667085;
  --line: #e6e8ee;
  --green: #12a66a;
  --green-soft: #eaf8f1;
  --coral: #f04f23;
  --coral-soft: #fff1eb;
  --gold: #d98806;
  --gold-soft: #fff7e8;
  --blue: #2563eb;
  --blue-soft: #edf4ff;
  --charcoal: #0b0e14;
  --sidebar-soft: #171b23;
  --accent: #f04f23;
  --accent-strong: #d83f16;
  --shadow: 0 18px 48px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
}

body.auth-required {
  overflow: hidden;
}

body.auth-required .app-shell {
  filter: blur(2px);
  pointer-events: none;
  user-select: none;
}

body:not(.auth-required) .auth-gate {
  display: none;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(9, 12, 18, 0.92);
}

.auth-card {
  display: grid;
  width: min(420px, 100%);
  gap: 13px;
  padding: 32px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: #111722;
  color: #fff;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.42);
}

.auth-brand img {
  display: block;
  width: 184px;
  max-width: 74%;
  height: auto;
  border-radius: 7px;
  background: #fff;
}

.auth-kicker {
  color: #ff7144;
  font-size: 0.68rem;
  font-weight: 900;
  text-transform: uppercase;
}

.auth-card h1 {
  margin: -5px 0 0;
  font-size: 1.9rem;
}

.auth-card p {
  margin: 0;
  color: #9fa9b7;
  font-size: 0.76rem;
  line-height: 1.6;
}

.auth-card label {
  color: #cbd2dc;
}

.auth-card input {
  border-color: rgba(255, 255, 255, 0.13);
  background: #0b1018;
  color: #fff;
}

.auth-message {
  padding: 10px 12px;
  border: 1px solid rgba(240, 82, 29, 0.32);
  border-radius: 6px;
  background: rgba(240, 82, 29, 0.1);
  color: #ffb39a;
  font-size: 0.72rem;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 30px;
  padding: 22px 16px 18px;
  color: #fff;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), transparent 28%),
    var(--charcoal);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand.has-logo {
  align-items: center;
}

.brand.has-logo > div:not(.brand-mark) {
  display: none;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 0;
  border-radius: 7px;
  background: var(--accent);
}

.brand.has-logo .brand-mark {
  width: 168px;
  height: 72px;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.15);
}

.brand-mark span {
  font-size: 1.12rem;
  font-weight: 900;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 6px;
}

.brand h1,
.topbar h2,
.section-heading h2,
.panel h3 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  overflow: hidden;
  color: #fff;
  font-size: 1.05rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.nav-tabs {
  display: grid;
  gap: 6px;
  margin-top: 4px;
}

.nav-tab {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 0;
  border-radius: 7px;
  color: #aeb6c3;
  text-align: left;
  background: transparent;
  font-size: 0.84rem;
  font-weight: 750;
}

.nav-tab:hover,
.nav-tab.is-active {
  color: #fff;
  background: var(--sidebar-soft);
}

.nav-tab.is-active {
  box-shadow: inset 3px 0 var(--accent);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.muted,
.sidebar-footer p {
  color: var(--muted);
}

.sidebar-footer p {
  margin: 0 0 6px;
  color: #697483;
  font-size: 0.61rem;
}

.sidebar-footer strong {
  color: #ccd3dc;
  font-size: 0.74rem;
}

.main {
  min-width: 0;
  width: 100%;
  max-width: 1760px;
  margin: 0 auto;
  padding: 28px 40px 56px;
}

.topbar,
.section-heading,
.panel-heading,
.panel-actions,
.quick-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  margin-bottom: 24px;
}

.topbar h2 {
  margin: 5px 0 0;
  font-size: 1.65rem;
  line-height: 1;
}

.quick-actions {
  flex-wrap: wrap;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metric-card,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 10px 28px rgba(16, 24, 40, 0.045);
}

.metric-card {
  display: grid;
  gap: 8px;
  min-height: 116px;
  padding: 18px;
}

.metric-card span,
.metric-card small {
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 750;
}

.metric-card strong {
  font-size: 2rem;
  line-height: 1;
}

.accent-green {
  background: linear-gradient(180deg, var(--surface), var(--green-soft));
}

.accent-coral {
  background: linear-gradient(180deg, var(--surface), var(--coral-soft));
}

.accent-gold {
  background: linear-gradient(180deg, var(--surface), var(--gold-soft));
}

.dashboard-layout,
.workout-layout,
.measure-layout,
.reminder-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: 14px;
}

.panel {
  min-width: 0;
  padding: 20px;
}

.panel-heading {
  margin-bottom: 16px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  color: #fff;
  font-size: 0.66rem;
  font-weight: 800;
  background: var(--accent);
  white-space: nowrap;
}

.status-pill.neutral {
  color: var(--ink);
  background: var(--accent-soft);
}

.workout-preview,
.exercise-list,
.habit-list,
.channel-list,
.reminder-list,
.recent-log {
  display: grid;
  gap: 10px;
}

.exercise-item,
.habit-item,
.channel-item,
.reminder-item,
.log-item {
  display: grid;
  gap: 7px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-soft);
}

.exercise-title,
.habit-main,
.reminder-main,
.channel-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.exercise-title strong,
.habit-main strong,
.reminder-main strong,
.channel-main strong {
  font-size: 15px;
}

.exercise-item p,
.habit-item p,
.reminder-item p,
.channel-item p,
.log-item p {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
}

.primary-action,
.secondary-action,
.ghost-action,
.icon-button {
  min-height: 40px;
  padding: 0 16px;
  border-radius: 7px;
  border: 1px solid transparent;
  font-size: 0.78rem;
  font-weight: 850;
}

.primary-action {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

.primary-action:hover {
  background: var(--accent-strong);
}

.secondary-action {
  color: var(--ink);
  border-color: var(--line);
  background: var(--surface);
}

.ghost-action,
.icon-button {
  color: var(--accent);
  border-color: var(--line);
  background: var(--surface);
}

.habits-panel {
  margin-top: 18px;
}

.habit-item {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.habit-progress {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf1f6;
}

.habit-progress span {
  display: block;
  height: 100%;
  width: var(--progress);
  background: var(--accent);
}

.section-heading {
  margin-bottom: 18px;
}

.section-heading h2 {
  margin: 5px 0 0;
  font-size: 1.65rem;
  line-height: 1;
}

.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.segmented button {
  min-height: 34px;
  padding: 0 11px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
}

.segmented button.is-active {
  color: var(--accent);
  background: var(--accent-soft);
}

.stack-form {
  display: grid;
  gap: 13px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  outline: 0;
  background: var(--surface);
}

input:focus,
select:focus {
  border-color: rgba(240, 79, 35, 0.5);
  box-shadow: 0 0 0 4px rgba(240, 79, 35, 0.12);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.measurement-table-wrap {
  overflow: auto;
}

.measurement-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 520px;
}

.measurement-table th,
.measurement-table td {
  padding: 11px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 14px;
}

.measurement-table th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

canvas {
  width: 100%;
  max-width: 100%;
  height: 260px;
  border-radius: 8px;
  background: var(--surface-soft);
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 32px));
  padding: 14px 16px;
  border-radius: 8px;
  color: #fffaf0;
  background: var(--charcoal);
  box-shadow: var(--shadow);
  transform: translateY(120px);
  opacity: 0;
  transition: transform 180ms ease, opacity 180ms ease;
}

.toast.is-visible {
  transform: translateY(0);
  opacity: 1;
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .nav-tabs {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .sidebar-footer {
    display: none;
  }

  .metrics-grid,
  .dashboard-layout,
  .workout-layout,
  .measure-layout,
  .reminder-layout {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 760px) {
  .main,
  .sidebar {
    padding: 18px;
  }

  .topbar,
  .section-heading,
  .panel-heading,
  .panel-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .quick-actions {
    width: 100%;
  }

  .quick-actions button,
  .panel-actions button {
    width: 100%;
  }

  .nav-tabs,
  .metrics-grid,
  .dashboard-layout,
  .workout-layout,
  .measure-layout,
  .reminder-layout,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .segmented {
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-flow: row;
  }

  .metric-card strong {
    font-size: 26px;
  }
}
