/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #111214;
  --surface:    #1c1e22;
  --surface2:   #26292f;
  --border:     #2e3138;
  --accent:     #4a9eff;
  --accent-dim: #1e3a5f;
  --danger:     #cc3333;
  --text:       #e8eaf0;
  --text-dim:   #7a7f8e;
  --green:      #2ecc71;
  --radius:     12px;
  --radius-sm:  8px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ── */
body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header {
  padding: 20px 16px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

header h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.5px;
}

.subtitle {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

main {
  flex: 1;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}

footer {
  padding: 12px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

/* ── Labels & inputs ── */
.field-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.text-input, .select-input, .num-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  padding: 10px 12px;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 0.15s;
}

.text-input:focus, .select-input:focus, .num-input:focus {
  border-color: var(--accent);
}

.num-input { text-align: center; }

.select-input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%237a7f8e' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

/* ── Badge ── */
.badge {
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
}

/* ── Exercise list ── */
.exercise-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.empty-state {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  padding: 20px 0;
}

.exercise-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.exercise-item:active { border-color: var(--accent); }

.exercise-index {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.exercise-info { flex: 1; min-width: 0; }

.exercise-name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.exercise-params {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

.exercise-drag {
  color: var(--text-dim);
  font-size: 16px;
  padding: 4px;
}

/* ── Buttons ── */
.btn-add {
  width: 100%;
  background: transparent;
  border: 1px dashed var(--accent);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  padding: 10px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-add:active { background: var(--accent-dim); }

.btn-save {
  width: 100%;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  padding: 14px;
  cursor: pointer;
  letter-spacing: 0.3px;
  transition: opacity 0.15s;
}

.btn-save:active { opacity: 0.85; }

.btn-primary {
  width: 100%;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  padding: 12px;
  cursor: pointer;
  margin-top: 16px;
  transition: opacity 0.15s;
}

.btn-primary:active { opacity: 0.85; }

.btn-danger {
  width: 100%;
  background: transparent;
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: 14px;
  font-weight: 600;
  padding: 11px;
  cursor: pointer;
  margin-top: 8px;
  transition: background 0.15s;
}

.btn-danger:active { background: rgba(204,51,51,0.15); }

/* ── Plan list ── */
.plan-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.plan-card-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.plan-card-meta {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

.btn-remove-plan {
  background: transparent;
  border: none;
  color: var(--danger);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  flex-shrink: 0;
}

.btn-remove-plan:hover { background: rgba(204,51,51,0.12); }

.btn-generate {
  width: 100%;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  padding: 12px;
  margin-top: 12px;
  cursor: pointer;
  letter-spacing: 0.5px;
}

.btn-generate:active { opacity: 0.85; }

/* ── Plan output ── */
.plan-output {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: 'Courier New', monospace;
  font-size: 12px;
  padding: 10px 12px;
  resize: none;
  margin-top: 8px;
  word-break: break-all;
}

.btn-copy {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  padding: 10px;
  margin-top: 8px;
  cursor: pointer;
}

.btn-copy:active { background: var(--accent-dim); }

.output-hint {
  margin-top: 12px;
  padding: 12px;
  background: var(--surface2);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.6;
}

.output-hint strong { color: var(--text); }
.output-hint em { color: var(--accent); font-style: normal; }

.btn-close {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-dim);
  font-size: 14px;
  width: 30px;
  height: 30px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 100;
  align-items: flex-end;
}

.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-height: 88vh;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: slideUp 0.22s ease;
}

@keyframes slideUp {
  from { transform: translateY(40px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h2 { font-size: 17px; font-weight: 700; }

/* ── Tabs ── */
.tabs {
  display: flex;
  gap: 8px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 4px;
}

.tab {
  flex: 1;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  padding: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.tab.active {
  background: var(--surface);
  color: var(--text);
}

.tab-content { display: flex; flex-direction: column; gap: 10px; }
.tab-content.hidden { display: none; }

/* ── Search ── */
.search-box { position: relative; }

.filter-row {
  display: flex;
  gap: 8px;
}

.filter-row .select-input { flex: 1; font-size: 13px; padding: 8px 10px; }

.search-results {
  list-style: none;
  max-height: 280px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.search-result-item {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.1s;
}

.search-result-item:hover, .search-result-item.selected {
  background: var(--accent-dim);
}

.result-name { font-size: 14px; font-weight: 500; }
.result-meta { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

/* ── Params panel ── */
.params-panel {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.params-panel.hidden { display: none; }

.selected-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 4px;
}

.params-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.param-field { display: flex; flex-direction: column; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--green);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 20px;
  border-radius: 20px;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  white-space: nowrap;
  z-index: 200;
}

.toast.show { opacity: 1; }

/* ── Import section ── */
.btn-import {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  padding: 10px;
  margin-top: 8px;
  cursor: pointer;
}
.btn-import:active { background: var(--accent-dim); }

/* ── Params extras ── */
.params-grid-2 {
  grid-template-columns: 1fr 1fr;
  margin-top: 4px;
}

.checkbox-field { align-items: center; justify-content: center; text-align: center; }
.checkbox-input { width: 24px; height: 24px; margin-top: 6px; accent-color: var(--accent); cursor: pointer; }

.params-hint {
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
  margin-top: 2px;
}

/* ── Edit reorder ── */
.edit-reorder {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.btn-reorder {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  padding: 9px;
  cursor: pointer;
}
.btn-reorder:active { background: var(--border); color: var(--text); }

/* ── Section close button ── */
.btn-close-section {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: auto;
}
.btn-close-section:active { color: var(--text); }

/* ── Config history ── */
.history-entry {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.history-entry:last-child { border-bottom: none; }
.history-meta { font-size: 11px; color: var(--text-dim); margin-bottom: 4px; }
.history-str {
  font-family: 'Courier New', monospace;
  font-size: 11px;
  color: var(--text);
  word-break: break-all;
  margin-bottom: 6px;
}
.history-actions { display: flex; gap: 8px; }
.btn-history-copy, .btn-history-load {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  padding: 6px;
  cursor: pointer;
}
.btn-history-load { border-color: var(--accent); color: var(--accent); }
.btn-history-copy:active { background: var(--border); }
.btn-history-load:active { background: var(--accent-dim); }
