/* ─── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #1a1a2e;
  --bg2:         #16213e;
  --bg3:         #0f3460;
  --surface:     #1e2a45;
  --surface2:    #253350;
  --border:      #2d4070;
  --text:        #e0e6f0;
  --text-muted:  #8899bb;
  --accent:      #4a9eff;
  --accent-dim:  #2d6fcc;
  --green:       #2ecc71;
  --red:         #e74c3c;
  --yellow:      #f39c12;
  --heart:       #e74c3c;
  --diamond:     #e74c3c;
  --club:        #e0e6f0;
  --spade:       #e0e6f0;
  --radius:      6px;
  --radius-lg:   12px;
  --font:        'Segoe UI', system-ui, sans-serif;
  --font-mono:   'Cascadia Code', 'Fira Code', monospace;
}

html { height: 100%; }
body {
  font-family: var(--font);
  background:  var(--bg);
  color:       var(--text);
  height:      100%;
  display:     flex;
  flex-direction: column;
}

/* ─── Layout ──────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

#topbar {
  background:    var(--bg2);
  border-bottom: 1px solid var(--border);
  padding:       0.6rem 1.2rem;
  display:       flex;
  align-items:   center;
  gap:           1rem;
}

#topbar h1 {
  font-size: 1.1rem;
  color: var(--accent);
  flex: 1;
}
#topbar h1 span { color: var(--text-muted); font-weight: 400; }

#system-name-display {
  font-size: 0.9rem;
  color: var(--text-muted);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#nav {
  display: flex;
  gap: 0.25rem;
}

#nav button {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.15s;
}
#nav button:hover   { border-color: var(--border); color: var(--text); }
#nav button.active  { background: var(--bg3); border-color: var(--accent); color: var(--accent); }

#main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

#sidebar {
  width: 240px;
  min-width: 180px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

#sidebar-header {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#content {
  flex: 1;
  overflow-y: auto;
  padding: 1.2rem;
}

/* ─── Panels (views) ──────────────────────────────────────────────────────── */
.panel { display: none; }
.panel.active { display: block; }

/* ─── Bid tree ────────────────────────────────────────────────────────────── */
.bid-tree { font-size: 0.9rem; }

.bid-node {
  display: flex;
  flex-direction: column;
}

.bid-node-header {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.1s;
}
.bid-node-header:hover { background: var(--surface); }
.bid-node-header.selected { background: var(--bg3); }

.bid-node-children {
  margin-left: 1.5rem;
  border-left: 1px solid var(--border);
  padding-left: 0.75rem;
  margin-top: 0.1rem;
}
.bid-node-children.collapsed { display: none; }

.call-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.1em;
  font-weight: 600;
  min-width: 3em;
}
.call-pass     { color: var(--text-muted); }
.call-double   { color: var(--yellow); font-weight: 700; }
.call-redouble { color: var(--green);  font-weight: 700; }
.call-bid      { }
.suit-club     { color: var(--club);    }
.suit-spade    { color: var(--spade);   }
.suit-heart    { color: var(--heart);   }
.suit-diamond  { color: var(--diamond); }
.suit-nt       { color: var(--accent);  }

.bid-meaning {
  color: var(--text-muted);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 420px;
}

.bid-tags {
  display: flex;
  gap: 0.3rem;
  margin-left: auto;
}
.tag {
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 99px;
  background: var(--bg3);
  color: var(--text-muted);
}
.tag-alert   { background: #5a2020; color: #f99; }
.tag-gf      { background: #1a3a20; color: #7f7; }
.tag-forcing { background: #1a2a40; color: #7af; }
.tag-tbd     { background: #3a3a20; color: #cc8; }

/* ─── Detail panel ────────────────────────────────────────────────────────── */
#detail-panel {
  width: 340px;
  min-width: 260px;
  background: var(--bg2);
  border-left: 1px solid var(--border);
  padding: 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.detail-section { display: flex; flex-direction: column; gap: 0.4rem; }
.detail-section h3 {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.3rem;
}

.hcp-range {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--accent);
  font-family: var(--font-mono);
}

.variants-list { display: flex; flex-direction: column; gap: 0.5rem; }
.variant-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.65rem;
  font-size: 0.82rem;
}
.variant-condition {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.competitive-list { display: flex; flex-direction: column; gap: 0.4rem; }
.competitive-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.4rem 0.65rem;
  font-size: 0.82rem;
  cursor: pointer;
}
.competitive-item:hover { border-color: var(--accent); }

.intervention-label {
  color: var(--yellow);
  font-weight: 600;
  font-size: 0.8rem;
}

/* ─── Resolved nodes table ────────────────────────────────────────────────── */
.resolved-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.resolved-table th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 500;
  padding: 0.2rem 0.4rem;
  border-bottom: 1px solid var(--border);
}
.resolved-table td { padding: 0.25rem 0.4rem; vertical-align: top; }
.resolved-table tr:hover td { background: var(--surface); }

.status-inherited { opacity: 0.6; }
.status-added     td:first-child::before { content: '✦ '; color: var(--green); }
.status-overridden .old-meaning { text-decoration: line-through; color: var(--text-muted); font-size: 0.78rem; }
.status-removed   { opacity: 0.35; }
.status-removed   td:first-child::before { content: '✕ '; color: var(--red); }

/* ─── Forms / Editor ─────────────────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.75rem;
}
.form-group label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
input[type=text], input[type=number], textarea, select {
  background:   var(--surface);
  border:       1px solid var(--border);
  color:        var(--text);
  border-radius: var(--radius);
  padding:      0.45rem 0.6rem;
  font-size:    0.9rem;
  font-family:  var(--font);
  width:        100%;
  transition:   border-color 0.15s;
}
input:focus, textarea:focus, select:focus {
  outline:      none;
  border-color: var(--accent);
}
textarea { resize: vertical; min-height: 80px; }

/* ─── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.85rem;
  font-family: var(--font);
  transition: all 0.15s;
  background: var(--surface);
  color: var(--text);
}
.btn:hover   { border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--accent-dim); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent); }
.btn-danger  { border-color: var(--red); color: var(--red); }
.btn-danger:hover  { background: var(--red); color: #fff; }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.78rem; }
.btn-icon { padding: 0.25rem 0.4rem; font-size: 1rem; border: none; background: transparent; color: var(--text-muted); }
.btn-icon:hover { color: var(--accent); }

/* ─── Modals ──────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  min-width: 360px;
  max-width: 560px;
  width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
}
.modal h2 { font-size: 1.1rem; margin-bottom: 1rem; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

/* ─── Sequence bar ────────────────────────────────────────────────────────── */
#sequence-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9rem;
}
.seq-call { color: var(--text); font-weight: 500; }
.seq-intervention { color: var(--yellow); }
.seq-separator { color: var(--text-muted); }

/* ─── Context picker ─────────────────────────────────────────────────────── */
#context-bar {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0.4rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}
#context-bar label { display: flex; align-items: center; gap: 0.4rem; }
#context-bar select { width: auto; padding: 0.2rem 0.4rem; font-size: 0.8rem; }

/* ─── Scroll & misc ──────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.hidden { display: none !important; }
.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 1rem;
  font-size: 0.9rem;
}
.empty-state .big { font-size: 2.5rem; margin-bottom: 0.5rem; }

.flash {
  position: fixed; bottom: 1rem; right: 1rem;
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  z-index: 200;
  animation: fadeout 3s forwards;
}
.flash-ok  { background: #1a4a2a; border: 1px solid var(--green); color: var(--green); }
.flash-err { background: #4a1a1a; border: 1px solid var(--red);   color: var(--red);   }
@keyframes fadeout { 0%{opacity:1} 70%{opacity:1} 100%{opacity:0;pointer-events:none} }
