/* Touch and responsive refinements loaded after the base stylesheet. */

html,
body,
.app-shell { min-height: 100dvh; }

.content { min-height: 100dvh; }
.view-plan { height: calc(100dvh - var(--topbar)); }

.element { cursor: default; }
.canvas-viewport[data-tool="select"] .element { cursor: grab; }
.canvas-viewport[data-tool="select"] .element:active { cursor: grabbing; }

.server-load-button svg { width: 17px; }
.server-load-button:disabled,
.button:disabled { opacity: .5; cursor: wait; }

.plan-edit-button {
  flex: 0 0 auto;
  min-width: 42px;
  padding: 0 10px;
  border: 0;
  border-right: 1px solid var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--ink-soft);
  background: transparent;
  cursor: pointer;
  font-size: 10px;
  font-weight: 750;
}
.plan-edit-button:hover { color: var(--green-dark); background: var(--green-soft); }
.plan-edit-button svg { width: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.tool-mode-chip {
  position: absolute;
  z-index: 12;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100% - 32px);
  padding: 6px 6px 6px 12px;
  border: 1px solid rgba(20,107,85,.3);
  border-radius: 999px;
  color: var(--green-dark);
  background: rgba(244,250,247,.96);
  box-shadow: var(--shadow-small);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
  backdrop-filter: blur(10px);
}
.tool-mode-chip[hidden] { display: none; }
.tool-mode-chip button {
  min-height: 34px;
  padding: 0 13px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: var(--green);
  cursor: pointer;
  font-weight: 800;
}

.selection-actions {
  position: absolute;
  z-index: 13;
  left: 50%;
  bottom: 15px;
  transform: translateX(-50%);
  max-width: calc(100% - 370px);
  min-height: 48px;
  padding: 5px;
  display: flex;
  align-items: center;
  gap: 3px;
  border: 1px solid var(--line-strong);
  border-radius: 13px;
  background: rgba(255,253,250,.97);
  box-shadow: 0 10px 28px rgba(23,37,35,.18);
  backdrop-filter: blur(12px);
}
.selection-actions[hidden] { display: none; }
.selection-actions > strong {
  max-width: 150px;
  padding: 0 9px;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink-soft);
  font-size: 10px;
  white-space: nowrap;
}
.selection-actions button {
  min-height: 38px;
  padding: 0 10px;
  border: 0;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
  font-size: 10px;
  font-weight: 750;
}
.selection-actions button:hover { color: var(--green-dark); background: var(--green-soft); }
.selection-actions button.is-danger:hover { color: var(--red); background: var(--red-soft); }
.quick-action-icon { font-size: 17px; line-height: 1; }

@media (any-pointer: coarse), (hover: none) {
  button,
  .button,
  .icon-button { min-height: 44px; }
  .icon-button { min-width: 44px; }
  .field input,
  .field select,
  .field textarea,
  .filter-bar select,
  .search-field,
  .search-field input { min-height: 46px; font-size: 16px; }
  .field textarea { min-height: 100px; }
  .field > span,
  .field-label,
  .field-hint { font-size: 12px; }
  .layer-row,
  .check-field { min-height: 48px; font-size: 13px; }
  .layer-row input,
  .check-field input,
  .snap-toggle input { width: 22px; height: 22px; }
  .zoom-controls { height: 48px; }
  .zoom-controls button { min-width: 48px; }
  .zoom-controls .zoom-value { min-width: 62px; font-size: 12px; }
  .plan-tab { min-height: 48px; font-size: 12px; }
}

@media (max-width: 1100px), (any-pointer: coarse) and (max-width: 1400px) {
  :root { --topbar: 112px; }

  .topbar {
    height: var(--topbar);
    grid-template-columns: minmax(0,1fr) auto;
    grid-template-rows: 58px 54px;
    gap: 0 8px;
    padding: env(safe-area-inset-top) max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
  }
  .brand { grid-column: 1; grid-row: 1; }
  .brand-copy small { display: none; }
  .main-nav {
    grid-column: 1 / -1;
    grid-row: 2;
    min-width: 0;
    overflow-x: auto;
    justify-content: stretch;
    scrollbar-width: none;
  }
  .nav-button {
    flex: 1 0 auto;
    min-width: 82px;
    height: 54px;
    padding: 0 9px;
    font-size: 11px;
  }
  .top-actions { grid-column: 2; grid-row: 1; gap: 3px; }
  .top-actions .save-state,
  .top-actions .hide-small,
  .top-actions .server-load-button span,
  .top-actions .button-primary span { display: none; }
  .top-actions .button { width: 44px; min-width: 44px; padding: 0; }
  .history-actions { padding-right: 3px; margin-right: 0; }
  .more-button { display: grid; }
  .action-menu { top: calc(52px + env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right)); }

  .view-plan {
    grid-template-columns: minmax(0,1fr);
    grid-template-rows: minmax(0,1fr) calc(75px + env(safe-area-inset-bottom));
  }
  .editor-stage { grid-column: 1; grid-row: 1; grid-template-rows: 49px minmax(0,1fr); }
  .plan-tabs-bar { padding: 0 6px; }
  .plan-tabs { flex: 1 1 auto; }
  .plan-tab { min-width: 115px; padding: 0 13px; }
  .add-plan-button { width: 46px; flex: 0 0 46px; }
  .plan-edit-button { min-width: 46px; padding: 0; }
  .plan-edit-button span { display: none; }
  .stage-meta { padding-left: 6px; gap: 6px; }
  .scale-label { display: none; }

  .tool-rail {
    grid-column: 1;
    grid-row: 2;
    display: flex;
    align-items: stretch;
    gap: 4px;
    padding: 5px max(8px, env(safe-area-inset-right)) calc(5px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    overflow-x: auto;
    overflow-y: hidden;
    border: 0;
    border-top: 1px solid var(--line);
    scroll-snap-type: x proximity;
    scrollbar-width: thin;
  }
  .tool-group { display: flex; gap: 3px; margin: 0; }
  .tool-group + .tool-group { padding: 0 0 0 5px; border: 0; border-left: 1px solid var(--line); }
  .tool-group-label { display: none; }
  .tool-button { flex: 0 0 66px; min-height: 60px; scroll-snap-align: start; }
  .tool-button > span:last-child { font-size: 10px; }
  .tool-utility { margin: 0; }
  .tool-group:first-child { position: sticky; left: -8px; z-index: 2; padding-left: 8px; background: linear-gradient(90deg,var(--surface) 88%,rgba(255,253,250,0)); }

  .inspector {
    position: fixed;
    z-index: 70;
    inset: auto 0 0;
    height: min(70dvh, 680px);
    max-height: calc(100dvh - 30px);
    border: 0;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -16px 45px rgba(23,37,35,.22);
    transform: translateY(105%);
    transition: transform .22s ease;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .inspector.is-open { transform: translateY(0); }
  .inspector-close { display: grid; }
  .mobile-inspector-button { display: none !important; }
  .inspector-head { padding-top: 20px; }
  .inspector-tabs button { height: 48px; font-size: 12px; }
  .inspector-body { padding-bottom: calc(32px + env(safe-area-inset-bottom)); }

  .tool-mode-chip { top: auto; bottom: 14px; }
  .tool-mode-chip button { min-height: 40px; }
  .selection-actions {
    top: 10px;
    bottom: auto;
    max-width: calc(100% - 20px);
    min-height: 54px;
    overflow-x: auto;
    justify-content: flex-start;
  }
  .selection-actions > strong { max-width: 125px; flex: 0 1 125px; }
  .selection-actions button { min-width: 50px; min-height: 46px; padding: 0 9px; }
  .selection-actions button span:last-child { display: none; }
  .quick-action-icon { font-size: 21px; }
  .zoom-controls { right: 10px; bottom: 10px; }
  .canvas-status { left: 10px; bottom: 10px; max-width: calc(100% - 235px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .page-view { min-height: calc(100dvh - var(--topbar)); padding-top: 28px; padding-bottom: calc(48px + env(safe-area-inset-bottom)); }
  .page-header h1 { font-size: clamp(28px, 6vw, 42px); }
}

@media (max-width: 700px) {
  .brand-copy strong { font-size: 14px; }
  .brand-mark { width: 34px; height: 34px; }
  .history-actions { display: flex; }
  .nav-button { min-width: 72px; padding: 0 5px; font-size: 10px; }
  .nav-button[data-view="distribution"] { display: block; }
  .selection-actions > strong { display: none; }
  .selection-actions { width: max-content; max-width: calc(100% - 20px); }
  .selection-actions button { min-width: 52px; }

  .filter-bar { grid-template-columns: 1fr; }
  .search-field,
  .filter-result { grid-column: auto; }
  .table-card { overflow: visible; border: 0; background: transparent; box-shadow: none; }
  .check-table { display: block; min-width: 0; }
  .check-table thead { display: none; }
  .check-table tbody { display: grid; gap: 12px; }
  .check-table tr {
    position: relative;
    display: grid;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow-small);
  }
  .check-table td { display: grid; grid-template-columns: 105px minmax(0,1fr); align-items: center; gap: 8px; padding: 7px 0; border: 0; }
  .check-table td:first-child { position: absolute; top: 13px; right: 14px; display: block; padding: 0; }
  .check-table td:nth-child(2) { display: block; padding: 0 48px 10px 0; }
  .check-table td:nth-child(n+3)::before { color: var(--ink-soft); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
  .check-table td:nth-child(3)::before { content: "Plan / Raum"; }
  .check-table td:nth-child(4)::before { content: "Stromkreis"; }
  .check-table td:nth-child(5)::before { content: "Anzahl"; }
  .check-table td:nth-child(6)::before { content: "Prüfstatus"; }
  .check-table td:nth-child(7)::before { content: "Quelle"; }
  .check-table td:nth-child(8)::before { content: "Notiz"; }
  .check-table td:nth-child(8) { align-items: start; }
}

@media (prefers-reduced-motion: reduce) {
  .inspector { transition: none; }
  * { scroll-behavior: auto !important; }
}

@media print {
  .selection-actions,
  .tool-mode-chip,
  .server-load-button,
  .plan-edit-button { display: none !important; }
}
