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

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #263549;
  --border: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 10px;
  --sidebar-width: 320px;
}

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

/* ── Topbar ── */
.topbar {
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-inner {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
}
.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -.3px;
  color: var(--text);
}
.topbar-sub {
  color: var(--muted);
  font-size: 13px;
}

/* ── Layout ── */
.layout {
  display: flex;
  height: calc(100vh - 52px);
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Upload Zone ── */
.upload-zone {
  margin: 16px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
}
.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--accent);
  background: rgba(59, 130, 246, .05);
}
.upload-icon { display: flex; justify-content: center; margin-bottom: 10px; }
.upload-label { color: var(--muted); font-size: 13px; line-height: 1.6; }
.upload-label strong { color: var(--text); }
.upload-link { color: var(--accent); cursor: pointer; text-decoration: underline; }
.upload-hint { font-size: 11px; color: var(--border); margin-top: 8px; }

/* ── Progress ── */
.upload-progress {
  margin: 0 16px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
}
.progress-bar {
  flex: 1;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width .3s;
  width: 0%;
}
.hidden { display: none !important; }

/* ── Files List ── */
.files-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px 8px;
}
.files-header h3 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.badge {
  background: var(--surface2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 20px;
}

.files-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 16px;
}
.files-list::-webkit-scrollbar { width: 4px; }
.files-list::-webkit-scrollbar-track { background: transparent; }
.files-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s;
  position: relative;
}
.file-item:hover { background: var(--surface2); }
.file-item.active { background: rgba(59, 130, 246, .15); }
.file-item.active .file-name { color: var(--accent); }

.file-icon {
  width: 34px;
  height: 34px;
  background: var(--surface2);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -.5px;
}
.file-info { flex: 1; min-width: 0; }
.file-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }

.file-del {
  opacity: 0;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: opacity .15s, color .15s;
  flex-shrink: 0;
}
.file-item:hover .file-del { opacity: 1; }
.file-del:hover { color: var(--danger); }

.empty-state {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 32px 16px;
  line-height: 1.7;
}

/* ── Content ── */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}
.content::-webkit-scrollbar { width: 6px; }
.content::-webkit-scrollbar-track { background: transparent; }
.content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Welcome ── */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  gap: 14px;
  color: var(--muted);
}
.welcome h2 { font-size: 20px; font-weight: 600; color: var(--text); }
.welcome p { max-width: 320px; font-size: 14px; }

/* ── File Detail ── */
.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.detail-title h2 { font-size: 20px; font-weight: 700; }
.detail-title p { color: var(--muted); font-size: 13px; margin-top: 4px; }
.type-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.type-badge.activity { background: rgba(34, 197, 94, .15); color: var(--success); }
.type-badge.workout { background: rgba(59, 130, 246, .15); color: var(--accent); }

/* ── Stats ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.stat-value { font-size: 20px; font-weight: 700; margin-top: 4px; }
.stat-unit { font-size: 12px; color: var(--muted); font-weight: 400; }

/* ── Segments Editor ── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.section-title {
  font-size: 15px;
  font-weight: 600;
}
.section-sub { font-size: 12px; color: var(--muted); margin-left: 6px; font-weight: 400; }

.segments-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 24px;
}
.segments-table {
  width: 100%;
  border-collapse: collapse;
}
.segments-table th {
  background: var(--surface2);
  padding: 10px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  white-space: nowrap;
}
.segments-table td {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  vertical-align: middle;
}
.segments-table tr:hover td { background: rgba(255,255,255,.02); }

/* Inputs dentro da tabela */
.seg-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 5px 8px;
  font-size: 13px;
  width: 100%;
  min-width: 0;
  outline: none;
  transition: border-color .15s;
}
.seg-input:focus { border-color: var(--accent); }
.seg-select {
  appearance: none;
  background: var(--surface2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%2394a3b8' stroke-width='1.5' fill='none'/%3E%3C/svg%3E") no-repeat right 8px center;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 5px 24px 5px 8px;
  font-size: 13px;
  width: 100%;
  outline: none;
  cursor: pointer;
  transition: border-color .15s;
}
.seg-select:focus { border-color: var(--accent); }

.duration-group { display: flex; gap: 4px; align-items: center; }
.duration-group .seg-input { width: 70px; }
.duration-group .seg-select { flex: 1; }

.target-group { display: flex; gap: 4px; align-items: center; }
.target-group .seg-input { width: 70px; }
.target-group .seg-select { flex: 1; }

.row-actions {
  display: flex;
  gap: 4px;
}
.row-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  padding: 4px;
  border-radius: 4px;
  line-height: 0;
  transition: color .15s, background .15s;
}
.row-btn:hover { background: var(--surface2); color: var(--text); }
.row-btn.danger:hover { color: var(--danger); }

/* ── Workout Form ── */
.workout-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.form-field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
.form-field input, .form-field select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}
.form-field select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%2394a3b8' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
  cursor: pointer;
}
.form-field input:focus, .form-field select:focus { border-color: var(--accent); }
.form-field.full { grid-column: 1 / -1; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-ghost { background: none; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--surface2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .85; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: 5px 12px; font-size: 12px; }

/* ── Generate bar ── */
.generate-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 28px;
}
.notes-input {
  flex: 1;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 12px;
  font-size: 13px;
  outline: none;
}
.notes-input:focus { border-color: var(--accent); }
.notes-input::placeholder { color: var(--muted); }

/* ── Versions ── */
.versions-list { display: flex; flex-direction: column; gap: 10px; }

.version-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.version-num {
  width: 36px;
  height: 36px;
  background: rgba(59, 130, 246, .1);
  border: 1px solid rgba(59, 130, 246, .3);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
}
.version-info { flex: 1; min-width: 0; }
.version-title { font-size: 14px; font-weight: 500; }
.version-meta { font-size: 12px; color: var(--muted); margin-top: 3px; }
.version-notes { font-size: 12px; color: var(--muted); font-style: italic; margin-top: 2px; }
.version-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

/* ── Modal ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 360px;
  max-width: 90vw;
}
.modal h3 { font-size: 16px; margin-bottom: 8px; }
.modal p { color: var(--muted); font-size: 14px; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 13px;
  font-weight: 500;
  z-index: 300;
  animation: toastIn .2s ease;
  max-width: 320px;
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
}
.toast.success { border-color: var(--success); color: var(--success); }
.toast.error { border-color: var(--danger); color: var(--danger); }
@keyframes toastIn {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ── Intensity chips ── */
.intensity-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}
.intensity-chip.active { background: rgba(34,197,94,.12); color: var(--success); }
.intensity-chip.rest { background: rgba(148,163,184,.12); color: var(--muted); }
.intensity-chip.warmup { background: rgba(245,158,11,.12); color: var(--warning); }
.intensity-chip.cooldown { background: rgba(59,130,246,.12); color: var(--accent); }
.intensity-chip.interval { background: rgba(239,68,68,.12); color: var(--danger); }
.intensity-chip.recovery { background: rgba(168,85,247,.12); color: #a855f7; }

/* ── Add segment row ── */
.add-row {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  text-align: center;
}

/* ── Responsive ── */
@media (max-width: 680px) {
  .sidebar { width: 100%; min-width: 100%; }
  .layout { flex-direction: column; }
  .content { display: none; }
  .content.show { display: block; }
  .workout-form { grid-template-columns: 1fr; }
}
