:root {
  color-scheme: dark;
  --bg: #0b0e13;
  --surface: #121720;
  --surface-2: #171e29;
  --surface-3: #202938;
  --text: #f4f6f8;
  --muted: #9aa6b6;
  --line: #263140;
  --accent: #7dd3a7;
  --accent-2: #9ac7ff;
  --danger: #ff8585;
  --warn: #f5c96a;
  --radius: 18px;
  --shadow: 0 16px 50px rgba(0,0,0,.28);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 75% -10%, #1d2a32 0, transparent 35%), var(--bg); color: var(--text); }
button,input,select,textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.eyebrow { margin: 0 0 7px; color: var(--accent); font-size: .76rem; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; }
h1,h2,h3,p { margin-top: 0; }
h1 { font-size: clamp(1.8rem, 4vw, 2.7rem); margin-bottom: 8px; letter-spacing: -.04em; }
h2 { font-size: 1.25rem; margin-bottom: 16px; }
h3 { font-size: 1rem; margin-bottom: 10px; }
a { color: inherit; }
.app-shell { min-height: 100vh; }
.boot-screen { min-height: 100vh; display: grid; place-items: center; align-content: center; gap: 14px; color: var(--muted); }
.brand-mark { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; background: var(--accent); color: #07120d; font-weight: 900; letter-spacing: -.04em; }
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(100%, 430px); padding: 32px; background: rgba(18,23,32,.94); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); }
.auth-card .brand-mark { margin-bottom: 24px; }
.field { display: grid; gap: 7px; margin-bottom: 14px; }
.field label { color: #cbd3dd; font-size: .86rem; font-weight: 650; }
.field input,.field select,.field textarea { width: 100%; border: 1px solid var(--line); border-radius: 12px; background: #0e131b; color: var(--text); padding: 11px 12px; outline: none; transition: .18s ease; }
.field textarea { resize: vertical; min-height: 84px; }
.field input:focus,.field select:focus,.field textarea:focus { border-color: #4e7668; box-shadow: 0 0 0 3px rgba(125,211,167,.1); }
.grid-2,.grid-3,.grid-4 { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2,minmax(0,1fr)); }
.grid-3 { grid-template-columns: repeat(3,minmax(0,1fr)); }
.grid-4 { grid-template-columns: repeat(4,minmax(0,1fr)); }
.btn { border: 0; border-radius: 12px; padding: 11px 15px; font-weight: 750; background: var(--surface-3); color: var(--text); }
.btn:hover { filter: brightness(1.08); }
.btn-primary { background: var(--accent); color: #07120d; }
.btn-danger { background: rgba(255,133,133,.12); color: #ffaaaa; border: 1px solid rgba(255,133,133,.2); }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: #d6dde6; }
.btn-sm { padding: 7px 10px; font-size: .8rem; border-radius: 9px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; }
.error-box,.success-box { margin: 14px 0; padding: 11px 12px; border-radius: 12px; font-size: .9rem; }
.error-box { background: rgba(255,133,133,.1); color: #ffb1b1; border: 1px solid rgba(255,133,133,.2); }
.success-box { background: rgba(125,211,167,.1); color: #a8e7c7; border: 1px solid rgba(125,211,167,.2); }
.layout { display: grid; grid-template-columns: 230px minmax(0,1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 24px 16px; border-right: 1px solid var(--line); background: rgba(11,14,19,.9); backdrop-filter: blur(10px); }
.sidebar-head { display: flex; gap: 11px; align-items: center; padding: 0 8px 24px; }
.sidebar-head .brand-mark { width: 42px; height: 42px; border-radius: 13px; }
.sidebar-title { font-weight: 850; letter-spacing: -.03em; }
.sidebar-sub { color: var(--muted); font-size: .76rem; margin-top: 2px; }
.nav { display: grid; gap: 4px; }
.nav button { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; color: #b9c2ce; background: transparent; padding: 11px 12px; border-radius: 12px; text-align: left; font-weight: 650; }
.nav button:hover,.nav button.active { background: var(--surface-2); color: var(--text); }
.nav .dot { width: 8px; height: 8px; border-radius: 99px; background: #4c596a; }
.nav button.active .dot { background: var(--accent); }
.sidebar-bottom { position: absolute; left: 16px; right: 16px; bottom: 20px; }
.main { min-width: 0; padding: 30px clamp(20px,4vw,54px) 70px; }
.topbar { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; margin-bottom: 26px; }
.user-pill { border: 1px solid var(--line); border-radius: 999px; padding: 8px 12px; color: #cbd3dd; font-size: .86rem; }
.section { display: none; }
.section.active { display: block; }
.cards { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 14px; margin-bottom: 18px; }
.card { background: linear-gradient(180deg, rgba(23,30,41,.96), rgba(18,23,32,.96)); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: 0 10px 30px rgba(0,0,0,.11); }
.card-title { color: var(--muted); font-size: .8rem; margin-bottom: 8px; }
.card-value { font-weight: 850; font-size: 1.7rem; letter-spacing: -.04em; }
.card-foot { margin-top: 7px; color: var(--muted); font-size: .76rem; }
.panel { background: rgba(18,23,32,.91); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.panel-head h2 { margin: 0; }
.chart-wrap { height: 280px; }
canvas { width: 100%; height: 100%; display: block; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th,td { text-align: left; padding: 11px 9px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; }
tr:last-child td { border-bottom: 0; }
.tag { display: inline-flex; align-items: center; min-height: 25px; padding: 3px 8px; border-radius: 999px; background: var(--surface-3); color: #d8dfe8; font-size: .76rem; }
.tag.green { background: rgba(125,211,167,.11); color: #a6e6c5; }
.tag.blue { background: rgba(154,199,255,.11); color: #bad7ff; }
.tag.orange { background: rgba(245,201,106,.11); color: #f5c96a; }
.tag.gray { background: rgba(154,166,182,.11); color: #9aa6b6; }
.tag.today { background: var(--accent); color: #07120d; font-weight: 800; }
.progress { height: 8px; border-radius: 99px; overflow: hidden; background: #0c1118; border: 1px solid #202a37; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.inline-note { border-left: 3px solid var(--accent-2); padding: 10px 12px; background: rgba(154,199,255,.06); color: #bfcaD8; border-radius: 0 10px 10px 0; font-size: .87rem; }
.exercise-builder { display: grid; gap: 9px; margin-top: 12px; }
.exercise-row { display: grid; grid-template-columns: minmax(220px,2.2fr) 80px 110px 100px auto; gap: 8px; align-items: end; padding: 12px; border-radius: 13px; border: 1px solid var(--line); background: #0e131b; }
.exercise-row .field { margin: 0; }
.exercise-row .field label { font-size: .7rem; }
.exercise-row button { align-self: end; margin-bottom: 1px; }
.custom-ex-input { margin-top: 6px !important; }
.exercise-select-wrap { display: flex; gap: 8px; align-items: center; }
.exercise-select-wrap select { flex: 1; min-width: 0; }

/* Exercise Thumbnails & Graphics */
.exercise-thumb { width: 44px; height: 44px; aspect-ratio: 1 / 1; border-radius: 10px; object-fit: cover; background: #161e2b; border: 1px solid var(--line); flex-shrink: 0; cursor: pointer; transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease; }
.exercise-thumb:hover { transform: scale(1.08); border-color: var(--accent); box-shadow: 0 4px 14px rgba(0,0,0,.4); }
.exercise-thumb-sm { width: 38px; height: 38px; aspect-ratio: 1 / 1; border-radius: 9px; object-fit: cover; background: #161e2b; border: 1px solid var(--line); flex-shrink: 0; }
.exercise-thumb-xs { width: 28px; height: 28px; aspect-ratio: 1 / 1; border-radius: 6px; object-fit: cover; background: #161e2b; border: 1px solid var(--line); flex-shrink: 0; cursor: pointer; }
.exercise-thumb-preview { width: 42px; height: 42px; aspect-ratio: 1 / 1; border-radius: 10px; object-fit: cover; background: #161e2b; border: 1px solid var(--line); flex-shrink: 0; }
.exercise-name-cell { display: inline-flex; align-items: center; gap: 8px; vertical-align: middle; }
.img-fallback { opacity: .4; }

/* Weekly Schedule Grid */
.week-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 10px; margin: 16px 0; }
.week-card { background: #0e131b; border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; justify-content: space-between; min-height: 180px; position: relative; transition: border-color .15s ease, transform .15s ease; }
.week-card:hover { border-color: #3b495d; }
.week-card.is-today { border-color: var(--accent); background: linear-gradient(180deg, rgba(125,211,167,.06), #0e131b); }
.week-card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.week-day-name { font-weight: 800; font-size: .86rem; color: #d6dde6; }
.week-card-body { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.week-activity-title { font-weight: 700; font-size: .88rem; line-height: 1.25; margin-top: 2px; }
.week-activity-note { font-size: .75rem; color: var(--muted); line-height: 1.3; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.week-card-foot { margin-top: 10px; display: flex; gap: 5px; flex-direction: column; }
.week-card-foot .btn { width: 100%; text-align: center; justify-content: center; padding: 6px 8px; font-size: .75rem; }

/* Plan Management */
.plan-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; margin-top: 14px; }
.plan-card { display: flex; flex-direction: column; justify-content: space-between; min-height: 100%; border: 1px solid var(--line); }
.plan-card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 8px; }
.plan-card-actions { display: flex; gap: 6px; }
.plan-meta { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 12px; }
.plan-exercise-list { list-style: none; padding: 0; margin: 10px 0 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.plan-exercise-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: rgba(14,19,27,.6); border: 1px solid var(--line); border-radius: 12px; transition: background .15s ease, border-color .15s ease; }
.plan-exercise-item:hover { background: rgba(23,30,41,.8); border-color: #3b495d; }
.plan-exercise-info { flex: 1; min-width: 0; }
.plan-exercise-title { font-weight: 700; font-size: .88rem; color: var(--text); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plan-exercise-meta { color: var(--muted); font-size: .78rem; display: block; margin-top: 2px; }
.plan-card-foot { display: flex; gap: 8px; margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line); }

/* Modals & Lightbox */
.modal-backdrop { position: fixed; inset: 0; z-index: 120; background: rgba(5,7,10,.78); backdrop-filter: blur(8px); display: grid; place-items: center; padding: 20px; animation: modalFadeIn .18s ease-out; }
.modal-dialog { width: min(100%, 680px); max-height: 90vh; background: #121720; border: 1px solid var(--line); border-radius: 20px; box-shadow: 0 24px 70px rgba(0,0,0,.6); display: flex; flex-direction: column; overflow: hidden; }
.modal-dialog-sm { width: min(100%, 420px); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 1.18rem; }
.modal-close { background: transparent; border: 0; color: var(--muted); font-size: 1.4rem; line-height: 1; padding: 4px 8px; border-radius: 8px; }
.modal-close:hover { color: var(--text); background: var(--surface-3); }
.modal-body { padding: 20px 22px; overflow-y: auto; flex: 1; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--line); background: rgba(14,19,27,.6); }
.lightbox-img-wrap { display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; }
.lightbox-img { width: 100%; max-width: 340px; aspect-ratio: 1 / 1; border-radius: 16px; border: 1px solid var(--line); box-shadow: 0 12px 40px rgba(0,0,0,.5); object-fit: cover; }

@keyframes modalFadeIn { from { opacity: 0; transform: scale(.98); } to { opacity: 1; transform: scale(1); } }

/* Schedule Edit Day Row */
.sched-day-row { display: grid; grid-template-columns: 100px 1fr 1.2fr; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: #0e131b; margin-bottom: 8px; }
.sched-day-row .field { margin: 0; }

.empty { color: var(--muted); text-align: center; padding: 26px 12px; }
.mobile-nav { display: none; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 200; width: min(360px, calc(100vw - 40px)); padding: 13px 15px; border-radius: 13px; background: #202938; border: 1px solid #344256; box-shadow: var(--shadow); }

@media (max-width: 1150px) {
  .week-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 1050px) {
  .cards { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .grid-4 { grid-template-columns: repeat(2,minmax(0,1fr)); }
}
@media (max-width: 800px) {
  .layout { display: block; }
  .sidebar { display: none; }
  .main { padding: 22px 16px 94px; }
  .mobile-nav { position: fixed; z-index: 90; left: 12px; right: 12px; bottom: 10px; display: grid; grid-template-columns: repeat(5,1fr); background: rgba(18,23,32,.96); border: 1px solid var(--line); border-radius: 16px; padding: 6px; box-shadow: var(--shadow); backdrop-filter: blur(12px); }
  .mobile-nav button { border: 0; background: transparent; color: var(--muted); padding: 10px 4px; border-radius: 10px; font-size: .68rem; font-weight: 750; }
  .mobile-nav button.active { background: var(--surface-3); color: var(--text); }
  .week-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .exercise-row { grid-template-columns: 1fr 1fr; }
  .exercise-row .name-field { grid-column: 1 / -1; }
  .sched-day-row { grid-template-columns: 1fr; gap: 8px; }
  .topbar { align-items: center; }
}
@media (max-width: 560px) {
  .auth-card { padding: 24px 19px; }
  .cards,.grid-2,.grid-3,.grid-4 { grid-template-columns: 1fr; }
  .week-grid { grid-template-columns: 1fr; }
  .plan-grid { grid-template-columns: 1fr; }
  .card-value { font-size: 1.5rem; }
  .panel { padding: 16px; }
  .chart-wrap { height: 235px; }
  .user-pill { display: none; }
  .exercise-row { grid-template-columns: 1fr; }
  .exercise-row .name-field { grid-column: auto; }
  .form-actions { justify-content: stretch; }
  .form-actions .btn { flex: 1; }
  .plan-card-foot { flex-direction: column; }
}
