/* ── Multi-Workout Editor Styles ── */

:root {
  --topbar-height: 220px;
  --sidebar-w: 540px;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "SF Mono", monospace;
}

html, body {
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  font-size: 13px;
  line-height: 1.45;
  display: block;
}

button { cursor: pointer; font-family: inherit; font-size: inherit; }

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.2);
}

/* ── Layout ── */
.app-layout { display: grid; grid-template-columns: var(--sidebar-w) 1fr; height: calc(100vh - var(--nav-h, 48px)); transition: grid-template-columns 0.2s ease; }
.app-layout.sidebar-collapsed { grid-template-columns: 32px 1fr; }
.sidebar { position: relative; display: flex; flex-direction: column; border-right: 1px solid var(--border); background: var(--surface); overflow: hidden; min-height: 0; }
.content-col { display: flex; flex-direction: column; overflow: hidden; min-height: 0; }

/* ── Sidebar collapse button (absolute, no dedicated row) ── */
.sidebar-collapse-btn { position: absolute; top: 10px; right: 6px; z-index: 10; background: none; border: none; color: var(--muted); font-size: 20px; line-height: 1; padding: 2px 5px; border-radius: var(--radiusMd); cursor: pointer; transition: color 0.15s, background 0.15s; }
.sidebar-collapse-btn:hover { background: var(--btn); color: var(--text); }
.sidebar-body { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-height: 0; transition: opacity 0.15s; }
.app-layout.sidebar-collapsed .sidebar-body { opacity: 0; pointer-events: none; overflow: hidden; width: 0; }

/* ── Sidebar ── */
.cred-block { padding: 12px 14px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; flex-shrink: 0; }
.cred-row { display: flex; gap: 8px; align-items: center; padding-right: 30px; }
.cred-row input { flex: 1; min-width: 0; height: 36px; font-size: 13px; }
.fetch-row { display: flex; gap: 8px; align-items: center; }
.source-select { flex: 1; min-width: 0; height: 36px; font-size: 13px; background: var(--bg); appearance: auto; border-radius: var(--radius); }

/* Buttons */
.mwe-btn-save:not(:disabled) { background: var(--success); border-color: var(--success); color: #fff; }
.mwe-btn-save:not(:disabled):hover { background: #2ea043; }

/* Status line */
.status-line { padding: 4px 14px 8px; font-size: 12px; color: var(--muted); min-height: 22px; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-line.error { color: var(--danger); }
.status-line.success { color: var(--success); }

/* ── Table ── */
.table-wrap { flex: 1; overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.table-wrap table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.table-wrap thead { position: sticky; top: 0; z-index: 2; background: var(--surface); }
.table-wrap thead th { padding: 8px 8px; text-align: left; font-size: 11px; font-weight: 700; color: var(--muted2); text-transform: uppercase; letter-spacing: 0.05em; border-bottom: 1px solid var(--border); white-space: nowrap; user-select: none; }
.table-wrap thead th.sortable { cursor: pointer; }
.table-wrap thead th.sortable:hover { color: var(--text); }
.table-wrap .sort-ind { font-size: 10px; margin-left: 2px; }
.table-wrap .filter-row th { padding: 4px 4px 8px; border-bottom: 1px solid var(--border); }
.table-wrap .filter-row input { width: 100%; height: 28px; font-size: 12px; padding: 4px 8px; border-radius: 8px; }
.table-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; min-height: 0; scrollbar-width: none; }
.table-scroll::-webkit-scrollbar { display: none; }
.table-scroll table { table-layout: fixed; width: 100%; border-collapse: collapse; }
.table-scroll td { padding: 6px 8px; border-bottom: 1px solid var(--borderMuted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
.table-scroll tr:hover { background: rgba(88,166,255,0.06); }
.table-scroll tr.selected { background: rgba(56,139,253,0.15); }
.col-action { width: 32px; text-align: center; }
.col-sport { width: 70px; }
.col-date { width: 90px; }

.icon-btn { background: none; border: none; color: var(--muted); font-size: 16px; line-height: 1; padding: 2px; border-radius: var(--radiusMd); width: 24px; height: 24px; display: inline-flex; align-items: center; justify-content: center; transition: all 0.15s; }
.icon-btn:hover { background: var(--btn); color: var(--text); }
.icon-btn.remove { color: var(--danger); }

.sport-pill { display: inline-block; padding: 2px 8px; border-radius: var(--radiusLg); font-size: 10px; font-weight: 600; text-transform: uppercase; background: var(--btn); color: var(--muted); letter-spacing: 0.03em; }

/* ── Topbar (chart area) ── */
.mwe-topbar { flex-shrink: 0; height: var(--topbar-height); border-bottom: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; overflow: hidden; transition: height 0.2s ease; }
.mwe-topbar.chart-collapsed { height: auto; }
.mwe-topbar.chart-collapsed .chart-area { display: none; }
.mwe-topbar.chart-collapsed { border-bottom-color: var(--border); }

.tabs-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 2px;
  border-bottom: 1px solid var(--border);
  background: transparent;
  flex-shrink: 0;
  overflow-x: auto;
  overflow-y: visible;
  min-height: 38px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs-strip::-webkit-scrollbar { display: none; }

.tab-btn {
  font-size: 13px;
}
.tab-btn > span:first-child { padding: 9px 12px; }
.tab-btn .kebab {
  font-size: 17px;
  line-height: 1;
  transform: translateY(-1px);
  letter-spacing: -0.02em;
}
.tab-add {
  font-size: 16px;
}
.tab-bundle-btn {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.topbar-collapse-btn { margin-left: auto; background: none; border: none; color: var(--muted); font-size: 16px; line-height: 1; padding: 2px 6px; border-radius: var(--radiusMd); cursor: pointer; transition: color 0.15s, background 0.15s; flex-shrink: 0; user-select: none; }
.topbar-collapse-btn:hover { background: var(--btn); color: var(--text); }
.mwe-topbar.chart-collapsed .topbar-collapse-btn { color: var(--accent); }

.chart-area { flex: 1; position: relative; min-height: 0; padding: 4px 8px 4px 4px; }
.chart-area canvas { width: 100% !important; height: 100% !important; }

.metric-sel { position: absolute; top: 8px; right: 14px; z-index: 3; font-size: 12px; padding: 4px 8px; height: 28px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); color: var(--muted); font-weight: 600; }

.risk-actions {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
}

.risk-actions .btn {
  width: 100%;
}

/* Context menu */
.ctx-menu { position: fixed; z-index: 100; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radiusLg); box-shadow: 0 12px 26px rgba(0,0,0,0.35); padding: 6px; min-width: 140px; }
.ctx-menu button { display: block; width: 100%; text-align: left; padding: 8px 12px; background: none; border: none; border-radius: 8px; color: var(--text); font-size: 13px; font-weight: 500; transition: all 0.15s; }
.ctx-menu button:hover { background: rgba(88,166,255,0.12); color: var(--accent); }
.ctx-menu button:disabled { opacity: 0.5; color: var(--muted2); cursor: default; }
.ctx-menu button:disabled:hover { background: none; color: var(--muted2); }
.ctx-menu-title { padding: 4px 10px 6px; color: var(--muted2); font-size: 10px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; }
.ctx-check-row { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 8px; color: var(--text); font-size: 13px; cursor: pointer; transition: all 0.15s; }
.ctx-check-row:hover { background: rgba(88,166,255,0.12); color: var(--accent); }
.ctx-check-row input[type="checkbox"] { appearance: auto; margin: 0; width: 14px; height: 14px; padding: 0; border: none; border-radius: 0; background: transparent; box-shadow: none; accent-color: var(--accent); cursor: pointer; }
.ctx-check-row.ctx-check-row-disabled { color: var(--muted2); cursor: default; }
.ctx-check-row.ctx-check-row-disabled:hover { background: none; color: var(--muted2); }
.ctx-check-row.ctx-check-row-disabled input[type="checkbox"] { cursor: default; opacity: 0.8; }
.ctx-menu-hint { padding: 6px 10px 4px; color: var(--muted2); font-size: 11px; }

/* TOD modal grid */
.tod-grid { display: flex; gap: 6px; justify-content: space-between; margin: 10px 0; }
.tod-day { display: flex; flex-direction: column; align-items: center; gap: 5px; flex: 1; min-width: 0; }
.tod-day label { font-size: 0.75rem; font-weight: 600; color: var(--text-muted); white-space: nowrap; }
.tod-day input[type="time"] { width: 100%; font-size: 0.8125rem; background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); padding: 5px 3px; text-align: center; }

/* ── Main panel ── */
#cardsGrid[hidden], #weekView[hidden] { display: none !important; }
.main-panel { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 16px; min-height: 0; scrollbar-width: none; }
.main-panel::-webkit-scrollbar { display: none; }

.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 16px; }

/* ── Week view ── */
.week-view { display: flex; flex-direction: column; gap: 16px; }
.week-grid { display: flex; flex-direction: column; gap: 16px; }
.week-block { border: 1px solid var(--border); border-radius: var(--radiusLg); overflow: hidden; }
.week-block-header { display: flex; align-items: center; padding: 5px 12px; background: var(--surface); border-bottom: 1px solid var(--border); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted2); }
.week-start-label { font-size: 10px; font-weight: 600; color: var(--muted2); text-transform: uppercase; letter-spacing: 0.05em; padding-left: 14px; margin-right: 6px; }
.week-start-label:first-of-type { margin-left: auto; }
.week-start-toggle { min-height: 0; padding: 2px; }
.week-start-toggle button { padding: 3px 9px; font-size: 10px; min-width: 0; }
.week-start-select { height: 22px; font-size: 11px; padding: 0 6px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radiusMd); color: var(--text); }
.week-day-row { display: grid; grid-template-columns: repeat(7, 1fr); }
.week-day-col { display: flex; flex-direction: column; border-right: 1px solid var(--border); }
.week-day-col:last-child { border-right: none; }
.week-day-header { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: center; background: var(--surface); }
.week-day-header .day-name { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted2); }
.week-day-header .day-date { font-size: 12px; color: var(--muted); margin-top: 1px; }
.week-day-col.today .week-day-header { background: rgba(31,111,235,0.08); }
.week-day-col.today .day-name { color: var(--accent); }
.week-day-body { padding: 6px; display: flex; flex-direction: column; gap: 6px; min-height: 60px; }
.cal-tile { background: var(--bg); border: 1px solid var(--borderMuted); border-radius: var(--radius); padding: 7px 8px; display: flex; flex-direction: column; gap: 3px; cursor: grab; transition: border-color 0.15s, opacity 0.15s; }
.cal-tile:hover { border-color: var(--accent); }
.cal-tile.dirty { border-color: var(--warn); }
.cal-tile.dragging { opacity: 0.35; cursor: grabbing; }
.week-day-body.drag-over { background: rgba(31,111,235,0.07); outline: 2px dashed var(--accent); outline-offset: -2px; }
.cal-tile .sport-pill { align-self: flex-start; }
.cal-tile-name { font-size: 12px; font-weight: 600; color: var(--text); line-height: 1.3; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.cal-tile-stats { font-size: 11px; color: var(--muted); }
.cal-tile-time { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ── View toggle (compact unit-toggle in tabs-strip) ── */
.tabs-strip .unit-toggle { min-height: 0; padding: 2px; flex-shrink: 0; }
.tabs-strip .unit-toggle button { padding: 4px 10px; font-size: 10px; min-width: 36px; }

/* Workout cards */
.mwe-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radiusLg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  transition: border-color 0.15s;
}

.mwe-card.dirty { border-color: var(--warn); }
.mwe-card .card-remove { position: absolute; top: 10px; right: 10px; }

.card-title { width: calc(100% - 32px); height: 34px; font-size: 14px; font-weight: 600; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 10px; }

.meta-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.meta-pill { display: inline-block; padding: 2px 10px; border-radius: var(--radiusLg); font-size: 11px; font-weight: 600; background: var(--btn); color: var(--muted); }
.meta-pill.meta-pill-warn { background: rgba(210, 153, 34, 0.16); color: #f2cc60; border: 1px solid rgba(210, 153, 34, 0.4); }

.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat-box { text-align: center; padding: 8px 4px; background: var(--bg); border: 1px solid var(--borderMuted); border-radius: var(--radius); }
.stat-box .stat-val { font-size: 13px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.stat-box .stat-lbl { font-size: 10px; text-transform: uppercase; font-weight: 700; color: var(--muted2); letter-spacing: 0.04em; margin-top: 2px; }

.mwe-card textarea { width: 100%; min-height: 120px; resize: vertical; font-family: var(--font-mono); font-size: 12px; line-height: 1.5; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; }

.card-actions { display: flex; gap: 8px; justify-content: space-between; align-items: center; flex-wrap: wrap; }
.card-actions-left, .card-actions-right { display: flex; gap: 8px; align-items: center; }
.card-actions-right { margin-left: auto; }

/* ── Track-changes diff view ── */
.diff-view { font-family: var(--font-mono); font-size: 11px; line-height: 1.6; border: 1px solid var(--border); border-radius: var(--radius); overflow-y: auto; max-height: 200px; background: var(--bg); }
.diff-line { display: flex; gap: 8px; padding: 0 10px; white-space: pre-wrap; word-break: break-all; }
.diff-prefix { flex-shrink: 0; width: 10px; user-select: none; font-weight: 700; }
.diff-keep { color: var(--muted); }
.diff-add { background: rgba(46,160,67,0.15); color: var(--success); }
.diff-del { background: rgba(248,81,73,0.12); color: var(--danger); text-decoration: line-through; }

/* ── Scrollbar (global) ── */
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--muted2); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── Mobile ── */
@media (max-width: 960px) {
  .app-layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .app-layout.sidebar-collapsed { grid-template-columns: 1fr; grid-template-rows: 36px 1fr; }
  .sidebar { max-height: 45vh; border-right: none; border-bottom: 1px solid var(--border); }
  .app-layout.sidebar-collapsed .sidebar { max-height: none; border-bottom: 1px solid var(--border); }
  :root { --sidebar-w: 100%; }
  .cards-grid { grid-template-columns: 1fr; }
  .week-day-row { grid-template-columns: 1fr; }
  .week-day-col { border-right: none; border-bottom: 1px solid var(--border); }
  .week-day-col:last-child { border-bottom: none; }
}
