:root {
  --bg:        #0b0d14;
  --surface:   #13161f;
  --surface2:  #1c2030;
  --surface3:  #242840;
  --border:    #2a2f4a;
  --accent:    #4f8ef7;
  --green:     #22c55e;
  --orange:    #f97316;
  --red:       #ef4444;
  --purple:    #a78bfa;
  --text:      #e8eaf0;
  --muted:     #6b7499;
  --radius:    10px;
  --nav-h:     64px;
  --sidebar-w: 240px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.5;
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + 8px);
}

/* ══════════════════════════════════════
   MOBILE (default)
══════════════════════════════════════ */

.sidebar        { display: none; }
.desktop-hide   { display: inline-flex; }
.desktop-shell  { display: block; }
.desktop-content { display: block; }

/* ── Mobile Header ── */
.app-header {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px 12px;
  display: flex; align-items: center; justify-content: space-between;
}
.app-header h1 { font-size: 18px; font-weight: 700; letter-spacing: -.3px; }
.app-header .week-label { font-size: 12px; color: var(--muted); margin-top: 1px; }

/* ── Bottom Nav (mobile only) ── */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; z-index: 20;
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 3px; border: none; background: none;
  color: var(--muted); font-size: 11px; cursor: pointer; transition: color .15s;
}
.nav-btn svg { width: 22px; height: 22px; }
.nav-btn.active { color: var(--accent); }

/* ── Views (mobile) ── */
.view { display: none; padding: 16px; }
.view.active { display: block; }

/* ── Buttons ── */
.btn-reset {
  background: none; border: 1px solid var(--border);
  color: var(--muted); font-size: 12px; padding: 5px 10px;
  border-radius: 20px; cursor: pointer; white-space: nowrap;
}
.btn-reset:hover { border-color: var(--accent); color: var(--accent); }

.btn-export {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; padding: 8px 12px;
  background: rgba(79,142,247,.1); border: 1px solid rgba(79,142,247,.3);
  color: var(--accent); font-size: 13px; font-weight: 500;
  border-radius: 8px; cursor: pointer; margin-top: 8px;
}
.btn-export:hover { background: rgba(79,142,247,.18); }
.btn-export svg { width: 14px; height: 14px; flex-shrink: 0; }

/* ══════════════════════════════════════
   DESKTOP (≥ 900px)
══════════════════════════════════════ */
@media (min-width: 900px) {

  body { padding-bottom: 0; display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }

  .app-header { display: none; }
  .bottom-nav { display: none; }
  .desktop-hide { display: none !important; }

  /* Shell */
  .desktop-shell { display: flex; flex: 1; overflow: hidden; }

  /* ── Sidebar ── */
  .sidebar {
    display: flex; flex-direction: column;
    width: var(--sidebar-w); flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 0;
    overflow-y: auto;
  }

  .sidebar-top {
    padding: 24px 20px 20px;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-top h1 { font-size: 17px; font-weight: 700; letter-spacing: -.3px; }
  .sidebar-week-label { font-size: 12px; color: var(--muted); margin-top: 3px; }

  .sidebar-progress {
    margin-top: 14px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
  }
  .sidebar-progress-label {
    display: flex; justify-content: space-between;
    font-size: 12px; color: var(--muted); margin-bottom: 6px;
  }
  .sidebar-progress-label span { color: var(--text); font-weight: 600; }

  .sidebar-nav {
    padding: 16px 12px;
    display: flex; flex-direction: column; gap: 2px;
    flex: 1;
  }
  .sidebar-nav-label {
    font-size: 10px; font-weight: 700; letter-spacing: 1px;
    text-transform: uppercase; color: var(--muted);
    padding: 0 8px; margin-bottom: 6px;
  }

  .nav-btn {
    flex-direction: row; justify-content: flex-start;
    gap: 10px; font-size: 14px; font-weight: 500;
    padding: 10px 12px; border-radius: 8px;
    width: 100%; text-align: left;
  }
  .nav-btn svg { width: 17px; height: 17px; flex-shrink: 0; }
  .nav-btn:hover { background: var(--surface2); color: var(--text); }
  .nav-btn.active { background: rgba(79,142,247,.12); color: var(--accent); }

  .sidebar-footer {
    padding: 16px 12px 20px;
    border-top: 1px solid var(--border);
  }
  .sidebar-footer .btn-reset {
    width: 100%; text-align: center;
    padding: 8px 12px; font-size: 13px; border-radius: 8px;
  }

  /* ── Desktop Content ── */
  .desktop-content {
    flex: 1; overflow-y: auto; padding: 28px 36px;
  }

  /* ── Views (desktop) ── */
  .view { padding: 0; }
  .view.active { display: block; }

  /* 2-col section grid */
  #sections-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    align-items: start;
    margin-top: 20px;
  }
  #sections-container .section { margin-bottom: 0; }

  /* Date nav */
  .date-nav { margin-bottom: 4px; }
  .date-nav .date-label { font-size: 20px; }

  /* Week view: 2-col grid */
  #view-week { max-width: 900px; }
  .week-cards-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-top: 8px;
  }
  .week-cards-grid .week-day-card { margin-bottom: 0; }

  /* History */
  #view-history { max-width: 900px; }
  .history-week { padding: 20px 24px; }

  /* Modal centered */
  .modal-overlay { align-items: center; }
  .modal { border-radius: var(--radius); max-width: 420px; padding: 32px; }

  /* Toast */
  .toast { bottom: 24px; }
}

/* ══════════════════════════════════════
   SHARED COMPONENTS
══════════════════════════════════════ */

/* Date nav */
.date-nav {
  display: flex; align-items: center; gap: 8px; margin-bottom: 16px;
}
.date-nav .date-label {
  flex: 1; text-align: center; font-weight: 700; font-size: 16px;
}
.btn-day {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); width: 36px; height: 36px;
  border-radius: 50%; cursor: pointer; font-size: 18px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.btn-day:hover { background: var(--surface2); }

.day-type-badge {
  display: inline-block; font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 20px; margin-left: 8px; vertical-align: middle;
}
.day-type-badge.training { background: rgba(79,142,247,.18); color: var(--accent); }
.day-type-badge.rest     { background: rgba(34,197,94,.13);  color: var(--green); }

/* Progress bar */
.day-progress {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 16px;
}
.progress-label {
  display: flex; justify-content: space-between;
  font-size: 13px; color: var(--muted); margin-bottom: 8px;
}
.progress-label strong { color: var(--text); }
.progress-bar-track {
  height: 6px; background: var(--surface2); border-radius: 3px; overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--green));
  border-radius: 3px; transition: width .4s ease;
}

/* Sections */
.section { margin-bottom: 16px; }
.section-header {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  cursor: pointer; user-select: none;
}
.section-header .section-icon { font-size: 17px; }
.section-header .section-title { font-weight: 600; font-size: 14px; flex: 1; }
.section-header .section-progress {
  font-size: 11px; color: var(--muted);
  background: var(--surface2); padding: 2px 8px; border-radius: 20px;
}
.section-header .chevron { color: var(--muted); font-size: 11px; transition: transform .2s; }
.section.collapsed .chevron { transform: rotate(-90deg); }
.section-body {
  background: var(--surface); border: 1px solid var(--border);
  border-top: none; border-radius: 0 0 var(--radius) var(--radius); overflow: hidden;
}
.section.collapsed .section-body { display: none; }

/* Tick items */
.tick-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 11px 14px; border-top: 1px solid var(--border);
  cursor: pointer; transition: background .1s;
  -webkit-tap-highlight-color: transparent;
}
.tick-item:first-child { border-top: none; }
.tick-item:hover { background: var(--surface2); }

.tick-box {
  flex-shrink: 0; width: 22px; height: 22px;
  border: 2px solid var(--border); border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  margin-top: 2px; transition: background .15s, border-color .15s;
}
.tick-item.done .tick-box { background: var(--green); border-color: var(--green); }
.tick-item.done .tick-box::after {
  content: '✓'; color: #fff; font-size: 13px; font-weight: 700;
}
.tick-item.done .item-label { color: var(--muted); text-decoration: line-through; }

.item-content { flex: 1; min-width: 0; }
.item-label { font-weight: 500; font-size: 14px; }
.item-detail { font-size: 12px; color: var(--muted); margin-top: 2px; line-height: 1.4; }
.item-time { font-size: 11px; color: var(--accent); font-weight: 600; margin-bottom: 2px; }
.item-macros {
  display: inline-block; font-size: 11px; color: var(--muted);
  background: var(--surface2); padding: 2px 7px; border-radius: 20px; margin-top: 4px;
}
.sub-items { margin-top: 5px; }
.sub-item { font-size: 12px; color: var(--muted); padding-left: 12px; position: relative; line-height: 1.6; }
.sub-item::before { content: '·'; position: absolute; left: 4px; }

.ex-category {
  font-size: 10px; font-weight: 700; letter-spacing: .5px;
  text-transform: uppercase; padding: 1px 6px; border-radius: 4px;
  margin-top: 3px; display: inline-block;
}
.ex-category.warmup   { background: rgba(249,115,22,.15); color: var(--orange); }
.ex-category.main     { background: rgba(79,142,247,.15); color: var(--accent); }
.ex-category.cooldown { background: rgba(34,197,94,.12);  color: var(--green); }

/* History */
.history-week {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
}
.history-week h3 { font-size: 15px; font-weight: 700; margin-bottom: 6px; }
.history-week .week-badge {
  display: inline-block; font-size: 11px; padding: 1px 7px;
  border-radius: 20px; margin-left: 6px; vertical-align: middle;
}
.week-badge.current { background: rgba(79,142,247,.18); color: var(--accent); }
.history-stat { font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.history-stat strong { color: var(--text); }

/* Day grid — fixed so dots stay circular */
.day-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.day-cell {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.day-cell .day-name { font-size: 10px; color: var(--muted); text-align: center; }
.day-cell .day-dot {
  width: 38px; height: 38px;          /* explicit equal w/h = perfect circle */
  min-width: 38px; min-height: 38px;  /* prevent flex from squishing */
  border-radius: 50%;
  background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; color: var(--muted);
}
.day-dot.done    { background: rgba(34,197,94,.2);  color: var(--green); }
.day-dot.partial { background: rgba(249,115,22,.2); color: var(--orange); }
.day-dot.empty   { background: var(--surface2); color: var(--border); }

/* Week view */
.week-day-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 10px;
  display: flex; align-items: center; gap: 12px; cursor: pointer;
  transition: border-color .15s;
}
.week-day-card:hover { border-color: var(--accent); }
.week-day-card .day-num { font-size: 22px; font-weight: 700; line-height: 1; min-width: 32px; text-align: center; }
.week-day-card .day-info { flex: 1; }
.week-day-card .day-name-full { font-weight: 600; font-size: 14px; }
.week-day-card .day-subtitle  { font-size: 12px; color: var(--muted); margin-top: 1px; }
.week-day-card .day-mini-progress { font-size: 13px; font-weight: 600; color: var(--muted); }
.week-day-card .day-mini-progress.done { color: var(--green); }

/* Loading/empty */
.loading { text-align: center; padding: 40px 0; color: var(--muted); }
.empty   { text-align: center; padding: 40px 16px; color: var(--muted); font-size: 14px; }

/* Toast */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + 12px);
  left: 50%; transform: translateX(-50%);
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); font-size: 13px; padding: 8px 16px;
  border-radius: 20px; white-space: nowrap;
  opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 100;
}
.toast.show { opacity: 1; }

/* Modal */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.65); z-index: 50;
  align-items: flex-end; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-width: 480px; padding: 24px 20px 32px;
}
.modal h2 { font-size: 17px; font-weight: 700; margin-bottom: 8px; }
.modal p  { font-size: 14px; color: var(--muted); margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; }
.btn-confirm {
  flex: 1; padding: 12px; border-radius: 10px; border: none;
  font-size: 15px; font-weight: 600; cursor: pointer; background: var(--red); color: #fff;
}
.btn-cancel {
  flex: 1; padding: 12px; border-radius: 10px;
  border: 1px solid var(--border); background: none;
  color: var(--text); font-size: 15px; cursor: pointer;
}

/* ══════════════════════════════════════
   PRINT / PDF EXPORT
══════════════════════════════════════ */
@media print {
  body { background: #fff; color: #111; font-size: 12px; padding: 0; }
  .no-print { display: none !important; }
  .print-page { page-break-after: always; }
}
