/* Port of ui/Theme.h — Qt Fusion + a flat dark palette with a single blue
   accent, translated one-for-one to CSS. Colours, paddings and radii match the
   desktop stylesheet exactly. */

:root {
  --bg: #17171a;
  --panel: #1e1e22;
  --field: #27272c;
  --text: #e6e6e9;
  --sub: #9b9ba3;
  --disabled: #5c5c63;
  --accent: #3b82f6;
  --chrome: #1b1b1f;
  --border: #2a2a30;
  --line: #34343b;
  --sep: #2e2e35;
}

* { box-sizing: border-box; outline: none; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 12px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app { display: flex; flex-direction: column; height: 100%; }
[hidden] { display: none !important; }

/* --- Menu bar ------------------------------------------------------------ */
#menubar {
  display: flex;
  align-items: center;
  background: var(--chrome);
  color: #c8c8cf;
  flex: none;
  padding: 0 2px;
  user-select: none;
}
.menubar-item {
  padding: 5px 10px;
  border-radius: 6px;
  cursor: default;
}
.menubar-item:hover, .menubar-item.open { background: #292930; }

/* Back to the landing page. */
.menubar-brand {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px 3px 6px;
  margin-right: 4px;
  border-radius: 6px;
  color: #c8c8cf;
  text-decoration: none;
  font-weight: 500;
}
.menubar-brand img { width: 16px; height: 16px; border-radius: 4px; display: block; }
.menubar-brand b { color: var(--accent); font-weight: 700; }
.menubar-brand:hover { background: #292930; color: #f0f0f3; }

/* --- Toolbar ------------------------------------------------------------- */
#toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--chrome);
  border-bottom: 1px solid var(--border);
  padding: 3px 6px;
  flex: none;
  user-select: none;
}
.tool-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  color: #c8c8cf;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 4px 8px;
  font: inherit;
  font-weight: 500;
  cursor: default;
}
.tool-button svg, .tool-button img { width: 28px; height: 28px; display: block; }
.tool-button:hover:not(:disabled) { background: #292930; color: #f0f0f3; }
.tool-button:active:not(:disabled) { background: #313139; }
.tool-button.checked {
  background: rgba(59, 130, 246, 0.16);
  color: #93c5fd;
  border-color: rgba(59, 130, 246, 0.45);
}
.tool-button:disabled { color: #50505a; opacity: 0.55; }
.tool-separator {
  width: 1px;
  align-self: stretch;
  background: var(--sep);
  margin: 4px 5px;
}

/* --- Main area ------------------------------------------------------------ */
#main { flex: 1; display: flex; min-height: 0; }
#stack { position: relative; flex: 1; min-width: 0; }
.page { position: absolute; inset: 0; }
#stack[data-page="0"] #viewerPage,
#stack[data-page="1"] #gridPage { display: none; }

/* --- Docks (folder tree / inspector) -------------------------------------- */
.dock {
  display: flex;
  flex-direction: column;
  flex: none;
  width: 280px;
  background: var(--bg);
  color: var(--sub);
  border-right: 1px solid var(--border);
}
.dock.right { border-right: none; border-left: 1px solid var(--border); width: 232px; }
.dock-title {
  background: var(--chrome);
  padding: 5px 11px;
  border-bottom: 1px solid var(--border);
  color: var(--sub);
  flex: none;
}
.dock-body { flex: 1; overflow: auto; padding: 6px; }

/* Folder tree */
.tree-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px;
  border-radius: 6px;
  color: #c8c8cf;
  cursor: default;
  white-space: nowrap;
}
.tree-row:hover { background: #292930; }
.tree-row.current { background: rgba(59, 130, 246, 0.16); color: #93c5fd; }
.tree-arrow { width: 12px; color: var(--sub); text-align: center; }
.tree-label { overflow: hidden; text-overflow: ellipsis; }

/* --- Thumbnail grid ------------------------------------------------------- */
#gridScroll {
  position: relative;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  background: #161618;
}
#gridCanvas { position: absolute; top: 0; left: 0; display: block; }
#gridSpacer { width: 1px; }
.grid-editor {
  position: absolute;
  background: var(--field);
  border: 1px solid var(--accent);
  border-radius: 3px;
  color: var(--text);
  font: inherit;
  text-align: center;
  padding: 0 4px;
  z-index: 5;
}

/* --- Viewer --------------------------------------------------------------- */
#viewerCanvas { display: block; width: 100%; height: 100%; background: rgb(30, 30, 33); }

/* --- Status bar ----------------------------------------------------------- */
#statusbar {
  flex: none;
  background: var(--chrome);
  color: var(--sub);
  border-top: 1px solid var(--border);
  padding: 4px 10px;
  min-height: 24px;
  user-select: none;
}

/* --- Group boxes (inspector) ---------------------------------------------- */
.group {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 11px 0 0;
  padding: 9px 8px 7px;
  font-weight: 600;
}
.group > legend {
  color: #8c8c95;
  padding: 1px 4px;
  margin-left: 5px;
  font-weight: 600;
}
.form-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
}
.form-label { color: #c8c8cf; font-weight: 400; flex: none; min-width: 62px; }
.preset-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }

/* --- Inputs --------------------------------------------------------------- */
.spin { position: relative; flex: 1; display: flex; }
.spin[data-suffix]::after {
  content: attr(data-suffix);
  position: absolute;
  right: 22px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--sub);
  pointer-events: none;
}
.spin-input, .text-input, .select {
  width: 100%;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 6px;
  color: var(--text);
  font: inherit;
  min-height: 24px;
}
.select { cursor: default; }
.spin-input:hover, .text-input:hover, .select:hover,
.spin-input:focus, .text-input:focus, .select:focus { border-color: var(--accent); }
.spin-input:disabled, .select:disabled { color: var(--disabled); }
.check {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 6px 0;
  color: #c8c8cf;
  font-weight: 400;
}
.check input { accent-color: var(--accent); }

.btn {
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 10px;
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: default;
}
.btn:hover:not(:disabled) { background: #2f2f37; border-color: #44444d; }
.btn:active:not(:disabled) { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn:disabled { color: #50505a; background: #202024; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #2f76ef; }

/* --- Popup menus ---------------------------------------------------------- */
.menu-overlay { position: fixed; inset: 0; z-index: 60; }
.popup-menu {
  position: absolute;
  min-width: 190px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  user-select: none;
}
.menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 6px 14px;
  border-radius: 6px;
  color: var(--text);
  cursor: default;
  white-space: nowrap;
}
.menu-item:hover:not(.disabled) { background: var(--accent); color: #fff; }
.menu-item:hover:not(.disabled) .menu-shortcut { color: rgba(255, 255, 255, 0.75); }
.menu-item.disabled { color: var(--disabled); }
.menu-item.checkable { padding-left: 26px; position: relative; }
.menu-item.checked::before {
  content: "✓";
  position: absolute;
  left: 9px;
  color: var(--accent);
}
.menu-item.checked:hover::before { color: #fff; }
.menu-shortcut { color: var(--sub); }
.menu-separator { height: 1px; background: var(--sep); margin: 5px 8px; }

/* --- Dialogs -------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
}
.dialog {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  max-width: min(90vw, 640px);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
}
.dialog-title {
  background: var(--chrome);
  border-bottom: 1px solid var(--border);
  border-radius: 10px 10px 0 0;
  padding: 8px 14px;
  color: var(--sub);
  font-weight: 600;
}
.dialog-body { padding: 14px; overflow: auto; }
.dialog-body .group:first-child { margin-top: 0; }
.dialog-text { margin: 0 0 8px; color: var(--text); white-space: pre-wrap; }
.dialog-sub { margin: 0 0 8px; color: var(--sub); }
.dialog-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
}
.row { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.row .text-input { flex: 1; }
.stack-page { margin-top: 6px; }
.list {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  max-height: 340px;
  overflow: auto;
}
.list-item { padding: 5px 10px; color: var(--text); border-bottom: 1px solid #232329; }
.list-item:last-child { border-bottom: none; }

/* --- Welcome -------------------------------------------------------------- */
#welcome {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.welcome-card { max-width: 520px; text-align: center; }
.welcome-icon { width: 84px; height: 84px; border-radius: 18px; margin-bottom: 12px; }
.welcome-card h1 { font-size: 30px; margin: 0 0 10px; font-weight: 700; letter-spacing: -0.02em; }
.accent { color: var(--accent); }
.welcome-lead { color: var(--sub); font-size: 14px; line-height: 1.6; margin: 0 0 22px; }
.welcome-actions { display: flex; gap: 10px; justify-content: center; }
.welcome-actions .btn { padding: 10px 20px; font-size: 14px; cursor: pointer; }
.welcome-note { color: var(--sub); margin: 18px 0 0; }
.welcome-links { margin: 26px 0 0; color: var(--sub); }
.welcome-links a { color: var(--sub); }
.welcome-links a:hover { color: var(--accent); }

/* --- Scrollbars (QSS: 11px track, #3a3a42 handle, radius 5) --------------- */
* { scrollbar-width: thin; scrollbar-color: #3a3a42 transparent; }
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #3a3a42; border-radius: 5px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: #4a4a54; background-clip: padding-box; border: 2px solid transparent; }
::-webkit-scrollbar-corner { background: transparent; }
