/* ─── Reset & tokens ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  /* Warm, low-contrast dark palette — easier on the eyes than github-dark */
  --bg:       #1a1d23;   /* warm charcoal, slight blue undertone */
  --bg2:      #1f232a;   /* sidebar/topbar — slightly lighter than main bg */
  --surface:  #252a32;   /* cards */
  --surface2: #2d333d;   /* hover/inputs */
  --surface3: #363c47;   /* highest elevation */
  --border:   #353b46;   /* soft dividers */
  --border2:  #424956;
  /* Softer accents — less retina-burning */
  --accent:   #6aa3f0;   /* gentler than #2f81f7 — lower saturation */
  --accent2:  #4d8bd9;
  --accent3:  #88b8f4;
  --green:    #7cc78a;   /* desaturated */
  --green2:   #6ab878;
  --yellow:   #e3b664;   /* warm amber instead of yellow */
  --red:      #e88072;   /* coral instead of red — less alarming */
  --purple:   #b89cf0;
  --teal:     #74c8d0;
  --pink:     #d589b3;
  /* Text — warm off-white, not pure white */
  --text:     #d8d4cf;   /* warm off-white, easier than #e6edf3 */
  --text2:    #a39d94;   /* warm gray */
  --text3:    #756f66;   /* muted warm gray */
  --r: 8px;
  --r-sm: 6px;
  --r-lg: 12px;
  --shadow: 0 4px 14px rgba(0,0,0,.25);
  --sidebar-w: 240px;
}

html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "SF Pro Text", "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;          /* up from 14 */
  line-height: 1.6;         /* up from 1.5 — more breathing room */
  letter-spacing: 0.01em;   /* subtle tracking helps readability */
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent3); }

/* ─── Sidebar ────────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 50;
}
.brand {
  padding: 18px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}
.brand-icon {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  box-shadow: 0 0 16px rgba(106,163,240,.25);
}
.brand-name { font-size: 16px; font-weight: 700; letter-spacing: -.2px; }
.brand-sub { font-size: 10px; color: var(--text3); text-transform: uppercase; letter-spacing: .8px; margin-top: 1px; }

.nav { flex: 1; overflow-y: auto; padding: 12px 8px; }
.nav-section {
  font-size: 10px;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 14px 10px 6px;
  font-weight: 600;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--r-sm);
  color: var(--text2);
  font-size: 13px;
  margin-bottom: 1px;
  transition: all .15s;
  position: relative;
}
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active {
  background: var(--surface2);
  color: var(--text);
  box-shadow: inset 3px 0 0 var(--accent);
}
.nav-icon { font-size: 14px; opacity: .9; }
.badge {
  margin-left: auto;
  font-size: 9px;
  padding: 1px 6px;
  background: var(--surface3);
  border-radius: 8px;
  color: var(--text3);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); }
.model-status-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: border-color .2s;
}
.model-status-card:hover { border-color: var(--accent); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text3); flex-shrink: 0; }
.dot.green { background: var(--green); box-shadow: 0 0 8px var(--green); }
.dot.yellow { background: var(--yellow); box-shadow: 0 0 8px var(--yellow); animation: pulse 1.5s infinite; }
.dot.red { background: var(--red); }
@keyframes pulse { 50% { opacity: .4; } }
.model-status-label { font-size: 12px; font-weight: 600; }
.model-status-sub { font-size: 10px; color: var(--text3); }

/* ─── Main area ──────────────────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.topbar {
  padding: 16px 24px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}
.topbar-title { display: flex; align-items: center; gap: 14px; }
.topbar-icon {
  font-size: 24px;
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface);
  border-radius: var(--r);
}
.topbar h1 { font-size: 18px; font-weight: 700; }
.topbar-sub { font-size: 12px; color: var(--text2); margin-top: 2px; }
.topbar-actions { display: flex; gap: 10px; }

.content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* ─── Cards & form elements ──────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
}
.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: .5px;
  display: flex; align-items: center; gap: 8px;
  justify-content: space-between;
}
.card-body { padding: 18px; }

label { font-size: 13px; color: var(--text2); display: block; margin-bottom: 6px; font-weight: 500; }
textarea, input[type=text], input[type=number], select {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  color: var(--text);
  font-family: "JetBrains Mono", "SF Mono", monospace;
  font-size: 14px;          /* up from 13 */
  padding: 11px 13px;       /* slightly more padding */
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  line-height: 1.5;
}
textarea:focus, input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(106,163,240,.18);
}
textarea { resize: vertical; min-height: 80px; font-family: "SF Mono", "JetBrains Mono", monospace; }
select { font-family: inherit; cursor: pointer; }

/* Monospace SMILES strings need to be readable, not glaring */
.smiles-mono, code, pre {
  color: var(--text2) !important;
  background: var(--bg2);
}

.btn {
  padding: 10px 16px;
  border: none;
  border-radius: var(--r);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent2); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--surface3); border-color: var(--border2); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text2); }
.btn-outline:hover { border-color: var(--accent); color: var(--text); }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ─── Coming Soon module ─────────────────────────────────────────── */
.coming-soon {
  max-width: 600px;
  margin: 60px auto;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 60px 40px;
}
.coming-soon-icon { font-size: 56px; margin-bottom: 16px; }
.coming-soon h2 { font-size: 22px; margin-bottom: 8px; }
.coming-soon p { color: var(--text2); margin-bottom: 24px; }
.coming-soon-features {
  text-align: left;
  background: var(--bg);
  border-radius: var(--r);
  padding: 18px;
  margin-bottom: 20px;
}
.coming-soon-features h4 { font-size: 12px; color: var(--text2); text-transform: uppercase; margin-bottom: 10px; letter-spacing: .5px; }
.coming-soon-features ul { list-style: none; }
.coming-soon-features li {
  padding: 6px 0;
  color: var(--text);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.coming-soon-features li::before { content: "→"; color: var(--accent); }

/* ─── Toast ──────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 12px 16px;
  font-size: 13px;
  z-index: 999;
  transform: translateY(80px);
  opacity: 0;
  transition: all .3s;
  max-width: 320px;
  box-shadow: var(--shadow);
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { border-color: var(--green); color: var(--green); }
.toast.error { border-color: var(--red); color: var(--red); }

/* ─── Layout helpers ─────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 380px 1fr; gap: 20px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 10px; }
.muted { color: var(--text2); font-size: 12px; }

/* ─── Synthesis-specific (planner) ───────────────────────────────── */
.valid-badge {
  position: absolute;
  right: 10px; top: 10px;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 700;
  pointer-events: none;
}
.valid-badge.ok { background: rgba(63,185,80,.15); color: var(--green); }
.valid-badge.err { background: rgba(248,81,73,.15); color: var(--red); }

.mol-preview {
  background: #fff;
  border-radius: var(--r);
  display: flex; align-items: center; justify-content: center;
  min-height: 160px;
  margin-top: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.mol-preview svg { max-width: 100%; }
.mol-placeholder { color: #aaa; font-size: 12px; padding: 24px; text-align: center; }

.examples-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 8px;
}
.ex-chip {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 8px 10px;
  cursor: pointer;
  transition: all .15s;
  font-size: 12px;
}
.ex-chip:hover { border-color: var(--accent); background: var(--surface2); }
.ex-chip .ex-name { font-weight: 600; color: var(--text); font-size: 12px; }
.ex-chip .ex-desc { color: var(--text3); font-size: 10px; margin-top: 1px; }

.smiles-row { position: relative; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text2); }
.empty-state .icon { font-size: 52px; margin-bottom: 14px; opacity: .6; }
.empty-state h3 { color: var(--text); font-size: 17px; margin-bottom: 8px; font-weight: 600; }
.empty-state p { color: var(--text2); font-size: 14px; }

.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-box {
  background: rgba(248,81,73,.1);
  border: 1px solid var(--red);
  border-radius: var(--r);
  padding: 14px 16px;
  color: var(--red);
  font-size: 13px;
}

.hero-mol {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
}
.hero-mol-img {
  background: #fff;
  border-radius: var(--r-sm);
  width: 220px; height: 150px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.hero-mol-img svg { max-width: 100%; max-height: 100%; }
.hero-mol-info { flex: 1; }
.hero-mol-info h2 { font-size: 18px; margin-bottom: 6px; }
.smiles-mono {
  font-family: monospace;
  font-size: 11px;
  color: var(--text2);
  word-break: break-all;
  background: var(--bg);
  padding: 6px 8px;
  border-radius: 4px;
  margin-bottom: 8px;
}

.tag {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
  margin-right: 4px;
}
.tag-demo { background: rgba(210,153,34,.15); color: var(--yellow); }
.tag-real { background: rgba(63,185,80,.15); color: var(--green); }
.tag-mode { background: rgba(57,197,207,.15); color: var(--teal); }

.step-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
  margin-bottom: 10px;
}
.step-header {
  background: var(--surface2);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}
.step-num {
  background: var(--accent);
  color: #fff;
  width: 22px; height: 22px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.step-rxn {
  font-family: monospace;
  font-size: 12px;
  color: var(--teal);
  flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  opacity: .85;
}
.step-body { padding: 14px 16px; }
.reactants-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.mol-card {
  background: #fff;
  border-radius: var(--r-sm);
  width: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  flex-shrink: 0;
}
.mol-card svg { width: 120px; height: 90px; }
.mol-card .mol-label {
  font-size: 9px;
  color: #555;
  text-align: center;
  padding: 3px 4px;
  word-break: break-all;
  background: #f0f0f0;
  width: 100%;
  font-family: monospace;
}
.mol-card.product { border: 2px solid var(--green); }
.arrow { font-size: 20px; color: var(--accent); flex-shrink: 0; }
.rxn-label {
  font-size: 12px;
  font-family: monospace;
  color: var(--purple);
  background: rgba(184,156,240,.08);
  padding: 5px 10px;
  border-radius: 4px;
  margin-bottom: 8px;
  display: inline-block;
  opacity: .9;
}
.bb-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.bb-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 6px 10px;
  font-family: monospace;
  font-size: 11px;
  color: var(--green);
}

/* History table */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--r);
  overflow: hidden;
}
.table th, .table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.table th {
  background: var(--surface2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text2);
  font-weight: 600;
}
.table tr:hover { background: var(--surface2); }
.table tr:last-child td { border-bottom: none; }

/* Settings */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.setting-row:last-child { border: none; }
.setting-label { font-weight: 600; font-size: 13px; }
.setting-desc { font-size: 12px; color: var(--text2); margin-top: 2px; }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border2); }

/* ─── LIGHT THEME (toggle via body.theme-light) ────────────────────── */
body.theme-light {
  --bg:       #faf8f3;   /* warm cream, not pure white */
  --bg2:      #f1ede5;   /* sidebar */
  --surface:  #ffffff;
  --surface2: #f5f1eb;
  --surface3: #ebe5dc;
  --border:   #ddd6cb;
  --border2:  #c8bfb1;
  --accent:   #4d8bd9;
  --accent2:  #3a72bc;
  --accent3:  #5a9ce8;
  --green:    #4a9056;
  --green2:   #3e7b48;
  --yellow:   #b58940;
  --red:      #c95a4a;
  --purple:   #7a5fbf;
  --teal:     #4a9fa8;
  --text:     #2d2920;   /* warm dark, not black */
  --text2:    #6b6359;
  --text3:    #948b7c;
}

/* ─── SEPIA / READING MODE (toggle via body.theme-sepia) ──────────── */
body.theme-sepia {
  --bg:       #2a2520;   /* sepia dark — like e-reader */
  --bg2:      #2f2a24;
  --surface:  #36302a;
  --surface2: #3e372f;
  --surface3: #463e35;
  --border:   #4a4239;
  --border2:  #5a4f44;
  --accent:   #c98f5a;   /* warm amber accent */
  --accent2:  #b07d4a;
  --accent3:  #d8a472;
  --green:    #9bb578;
  --yellow:   #d4b76a;
  --red:      #d68073;
  --text:     #e8dcc6;   /* warm parchment */
  --text2:    #b0a08a;
  --text3:    #82755f;
}

/* Theme switcher chip */
.theme-toggle {
  display: flex;
  gap: 4px;
  padding: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r);
  margin-top: 8px;
}
.theme-toggle button {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text2);
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--r-sm);
  font-size: 12px;
  font-family: inherit;
  transition: all .15s;
}
.theme-toggle button:hover { background: var(--surface); color: var(--text); }
.theme-toggle button.active { background: var(--accent); color: #fff; font-weight: 600; }

@media (max-width: 980px) {
  .sidebar { width: 60px; }
  .brand-name, .brand-sub, .nav-section, .nav-item span:not(.nav-icon):not(.badge), .badge, .sidebar-footer { display: none; }
  .nav-item { justify-content: center; }
  .main { margin-left: 60px; }
  .grid-2 { grid-template-columns: 1fr; }
}
