/* ============================================================
   Peptidex — styles
   ============================================================ */

:root[data-theme="dark"] {
  --bg: #0b0f17;
  --bg-grad: radial-gradient(1200px 600px at 80% -10%, rgba(255,107,157,0.10), transparent),
             radial-gradient(900px 500px at -10% 10%, rgba(79,209,197,0.08), transparent),
             #0b0f17;
  --card: #131826;
  --card-2: #1a2030;
  --text: #e6edf3;
  --text-dim: #8b95a7;
  --border: rgba(255,255,255,0.07);
  --border-strong: rgba(255,255,255,0.12);
  --accent: #ff6b9d;
  --accent-2: #4fd1c5;
  --accent-grad: linear-gradient(135deg, #ff6b9d, #4fd1c5);
  --danger: #ff6b6b;
  --shadow: 0 10px 40px -10px rgba(0,0,0,0.6);
}
:root[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-grad: radial-gradient(1200px 600px at 80% -10%, rgba(255,107,157,0.12), transparent),
             radial-gradient(900px 500px at -10% 10%, rgba(79,209,197,0.10), transparent),
             #f4f6fb;
  --card: #ffffff;
  --card-2: #f7f9fc;
  --text: #1a2233;
  --text-dim: #6b7585;
  --border: rgba(10,20,40,0.08);
  --border-strong: rgba(10,20,40,0.14);
  --accent: #d6336c;
  --accent-2: #0ca678;
  --accent-grad: linear-gradient(135deg, #d6336c, #0ca678);
  --danger: #e03131;
  --shadow: 0 10px 30px -10px rgba(20,40,80,0.18);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}

h1, h2, h3 { margin: 0; font-weight: 800; letter-spacing: -0.02em; }

/* ---------- App bar ---------- */
.appbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; gap: 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(11,15,23,0.55);
  backdrop-filter: blur(14px);
  position: sticky; top: 0; z-index: 50;
}
:root[data-theme="light"] .appbar { background: rgba(255,255,255,0.7); }

.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 40px; height: 40px; flex-shrink: 0; }
.brand h1 { font-size: 18px; font-weight: 800; line-height: 1; background: var(--accent-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand .tag { font-size: 11px; color: var(--text-dim); font-weight: 500; }

.actions { display: flex; gap: 8px; }
.actions button { min-height: 40px; min-width: 44px; }

.ghost, .primary, .tab, .chip, .dose-pill, .file-btn {
  font-family: inherit; font-size: 14px; font-weight: 600; cursor: pointer; border-radius: 10px; transition: all 0.15s ease;
}
.ghost {
  background: transparent; color: var(--text); border: 1px solid var(--border-strong);
  padding: 9px 12px; display: inline-flex; align-items: center; gap: 8px;
}
.ghost:hover { background: var(--card-2); border-color: var(--accent); }
.primary {
  background: var(--accent-grad); color: #fff; border: none;
  padding: 12px 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 6px 18px -6px rgba(255,107,157,0.5);
}
.primary:hover { transform: translateY(-1px); box-shadow: 0 10px 24px -6px rgba(255,107,157,0.55); }
.primary:active { transform: translateY(0); }

/* ---------- Tabs ---------- */
.tabs {
  display: flex; gap: 4px; padding: 8px 12px; overflow-x: auto;
  border-bottom: 1px solid var(--border);
  background: rgba(11,15,23,0.3);
  position: sticky; top: 68px; z-index: 40;
}
:root[data-theme="light"] .tabs { background: rgba(255,255,255,0.5); }
.tab {
  background: transparent; color: var(--text-dim); border: none;
  padding: 10px 14px; white-space: nowrap; position: relative;
}
.tab.active { color: var(--text); }
.tab.active::after {
  content: ''; position: absolute; left: 12px; right: 12px; bottom: -1px;
  height: 3px; border-radius: 3px; background: var(--accent-grad);
}

/* ---------- Panels ---------- */
main { max-width: 1100px; margin: 0 auto; padding: 16px; position: relative; }
.panel { display: none; animation: fade 0.25s ease; }
.panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 16px; padding: 18px; box-shadow: var(--shadow);
}

/* ---------- Loader ---------- */
.loader-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(11,15,23,0.85);
  backdrop-filter: blur(10px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  transition: opacity 0.3s ease;
}
.loader-overlay.hidden { display: none; }
:root[data-theme="light"] .loader-overlay { background: rgba(244,246,251,0.9); }

.spinner-ring {
  width: 44px; height: 44px; border-radius: 50%;
  border: 3px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-text { font-size: 14px; font-weight: 600; color: var(--text-dim); }

/* ---------- Calc ---------- */
.calc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 760px) { .calc-grid { grid-template-columns: 1fr; } }

.calc-form h2 { margin-bottom: 14px; font-size: 18px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }

input[type="text"], input[type="number"], input[type="search"], select {
  width: 100%; padding: 11px 12px; background: var(--card-2);
  border: 1px solid var(--border-strong); border-radius: 10px;
  color: var(--text); font-family: inherit; font-size: 15px; font-weight: 600; outline: none; transition: border-color 0.15s;
}
input:focus, select:focus { border-color: var(--accent); }
input::placeholder { color: var(--text-dim); font-weight: 500; }

.select-wrap { position: relative; }
.select-wrap .chev { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--text-dim); pointer-events: none; }
.select-wrap select { appearance: none; padding-right: 32px; }
.select-wrap input { padding-right: 32px; }

.input-with-unit { position: relative; display: flex; align-items: center; }
.input-with-unit input { padding-right: 48px; }
.input-with-unit .unit {
  position: absolute; right: 12px;
  font-family: 'JetBrains Mono', monospace; font-size: 13px; font-weight: 700;
  color: var(--accent-2); pointer-events: none;
}

.quick { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.quick button {
  font-family: inherit; font-size: 12px; font-weight: 700;
  padding: 6px 10px; background: var(--card-2); border: 1px solid var(--border-strong);
  color: var(--text-dim); border-radius: 8px; cursor: pointer; transition: all 0.15s;
}
.quick button:hover { color: var(--text); border-color: var(--accent); background: rgba(255,107,157,0.08); }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .row2 { grid-template-columns: 1fr; } }

#add-stack { width: 100%; margin-top: 6px; }

/* ---------- Result ---------- */
.calc-result {
  display: flex; flex-direction: column; gap: 14px;
  background: linear-gradient(180deg, var(--card), var(--card-2));
}
.vial-stage { display: flex; justify-content: center; padding: 8px 0 4px; }
#vial-svg { width: 140px; height: 240px; color: var(--text); filter: drop-shadow(0 12px 24px rgba(0,0,0,0.25)); }

.result-block {
  background: var(--card-2); border: 1px solid var(--border); border-radius: 14px; padding: 16px;
}
.result-big { text-align: center; padding: 8px 0 14px; border-bottom: 1px dashed var(--border); margin-bottom: 14px; }
.result-num {
  font-family: 'JetBrains Mono', monospace; font-size: 44px; font-weight: 700; line-height: 1;
  background: var(--accent-grad); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.result-lbl { font-size: 13px; color: var(--text-dim); font-weight: 600; margin-top: 4px; text-transform: uppercase; letter-spacing: 0.05em; }

.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.result-grid > div { display: flex; justify-content: space-between; align-items: baseline; }
.rk { font-size: 12px; color: var(--text-dim); }
.rv { font-family: 'JetBrains Mono', monospace; font-size: 13px; font-weight: 700; color: var(--text); }

.warning {
  margin-top: 14px; padding: 12px 14px;
  background: rgba(255,107,107,0.10); border: 1px solid rgba(255,107,107,0.35);
  border-radius: 10px; display: flex; gap: 10px; align-items: flex-start;
  color: var(--text); font-size: 13px; line-height: 1.5;
}
.warning svg { color: var(--danger); flex-shrink: 0; margin-top: 1px; }
.warning strong { color: var(--danger); }
.hidden { display: none !important; }

/* ---------- Syringe vis ---------- */
.syringe-vis {
  position: relative; height: 38px;
  background: var(--card-2); border: 1px solid var(--border-strong);
  border-radius: 19px; overflow: hidden; margin-top: 4px; margin-bottom: 20px;
}
.syr-grad {
  position: absolute; inset: 0;
  background: repeating-linear-gradient(90deg, transparent 0, transparent 9px, rgba(255,255,255,0.04) 9px, rgba(255,255,255,0.04) 10px);
}
.syr-fill {
  position: absolute; left: 0; top: 0; bottom: 0; width: 0%;
  border-radius: 19px 0 0 19px; transition: width 0.3s ease;
  box-shadow: inset 0 0 8px rgba(255,255,255,0.2);
}
.syr-marks { position: absolute; inset: 0; pointer-events: none; }
.mark {
  position: absolute; top: 0; bottom: 0; width: 1px;
  background: rgba(255,255,255,0.18);
}
.mark.big { background: rgba(255,255,255,0.35); }
.mark span {
  position: absolute; bottom: -16px; left: 50%; transform: translateX(-50%);
  font-family: 'JetBrains Mono', monospace; font-size: 9px; color: var(--text-dim); white-space: nowrap;
}

/* ---------- Library ---------- */
.lib-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.lib-head h2 { font-size: 20px; flex-shrink: 0; }
.lib-head input[type="search"] { flex: 1; min-width: 200px; max-width: 340px; }
.lib-cats { display: flex; gap: 6px; flex-wrap: wrap; width: 100%; }
.chip {
  padding: 6px 12px; background: var(--card); border: 1px solid var(--border-strong);
  color: var(--text-dim); border-radius: 999px; font-size: 13px; font-weight: 600; cursor: pointer; transition: all 0.15s;
}
.chip.active { background: var(--accent-grad); color: #fff; border-color: transparent; }
.chip:hover:not(.active) { color: var(--text); border-color: var(--accent); }

.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.lib-card { position: relative; padding: 16px; }
.lib-tag {
  display: inline-block; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  padding: 3px 8px; background: rgba(79,209,197,0.14); color: var(--accent-2); border-radius: 6px; margin-bottom: 8px;
}
.lib-card h3 { font-size: 17px; margin-bottom: 10px; }
.lib-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.lib-meta > div { display: flex; flex-direction: column; }
.lib-meta span { font-size: 11px; color: var(--text-dim); }
.lib-meta b { font-size: 13px; font-family: 'JetBrains Mono', monospace; }
.lib-doses { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.dose-pill {
  padding: 6px 10px; background: var(--card-2); border: 1px solid var(--border-strong);
  color: var(--text); border-radius: 8px; font-size: 12px; font-weight: 700;
  font-family: 'JetBrains Mono', monospace; cursor: pointer; transition: all 0.15s;
}
.dose-pill:hover { border-color: var(--accent); background: rgba(255,107,157,0.10); transform: translateY(-1px); }
.lib-note { font-size: 12px; color: var(--text-dim); margin: 0; line-height: 1.5; }

/* ---------- Stack ---------- */
.stack-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 8px; }
.stack-head h2 { font-size: 20px; }
.stack-stats { display: flex; gap: 16px; font-size: 13px; color: var(--text-dim); }
.stack-stats b { color: var(--text); font-family: 'JetBrains Mono', monospace; }

.stack-list { display: flex; flex-direction: column; gap: 12px; }
.stack-item { display: flex; align-items: stretch; overflow: hidden; padding: 0; }
.si-color { width: 6px; background: var(--c); flex-shrink: 0; }
.si-main { flex: 1; padding: 14px 14px 14px 16px; }
.si-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.si-head h3 { font-size: 16px; }
.si-cat { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent-2); }
.si-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px 12px; }
.si-grid > div { display: flex; flex-direction: column; }
.si-grid span { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.si-grid b { font-size: 13px; font-family: 'JetBrains Mono', monospace; }
.si-grid b.warn { color: var(--danger); }
.si-warn { margin-top: 8px; font-size: 12px; color: var(--danger); }
.si-actions { display: flex; flex-direction: column; gap: 4px; padding: 12px; }
.si-actions button {
  width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
  background: var(--card-2); border: 1px solid var(--border-strong); border-radius: 8px;
  color: var(--text-dim); cursor: pointer; transition: all 0.15s;
}
.si-actions button:hover { color: var(--text); }
.si-edit:hover { border-color: var(--accent); color: var(--accent); }
.si-del:hover { border-color: var(--danger); color: var(--danger); }

.empty { text-align: center; padding: 50px 20px; color: var(--text-dim); }
.empty svg { opacity: 0.4; margin-bottom: 12px; }
.empty p { margin: 0; font-size: 14px; }

/* ---------- Schedule ---------- */
.sched-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.sched-head h2 { font-size: 20px; }
.sched-legend { display: flex; gap: 10px; flex-wrap: wrap; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text-dim); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; }

.sched-cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; margin-bottom: 18px; }
@media (max-width: 720px) { .sched-cal { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 420px) { .sched-cal { grid-template-columns: 1fr; } }
.day-cell {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px; min-height: 110px; display: flex; flex-direction: column;
}
.day-cell.none { opacity: 0.55; }
.day-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; padding-bottom: 6px; border-bottom: 1px dashed var(--border); }
.day-name { font-size: 12px; font-weight: 700; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }
.day-total { font-size: 12px; font-weight: 700; font-family: 'JetBrains Mono', monospace; color: var(--accent); }
.day-cell.none .day-total { color: var(--text-dim); }
.day-items { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.day-item {
  display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: 6px;
  font-size: 12px; padding: 5px 6px; background: var(--card-2); border-left: 3px solid var(--c); border-radius: 6px;
}
.di-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.di-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.di-dose { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--text-dim); }
.rest-tag { font-size: 11px; color: var(--text-dim); font-style: italic; align-self: center; margin-top: auto; }

.chart-card { padding: 16px; }
.chart-card h3 { font-size: 14px; color: var(--text-dim); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.05em; }
#week-chart { width: 100%; height: 220px; color: var(--text); }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(5,8,14,0.6); backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 100; animation: fade 0.18s ease;
}
.modal-card {
  background: var(--card); border: 1px solid var(--border-strong); border-radius: 18px;
  padding: 22px; max-width: 460px; width: 100%; box-shadow: var(--shadow);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.modal-head h3 { font-size: 18px; }
.x {
  width: 36px; height: 36px; background: var(--card-2); border: 1px solid var(--border-strong);
  border-radius: 8px; color: var(--text-dim); cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.x:hover { color: var(--text); }
.modal-sub { font-size: 13px; color: var(--text-dim); margin: 0 0 18px; line-height: 1.55; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.modal-actions > * { flex: 1; min-width: 130px; }
.file-btn { position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 16px; }
.danger-ghost {
  background: transparent; border: 1px solid rgba(255,107,107,0.4); color: var(--danger);
  padding: 12px 16px; border-radius: 10px; font-family: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
}
.danger-ghost:hover { background: rgba(255,107,107,0.10); }
.backup-status { margin-top: 14px; font-size: 13px; font-weight: 600; padding: 0; min-height: 0; }
.backup-status.ok { color: var(--accent-2); }
.backup-status.err { color: var(--danger); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--card); border: 1px solid var(--border-strong); color: var(--text);
  padding: 12px 18px; border-radius: 12px; font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow); z-index: 200; animation: toastIn 0.25s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

@media (max-width: 480px) {
  .appbar { padding: 12px; }
  .brand .tag { display: none; }
  .actions button span { display: none; }
  main { padding: 12px; }
  .result-num { font-size: 36px; }
  .calc-form, .calc-result { padding: 14px; }
}

