/* v26 component rules — built up across phases 1-3.
   Phase 1 scope: icon base, focus rings, toast shell, settings dialog,
   theme/menu-size pickers. */

.icon {
  width: 1em;
  height: 1em;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
  vertical-align: -0.125em;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Settings dialog ---------- */
#settings-modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  padding: var(--space-lg);
}
#settings-modal.open {
  display: flex;
}
#settings-modal .settings-dialog {
  width: min(560px, 100%);
  max-height: min(720px, 90vh);
  overflow-y: auto;
  background: var(--surface-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-3);
  color: var(--text-1);
  font-family: var(--font-ui);
}
#settings-modal .settings-header {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg);
  border-bottom: 1px solid var(--border-1);
  background: var(--surface-1);
}
#settings-modal .settings-header h2 {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
}
#settings-modal .settings-section {
  padding: var(--space-lg);
  border-bottom: 1px solid var(--border-1);
}
#settings-modal .settings-section:last-child {
  border-bottom: none;
}
#settings-modal .settings-section h3 {
  margin: 0 0 var(--space-sm);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-2);
  text-transform: none;
  letter-spacing: normal;
}
#settings-close {
  background: transparent;
  border: none;
  color: var(--text-2);
  cursor: pointer;
  width: var(--touch-min);
  height: var(--touch-min);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
}
#settings-close:hover {
  background: var(--surface-2);
  color: var(--text-1);
}

/* Theme grid (id="theme-menu" for spec-compat, lives inside #settings-modal now) */
#theme-menu.theme-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-sm);
}
.theme-option {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  padding: var(--space-sm);
  background: var(--surface-2);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  cursor: pointer;
  text-align: left;
  color: var(--text-1);
  font-family: var(--font-ui);
  transition: border-color var(--transition-fast), background var(--transition-fast);
}
.theme-option:hover {
  background: var(--surface-3);
}
.theme-option[aria-checked='true'] {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.theme-option .theme-name {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}
.theme-option .theme-sub {
  font-size: var(--text-xs);
  color: var(--text-2);
}

/* Menu-size segmented control */
#menu-size-group {
  display: flex;
  gap: var(--space-xs);
  background: var(--surface-2);
  padding: var(--space-xs);
  border-radius: var(--radius-md);
  width: fit-content;
}
.menu-size-option {
  padding: var(--space-xs) var(--space-md);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  cursor: pointer;
}
.menu-size-option:hover {
  color: var(--text-1);
}
.menu-size-option.active {
  background: var(--surface-0);
  color: var(--text-1);
  font-weight: var(--weight-medium);
}

/* Settings toggle row (checkboxes) */
.settings-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  padding: var(--space-xs) 0;
}
.settings-toggle-row label {
  font-size: var(--text-sm);
  color: var(--text-1);
}

.settings-info-row {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-sm);
  padding: var(--space-xs) 0;
  color: var(--text-2);
}
.settings-info-row .info-value {
  color: var(--text-1);
  font-family: var(--font-mono);
}

.settings-action-btn {
  margin-top: var(--space-sm);
  padding: var(--space-xs) var(--space-md);
  background: var(--surface-2);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-sm);
  color: var(--text-1);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
}
.settings-action-btn:hover { background: var(--surface-3); }

/* ---------- Restore banner (v26.1 autosave) ---------- */
#restore-banner {
  position: fixed;
  top: calc(var(--topbar-h) + var(--space-sm));
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-2);
  color: var(--text-1);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  max-width: min(90vw, 480px);
}
#restore-banner .settings-action-btn { margin-top: 0; }

/* ---------- Startup splash ---------- */
#app-splash {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  background: var(--stage-bg);
  color: var(--text-1);
  font-family: var(--font-ui);
}
#app-splash[hidden] {
  display: none;
}
#app-splash img {
  opacity: 0.9;
}
#app-splash-text {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--text-2);
}
#app-splash-bar {
  width: 160px;
  height: 3px;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  overflow: hidden;
}
#app-splash-bar-fill {
  width: 40%;
  height: 100%;
  background: var(--accent);
  border-radius: var(--radius-full);
  animation: jf-splash-indeterminate 1.2s ease-in-out infinite;
}
@media (prefers-reduced-motion: reduce) {
  #app-splash-bar-fill {
    animation: none;
    width: 60%;
  }
}
@keyframes jf-splash-indeterminate {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(250%); }
}
#app-splash-reload {
  padding: var(--space-sm) var(--space-lg);
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
}

/* ---------- Canvas HUD (zoom + grid) ---------- */
#canvas-hud {
  position: absolute;
  left: var(--space-md);
  bottom: var(--space-md);
  z-index: var(--z-hud);
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--surface-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-2);
  padding: 4px;
}
#canvas-hud button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}
#canvas-hud button:hover {
  background: var(--surface-2);
  color: var(--text-1);
}
#canvas-hud button.active {
  background: var(--accent-soft);
  color: var(--accent);
}
#zoom-level {
  width: auto;
  padding: 0 var(--space-sm);
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  white-space: nowrap;
}
/* Menu opens upward from the HUD (which sits at the bottom of the canvas
   area) instead of downward like the top-bar's Speichern menu. */
.canvas-hud-menu {
  top: auto;
  bottom: 100%;
  right: auto;
  left: 0;
  margin-top: 0;
  margin-bottom: var(--space-xs);
}

/* ---------- Top bar dropdown menu (Speichern) ---------- */
.top-bar-menu-container {
  position: relative;
  display: inline-flex;
}
.top-bar-menu {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: var(--space-xs);
  min-width: 220px;
  background: var(--surface-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-3);
  padding: var(--space-xs);
  z-index: var(--z-topbar);
  flex-direction: column;
  gap: 2px;
}
.top-bar-menu.open {
  display: flex;
}
.top-bar-menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-1);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}
.top-bar-menu-item:hover {
  background: var(--surface-2);
}

/* ---------- Toast shell (filled in further in Phase 3) ---------- */
#toast-region {
  position: fixed;
  left: 50%;
  bottom: var(--space-xl);
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  pointer-events: none;
}
/* Toasts are status messages without actions: they must never swallow taps on the
   controls underneath (they sit over the bottom colour panel on phones). */
.jf-toast {
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-2);
  color: var(--text-1);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  max-width: 360px;
}
.jf-toast--success { border-color: color-mix(in srgb, var(--success) 50%, var(--border-1)); }
.jf-toast--warning { border-color: color-mix(in srgb, var(--warning) 50%, var(--border-1)); }
.jf-toast--error { border-color: color-mix(in srgb, var(--danger) 50%, var(--border-1)); }

/* ---------- Recent colors (v26.1 phase 6) ---------- */
.recent-colors-row {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) 0;
  flex-wrap: wrap;
}
.recent-color-swatch {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-1);
  cursor: pointer;
  padding: 0;
  flex: none;
}
.recent-color-swatch:hover { border-color: var(--accent); }

/* ---------- Selection transform bar (v26.1 phase 6) ---------- */
#transform-bar {
  position: fixed;
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: var(--surface-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-3);
  color: var(--text-1);
  font-family: var(--font-ui);
  font-size: var(--text-xs);
}
#transform-bar label {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--text-2);
  white-space: nowrap;
}
#transform-bar input[type="number"] {
  width: 52px;
  padding: 2px 4px;
  background: var(--surface-2);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-sm);
  color: var(--text-1);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}
#transform-bar button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--surface-2);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  cursor: pointer;
}
#transform-bar button:hover { background: var(--surface-3); color: var(--text-1); }
#transform-bar button.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
#transform-bar #tf-cancel { color: var(--danger); }

/* ---------- Zoom/pan (v26.1 phase 6) ---------- */
/* .canvas-container has `transition: transform .3s` (main inline <style>);
   suppress it while actively zooming via wheel/pinch so panning-toward-cursor
   doesn't lag behind the pointer. */
.canvas-container.is-zooming { transition: none !important; }

/* ---------- New Document dialog (v26.1 phase 6) — same modal pattern as
   #settings-modal, duplicated rather than shared to avoid coupling the two
   dialogs' styling together. ---------- */
#new-doc-modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  padding: var(--space-lg);
}
#new-doc-modal.open { display: flex; }
#new-doc-modal .new-doc-dialog {
  width: min(480px, 100%);
  max-height: min(720px, 90vh);
  overflow-y: auto;
  background: var(--surface-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-3);
  color: var(--text-1);
  font-family: var(--font-ui);
}
#new-doc-modal .new-doc-header {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg);
  border-bottom: 1px solid var(--border-1);
  background: var(--surface-1);
}
#new-doc-modal .new-doc-header h2 {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
}
#new-doc-close {
  background: transparent;
  border: none;
  color: var(--text-2);
  cursor: pointer;
  width: var(--touch-min);
  height: var(--touch-min);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
}
#new-doc-close:hover { background: var(--surface-2); color: var(--text-1); }
#new-doc-modal .new-doc-section {
  padding: var(--space-lg);
  border-bottom: 1px solid var(--border-1);
}
#new-doc-modal .new-doc-section h3 {
  margin: 0 0 var(--space-sm);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-2);
}
.new-doc-presets {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-sm);
}
.new-doc-preset {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: var(--space-sm) var(--space-md);
  background: var(--surface-2);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-sm);
  color: var(--text-1);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
  text-align: left;
}
.new-doc-preset span { color: var(--text-2); font-size: var(--text-xs); font-weight: 400; }
.new-doc-preset:hover { background: var(--surface-3); }
.new-doc-preset.active { background: var(--accent-soft); border-color: var(--accent); }
.new-doc-fields {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-md);
}
.new-doc-fields label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: var(--text-xs);
  color: var(--text-2);
}
.new-doc-fields input {
  width: 90px;
  padding: var(--space-xs) var(--space-sm);
  background: var(--surface-2);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-sm);
  color: var(--text-1);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}
.new-doc-bg-group { display: flex; gap: var(--space-sm); }
.new-doc-bg-option {
  padding: var(--space-xs) var(--space-md);
  background: var(--surface-2);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-sm);
  color: var(--text-1);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  cursor: pointer;
}
.new-doc-bg-option.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.new-doc-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
  padding: var(--space-lg);
}

/* ---------- Work title (v26.1 phase 7, "Meine Werke") ---------- */
#work-title {
  margin-left: var(--space-sm);
  padding: 2px var(--space-sm);
  font-size: var(--text-xs);
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}
#work-title.saved { color: var(--text-2); }

/* ---------- Meine Werke / Export / Shortcuts modals (v26.1 phase 7) —
   same modal shell pattern as #settings-modal / #new-doc-modal. ---------- */
#works-modal, #export-modal, #shortcuts-modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  padding: var(--space-lg);
}
#works-modal.open, #export-modal.open, #shortcuts-modal.open { display: flex; }

.works-dialog, .export-modal-dialog {
  width: min(640px, 100%);
  max-height: min(720px, 90vh);
  overflow-y: auto;
  background: var(--surface-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-3);
  color: var(--text-1);
  font-family: var(--font-ui);
}
.export-modal-dialog { width: min(400px, 100%); }
.works-header, .export-modal-header {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg);
  border-bottom: 1px solid var(--border-1);
  background: var(--surface-1);
}
.works-header h2, .export-modal-header h2 {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
}
#works-close, #export-modal-close, #shortcuts-close {
  background: transparent;
  border: none;
  color: var(--text-2);
  cursor: pointer;
  width: var(--touch-min);
  height: var(--touch-min);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
}
#works-close:hover, #export-modal-close:hover, #shortcuts-close:hover { background: var(--surface-2); color: var(--text-1); }

.works-empty {
  padding: var(--space-xl);
  text-align: center;
  color: var(--text-2);
  font-size: var(--text-sm);
}
/* Shown in place of the grid when listWorks() fails. Deliberately distinct
   from .works-empty: "you have no works" and "we could not read your works"
   must never look the same. */
.works-error {
  padding: var(--space-xl);
  margin: 0;
  text-align: center;
  color: var(--danger);
  font-size: var(--text-sm);
}
.works-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--space-md);
  padding: var(--space-lg);
}
.work-card {
  background: var(--surface-2);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.work-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: var(--surface-3);
  display: block;
}
.work-card-body { padding: var(--space-sm); }
.work-card-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.work-card-date { font-size: var(--text-xs); color: var(--text-2); }
.work-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 0 var(--space-sm) var(--space-sm);
}
.work-card-actions button {
  flex: 1;
  min-width: 60px;
  padding: 4px 6px;
  background: var(--surface-3);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-sm);
  color: var(--text-1);
  font-size: 10px;
  cursor: pointer;
}
.work-card-actions button:hover { background: var(--accent-soft); color: var(--accent); }

#export-modal-quality { width: 100%; }
#export-modal-quality-value { font-size: var(--text-xs); color: var(--text-2); }

.shortcuts-group { padding: var(--space-lg); border-bottom: 1px solid var(--border-1); }
.shortcuts-group:last-child { border-bottom: none; }
.shortcuts-group h3 {
  margin: 0 0 var(--space-sm);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-2);
}
.shortcuts-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
  font-size: var(--text-sm);
}
.shortcuts-row kbd {
  background: var(--surface-2);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  margin-left: 4px;
}
