/* =========================================================================
   TotalSnooker Designer - stylesheet
   Design language: dark, precise, "professional graphics tool" register -
   the same register a snooker player already trusts from broadcast
   graphics: baize green accent, brushed charcoal chrome, crisp mono
   numerals for coordinates.
   ========================================================================= */

:root {
  --bg-app:        #14181a;
  --bg-panel:      #1c2123;
  --bg-panel-2:    #21272a;
  --bg-raised:     #262d30;
  --border:        #30383b;
  --border-soft:   #2a3134;
  --text:          #e9ece9;
  --text-muted:    #8fa09a;
  --text-faint:    #61706b;
  --accent:        #1fae72;
  --accent-bright: #4fd1a5;
  --accent-soft:   rgba(79, 209, 165, 0.14);
  --danger:        #e0564d;
  --danger-soft:   rgba(224, 86, 77, 0.14);
  --warn:          #ff8a5c;
  --radius-sm:     6px;
  --radius-md:     10px;
  --font-ui:       'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:     'JetBrains Mono', 'SFMono-Regular', Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg-app);
  color: var(--text);
  font-family: var(--font-ui);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; color: inherit; }
button { cursor: pointer; }
::selection { background: var(--accent-soft); }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
*::-webkit-scrollbar-track { background: transparent; }

/* ============================== App shell ============================== */

#app {
  display: grid;
  grid-template-rows: 52px 1fr 28px;
  height: 100vh;
  width: 100vw;
}

.app-body {
  /* Flex rather than grid: panel widths animate cleanly, and a floating
     panel can drop out of flow so the canvas immediately claims the space. */
  display: flex;
  position: relative;
  min-height: 0;
  overflow: hidden;
}

/* ============================== Top toolbar ============================== */

.top-toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 14px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 6px;
  white-space: nowrap;
}
.brand-text {
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.2px;
}
.brand-version {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-faint);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 5px;
  line-height: 1;
}


.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-left: 12px;
  border-left: 1px solid var(--border-soft);
}
.toolbar-group:first-of-type { border-left: none; padding-left: 0; }
.toolbar-spacer { flex: 1; }

.tbtn {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 500;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  white-space: nowrap;
}
.tbtn:hover { background: #2c3437; border-color: #3a4448; }
.tbtn:active { transform: translateY(1px); }
.tbtn:disabled { opacity: 0.35; cursor: default; pointer-events: none; }
.tbtn.danger:hover { background: var(--danger-soft); border-color: var(--danger); color: #ffb4ae; }
.tbtn.small { padding: 5px 9px; font-size: 11.5px; }
.tbtn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-bright); }

.icon-btn { font-size: 15px; padding: 6px 10px; line-height: 1; }

.zoom-label {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  min-width: 44px;
  text-align: center;
}

.dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 30px rgba(0,0,0,0.45);
  display: none;
  flex-direction: column;
  min-width: 150px;
  overflow: hidden;
  z-index: 50;
}
.dropdown-menu.open { display: flex; }
.dropdown-menu button {
  background: none; border: none; color: var(--text);
  text-align: left; padding: 9px 12px; font-size: 12.5px;
}
.dropdown-menu button:hover { background: var(--accent-soft); color: var(--accent-bright); }

/* ============================== Left toolbox ============================== */

/* ---------------------------- Side panels ---------------------------- */

.side-panel {
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  background: var(--bg-panel);
  min-height: 0;
  transition: width 0.18s ease, opacity 0.14s ease;
  will-change: width;
}
.left-toolbox {
  width: 236px;
  border-right: 1px solid var(--border);
}
.right-panel {
  width: 288px;
  border-left: 1px solid var(--border);
}

.side-panel.collapsed {
  width: 0;
  opacity: 0;
  pointer-events: none;
  border-width: 0;
}

/* A floating panel overlays the canvas rather than shrinking it. */
.side-panel.floating {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 30;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.55);
}
.side-panel.floating.left-toolbox { left: 0; }
.side-panel.floating.right-panel { right: 0; }

.side-panel-body {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  padding: 14px 12px 24px;
}
.left-toolbox .side-panel-body { padding: 14px 12px 24px; }

/* ---- Titlebar ---- */

.panel-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 8px 0 12px;
  height: 32px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg-panel-2);
  white-space: nowrap;
}
.panel-title {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 700;
}
.panel-titlebar-actions { display: flex; gap: 2px; }

.panel-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: none;
  color: var(--text-faint);
  transition: color 0.12s, background 0.12s;
}
.panel-btn svg {
  width: 14px; height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.panel-btn:hover { color: var(--text); background: var(--bg-raised); }
/* The pin reads as engaged when the panel is docked in place. */
.panel-btn.active[data-panel-action="pin"] { color: var(--accent-bright); }
.panel-btn.active[data-panel-action="pin"] svg { fill: currentColor; stroke: none; }

/* ---- Edge rails, shown when a panel is hidden ---- */

.panel-rail {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 64px;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text-faint);
  z-index: 25;
  transition: color 0.12s, background 0.12s;
}
.panel-rail.visible { display: flex; }
.panel-rail:hover { color: var(--accent-bright); background: var(--bg-raised); }
.panel-rail svg {
  width: 12px; height: 12px;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
.rail-left { left: 0; border-left: none; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.rail-right { right: 0; border-right: none; border-radius: var(--radius-sm) 0 0 var(--radius-sm); }

.toolbox-section { margin-bottom: 20px; }
.toolbox-section h3,
.panel-section h3 {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin: 0 0 10px;
  font-weight: 700;
}

.tool-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  background: var(--bg-panel-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 10px 4px 8px;
  color: var(--text-muted);
  transition: all 0.12s;
}
.tool-btn svg {
  width: 20px; height: 20px;
  fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round;
}
.tool-btn span { font-size: 10.5px; font-weight: 500; }
.tool-btn:hover { border-color: var(--border); color: var(--text); background: var(--bg-raised); }
.tool-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-bright);
}

.hint-text {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0 0 10px;
}
.hint-text.small { font-size: 10.8px; margin-bottom: 8px; }

/* Ball library */
.ball-library {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 10px;
}
.ball-swatch {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--bg-panel-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  cursor: grab;
  transition: all 0.12s;
}
.ball-swatch:hover { border-color: var(--accent); background: var(--bg-raised); }
.ball-swatch:active { cursor: grabbing; }
.ball-dot {
  width: 18px; height: 18px; border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0,0,0,0.5), inset 0 0 0 1px rgba(0,0,0,0.25);
  flex-shrink: 0;
}
.ball-swatch-label { font-size: 11px; color: var(--text-muted); }

.ball-quick-actions { display: flex; flex-direction: column; gap: 6px; }
.ball-quick-actions .tbtn { width: 100%; }

/* ============================== Canvas viewport ============================== */

.canvas-viewport {
  position: relative;
  overflow: hidden;
  background: var(--bg-app);
  flex: 1 1 auto;
  min-width: 0;   /* lets the canvas shrink below its content width */
}
#main-canvas {
  display: block;
  width: 100%;
  height: 100%;
}
#main-canvas { cursor: default; }
.canvas-viewport.space-pan #main-canvas,
#main-canvas.space-pan { cursor: grab; }

#text-editor {
  position: absolute;
  display: none;
  background: rgba(20, 24, 26, 0.55);
  border: 1.5px dashed var(--accent-bright);
  outline: none;
  resize: none;
  padding: 2px 4px;
  min-width: 60px;
  min-height: 1.4em;
  line-height: 1.2;
  white-space: pre;
  border-radius: 3px;
}

/* ============================== Right properties panel ============================== */

.properties-panel { padding: 2px 2px 10px; }

.panel-section {
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-soft);
}
.panel-section:last-child { border-bottom: none; }

.panel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
}
.panel-row:last-child { margin-bottom: 0; }
.panel-row label {
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.panel-row input[type="text"],
.panel-row select {
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 5px 7px;
  font-size: 12px;
  max-width: 148px;
  width: 100%;
}
.panel-row select { cursor: pointer; }

.panel-row input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 30px; height: 26px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: none;
  padding: 0;
  cursor: pointer;
}
.panel-row input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
.panel-row input[type="color"]::-webkit-color-swatch { border: none; border-radius: 4px; }

.panel-row input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--accent);
}

.range-wrap { display: flex; align-items: center; gap: 8px; flex: 1; justify-content: flex-end; }
.range-wrap input[type="range"] {
  accent-color: var(--accent);
  width: 100px;
}
.range-value {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  min-width: 34px;
  text-align: right;
}

.segmented {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.segmented button {
  background: var(--bg-panel-2);
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  padding: 5px 9px;
  border-left: 1px solid var(--border);
}
.segmented button:first-child { border-left: none; }
.segmented button.active { background: var(--accent-soft); color: var(--accent-bright); }
.segmented button:hover { color: var(--text); }

.arrange-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 6px;
}
.arrange-buttons button {
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 11.5px;
  padding: 7px 4px;
  border-radius: var(--radius-sm);
}
.arrange-buttons button:hover { background: var(--bg-raised); border-color: var(--accent); }
.arrange-buttons button.danger:hover { background: var(--danger-soft); border-color: var(--danger); color: #ffb4ae; }

.recent-colors { display: flex; flex-wrap: wrap; gap: 6px; }
.color-swatch {
  width: 22px; height: 22px;
  border-radius: 5px;
  border: 1px solid rgba(255,255,255,0.15);
  padding: 0;
}
.color-swatch:hover { outline: 2px solid var(--accent-bright); outline-offset: 1px; }

/* ============================== Status bar ============================== */

.status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}
.status-bar .sep { color: var(--border); }
.status-spacer { flex: 1; }
.status-tip { color: var(--text-faint); font-family: var(--font-ui); font-size: 11px; }
#status-selection { color: var(--accent-bright); }

/* ============================== Responsive ============================== */

@media (max-width: 980px) {
  .left-toolbox { width: 200px; }
  .right-panel { width: 240px; }
  .brand-text { display: none; }
}

/* ============================== Toast ============================== */

.toast {
  position: absolute;
  right: 16px;
  bottom: 16px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  color: var(--text);
  font-size: 12.5px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  max-width: 320px;
}
.toast.visible { opacity: 1; transform: translateY(0); }
.toast.error { border-left-color: var(--danger); color: #ffc9c4; }

/* ============================== Shortcuts card ============================== */

.shortcuts-toggle {
  position: absolute;
  right: 16px;
  top: 16px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.12s;
}
.shortcuts-toggle:hover { color: var(--accent-bright); border-color: var(--accent); }

.shortcuts-card {
  position: absolute;
  right: 16px;
  top: 50px;
  width: 268px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 14px 40px rgba(0,0,0,0.55);
  padding: 14px 16px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
  transition: opacity 0.16s, transform 0.16s, visibility 0.16s;
  z-index: 15;
}
.shortcuts-card.visible { opacity: 1; visibility: visible; transform: translateY(0); }
.shortcuts-card h4 {
  margin: 0 0 10px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}
.shortcuts-card dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 5px 12px;
  font-size: 11.5px;
}
.shortcuts-card dt {
  font-family: var(--font-mono);
  color: var(--accent-bright);
  white-space: nowrap;
}
.shortcuts-card dd { margin: 0; color: var(--text-muted); }

/* ============================== Table picker ============================== */

.table-picker {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}
.table-option {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--bg-panel-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 5px 8px 5px 5px;
  transition: all 0.12s;
  text-align: left;
}
.table-option:hover { border-color: var(--border); background: var(--bg-raised); }
.table-option.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.table-thumb {
  width: 46px;
  height: 25px;
  border-radius: 3px;
  background-size: cover;
  background-position: center;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.35);
  flex-shrink: 0;
}
.table-option-name { font-size: 11.5px; color: var(--text-muted); }
.table-option.active .table-option-name { color: var(--accent-bright); }

.table-actions { margin-bottom: 8px; }
.table-actions .tbtn { width: 100%; }

#table-note { margin: 0; color: var(--text-faint); }
