/* =========================================================
   PAPAN TULIS DIGITAL – style.css
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── CSS Variables ──────────────────────────────────────── */
:root {
  --bg:          #0f0f17;
  --surface:     #1a1a2e;
  --surface2:    #22223b;
  --surface3:    #2d2d50;
  --border:      rgba(255,255,255,0.08);
  --border-hl:   rgba(255,255,255,0.18);
  --text:        #e8e8f0;
  --text-muted:  #8888aa;
  --accent:      #7c3aed;
  --accent-hover:#6d28d9;
  --accent-glow: rgba(124,58,237,0.35);
  --green:       #10b981;
  --red:         #ef4444;
  --canvas-bg:   #ffffff;
  --toolbar-w:   220px;
  --status-h:    40px;
  --radius:      10px;
  --radius-sm:   6px;
  --shadow:      0 4px 24px rgba(0,0,0,0.4);
  --transition:  0.18s cubic-bezier(.4,0,.2,1);
}

[data-theme="light"] {
  --bg:          #f0f0fa;
  --surface:     #ffffff;
  --surface2:    #f4f4fc;
  --surface3:    #e8e8f8;
  --border:      rgba(0,0,0,0.1);
  --border-hl:   rgba(0,0,0,0.2);
  --text:        #1a1a2e;
  --text-muted:  #6666aa;
  --canvas-bg:   #ffffff;
}

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

html, body {
  width: 100%; height: 100%; overflow: hidden;
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ─────────────────────────────────────────────── */
body {
  display: grid;
  grid-template-columns: var(--toolbar-w) 1fr;
  grid-template-rows: 1fr var(--status-h);
  grid-template-areas:
    "sidebar canvas"
    "sidebar status";
}

body.toolbar-hidden {
  grid-template-columns: 0 1fr;
}

/* ── Toolbar / Sidebar ──────────────────────────────────── */
.toolbar {
  grid-area: sidebar;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 12px 10px;
  gap: 4px;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width var(--transition), transform var(--transition);
  position: relative;
  z-index: 10;
  scrollbar-width: thin;
  scrollbar-color: var(--surface3) transparent;
}

.toolbar::-webkit-scrollbar { width: 4px; }
.toolbar::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 4px; }

/* Brand */
.toolbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 2px 8px;
  flex-shrink: 0;
}

.brand-name {
  font-weight: 700;
  font-size: 14px;
  background: linear-gradient(135deg, #a78bfa, #60a5fa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
}

.toolbar-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
  flex-shrink: 0;
}

/* ── Tool Buttons ────────────────────────────────────────── */
.tool-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tool-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  text-align: left;
  width: 100%;
  position: relative;
  overflow: hidden;
}

.tool-btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  transition: transform var(--transition);
}

.tool-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--accent);
  opacity: 0;
  transition: opacity var(--transition);
  border-radius: var(--radius-sm);
}

.tool-btn:hover {
  color: var(--text);
  background: var(--surface2);
}

.tool-btn:hover svg {
  transform: scale(1.1);
}

.tool-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 0 0 2px var(--accent-glow), 0 2px 12px var(--accent-glow);
}

.tool-btn.active svg { transform: scale(1.05); }

/* ── Tool Sections ───────────────────────────────────────── */
.tool-section {
  padding: 6px 2px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  user-select: none;
}

/* ── Color Palette ───────────────────────────────────────── */
.color-palette {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
}

.color-swatch {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}

.color-swatch:hover {
  transform: scale(1.2);
  box-shadow: 0 2px 12px rgba(0,0,0,0.4);
}

.color-swatch.active {
  border-color: #fff;
  box-shadow: 0 0 0 2px var(--accent), 0 2px 12px rgba(0,0,0,0.4);
  transform: scale(1.15);
}

.custom-color-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.color-picker {
  width: 36px;
  height: 28px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 0;
  background: none;
}

/* ── Range Slider ────────────────────────────────────────── */
.range-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 4px;
  background: var(--surface3);
  outline: none;
  cursor: pointer;
}

.range-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 0 3px var(--accent-glow);
  transition: all var(--transition);
}

.range-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 0 0 5px var(--accent-glow);
}

/* Sensitivity slider — blue→green gradient */
.sensitivity-slider-el {
  background: linear-gradient(to right, #2ecc71, #3498db, #9b59b6);
}

.sensitivity-hint {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--accent);
  text-align: right;
  margin-top: -4px;
  letter-spacing: 0.03em;
  transition: color 0.2s;
}

/* Cursor speed slider — orange→red gradient */
.cursor-speed-slider-el {
  background: linear-gradient(to right, #2ecc71, #f39c12, #e74c3c);
}

.cursor-speed-hint {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--accent);
  text-align: right;
  margin-top: -4px;
  letter-spacing: 0.03em;
  transition: color 0.2s;
}

/* ── Toggle Switch ───────────────────────────────────────── */
.toggle-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.toggle-label input { display: none; }

.toggle-switch {
  width: 36px;
  height: 20px;
  background: var(--surface3);
  border-radius: 20px;
  position: relative;
  transition: background var(--transition);
  flex-shrink: 0;
}

.toggle-switch::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: all var(--transition);
}

.toggle-label input:checked + .toggle-switch {
  background: var(--accent);
}

.toggle-label input:checked + .toggle-switch::after {
  left: 19px;
  background: #fff;
}

.toggle-text {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
}

/* ── Action Buttons ──────────────────────────────────────── */
.actions-section {
  gap: 5px;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  width: 100%;
}

.action-btn svg { width: 15px; height: 15px; flex-shrink: 0; }

.action-btn:hover {
  background: var(--surface3);
  border-color: var(--border-hl);
  transform: translateY(-1px);
  box-shadow: 0 3px 12px rgba(0,0,0,0.3);
}

.action-btn:active { transform: translateY(0); }

.action-btn.danger:hover {
  background: rgba(239,68,68,0.15);
  border-color: rgba(239,68,68,0.5);
  color: #ef4444;
}

.action-btn.success:hover {
  background: rgba(16,185,129,0.15);
  border-color: rgba(16,185,129,0.5);
  color: #10b981;
}

.action-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
}

/* ── Toolbar Toggle Button ───────────────────────────────── */
.toolbar-toggle {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}

.toolbar-toggle svg { width: 16px; height: 16px; display: block; }

.toolbar-toggle:hover {
  background: var(--surface3);
  color: var(--text);
}

/* ── Canvas Area ─────────────────────────────────────────── */
.canvas-container {
  grid-area: canvas;
  position: relative;
  overflow: hidden;
  background: var(--canvas-bg);
  cursor: crosshair;
}

/* Pen: diagonal pencil, tip at bottom-left */
.canvas-container.cursor-pen {
  cursor: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24'><path d='M18 0 L22 4 L20 4 L16 0 Z' fill='%23ef4444'/><path d='M4 18 L20 2 L22 4 L6 20 Z' fill='%237c3aed'/><path d='M4 18 L6 20 L2 22 Z' fill='%23c8a97e'/><path d='M2 22 L4 18 L3 20 Z' fill='%23111'/></svg>") 2 22, crosshair;
}

/* Brush: paintbrush, tip at bottom-left */
.canvas-container.cursor-brush {
  cursor: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24'><path d='M20 2 L22 4 L14 12 L12 10 Z' fill='%23c8a97e'/><path d='M8 14 L12 10 L14 12 L10 16 Z' fill='%237c3aed'/><path d='M6 16 L10 16 L8 19 L4 18 Z' fill='%23888'/><path d='M2 22 L4 18 L8 19 L5 22 Z' fill='%23111'/></svg>") 2 22, crosshair;
}

/* Highlighter: thick chisel marker, tip at bottom-left */
.canvas-container.cursor-highlighter {
  cursor: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24'><path d='M14 0 L22 8 L20 10 L12 2 Z' fill='%23666'/><path d='M2 20 L12 2 L14 4 L4 22 Z' fill='%23fbbf24'/><path d='M2 20 L4 22 L0 23 Z' fill='%23f59e0b'/></svg>") 2 21, crosshair;
}

/* Eraser: rectangle with pink/red colors */
.canvas-container.cursor-eraser {
  cursor: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24'><rect x='1' y='7' width='8' height='14' fill='%23f87171'/><rect x='9' y='7' width='14' height='14' fill='%23fecdd3'/><rect x='1' y='7' width='22' height='14' rx='2' fill='none' stroke='%23ef4444' stroke-width='1.5'/></svg>") 11 14, cell;
}

/* Line: purple crosshair */
.canvas-container.cursor-line {
  cursor: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24'><line x1='12' y1='2' x2='12' y2='10' stroke='%237c3aed' stroke-width='2' stroke-linecap='round'/><line x1='12' y1='14' x2='12' y2='22' stroke='%237c3aed' stroke-width='2' stroke-linecap='round'/><line x1='2' y1='12' x2='10' y2='12' stroke='%237c3aed' stroke-width='2' stroke-linecap='round'/><line x1='14' y1='12' x2='22' y2='12' stroke='%237c3aed' stroke-width='2' stroke-linecap='round'/><circle cx='12' cy='12' r='2' fill='%237c3aed'/></svg>") 12 12, crosshair;
}

/* Rect: crosshair + dashed rect hint */
.canvas-container.cursor-rect {
  cursor: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24'><line x1='12' y1='2' x2='12' y2='10' stroke='%237c3aed' stroke-width='2' stroke-linecap='round'/><line x1='12' y1='14' x2='12' y2='22' stroke='%237c3aed' stroke-width='2' stroke-linecap='round'/><line x1='2' y1='12' x2='10' y2='12' stroke='%237c3aed' stroke-width='2' stroke-linecap='round'/><line x1='14' y1='12' x2='22' y2='12' stroke='%237c3aed' stroke-width='2' stroke-linecap='round'/><circle cx='12' cy='12' r='2' fill='%237c3aed'/><rect x='2' y='2' width='9' height='9' fill='none' stroke='%237c3aed' stroke-width='1' rx='1' stroke-dasharray='2' opacity='0.6'/></svg>") 12 12, crosshair;
}

/* Circle: crosshair + dashed circle hint */
.canvas-container.cursor-circle {
  cursor: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24'><line x1='12' y1='2' x2='12' y2='10' stroke='%237c3aed' stroke-width='2' stroke-linecap='round'/><line x1='12' y1='14' x2='12' y2='22' stroke='%237c3aed' stroke-width='2' stroke-linecap='round'/><line x1='2' y1='12' x2='10' y2='12' stroke='%237c3aed' stroke-width='2' stroke-linecap='round'/><line x1='14' y1='12' x2='22' y2='12' stroke='%237c3aed' stroke-width='2' stroke-linecap='round'/><circle cx='12' cy='12' r='2' fill='%237c3aed'/><circle cx='5' cy='5' r='3' fill='none' stroke='%237c3aed' stroke-width='1' stroke-dasharray='2' opacity='0.6'/></svg>") 12 12, crosshair;
}

/* Arrow: crosshair + arrowhead hint */
.canvas-container.cursor-arrow {
  cursor: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24'><line x1='12' y1='2' x2='12' y2='10' stroke='%237c3aed' stroke-width='2' stroke-linecap='round'/><line x1='12' y1='14' x2='12' y2='22' stroke='%237c3aed' stroke-width='2' stroke-linecap='round'/><line x1='2' y1='12' x2='10' y2='12' stroke='%237c3aed' stroke-width='2' stroke-linecap='round'/><line x1='14' y1='12' x2='22' y2='12' stroke='%237c3aed' stroke-width='2' stroke-linecap='round'/><circle cx='12' cy='12' r='2' fill='%237c3aed'/><polygon points='19,2 23,6 19,6' fill='%237c3aed' opacity='0.65'/></svg>") 12 12, crosshair;
}

.canvas-container.cursor-text    { cursor: text; }
.canvas-container.cursor-select  { cursor: default; }
.canvas-container.cursor-grab    { cursor: grab; }
.canvas-container.cursor-grabbing{ cursor: grabbing; }

#grid-canvas, #main-canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
}

#grid-canvas   { pointer-events: none; z-index: 0; }
#main-canvas   { z-index: 1; }
#cursor-canvas {
  pointer-events: none;
  z-index: 2;
  /* cursor canvas is fully transparent; we draw on it via JS */
}

#text-layer {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none; /* Only allow events on text items when needed */
  z-index: 3;
}

.floating-text {
  position: absolute;
  white-space: pre;
  font-family: 'Inter', sans-serif;
  transform: translate(0, 0); /* For performance if needed */
  user-select: none;
  border: 2px solid transparent;
  padding: 4px;
  margin: -6px; /* Offset the padding visually */
  border-radius: 4px;
}

/* Text interaction is now handled via canvas hit testing */

.canvas-container.tool-select-active .floating-text {
  cursor: grab;
}

.canvas-container.tool-select-active .floating-text:hover {
  border-color: rgba(124, 58, 237, 0.4); /* Highlight on hover */
  background: rgba(255, 255, 255, 0.05);
}

.floating-text.selected {
  border-color: var(--accent) !important;
  background: rgba(124, 58, 237, 0.1) !important;
}

/* ── Text Input Overlay ──────────────────────────────────── */
.text-input-overlay {
  position: absolute;
  z-index: 5;
  display: none;
  border: 2px dashed var(--accent);
  border-radius: 4px;
  background: rgba(255,255,255,0.92);
  color: #1a1a2e;
  font-family: 'Inter', sans-serif;
  font-size: 20px;
  padding: 6px 10px;
  outline: none;
  resize: both;
  min-width: 120px;
  min-height: 40px;
  box-shadow: 0 4px 24px rgba(124,58,237,0.25);
  backdrop-filter: blur(4px);
}

/* ── Status Bar ──────────────────────────────────────────── */
.status-bar {
  grid-area: status;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  font-size: 11.5px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
}

.status-bar span {
  white-space: nowrap;
}

.status-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 4px;
}

.status-btn {
  padding: 3px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.status-btn:hover {
  background: var(--surface3);
  color: var(--text);
  border-color: var(--border-hl);
}

.status-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ── Toast ───────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-hl);
  border-radius: var(--radius);
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(.4,0,.2,1);
  z-index: 100;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Animations ──────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}

.tool-btn, .action-btn {
  animation: none;
}

/* ── Scrollbar for light mode ────────────────────────────── */
[data-theme="light"] .toolbar { background: #fff; border-right-color: rgba(0,0,0,0.1); }
[data-theme="light"] .status-bar { background: #fff; border-top-color: rgba(0,0,0,0.1); }
[data-theme="light"] .canvas-container { background: #ffffff; }

/* ── Toolbar Toggle (old in-sidebar button, kept hidden) ─── */
.toolbar-toggle { display: none; }

/* ── Floating Sidebar Tab ─────────────────────────────────── */
.sidebar-float-tab {
  position: fixed;
  left: var(--toolbar-w);
  top: 50%;
  transform: translateY(-50%);
  z-index: 50;
  width: 22px;
  height: 64px;
  background: var(--surface);
  border: 1px solid var(--border-hl);
  border-left: none;
  border-radius: 0 10px 10px 0;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--text-muted);
  transition: all 0.25s cubic-bezier(.4,0,.2,1);
  box-shadow: 4px 0 16px rgba(0,0,0,0.25);
  overflow: hidden;
  padding: 0;
}

.sidebar-float-tab .tab-arrow {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  transition: transform 0.25s cubic-bezier(.4,0,.2,1);
}

.sidebar-float-tab .tab-label {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-size: 8px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  user-select: none;
  line-height: 1;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 0.25s, opacity 0.2s;
}

.sidebar-float-tab:hover {
  width: 30px;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 4px 0 24px var(--accent-glow);
}

.sidebar-float-tab:hover .tab-label {
  max-height: 40px;
  opacity: 1;
  color: rgba(255,255,255,0.8);
}

/* When sidebar is hidden → button moves to left edge, arrow flips */
body.toolbar-hidden .sidebar-float-tab {
  left: 0;
  border-radius: 0 10px 10px 0;
}

body.toolbar-hidden .sidebar-float-tab .tab-arrow {
  transform: rotate(180deg);
}

/* Grid transition when sidebar toggles */
body, .sidebar-float-tab {
  transition: all 0.25s cubic-bezier(.4,0,.2,1);
}

/* ── Hotkey Open Button ───────────────────────────────────── */
.hotkey-open-btn {
  background: linear-gradient(135deg, rgba(124,58,237,0.15), rgba(79,70,229,0.1));
  border-color: rgba(124,58,237,0.35) !important;
  color: #a78bfa !important;
}
.hotkey-open-btn:hover {
  background: linear-gradient(135deg, rgba(124,58,237,0.3), rgba(79,70,229,0.2)) !important;
  border-color: rgba(124,58,237,0.6) !important;
  color: #c4b5fd !important;
}

/* ── Hotkey Manager Modal ─────────────────────────────────── */
.hk-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 20px;
  animation: hkOverlayIn 0.2s ease;
}

.hk-overlay[hidden] { display: none; }

@keyframes hkOverlayIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.hk-panel {
  background: var(--surface);
  border: 1px solid var(--border-hl);
  border-radius: 16px;
  width: 100%;
  max-width: 640px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 80px rgba(0,0,0,0.6), 0 0 0 1px rgba(124,58,237,0.2);
  animation: hkPanelIn 0.25s cubic-bezier(.34,1.56,.64,1);
  overflow: hidden;
}

@keyframes hkPanelIn {
  from { opacity: 0; transform: scale(0.92) translateY(16px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* Header */
.hk-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.hk-title-group {
  display: flex;
  align-items: center;
  gap: 14px;
}

.hk-icon {
  width: 42px; height: 42px;
  background: linear-gradient(135deg, #7c3aed, #4f46e5);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 16px rgba(124,58,237,0.4);
}

.hk-icon svg { width: 22px; height: 22px; stroke: #fff; }

.hk-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.hk-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin: 2px 0 0;
}

.hk-close {
  width: 32px; height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-muted);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}

.hk-close svg { width: 16px; height: 16px; }

.hk-close:hover {
  background: rgba(239,68,68,0.15);
  border-color: rgba(239,68,68,0.4);
  color: #ef4444;
}

/* Search */
.hk-search-wrap {
  position: relative;
  padding: 14px 24px 12px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.hk-search-icon {
  position: absolute;
  left: 38px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px; height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

.hk-search {
  width: 100%;
  padding: 9px 14px 9px 36px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: all var(--transition);
}

.hk-search::placeholder { color: var(--text-muted); }

.hk-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Conflict banner */
.hk-conflict-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 24px 0;
  padding: 10px 14px;
  background: rgba(239,68,68,0.12);
  border: 1px solid rgba(239,68,68,0.35);
  border-radius: var(--radius-sm);
  color: #ef4444;
  font-size: 12.5px;
  font-weight: 500;
  animation: hkConflictIn 0.2s ease;
}

@keyframes hkConflictIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.hk-conflict-banner[hidden] { display: none; }
.hk-conflict-banner svg { width: 16px; height: 16px; flex-shrink: 0; }

/* Body / Rows */
.hk-body {
  overflow-y: auto;
  flex: 1;
  padding: 12px 24px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--surface3) transparent;
}

.hk-body::-webkit-scrollbar { width: 5px; }
.hk-body::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 4px; }

.hk-category { margin-bottom: 16px; }

.hk-cat-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 6px;
  padding: 0 2px;
  user-select: none;
}

.hk-rows { display: flex; flex-direction: column; gap: 3px; }

/* Row */
.hk-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}

.hk-row:hover { background: var(--surface2); }

.hk-row.hk-hidden { display: none; }

.hk-row-icon {
  font-size: 16px;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}

.hk-row-label {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  user-select: none;
}

.hk-row-desc {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}

.hk-row-info { flex: 1; }

/* Badge */
.hk-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: 6px;
  background: var(--surface3);
  border: 1px solid var(--border-hl);
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  min-width: 70px;
  justify-content: center;
  user-select: none;
  position: relative;
  overflow: hidden;
}

.hk-badge::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--accent);
  opacity: 0;
  transition: opacity var(--transition);
}

.hk-badge:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
  transform: scale(1.04);
}

.hk-badge.listening {
  border-color: var(--accent);
  background: rgba(124,58,237,0.15);
  color: #a78bfa;
  animation: hkPulse 1s ease-in-out infinite;
  box-shadow: 0 0 0 3px var(--accent-glow);
}

@keyframes hkPulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--accent-glow); }
  50%       { box-shadow: 0 0 0 6px transparent; }
}

.hk-badge.conflict-badge {
  border-color: rgba(239,68,68,0.6);
  color: #ef4444;
  background: rgba(239,68,68,0.12);
}

.hk-badge.empty {
  color: var(--text-muted);
  font-style: italic;
  font-size: 11px;
  letter-spacing: normal;
  font-family: 'Inter', sans-serif;
}

.hk-badge-none { color: var(--text-muted); font-size: 11px; font-family: 'Inter', sans-serif; }

/* Key chips inside badge */
.key-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.1);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 10.5px;
}

/* Footer */
.hk-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  gap: 12px;
}

.hk-hint {
  font-size: 11.5px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.hk-hint kbd {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  background: var(--surface3);
  border: 1px solid var(--border-hl);
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--text);
}

.hk-footer-actions { display: flex; gap: 8px; }

.hk-btn {
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid transparent;
  white-space: nowrap;
}

.hk-btn-ghost {
  background: var(--surface2);
  border-color: var(--border);
  color: var(--text-muted);
}

.hk-btn-ghost:hover {
  background: var(--surface3);
  color: var(--text);
  border-color: var(--border-hl);
}

.hk-btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 12px var(--accent-glow);
}

.hk-btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 20px var(--accent-glow);
  transform: translateY(-1px);
}

/* ── Responsive tweaks ───────────────────────────────────── */
@media (max-width: 768px) {
  :root { --toolbar-w: 180px; }
  .brand-name { font-size: 12px; }
  .tool-btn span { display: none; }
  .tool-btn { padding: 10px; justify-content: center; }
  .tool-btn svg { width: 20px; height: 20px; }
  .action-btn span { display: none; }
  .hk-panel { max-height: 95vh; border-radius: 12px; }
  .hk-footer { flex-direction: column; align-items: stretch; }
  .hk-footer-actions { justify-content: flex-end; }
}
