/* ============================================================
   RushChess — application shell & component styles
   Structured panels, splitters, toolbars, menus. IDE-like.
   ============================================================ */

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

html, body { height: 100%; }
body {
  font-family: var(--font-ui);
  font-size: var(--fs-13);
  line-height: var(--lh-body);
  color: var(--text);
  background: var(--bg-app);
  overflow: hidden;
  user-select: none;
}
::selection { background: var(--accent); color: #fff; }

*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 5px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-corner { background: transparent; }

.ic { width: 16px; height: 16px; flex: none; display: block; }
.ic-sm { width: 13px; height: 13px; }

:focus { outline: none; }
:focus-visible { outline: 1.5px solid var(--focus-ring); outline-offset: 1px; }

/* ============ app frame ============ */
.app {
  display: grid;
  grid-template-columns: 44px 1fr;
  grid-template-rows: 34px 1fr 22px;
  grid-template-areas: "rail titlebar" "rail main" "rail statusbar";
  height: 100vh;
}

/* ---- mode rail ---- */
.rail {
  grid-area: rail;
  background: var(--bg-app);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center;
  padding: 6px 0; gap: 2px; z-index: var(--z-toolbar);
}
.rail-btn {
  width: 34px; height: 34px; border: none; background: none; color: var(--text-faint);
  border-radius: var(--rad-1); display: grid; place-items: center; cursor: pointer;
  position: relative;
}
.rail-btn:hover { background: var(--bg-hover); color: var(--text-secondary); }
.rail-btn.active { color: var(--text); background: var(--bg-active); }
.rail-btn.active::before {
  content: ''; position: absolute; left: -5px; top: 8px; bottom: 8px; width: 2px;
  background: var(--accent); border-radius: 1px;
}
.rail-spacer { flex: 1; }

/* ---- title bar ---- */
.titlebar {
  grid-area: titlebar;
  display: flex; align-items: stretch;
  background: var(--bg-app);
  border-bottom: 1px solid var(--border);
  z-index: var(--z-toolbar);
}
.menubar { display: flex; align-items: stretch; }
.menubar-item {
  border: none; background: none; color: var(--text-secondary);
  padding: 0 10px; font-size: var(--fs-13); cursor: pointer; font-family: inherit;
}
.menubar-item:hover, .menubar-item.open { background: var(--bg-hover); color: var(--text); }
.titlebar-title {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: var(--text-faint); font-size: var(--fs-12); gap: 8px; min-width: 0;
  overflow: hidden; white-space: nowrap;
}
.titlebar-actions { display: flex; align-items: center; gap: 2px; padding: 0 8px; }

/* ---- tab strip (documents) ---- */
.tabstrip {
  display: flex; align-items: stretch; overflow-x: auto; scrollbar-width: none;
  background: var(--bg-app); border-bottom: 1px solid var(--border); height: 30px;
}
.tabstrip::-webkit-scrollbar { display: none; }
.doc-tab {
  display: flex; align-items: center; gap: 6px; padding: 0 10px;
  border: none; border-right: 1px solid var(--border); background: none;
  color: var(--text-secondary); font-size: var(--fs-12); font-family: inherit;
  cursor: pointer; white-space: nowrap; max-width: 200px;
}
.doc-tab:hover { background: var(--bg-hover); }
.doc-tab.active { background: var(--bg-panel); color: var(--text); box-shadow: inset 0 2px 0 var(--accent); }
.doc-tab .tab-close { border: none; background: none; color: var(--text-faint); cursor: pointer; border-radius: 2px; padding: 1px; display: grid; place-items: center; }
.doc-tab .tab-close:hover { background: var(--bg-active); color: var(--text); }
.doc-tab-label { overflow: hidden; text-overflow: ellipsis; }
.tab-add { border: none; background: none; color: var(--text-faint); padding: 0 8px; cursor: pointer; }
.tab-add:hover { color: var(--text); background: var(--bg-hover); }

/* ---- main / status ---- */
.main { grid-area: main; position: relative; overflow: hidden; background: var(--bg-app); display: flex; flex-direction: column; }
.mode-root { flex: 1; overflow: hidden; position: relative; }

.statusbar {
  grid-area: statusbar; display: flex; align-items: center; gap: 14px;
  background: var(--bg-app); border-top: 1px solid var(--border);
  padding: 0 10px; font-size: var(--fs-11); color: var(--text-faint);
  white-space: nowrap; overflow: hidden;
}
.statusbar .sb-item { display: flex; align-items: center; gap: 5px; }
.statusbar .sb-item .ic { width: 12px; height: 12px; }
.statusbar .sb-click { cursor: pointer; border-radius: 2px; padding: 1px 5px; }
.statusbar .sb-click:hover { background: var(--bg-hover); color: var(--text-secondary); }
.sb-ok { color: var(--ok-text); }
.sb-err { color: var(--err-text); }
.sb-spacer { flex: 1; }

/* ============ dock layout ============ */
.dock-row { display: flex; height: 100%; width: 100%; overflow: hidden; }
.dock-col { display: flex; flex-direction: column; overflow: hidden; }
.dock-center { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.dock-side { flex: none; display: flex; flex-direction: column; overflow: hidden; background: var(--bg-app); }

.splitter { flex: none; z-index: var(--z-dock); }
.splitter.v { width: 4px; cursor: col-resize; margin: 0 -1.5px; }
.splitter.h { height: 4px; cursor: row-resize; margin: -1.5px 0; }
.splitter:hover, .splitter.dragging { background: var(--accent); opacity: .5; }

/* ---- panel ---- */
.panel {
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
  background: var(--bg-panel); border: 1px solid var(--border);
  overflow: hidden;
}
.dock-side .panel { border-left: none; border-right: none; }
.dock-side .panel + .panel { border-top: none; }
.panel-header {
  flex: none; display: flex; align-items: center; gap: 6px;
  height: 27px; padding: 0 4px 0 9px;
  background: var(--bg-app); border-bottom: 1px solid var(--border);
  font-size: var(--fs-11); font-weight: var(--fw-semibold);
  text-transform: uppercase; letter-spacing: .06em; color: var(--text-secondary);
  cursor: default;
}
.panel-header .ic { width: 13px; height: 13px; color: var(--text-faint); }
.panel-title { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.panel-actions { display: flex; align-items: center; gap: 1px; }
.panel-body { flex: 1; min-height: 0; overflow: auto; position: relative; }
.panel.collapsed .panel-body { display: none; }
.panel.collapsed { flex: none !important; }

.icon-btn {
  border: none; background: none; color: var(--text-faint); border-radius: var(--rad-1);
  width: 22px; height: 22px; display: grid; place-items: center; cursor: pointer; flex: none;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn.active { color: var(--accent-text); background: var(--bg-active); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn:disabled:hover { background: none; color: var(--text-faint); }

/* ============ controls ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--ctl-h); padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: var(--rad-1);
  background: var(--bg-raised); color: var(--text);
  font-family: inherit; font-size: var(--fs-12); font-weight: var(--fw-medium);
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.btn:active { background: var(--bg-active); }
.btn:disabled { opacity: .45; cursor: default; }
.btn:disabled:hover { background: var(--bg-raised); }
.btn .ic { width: 13px; height: 13px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--err-text); border-color: var(--err); }
.btn-danger:hover { background: color-mix(in srgb, var(--err) 12%, transparent); }
.btn-ghost { border-color: transparent; background: none; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-sm { height: 22px; padding: 0 8px; font-size: var(--fs-11); }

.input, .select, textarea.input {
  height: var(--ctl-h); padding: 0 8px;
  border: 1px solid var(--border-strong); border-radius: var(--rad-1);
  background: var(--bg-inset); color: var(--text);
  font-family: inherit; font-size: var(--fs-12);
  user-select: text;
}
textarea.input { height: auto; padding: 6px 8px; resize: vertical; font-family: var(--font-mono); line-height: 1.5; }
.input:focus, .select:focus, textarea.input:focus { border-color: var(--focus-ring); }
.input::placeholder { color: var(--text-faint); }
.select { appearance: none; padding-right: 22px; background-image: linear-gradient(45deg, transparent 50%, var(--text-faint) 50%), linear-gradient(135deg, var(--text-faint) 50%, transparent 50%); background-position: calc(100% - 12px) 55%, calc(100% - 8px) 55%; background-size: 4px 4px; background-repeat: no-repeat; cursor: pointer; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field > label { font-size: var(--fs-11); font-weight: var(--fw-semibold); color: var(--text-secondary); }
.field-row { display: flex; align-items: center; gap: 8px; }

.checkbox { display: flex; align-items: center; gap: 7px; cursor: pointer; font-size: var(--fs-12); color: var(--text); }
.checkbox input { accent-color: var(--accent); width: 14px; height: 14px; cursor: pointer; }

.radio-row { display: flex; gap: 2px; border: 1px solid var(--border-strong); border-radius: var(--rad-1); padding: 2px; background: var(--bg-inset); }
.radio-row .seg {
  flex: 1; border: none; background: none; color: var(--text-secondary);
  height: calc(var(--ctl-h) - 6px); padding: 0 10px; border-radius: 2px;
  font-family: inherit; font-size: var(--fs-12); cursor: pointer; white-space: nowrap;
}
.radio-row .seg:hover { color: var(--text); background: var(--bg-hover); }
.radio-row .seg.active { background: var(--bg-selected); color: var(--text); font-weight: var(--fw-medium); }

input[type="range"].range { accent-color: var(--accent); width: 100%; height: 3px; cursor: pointer; }

/* ============ toolbar ============ */
.toolbar {
  flex: none; display: flex; align-items: center; gap: 4px;
  height: 34px; padding: 0 8px;
  background: var(--bg-panel); border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: none;
}
.toolbar::-webkit-scrollbar { display: none; }
.toolbar-sep { width: 1px; height: 18px; background: var(--border); margin: 0 4px; flex: none; }
.toolbar-spacer { flex: 1; }
.toolbar-label { font-size: var(--fs-11); color: var(--text-faint); padding: 0 4px; white-space: nowrap; }

/* ============ menus ============ */
.menu {
  position: fixed; z-index: var(--z-menu);
  min-width: 180px; max-width: 320px; max-height: 70vh; overflow-y: auto;
  background: var(--bg-raised); border: 1px solid var(--border-strong);
  border-radius: var(--rad-2); box-shadow: var(--shadow-menu);
  padding: 4px;
}
.menu-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 5px 8px; border: none; background: none; border-radius: var(--rad-1);
  color: var(--text); font-family: inherit; font-size: var(--fs-12); text-align: left;
  cursor: pointer; white-space: nowrap;
}
.menu-item:hover:not(:disabled) { background: var(--bg-selected); }
.menu-item:disabled { color: var(--text-faint); cursor: default; }
.menu-item .ic { width: 14px; height: 14px; color: var(--text-faint); }
.menu-item .mi-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.menu-item .mi-kbd { color: var(--text-faint); font-size: var(--fs-11); font-family: var(--font-mono); }
.menu-item.checked .ic { color: var(--accent-text); }
.menu-sep { height: 1px; background: var(--border); margin: 4px 6px; }
.menu-head { padding: 4px 8px 2px; font-size: var(--fs-11); color: var(--text-faint); font-weight: var(--fw-semibold); text-transform: uppercase; letter-spacing: .05em; }

/* ============ dialogs ============ */
.veil {
  position: fixed; inset: 0; z-index: var(--z-dialog);
  background: rgba(0, 0, 0, .45);
  display: grid; place-items: center;
}
.dialog {
  background: var(--bg-raised); border: 1px solid var(--border-strong);
  border-radius: var(--rad-2); box-shadow: var(--shadow-dialog);
  min-width: 340px; max-width: min(720px, 92vw); max-height: 86vh;
  display: flex; flex-direction: column;
}
.dialog-header {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  font-size: var(--fs-14); font-weight: var(--fw-semibold);
}
.dialog-header .icon-btn { margin-left: auto; }
.dialog-body { padding: 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.dialog-footer {
  flex: none; display: flex; justify-content: flex-end; gap: 8px;
  padding: 10px 14px; border-top: 1px solid var(--border);
}

/* ============ command palette ============ */
.palette-veil { position: fixed; inset: 0; z-index: var(--z-palette); background: rgba(0,0,0,.3); }
.palette {
  position: fixed; z-index: var(--z-palette); left: 50%; top: 12vh; transform: translateX(-50%);
  width: min(560px, 92vw);
  background: var(--bg-raised); border: 1px solid var(--border-strong);
  border-radius: var(--rad-2); box-shadow: var(--shadow-dialog); overflow: hidden;
}
.palette-input {
  width: 100%; border: none; background: none; color: var(--text);
  padding: 12px 14px; font-size: var(--fs-14); font-family: inherit;
  border-bottom: 1px solid var(--border); user-select: text;
}
.palette-list { max-height: 46vh; overflow-y: auto; padding: 4px; }
.palette-item {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px;
  border-radius: var(--rad-1); cursor: pointer; font-size: var(--fs-13);
}
.palette-item .ic { color: var(--text-faint); }
.palette-item.sel { background: var(--bg-selected); }
.palette-item .pi-label { flex: 1; }
.palette-item .pi-label b { font-weight: var(--fw-semibold); color: var(--accent-text); }
.palette-item .pi-cat { color: var(--text-faint); font-size: var(--fs-11); }
.palette-item .pi-kbd { color: var(--text-faint); font-family: var(--font-mono); font-size: var(--fs-11); }
.palette-empty { padding: 18px; text-align: center; color: var(--text-faint); }

/* ============ toasts ============ */
.toasts { position: fixed; right: 14px; bottom: 34px; z-index: var(--z-toast); display: flex; flex-direction: column; gap: 8px; }
.toast {
  display: flex; align-items: center; gap: 9px;
  background: var(--bg-raised); border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  border-radius: var(--rad-1); box-shadow: var(--shadow-menu);
  padding: 9px 12px; font-size: var(--fs-12); max-width: 360px;
  animation: toast-in var(--t-med) var(--ease);
}
.toast.err { border-left-color: var(--err); }
.toast.ok { border-left-color: var(--ok); }
.toast.warn { border-left-color: var(--warn); }
@keyframes toast-in { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; } }

/* ============ tables & lists ============ */
.data-table { width: 100%; border-collapse: collapse; font-size: var(--fs-12); user-select: text; }
.data-table th {
  text-align: left; padding: 4px 8px; position: sticky; top: 0;
  background: var(--bg-panel); border-bottom: 1px solid var(--border-strong);
  font-size: var(--fs-11); font-weight: var(--fw-semibold); color: var(--text-secondary);
  cursor: default; white-space: nowrap; z-index: 1;
}
.data-table th.sortable { cursor: pointer; }
.data-table th.sortable:hover { color: var(--text); }
.data-table td { padding: 3px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: var(--bg-hover); }
.data-table tbody tr.sel { background: var(--bg-selected); }

.list-row {
  display: flex; align-items: center; gap: 8px; padding: 0 10px;
  height: var(--row-h); font-size: var(--fs-12); cursor: pointer;
  overflow: hidden; white-space: nowrap;
}
.list-row:hover { background: var(--bg-hover); }
.list-row.sel { background: var(--bg-selected); }

/* ============ states ============ */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 28px 16px; color: var(--text-faint); text-align: center; height: 100%;
}
.empty-state .ic { width: 28px; height: 28px; opacity: .5; }
.empty-state .es-title { font-size: var(--fs-13); font-weight: var(--fw-medium); color: var(--text-secondary); }
.empty-state .es-hint { font-size: var(--fs-12); max-width: 260px; }

.spinner {
  width: 14px; height: 14px; border-radius: 50%; flex: none;
  border: 2px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.badge {
  display: inline-flex; align-items: center; padding: 0 6px; height: 16px;
  border-radius: 8px; font-size: var(--fs-11); font-weight: var(--fw-semibold);
  background: var(--bg-active); color: var(--text-secondary);
}
.badge.acc { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent-text); }

kbd.kbd {
  font-family: var(--font-mono); font-size: var(--fs-11);
  background: var(--bg-inset); border: 1px solid var(--border-strong); border-bottom-width: 2px;
  border-radius: 3px; padding: 0 5px; color: var(--text-secondary);
}

.muted { color: var(--text-secondary); }
.faint { color: var(--text-faint); }
.mono { font-family: var(--font-mono); }
.tnum { font-variant-numeric: tabular-nums; }
.grow { flex: 1; min-width: 0; }
.nowrap { white-space: nowrap; }
.selectable { user-select: text; }

/* eval label coloring */
.ev-pos { color: var(--ok-text); }
.ev-neg { color: var(--err-text); }
