/* Sähkösuunnittelu – sovelluksen tyylit (vaalea teema, järjestelmäfontti). */

:root {
  color-scheme: light;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f6;
  --border: #d8dfe7;
  --border-strong: #c2ccd7;
  --text: #18212c;
  --text-2: #445264;
  --text-3: #66717f;
  --accent: #0b5cad;
  --accent-hover: #094c90;
  --accent-soft: #e7f0fb;
  --accent-ring: rgba(11, 92, 173, 0.35);
  --danger: #c0392b;
  --danger-hover: #a3301f;
  --danger-soft: #fdeceb;
  --warning: #a86200;
  --warning-soft: #fff3df;
  --success: #1d7a35;
  --success-soft: #e7f5ea;
  --info: #2a62a3;
  --info-soft: #e9f1fb;
  --canvas-bg: #dfe5ec;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-1: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow-2: 0 10px 30px rgba(16, 24, 40, 0.18);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas, monospace;
  --header-h: 52px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  line-height: 1.25;
  margin: 0;
}

p {
  margin: 0 0 0.75em;
}

a {
  color: var(--accent);
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

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

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 1000;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  transition: top 0.15s;
}

.skip-link:focus {
  top: 8px;
}

.muted {
  color: var(--text-3);
}

.small {
  font-size: 12.5px;
}

.row-gap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.noscript {
  margin: 24px auto;
  max-width: 600px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--warning-soft);
  color: var(--warning);
}

/* ---------------------------------------------------------------------------------------------
   Sovelluksen otsikkopalkki ja murupolku
   --------------------------------------------------------------------------------------------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 20px;
  height: var(--header-h);
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 650;
  font-size: 16px;
  text-decoration: none;
  white-space: nowrap;
}

.brand-mark {
  width: 28px;
  height: 28px;
  flex: none;
}

.breadcrumbs {
  min-width: 0;
}

.breadcrumb-list {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 14px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
}

.breadcrumb-list li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.breadcrumb-list li + li::before {
  content: "/";
  color: var(--border-strong);
}

.breadcrumb-list a {
  color: var(--text-2);
  text-decoration: none;
}

.breadcrumb-list a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.breadcrumb-list [aria-current] {
  color: var(--text);
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-main {
  outline: none;
}

body.mode-editor .app-header {
  display: none;
}

body.mode-editor {
  overflow: hidden;
}

/* ---------------------------------------------------------------------------------------------
   Painikkeet ja lomakkeet
   --------------------------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-weight: 550;
  font-size: 14px;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.12s, border-color 0.12s, color 0.12s;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-3);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

.btn-danger-text {
  color: var(--danger);
}

.btn-ghost {
  background: transparent;
  color: var(--text-2);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-3);
  color: var(--text);
}

.btn-danger-ghost:hover:not(:disabled) {
  background: var(--danger-soft);
  color: var(--danger);
}

.btn-icon {
  width: 36px;
  padding: 0;
}

.btn-sm {
  min-height: 30px;
  padding: 0 10px;
  font-size: 13px;
}

.btn-sm.btn-icon {
  width: 30px;
}

.input,
.modal-form input:not([type=checkbox]):not([type=radio]):not([type=range]),
.modal-form select,
.modal-form textarea {
  width: 100%;
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 14px;
}

textarea.input,
.modal-form textarea {
  resize: vertical;
  min-height: 72px;
}

.input:hover,
.modal-form input:hover,
.modal-form select:hover,
.modal-form textarea:hover {
  border-color: #9fadbd;
}

.input:focus-visible,
.modal-form input:focus-visible,
.modal-form select:focus-visible,
.modal-form textarea:focus-visible {
  outline: 2px solid var(--accent-ring);
  outline-offset: 0;
  border-color: var(--accent);
}

.input-sm {
  min-height: 30px;
  font-size: 13px;
}

.input.is-invalid {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.input.is-over {
  border-color: var(--warning);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
  min-width: 0;
}

.field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}

.field-hint {
  font-size: 12px;
  color: var(--text-3);
  line-height: 1.4;
}

.field-hint.warn {
  color: var(--warning);
}

.field-hint:empty {
  display: none;
}

.req {
  color: var(--danger);
}

.field-check {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.field-check .field-hint {
  flex-basis: 100%;
  margin-left: 26px;
}

.field-check label {
  font-size: 14px;
  cursor: pointer;
}

input[type=checkbox] {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 12px;
}

.field-control-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.field-control-row > :first-child {
  flex: 1;
  min-width: 0;
}

.input-with-extras {
  position: relative;
}

.char-counter {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--text-3);
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

.char-counter.is-over {
  color: var(--warning);
  font-weight: 650;
}

.input-with-extras .input {
  padding-right: 52px;
}

.input-unit {
  display: flex;
  align-items: center;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.input-unit:focus-within {
  outline: 2px solid var(--accent-ring);
  border-color: var(--accent);
}

.input-unit .input {
  border: none;
  min-width: 0;
}

.input-unit .input:focus-visible {
  outline: none;
}

.input-unit .unit {
  padding: 0 10px 0 2px;
  font-size: 12.5px;
  color: var(--text-3);
  white-space: nowrap;
}

.input-number {
  font-variant-numeric: tabular-nums;
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
}

.seg-btn {
  flex: 1 1 auto;
  min-height: 32px;
  padding: 0 8px;
  border: none;
  border-right: 1px solid var(--border);
  background: transparent;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.seg-btn:last-child {
  border-right: none;
}

.seg-btn:hover {
  background: var(--surface-3);
}

.seg-btn.is-active,
.seg-btn[aria-pressed=true] {
  background: var(--accent);
  color: #fff;
}

.seg-btn:focus-visible {
  outline-offset: -3px;
}

.range-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.range {
  flex: 1;
  accent-color: var(--accent);
}

.range-value {
  min-width: 48px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-3);
  min-width: 0;
}

.search-box:focus-within {
  outline: 2px solid var(--accent-ring);
  border-color: var(--accent);
}

.search-box .input {
  border: none;
  padding-left: 0;
  background: transparent;
}

.search-box .input:focus-visible {
  outline: none;
}

.search-box-sm {
  padding: 0 8px;
}

/* ---------------------------------------------------------------------------------------------
   Sivut: projektilista ja projekti
   --------------------------------------------------------------------------------------------- */

.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 16px 64px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.page-header-main {
  min-width: 0;
  flex: 1 1 320px;
}

.page-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.page-lead {
  margin: 6px 0 0;
  color: var(--text-2);
  max-width: 64ch;
}

.page-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 6px;
  font-size: 13.5px;
  color: var(--text-2);
  text-decoration: none;
}

.back-link:hover {
  color: var(--accent);
}

.meta-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 24px;
  margin: 12px 0 0;
  font-size: 13.5px;
}

.meta-list div {
  display: flex;
  gap: 6px;
}

.meta-list dt {
  color: var(--text-3);
}

.meta-list dd {
  margin: 0;
  color: var(--text);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 28px 0 12px;
  flex-wrap: wrap;
}

.section-title {
  font-size: 18px;
  font-weight: 650;
}

.toolbar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.toolbar-row .search-box {
  flex: 1 1 280px;
  max-width: 460px;
}

.count-label {
  font-size: 13.5px;
}

.card-list {
  display: grid;
  /* minmax(0, 1fr): sarake ei veny korttien nowrap-tekstin min-content-leveyteen (kapea näyttö),
     vaan pitkät nimet ja osoiterivit lyhenevät ellipsillä. */
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  transition: border-color 0.12s, box-shadow 0.12s;
}

.card:hover {
  border-color: var(--border-strong);
  box-shadow: 0 2px 8px rgba(16, 24, 40, 0.1);
}

.card-main {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1;
  min-width: 0;
  padding: 10px 8px;
  border-radius: calc(var(--radius) - 2px);
  color: inherit;
  text-decoration: none;
}

.card-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
}

.sheet-thumb {
  position: relative;
  background: #fff;
  border: 1.5px solid var(--border-strong);
}

.sheet-thumb.is-landscape {
  width: 50px;
  height: 36px;
}

.sheet-thumb.is-portrait {
  width: 36px;
  height: 48px;
  margin: 0 7px;
}

.sheet-thumb::after {
  content: "";
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 45%;
  height: 22%;
  border: 1px solid var(--border-strong);
}

.sheet-thumb-format {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-2);
  margin-bottom: 8px;
}

.card-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.card-title {
  font-weight: 650;
  font-size: 15.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-main:hover .card-title {
  color: var(--accent);
}

.card-meta {
  font-size: 13.5px;
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-meta.small {
  font-size: 12.5px;
  color: var(--text-3);
}

.card-desc {
  font-size: 13.5px;
  color: var(--text-3);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: none;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 48px 16px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
  color: var(--text-2);
}

.empty-state h2 {
  font-size: 18px;
  color: var(--text);
}

.empty-state p {
  max-width: 52ch;
  margin: 0;
}

.error-state {
  border-color: #f0b8b1;
  color: var(--danger);
}

.error-state .page-title,
.error-state p {
  color: var(--text);
}

.view-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 48px 16px;
  color: var(--text-2);
}

.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------------------------------------------------------------------------------------------
   Modaalit ja ilmoitukset
   --------------------------------------------------------------------------------------------- */

dialog.modal {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: none;
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-2);
}

dialog.modal-sm {
  width: min(440px, calc(100vw - 32px));
}

dialog.modal-lg {
  width: min(760px, calc(100vw - 32px));
}

dialog.modal::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.modal-form {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 48px);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px 8px;
}

.modal-title {
  font-size: 18px;
  font-weight: 650;
}

.modal-body {
  padding: 8px 20px 4px;
  overflow-y: auto;
}

.modal-intro,
.modal-message {
  color: var(--text-2);
}

.modal-list {
  margin: 0 0 8px;
  padding-left: 20px;
  color: var(--text-2);
}

.modal-list li {
  margin-bottom: 6px;
}

.modal-error {
  margin: 4px 0 12px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 14px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px 16px;
  flex-wrap: wrap;
}

.modal-form.is-busy {
  cursor: progress;
}

.progress-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.progress {
  flex: 1;
  height: 8px;
  accent-color: var(--accent);
}

.progress-percent {
  min-width: 44px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}

.toast-region {
  position: fixed;
  left: 50%;
  bottom: 44px;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(520px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px 10px 14px;
  border-radius: var(--radius);
  background: #1f2937;
  color: #fff;
  font-size: 14px;
  box-shadow: var(--shadow-2);
  pointer-events: auto;
  animation: toast-in 0.18s ease-out;
}

.toast-text {
  flex: 1;
}

.toast .btn-ghost {
  color: #cbd5e1;
}

.toast .btn-ghost:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.toast-success .icon {
  color: #6ee7a1;
}

.toast-error {
  background: #7f1d1d;
}

.toast-warning .icon {
  color: #fbbf24;
}

.toast-info .icon {
  color: #93c5fd;
}

.toast-leaving {
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.2s, transform 0.2s;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

kbd {
  display: inline-block;
  min-width: 22px;
  padding: 1px 6px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 12px;
  text-align: center;
  white-space: nowrap;
}

.kbd-plus {
  margin: 0 3px;
  color: var(--text-3);
}

.shortcut-groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 8px 28px;
}

.shortcut-title {
  margin: 8px 0 6px;
  font-size: 14px;
  color: var(--accent);
}

.shortcut-list {
  margin: 0 0 8px;
}

.shortcut-row {
  display: grid;
  grid-template-columns: minmax(110px, auto) 1fr;
  gap: 12px;
  padding: 4px 0;
  border-bottom: 1px solid var(--surface-3);
  font-size: 13.5px;
}

.shortcut-row dt {
  white-space: nowrap;
}

.shortcut-row dd {
  margin: 0;
  color: var(--text-2);
}

.shortcut-help-link {
  margin: 12px 0 0;
}

/* ---------------------------------------------------------------------------------------------
   Ohjesivu
   --------------------------------------------------------------------------------------------- */

.header-link {
  margin-left: auto;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 14px;
  font-weight: 550;
  text-decoration: none;
  white-space: nowrap;
}

.header-link:hover {
  background: var(--surface-3);
  color: var(--accent);
}

.help-page {
  max-width: 1240px;
}

.help-layout {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  gap: 28px;
  align-items: start;
}

.help-toc {
  position: sticky;
  top: calc(var(--header-h) + 16px);
  max-height: calc(100vh - var(--header-h) - 32px);
  overflow-y: auto;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13.5px;
}

.help-toc ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.help-toc-group + .help-toc-group {
  margin-top: 12px;
}

.help-toc-part,
.help-part {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-3);
}

.help-toc-link {
  display: block;
  width: 100%;
  padding: 4px 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-2);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.help-toc-link:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.help-toc-link:focus-visible {
  outline: 2px solid var(--accent-ring);
  outline-offset: 1px;
}

.help-content {
  min-width: 0;
}

.help-section {
  margin-bottom: 20px;
  padding: 20px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  scroll-margin-top: calc(var(--header-h) + 16px);
}

.help-heading {
  margin: 0 0 12px;
  font-size: 20px;
  font-weight: 650;
}

.help-heading:focus {
  outline: none;
}

.help-subheading {
  margin: 20px 0 8px;
  font-size: 15.5px;
  font-weight: 650;
}

.help-section p {
  margin: 0 0 10px;
  max-width: 82ch;
  line-height: 1.55;
}

.help-list {
  margin: 0 0 12px;
  padding-left: 22px;
  max-width: 82ch;
  line-height: 1.55;
}

.help-list li + li {
  margin-top: 4px;
}

.help-note {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0 0 12px;
  padding: 10px 14px;
  border-left: 3px solid;
  border-radius: var(--radius-sm);
}

.help-note svg {
  flex: none;
  margin-top: 2px;
}

.help-note p {
  margin: 0;
}

.help-note-info {
  background: var(--info-soft);
  border-color: var(--info);
}

.help-note-info svg {
  color: var(--info);
}

.help-note-warning {
  background: var(--warning-soft);
  border-color: var(--warning);
}

.help-note-warning svg {
  color: var(--warning);
}

.help-table-wrap {
  margin: 0 0 12px;
  overflow-x: auto;
}

.help-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  line-height: 1.45;
}

.help-table th,
.help-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.help-table th {
  background: var(--surface-2);
  color: var(--text-2);
  font-weight: 650;
  white-space: nowrap;
}

.help-practice-table td:first-child {
  min-width: 260px;
}

.help-practice-table td:nth-child(2) {
  white-space: nowrap;
}

.help-source {
  min-width: 160px;
  color: var(--text-2);
}

.help-kind {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.help-kind-rule {
  background: var(--danger-soft);
  color: var(--danger);
}

.help-kind-recommendation {
  background: var(--info-soft);
  color: var(--info);
}

.help-kind-practice {
  background: var(--surface-3);
  color: var(--text-2);
}

@media (max-width: 1000px) {
  .help-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .help-toc {
    position: static;
    max-height: none;
  }
}

@media (max-width: 760px) {
  .help-section {
    padding: 16px;
  }
}

@media print {
  .help-toc {
    display: none;
  }

  .help-layout {
    display: block;
  }

  .help-section {
    border: 0;
    padding: 0;
  }
}

/* ---------------------------------------------------------------------------------------------
   Editori
   --------------------------------------------------------------------------------------------- */

.editor {
  position: relative;
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr) 344px;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "toolbar toolbar toolbar"
    "palette canvas panel"
    "status status status";
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
  overflow: hidden;
}

/* Työkalurivi */
.ed-toolbar {
  grid-area: toolbar;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 52px;
  padding: 6px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: thin;
  z-index: 20;
}

.tb-group {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 6px;
  border-right: 1px solid var(--border);
  flex: none;
}

.tb-group:last-child {
  border-right: none;
}

.tb-nav {
  gap: 8px;
  padding-left: 0;
  flex: none;
}

.tb-nav .ed-title {
  min-width: 96px;
}

.tb-spacer {
  flex: 1 1 0;
  min-width: 0;
}

.tb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 34px;
  height: 34px;
  padding: 0 7px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 550;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  flex: none;
}

.tb-btn:hover:not(:disabled) {
  background: var(--surface-3);
  color: var(--text);
}

.tb-btn[aria-pressed=true] {
  background: var(--accent-soft);
  border-color: var(--accent-ring);
  color: var(--accent);
}

.tb-btn:disabled {
  opacity: 0.38;
  cursor: default;
}

.zoom-label {
  min-width: 58px;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}

.drawer-toggle {
  display: none;
}

.ed-title {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 280px;
  line-height: 1.2;
}

.ed-project {
  font-size: 11.5px;
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ed-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
  padding: 1px 4px;
  margin-left: -4px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  font-size: 15px;
  font-weight: 650;
  color: var(--text);
  cursor: pointer;
}

.ed-name:hover {
  border-color: var(--border);
  background: var(--surface-2);
}

.ed-name .icon {
  flex: none;
  color: var(--text-3);
}

.ed-name-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.save-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 12.5px;
  color: var(--text-2);
  cursor: pointer;
  white-space: nowrap;
  flex: none;
  /* Tavallisimmat tilat (Tallennettu / Tallentamatta / Tallennetaan…) mahtuvat samaan leveyteen,
     jolloin työkalurivin painikkeet eivät siirry automaattitallennuksen aikana. */
  min-width: 118px;
}

.save-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}

.save-status[data-state=dirty] .save-dot {
  background: #d4a106;
}

.save-status[data-state=saving] .save-dot {
  background: var(--accent);
  animation: pulse 0.9s ease-in-out infinite;
}

.save-status[data-state=error],
.save-status[data-state=conflict] {
  border-color: #f0b8b1;
  background: var(--danger-soft);
  color: var(--danger);
}

.save-status[data-state=error] .save-dot,
.save-status[data-state=conflict] .save-dot {
  background: var(--danger);
}

@keyframes pulse {
  50% { opacity: 0.3; }
}

/* Symbolipaletti */
.ed-palette {
  grid-area: palette;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
  z-index: 10;
}

.palette-head {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 12px 6px;
}

.panel-title {
  font-size: 14px;
  font-weight: 650;
}

.palette-help {
  margin: 0;
  padding: 0 12px 8px;
  font-size: 12px;
  color: var(--text-3);
  border-bottom: 1px solid var(--border);
}

/* Paletin vieritettävä alue: Pohjapiirustus-osio ja symbolikategoriat. */
.palette-scroll {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
}

.palette-groups {
  padding: 6px 8px 16px;
}

.palette-group-title {
  margin: 10px 4px 4px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-3);
}

.palette-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.palette-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 5px 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  text-align: left;
  cursor: grab;
}

.palette-item:hover {
  background: var(--surface-3);
}

.palette-item:active {
  cursor: grabbing;
}

.palette-item.is-armed {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.palette-glyph {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
}

.palette-item.is-armed .palette-glyph {
  border-color: var(--accent);
}

.palette-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.palette-name {
  font-size: 13px;
  font-weight: 550;
  color: var(--text);
  hyphens: auto;
  overflow-wrap: anywhere;
}

.palette-iec {
  font-size: 11.5px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.palette-empty {
  padding: 12px 6px;
  font-size: 13px;
}

/* Symbolien merkit pienessä koossa: viiva näkyväksi riippumatta mittakaavasta. */
.glyph * {
  vector-effect: non-scaling-stroke;
  stroke-width: 1.35px;
}

/* Symbolien tunnistus: "Mikä symboli tämä on?" (SPEC D7) */
.sr-dialog {
  display: grid;
  gap: 12px;
}

.sr-previews {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}

.sr-figure {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin: 0;
}

.sr-crop,
.sr-preview-symbol {
  display: grid;
  place-items: center;
  width: 132px;
  height: 132px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
}

.sr-preview-name {
  min-height: 1.3em;
  margin: 0;
  max-width: 180px;
  text-align: center;
}

.sr-arrow {
  font-size: 22px;
  color: var(--text-3);
}

.sr-orientation {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 14px;
}

.sr-orientation .field-label,
.sr-orientation .field-check {
  margin: 0;
}

.sr-picker {
  display: grid;
  gap: 6px;
}

.sr-symbol-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 4px;
  max-height: 220px;
  overflow-y: auto;
  padding: 2px;
}

.sr-symbol {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
}

.sr-symbol:hover {
  background: var(--surface-2);
}

.sr-symbol.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

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

.sr-symbol-glyph {
  display: grid;
  place-items: center;
  flex: none;
  width: 34px;
  height: 34px;
  background: #fff;
  border-radius: 3px;
}

.sr-symbol-name {
  min-width: 0;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.sr-options {
  display: grid;
  gap: 6px;
}

.sr-sensitivity select {
  max-width: 200px;
}

/* Tunnista kaikki: "Tunnistetut symbolit" (SPEC §D8) */
.sg-layout {
  display: grid;
  grid-template-columns: minmax(170px, 220px) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.sg-groups {
  display: grid;
  gap: 4px;
  max-height: 520px;
  overflow-y: auto;
  padding: 2px;
}

.sg-group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
}

.sg-group:hover {
  background: var(--surface-2);
}

.sg-group.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

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

.sg-thumb {
  flex: none;
  width: 56px;
  height: 56px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: #fff;
}

.sg-group-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.sg-count {
  font-weight: 600;
}

.sg-choice {
  overflow-wrap: anywhere;
}

.sg-group.is-named .sg-choice {
  color: var(--accent);
}

.sg-text-badge {
  justify-self: start;
  margin: 0;
}

.sg-editor {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.sg-current-title {
  margin: 0;
  font-weight: 600;
}

@media (max-width: 640px) {
  .sg-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .sg-groups {
    max-height: 220px;
  }
}

/* Piirtoalue */
.ed-canvas {
  grid-area: canvas;
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--canvas-bg);
  background-image: radial-gradient(circle, rgba(15, 23, 42, 0.07) 1px, transparent 1px);
  background-size: 18px 18px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  outline: none;
}

.ed-canvas:focus-visible {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.ed-svg {
  display: block;
  width: 100%;
  height: 100%;
}

.ed-paper {
  fill: #fff;
  stroke: #b7c1cd;
  stroke-width: 1px;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 3px 8px rgba(15, 23, 42, 0.18));
}

.ed-canvas[data-tool=wire],
.ed-canvas[data-tool=calibrate],
.ed-canvas[data-tool=wallSample],
.ed-canvas[data-tool=symbolCrop] {
  cursor: crosshair;
}

.ed-canvas[data-tool=text] {
  cursor: text;
}

.ed-canvas[data-tool=place] {
  cursor: copy;
}

.ed-canvas[data-tool=wall],
.ed-canvas[data-tool=window],
.ed-canvas[data-tool=door],
.ed-canvas[data-tool=line],
.ed-canvas[data-tool=ellipse],
.ed-canvas[data-tool=rectangle] {
  cursor: crosshair;
}

.ed-canvas.is-space,
.ed-canvas.is-space * {
  cursor: grab !important;
}

.ed-canvas.is-panning,
.ed-canvas.is-panning * {
  cursor: grabbing !important;
}

.ed-hit .hit-box {
  fill: transparent;
  stroke: none;
  pointer-events: all;
}

.ed-hit .hit-wire {
  fill: none;
  stroke: transparent;
  stroke-width: 12px;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  pointer-events: stroke;
}

/* Oman pohjapiirustuksen osuma-alueet (SPEC C7.5): seinän ääriviiva + 10 px reuna, muodot ja ovilehdet leveällä
   läpinäkyvällä viivalla. Ne ovat sisällön alla, joten symbolit, merkinnät ja selite pysyvät napsautettavina. */
.ed-hit-plan .hit-plan-area {
  fill: transparent;
  stroke: transparent;
  stroke-width: 10px;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  pointer-events: all;
}

.ed-hit-plan .hit-plan-line {
  fill: none;
  stroke: transparent;
  stroke-width: 12px;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
  pointer-events: stroke;
}

.ed-canvas:not([data-tool=select]) .ed-hit,
.ed-canvas:not([data-tool=select]) .ed-hit-plan,
.ed-canvas:not([data-tool=select]) .ed-handles {
  pointer-events: none;
}

.ed-canvas[data-tool=select] .ed-hit .hit-box,
.ed-canvas[data-tool=select] .ed-hit .hit-wire,
.ed-canvas[data-tool=select] .ed-hit-plan [data-id],
.ed-canvas[data-tool=select] .layer-content [data-id] {
  cursor: move;
}

.ed-handles .plan-flip {
  cursor: pointer;
}

.ed-canvas[data-tool=select] .layer-background.is-movable image {
  cursor: move;
}

.ed-canvas[data-tool=select] .sheet-legend [data-kind] {
  cursor: move;
}

.ed-handles .handle {
  cursor: crosshair;
}

.flash-ring {
  animation: flash 0.5s ease-in-out 3;
}

@keyframes flash {
  50% { opacity: 0.15; }
}

/* Oikea paneeli ja välilehdet */
.ed-panel {
  grid-area: panel;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow: hidden;
  z-index: 10;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  flex: none;
}

.tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
  padding: 8px 4px 7px;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-3);
  cursor: pointer;
}

.tab:hover {
  color: var(--text);
  background: var(--surface-3);
}

.tab[aria-selected=true] {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: var(--surface);
}

.tab:focus-visible {
  outline-offset: -3px;
}

.tab-label {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tab-badge {
  position: absolute;
  top: 4px;
  right: calc(50% - 22px);
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  font-size: 10.5px;
  line-height: 17px;
  text-align: center;
  color: #fff;
  background: var(--warning);
}

.tab-badge.is-error {
  background: var(--danger);
}

.tab-panels {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.tab-panel {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  outline: none;
}

.tab-panel:focus-visible {
  box-shadow: inset 0 0 0 2px var(--accent-ring);
}

.panel-content {
  padding: 14px 16px 28px;
}

.panel-empty {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
  color: var(--text-3);
}

.panel-empty .btn {
  margin: 4px 0;
}

.panel-heading {
  font-size: 16px;
  font-weight: 650;
  color: var(--text);
}

.panel-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 18px 0 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.panel-content > .panel-section-head:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.panel-section-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-3);
}

.prop-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

.prop-glyph {
  display: grid;
  place-items: center;
  flex: none;
  width: 52px;
  height: 52px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text-2);
}

.prop-glyph-unknown {
  color: var(--danger);
  font-size: 24px;
  font-weight: 700;
  border-color: var(--danger);
  border-style: dashed;
}

.prop-description {
  font-size: 13px;
  color: var(--text-2);
  white-space: pre-line;
}

.prop-info {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  margin: 0 0 12px;
  font-size: 13px;
}

.prop-info div {
  display: contents;
}

.prop-info dt {
  color: var(--text-3);
}

.prop-info dd {
  margin: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.prop-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.row-gap.wrap {
  margin-bottom: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 10px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge-ok {
  background: var(--success-soft);
  color: var(--success);
}

.badge-warn {
  background: var(--warning-soft);
  color: var(--warning);
}

.revision-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.revision-row {
  margin: 0;
  padding: 10px 12px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.revision-legend {
  padding: 0 4px;
  font-size: 12.5px;
  font-weight: 650;
  color: var(--text-2);
}

.revision-row .field {
  margin-bottom: 8px;
}

.revision-row > .btn {
  margin-bottom: 6px;
}

/* Tarkistus */
.validation-status {
  margin: 4px 0 10px;
}

.validation-status.is-error {
  color: var(--danger);
}

.validation-verdict {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
}

.validation-verdict.is-valid {
  background: var(--success-soft);
  color: var(--success);
}

.validation-verdict.is-invalid {
  background: var(--danger-soft);
  color: var(--danger);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 4px;
}

.chip {
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.chip-error {
  background: var(--danger-soft);
  color: var(--danger);
}

.chip-warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.chip-info {
  background: var(--info-soft);
  color: var(--info);
}

.validation-group {
  margin-top: 16px;
}

.validation-group-title {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 700;
}

.sev-error .validation-group-title,
.sev-error .issue-icon {
  color: var(--danger);
}

.sev-warning .validation-group-title,
.sev-warning .issue-icon {
  color: var(--warning);
}

.sev-info .validation-group-title,
.sev-info .issue-icon {
  color: var(--info);
}

.issue-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.issue {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.issue-button {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.issue-button:hover {
  background: var(--surface-3);
}

.issue-button.is-static {
  cursor: default;
}

.issue-button.is-static:hover {
  background: transparent;
}

.issue-icon {
  flex: none;
  margin-top: 1px;
}

.issue-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.issue-message {
  font-size: 13.5px;
  color: var(--text);
}

.issue-meta {
  font-size: 11.5px;
  color: var(--text-3);
}

.issue-action {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
}

.issue-rule {
  padding: 0 10px 6px 34px;
  font-size: 12.5px;
  color: var(--text-2);
}

.issue-rule summary {
  cursor: pointer;
  color: var(--text-3);
  font-size: 12px;
}

.issue-rule p {
  margin: 4px 0;
}

.bg-status .prop-info {
  margin-top: 2px;
}

/* Tilarivi */
.ed-statusbar {
  grid-area: status;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 28px;
  padding: 0 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  z-index: 20;
}

.sb-coords {
  min-width: 160px;
  font-variant-numeric: tabular-nums;
}

.sb-zone {
  min-width: 70px;
}

.sb-selection {
  min-width: 70px;
  color: var(--accent);
  font-weight: 600;
}

.sb-hint {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-3);
}

.ed-scrim {
  display: none;
}

/* ---------------------------------------------------------------------------------------------
   Oma pohjapiirustus (osa C): paletin osio, työkalun asetukset, kosketuspalkki
   --------------------------------------------------------------------------------------------- */

.palette-plan {
  padding: 6px 8px 8px;
  border-bottom: 1px solid var(--border);
}

.palette-plan-head {
  display: flex;
  align-items: center;
  gap: 4px;
}

.palette-plan-toggle {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 4px;
  min-height: 32px;
  padding: 0 4px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.palette-plan-toggle:hover {
  background: var(--surface-3);
}

.palette-plan-toggle .palette-group-title {
  margin: 0;
}

.palette-plan-chevron {
  width: 14px;
  color: var(--text-3);
  font-size: 12px;
}

.palette-plan-lock.is-locked {
  color: var(--accent);
}

.plan-tools {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  margin-top: 4px;
}

.plan-tool {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
}

.plan-tool:hover {
  background: var(--surface-3);
}

.plan-tool.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.plan-tool-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.plan-tool-key {
  padding: 0 4px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text-3);
  font-family: var(--mono);
  font-size: 10.5px;
}

.plan-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.plan-option-label {
  margin-bottom: 3px;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
}

.plan-options .segmented {
  flex-wrap: wrap;
}

.plan-options .seg-btn {
  font-size: 12px;
}

.segmented-vertical {
  flex-direction: column;
  width: 100%;
}

.segmented-vertical .seg-btn {
  border-right: none;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.segmented-vertical .seg-btn:last-child {
  border-bottom: none;
}

.plan-option-number .input-unit {
  max-width: 140px;
}

.plan-help {
  padding: 0;
  border-bottom: none;
}

.plan-flip-state {
  margin: 0;
  color: var(--text-3);
  font-size: 12px;
}

.plan-flip-state.is-on {
  color: var(--accent);
  font-weight: 600;
}

.prop-hosted {
  margin: 4px 0;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
}

.plan-section {
  margin-top: 8px;
}

.plan-counts {
  margin: 0 0 6px;
}

/* Kosketus ja kapea näyttö: seinä- ja viivaketjun toiminnot piirtoalueen alareunassa (SPEC C7.8). */
.ed-chain-bar {
  position: absolute;
  left: 50%;
  bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  /* left: 50 % kutistaisi palkin puoleen piirtoalueen leveydestä; luonnollinen leveys, enintään koko alue. */
  width: max-content;
  max-width: calc(100% - 24px);
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-2);
  transform: translateX(-50%);
  z-index: 15;
}

.ed-chain-bar[hidden] {
  display: none;
}

.ed-chain-bar .chain-btn {
  min-width: 44px;
  min-height: 44px;
}

.ed-chain-bar .chain-length {
  width: 120px;
  min-height: 44px;
}

/* Pituuden suuntapainikkeet (→ ↓ ← ↑, vinot vain 45° kulmilla) pysyvät yhdessä ryhmänä. */
.ed-chain-bar .chain-dirs {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
}

.ed-chain-bar .chain-dir {
  padding: 0 8px;
  font-size: 18px;
}

/* ---------------------------------------------------------------------------------------------
   Ohjattu aloitus (SPEC osa E): aloitustavan valinta ja editorin ohjekortti
   --------------------------------------------------------------------------------------------- */

/* "Miten aloitetaan?": suuret vaihtoehtopainikkeet (kuvake, otsikko ja kuvaus). */
.start-choices {
  display: grid;
  gap: 10px;
  margin: 4px 0 12px;
}

.start-choice {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 72px;
  padding: 12px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  white-space: normal;
  cursor: pointer;
  transition: border-color 0.12s, background-color 0.12s, box-shadow 0.12s;
}

.start-choice:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.start-choice:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.start-choice-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
}

.start-choice:hover .start-choice-icon {
  background: var(--surface);
}

.start-choice-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.start-choice-title {
  font-weight: 650;
  font-size: 15.5px;
}

.start-choice-desc {
  font-size: 13.5px;
  line-height: 1.4;
  color: var(--text-2);
}

/* Editorin kortti piirtoalueen vasemmassa yläkulmassa (sama ruudukkoalue kuin piirtoalueella). Kortti ei peitä
   työkaluriviä eikä paneeleja, ja piirtoalue kortin ulkopuolella ottaa napsautukset vastaan. */
.start-wizard {
  grid-area: canvas;
  align-self: start;
  justify-self: start;
  z-index: 14;
  display: flex;
  flex-direction: column;
  width: min(360px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  margin: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-2);
  overflow: auto;
  overscroll-behavior: contain;
  animation: sw-in 0.18s ease-out;
}

@keyframes sw-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
}

.sw-header {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 8px 6px 14px;
  background: var(--surface);
  z-index: 1;
}

.sw-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 650;
}

.sw-title .icon {
  color: var(--accent);
}

.sw-header-actions {
  display: flex;
  gap: 2px;
}

.sw-body {
  padding: 0 14px 14px;
}

.sw-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin: 0 0 12px;
  padding: 0 0 10px;
  list-style: none;
  border-bottom: 1px solid var(--border);
}

.sw-step {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-3);
}

.sw-step-mark {
  display: grid;
  place-items: center;
  flex: none;
  width: 22px;
  height: 22px;
  border: 1.5px solid var(--border-strong);
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}

.sw-step.is-current {
  color: var(--text);
  font-weight: 650;
}

.sw-step.is-current .sw-step-mark {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.sw-step.is-done {
  color: var(--text-2);
}

.sw-step.is-done .sw-step-mark {
  border-color: var(--success);
  background: var(--success-soft);
  color: var(--success);
}

.sw-step.is-skipped .sw-step-mark {
  border-style: dashed;
}

.sw-step.is-skipped .sw-step-label {
  text-decoration: line-through;
}

.sw-step-title {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 650;
  border-radius: 4px;
}

.sw-step-title:focus {
  outline: none;
}

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

.sw-text,
.sw-tip {
  margin: 0 0 8px;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--text-2);
}

.sw-tip {
  color: var(--text-3);
}

.sw-note {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin: 0 0 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.4;
}

.sw-note .icon {
  flex: none;
  margin-top: 1px;
}

.sw-note.is-ok {
  background: var(--success-soft);
  color: var(--success);
}

.sw-note.is-warn {
  background: var(--warning-soft);
  color: var(--warning);
}

.sw-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.sw-summary {
  display: grid;
  gap: 6px;
  margin: 0 0 10px;
  padding: 0;
  list-style: none;
  font-size: 13.5px;
  line-height: 1.4;
}

.sw-summary li {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  color: var(--text-2);
}

.sw-summary li .icon {
  flex: none;
  margin-top: 1px;
}

.sw-summary li.is-done .icon {
  color: var(--success);
}

.sw-summary li.is-skipped .icon {
  color: var(--text-3);
}

/* Kapea näyttö: kortti on alareunan levyinen paneeli (bottom sheet), joka vierii itsenäisesti. */
@media (max-width: 760px) {
  .start-wizard {
    align-self: end;
    justify-self: stretch;
    width: auto;
    max-height: min(55%, 440px);
    margin: 0;
    border-width: 1px 0 0;
    border-radius: var(--radius) var(--radius) 0 0;
    animation-name: sw-up;
  }

  .start-wizard .btn {
    min-height: 40px;
  }

  .start-wizard .btn-icon {
    width: 40px;
  }
}

@keyframes sw-up {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
}

/* "Tunnistetut johtovedot" (§D9): ei-modaalinen kortti piirtoalueen oikeassa yläkulmassa (ohjatun aloituksen kortti
   on vasemmassa), joten esikatselu ja piirtoalue jäävät näkyviin ja käytettäviksi. */
.wire-review {
  grid-area: canvas;
  align-self: start;
  justify-self: end;
  z-index: 15;
  display: flex;
  flex-direction: column;
  width: min(340px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  margin: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-2);
  overflow: auto;
  overscroll-behavior: contain;
  animation: sw-in 0.18s ease-out;
}

.wr-header {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 8px 6px 14px;
  background: var(--surface);
  z-index: 1;
}

.wr-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 650;
  border-radius: 4px;
}

.wr-title .icon {
  color: var(--accent);
}

.wr-title:focus {
  outline: none;
}

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

.wr-body {
  display: grid;
  gap: 10px;
  padding: 0 14px 14px;
}

.wr-text {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--text-2);
}

.wr-kinds {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
}

.wire-review .field {
  margin-bottom: 0;
}

/* Lajin väri esikatselun katkoviivana. */
.wr-swatch {
  flex: none;
  width: 22px;
  height: 0;
  border-top: 3px dashed;
}

.wr-kind .field-hint {
  margin-left: 56px;
}

.wr-notes {
  display: grid;
  gap: 4px;
  margin: 0;
  padding: 6px 8px;
  list-style: none;
  border-radius: var(--radius-sm);
  background: var(--warning-soft);
  color: var(--warning);
  font-size: 13px;
  line-height: 1.4;
}

.wr-notes li {
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

.wr-notes .icon {
  flex: none;
  margin-top: 2px;
}

.wr-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Kapea näyttö: alareunan levyinen paneeli kuten ohjatun aloituksen kortti (peittää pienennetyn kortin). */
@media (max-width: 760px) {
  .wire-review {
    align-self: end;
    justify-self: stretch;
    width: auto;
    max-height: min(55%, 440px);
    margin: 0;
    border-width: 1px 0 0;
    border-radius: var(--radius) var(--radius) 0 0;
    animation-name: sw-up;
  }

  .wire-review .btn {
    min-height: 40px;
  }

  .wire-review .btn-icon {
    width: 40px;
  }
}

/* ---------------------------------------------------------------------------------------------
   Responsiivisuus
   --------------------------------------------------------------------------------------------- */

/* Sivupaneelien avauspainikkeet näkyvät vain kapeilla näytöillä. */
.ed-toolbar > .tb-group[aria-label="Sivupaneelit"] {
  display: none;
}

@media (max-width: 1680px) {
  .tb-group:not([aria-label="Työkalut"]) .tb-text {
    display: none;
  }
}

@media (max-width: 1440px) {
  .tb-group .tb-text {
    display: none;
  }

  .tb-group {
    padding: 0 4px;
  }

  .ed-title {
    max-width: 190px;
  }
}

@media (max-width: 1100px) {
  .editor {
    grid-template-columns: 236px minmax(0, 1fr);
    grid-template-areas:
      "toolbar toolbar"
      "palette canvas"
      "status status";
  }

  .ed-toolbar > .tb-group[aria-label="Sivupaneelit"] {
    display: flex;
  }

  .drawer-toggle {
    display: inline-flex;
  }

  .drawer-toggle:first-child {
    display: none;
  }

  .save-status .save-text {
    display: none;
  }

  .save-status {
    padding: 0 9px;
    min-width: 0;
  }

  .ed-title {
    max-width: 130px;
  }

  .ed-toolbar {
    padding: 6px 6px;
  }

  .tb-group {
    padding: 0 3px;
  }

  .tb-btn {
    min-width: 32px;
    padding: 0 5px;
  }

  .zoom-label {
    min-width: 50px;
  }

  /* Ominaisuuspaneeli liukuu piirtoalueen päälle oikealta (sama ruudukkoalue kuin piirtoalueella). */
  .ed-panel {
    grid-area: canvas;
    justify-self: end;
    width: min(360px, 92vw);
    height: 100%;
    border-left: 1px solid var(--border);
    box-shadow: var(--shadow-2);
    transform: translateX(105%);
    transition: transform 0.2s ease, visibility 0.2s;
    z-index: 30;
    visibility: hidden;
  }

  .editor.show-panel .ed-panel {
    transform: none;
    visibility: visible;
  }

  .editor.show-panel .ed-scrim,
  .editor.show-palette .ed-scrim {
    display: block;
    grid-area: canvas;
    width: 100%;
    height: 100%;
    border: none;
    background: rgba(15, 23, 42, 0.25);
    z-index: 25;
  }
}

@media (max-width: 760px) {
  .editor {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "toolbar"
      "canvas"
      "status";
  }

  .drawer-toggle:first-child {
    display: inline-flex;
  }

  /* Kapealla näytöllä sivupaneelien painikkeet heti otsikon jälkeen; muu työkalurivi vierii. */
  .ed-toolbar > .tb-group {
    order: 2;
  }

  .ed-toolbar > .tb-nav {
    order: 0;
  }

  .ed-toolbar > .tb-group[aria-label="Sivupaneelit"] {
    order: 1;
    border-right: 1px solid var(--border);
  }

  .ed-toolbar > .tb-spacer {
    display: none;
  }

  /* Symbolipaletti liukuu piirtoalueen päälle vasemmalta. */
  .ed-palette {
    grid-area: canvas;
    justify-self: start;
    width: min(300px, 88vw);
    height: 100%;
    box-shadow: var(--shadow-2);
    transform: translateX(-105%);
    transition: transform 0.2s ease, visibility 0.2s;
    z-index: 30;
    visibility: hidden;
  }

  .editor.show-palette .ed-palette {
    transform: none;
    visibility: visible;
  }

  .ed-title {
    max-width: 140px;
  }

  .save-status {
    padding: 0 8px;
  }

  .sb-zone,
  .sb-hint {
    display: none;
  }

  .page {
    padding: 20px 16px 48px;
  }

  .page-title {
    font-size: 22px;
  }

  .card {
    flex-wrap: wrap;
    padding: 4px 8px 8px 4px;
  }

  .card-main {
    flex-basis: 100%;
  }

  .card-actions {
    margin-left: 62px;
  }

  .brand-name {
    display: none;
  }

  .field-grid {
    grid-template-columns: 1fr;
  }
}


@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media print {
  .app-header,
  .toast-region {
    display: none;
  }
}

/* ---------------------------------------------------------------------------------------------
   Kirjautuminen, kutsut ja käyttäjähallinta
   --------------------------------------------------------------------------------------------- */

.user-menu {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.user-menu[hidden] {
  display: none;
}

.user-name {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  color: var(--text-2);
}

.btn-small {
  min-height: 30px;
  padding: 0 10px;
  font-size: 13.5px;
}

.auth-page {
  max-width: 540px;
  padding-top: 48px;
}

.auth-card {
  display: grid;
  gap: 16px;
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-1);
}

.auth-card .page-lead {
  margin: 0;
}

.auth-providers {
  display: grid;
  gap: 10px;
}

.auth-provider {
  min-height: 44px;
  font-size: 15px;
}

.auth-error,
.auth-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
}

.auth-error {
  background: var(--danger-soft);
  color: var(--danger);
}

.auth-error[hidden] {
  display: none;
}

.auth-note {
  background: var(--info-soft);
  color: var(--text);
}

.auth-facts {
  margin: 0;
  padding-left: 20px;
  color: var(--text-2);
}

.auth-dev {
  display: grid;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px dashed var(--border-strong);
}

.auth-dev .field {
  margin: 0;
}

.auth-dev-title {
  margin: 0;
  font-size: 15px;
}

.auth-dev p {
  margin: 0;
}

.admin-section {
  margin-top: 28px;
}

.admin-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.admin-section-header h2 {
  margin: 0;
  font-size: 18px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th,
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.data-table th {
  background: var(--surface-2);
  color: var(--text-2);
  font-weight: 600;
  white-space: nowrap;
}

.data-table tr:last-child td {
  border-bottom: 0;
}

.admin-primary,
.admin-secondary {
  display: block;
}

.admin-secondary {
  margin-top: 2px;
  color: var(--text-3);
  font-size: 13px;
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
}

.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
}

.status-active {
  background: var(--success-soft);
  color: var(--success);
}

.status-used {
  background: var(--info-soft);
  color: var(--info);
}

.status-expired {
  background: var(--warning-soft);
  color: var(--warning);
}

.status-revoked {
  background: var(--danger-soft);
  color: var(--danger);
}

.invite-link-row {
  display: flex;
  gap: 8px;
  margin: 12px 0;
}

.invite-link {
  flex: 1;
  min-width: 0;
  font-family: var(--mono);
  font-size: 13px;
}

@media (max-width: 640px) {
  .user-name {
    display: none;
  }

  .auth-page {
    padding-top: 24px;
  }

  .auth-card {
    padding: 20px;
  }
}
