/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d1117;
  --sidebar:   #111827;
  --card:      #161d2a;
  --border:    #1f2d3d;
  --border2:   #2d3f52;
  --text:      #e2e8f0;
  --text-muted:#6b7fa3;
  --accent:    #6ee7b7;
  --accent-dim:#064e3b;
  --wo:        #1e3a5f;
  --wo-text:   #7dd3fc;
  --qb:        #3b1d6e;
  --qb-text:   #c4b5fd;
  --tag-bg:    #0f2d1a;
  --tag-text:  #4ade80;
  --danger:    #ef4444;
  --success:   #22c55e;
  --radius:    8px;
  --sidebar-w: 320px;
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 14px; background: var(--bg); color: var(--text); }

/* ── Login ── */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); }
.login-card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 40px; width: 380px; max-width: 90vw; }
.login-logo { text-align: center; margin-bottom: 16px; }
.login-card h1 { font-size: 20px; font-weight: 600; text-align: center; margin-bottom: 4px; }
.login-sub { text-align: center; color: var(--text-muted); font-size: 13px; margin-bottom: 32px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }
.field input { width: 100%; background: var(--bg); border: 1px solid var(--border2); border-radius: var(--radius); padding: 10px 12px; color: var(--text); font-size: 14px; outline: none; transition: border-color .2s; }
.field input:focus { border-color: var(--accent); }
.error-msg { background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.3); color: #fca5a5; padding: 10px 12px; border-radius: var(--radius); font-size: 13px; margin-bottom: 12px; }

/* ── Buttons ── */
button { cursor: pointer; border: none; border-radius: var(--radius); font-size: 13px; font-weight: 500; transition: all .15s; }
.btn-primary { background: var(--accent); color: #0a1f15; padding: 10px 18px; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary.has-changes { box-shadow: 0 0 0 2px var(--accent-dim); }
.btn-secondary { background: var(--card); border: 1px solid var(--border2); color: var(--text); padding: 8px 14px; }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-secondary:disabled { opacity: .5; cursor: not-allowed; }
.btn-secondary.active { border-color: var(--accent); color: var(--accent); }
.btn-apply { background: var(--accent-dim); border: 1px solid var(--accent); color: var(--accent); padding: 6px 14px; border-radius: 6px; font-size: 12px; }
.btn-apply:hover { background: var(--accent); color: #0a1f15; }
.btn-apply-small { background: transparent; border: 1px solid var(--border2); color: var(--text-muted); padding: 4px 10px; border-radius: 5px; font-size: 12px; margin-top: 8px; }
.btn-apply-small:hover { border-color: var(--accent); color: var(--accent); }
.full-width { width: 100%; }

/* ── App layout ── */
#app { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ── */
#sidebar { width: var(--sidebar-w); min-width: var(--sidebar-w); background: var(--sidebar); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 12px; border-bottom: 1px solid var(--border); }
.sidebar-title { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 600; }
.logout-link { color: var(--text-muted); text-decoration: none; font-size: 18px; line-height: 1; }
.logout-link:hover { color: var(--text); }
.sidebar-search { padding: 12px 12px 8px; }
.sidebar-search input { width: 100%; background: var(--bg); border: 1px solid var(--border2); border-radius: 6px; padding: 8px 12px; color: var(--text); font-size: 13px; outline: none; }
.sidebar-search input:focus { border-color: var(--accent); }
.filter-tabs { display: flex; padding: 0 12px 8px; gap: 4px; }
.filter-tab { background: transparent; border: 1px solid transparent; color: var(--text-muted); padding: 5px 12px; border-radius: 20px; font-size: 12px; }
.filter-tab:hover { color: var(--text); }
.filter-tab.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.workout-stats { padding: 0 16px 8px; font-size: 12px; color: var(--text-muted); }
.workout-list { flex: 1; overflow-y: auto; padding: 4px 8px 16px; }
.workout-list::-webkit-scrollbar { width: 4px; }
.workout-list::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

.loading-state, .error-state, .empty-list { padding: 24px 16px; text-align: center; color: var(--text-muted); font-size: 13px; }
.error-state { color: #fca5a5; }

/* ── Workout list items ── */
.workout-item { padding: 10px 12px; border-radius: 6px; cursor: pointer; margin-bottom: 2px; border: 1px solid transparent; transition: all .15s; }
.workout-item:hover { background: var(--card); border-color: var(--border); }
.workout-item.active { background: var(--card); border-color: var(--accent); }
.workout-item.is-audited .item-title { color: var(--text-muted); }
.workout-item-top { display: flex; align-items: flex-start; gap: 8px; }
.item-type-badge { flex-shrink: 0; font-size: 9px; font-weight: 700; padding: 2px 5px; border-radius: 3px; letter-spacing: .5px; margin-top: 2px; }
.item-type-badge.wo { background: var(--wo); color: var(--wo-text); }
.item-type-badge.qb { background: var(--qb); color: var(--qb-text); }
.item-title { font-size: 13px; line-height: 1.4; font-weight: 500; }
.workout-item-meta { display: flex; align-items: center; gap: 8px; margin-top: 4px; padding-left: 28px; }
.item-audited { font-size: 11px; color: var(--accent); }
.item-tags { font-size: 11px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Main / editor ── */
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; color: var(--text-muted); }
.empty-state p { font-size: 15px; }

#editor { flex: 1; display: flex; flex-direction: column; overflow-y: auto; }
#editor::-webkit-scrollbar { width: 4px; }
#editor::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

/* ── Editor header ── */
.editor-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 28px 16px; border-bottom: 1px solid var(--border); gap: 16px; background: var(--sidebar); }
.editor-title-row { display: flex; align-items: flex-start; gap: 12px; flex: 1; min-width: 0; }
.type-badge { flex-shrink: 0; font-size: 10px; font-weight: 700; padding: 3px 8px; border-radius: 4px; letter-spacing: .5px; margin-top: 4px; }
.type-badge.wo { background: var(--wo); color: var(--wo-text); }
.type-badge.qb { background: var(--qb); color: var(--qb-text); }
#editorTitle { font-size: 17px; font-weight: 600; line-height: 1.4; word-break: break-word; }
.editor-header-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.audited-badge { background: var(--accent-dim); border: 1px solid var(--accent); color: var(--accent); font-size: 12px; padding: 4px 10px; border-radius: 20px; }

.save-status { margin: 0 28px 0; padding: 10px 16px; border-radius: var(--radius); font-size: 13px; }
.save-status.success { background: rgba(34,197,94,.1); border: 1px solid rgba(34,197,94,.3); color: #86efac; }
.save-status.error { background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.3); color: #fca5a5; }

/* ── Editor sections ── */
.editor-section { padding: 24px 28px; border-bottom: 1px solid var(--border); }
.section-label { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 12px; }
.label-hint { font-weight: 400; color: var(--text-muted); }

/* VTT row */
.vtt-row { display: flex; gap: 10px; }
.vtt-input { flex: 1; background: var(--bg); border: 1px solid var(--border2); border-radius: var(--radius); padding: 9px 12px; color: var(--text); font-size: 13px; font-family: 'SF Mono', 'Cascadia Code', monospace; outline: none; }
.vtt-input:focus { border-color: var(--accent); }
.vtt-error { background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.3); color: #fca5a5; padding: 10px 14px; border-radius: var(--radius); font-size: 13px; margin-top: 10px; }

/* AI panel */
.ai-panel { background: var(--bg); border: 1px solid var(--accent); border-radius: var(--radius); padding: 16px; margin-top: 14px; }
.ai-panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.ai-label { font-size: 13px; font-weight: 600; color: var(--accent); }
.ai-field-label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.ai-description { font-size: 13px; line-height: 1.6; color: var(--text); background: var(--card); padding: 12px; border-radius: 6px; }
.ai-description-wrap { margin-bottom: 16px; }
.ai-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 0; }
.ai-tag { background: var(--tag-bg); color: var(--tag-text); border: 1px solid rgba(74,222,128,.2); padding: 3px 10px; border-radius: 20px; font-size: 12px; }

/* Excerpt */
.excerpt-input { width: 100%; background: var(--bg); border: 1px solid var(--border2); border-radius: var(--radius); padding: 12px; color: var(--text); font-size: 14px; line-height: 1.6; resize: vertical; min-height: 100px; outline: none; font-family: inherit; }
.excerpt-input:focus { border-color: var(--accent); }
.char-count { font-size: 12px; color: var(--text-muted); margin-top: 6px; text-align: right; }

/* Tags */
.tags-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; min-height: 32px; }
.tag-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--tag-bg); border: 1px solid rgba(74,222,128,.25); color: var(--tag-text); padding: 4px 10px; border-radius: 20px; font-size: 13px; }
.tag-remove { background: none; border: none; color: var(--tag-text); opacity: .6; font-size: 16px; line-height: 1; padding: 0; cursor: pointer; }
.tag-remove:hover { opacity: 1; }
.tag-add-row { display: flex; }
.tag-input { background: var(--bg); border: 1px solid var(--border2); border-radius: var(--radius); padding: 7px 12px; color: var(--text); font-size: 13px; outline: none; width: 260px; }
.tag-input:focus { border-color: var(--accent); }

/* Ghost link */
.ghost-link-row { padding: 16px 28px 28px; }
.ghost-link { font-size: 12px; color: var(--text-muted); text-decoration: none; }
.ghost-link:hover { color: var(--accent); }
