/* ==========================================================================
   PlanMeasure Pro - Anleitung, Updates & Handy-Layout
   ========================================================================== */

/* --------------------------------------------------------------------------
   Anleitung (alle Bildschirmgrößen)
   -------------------------------------------------------------------------- */
.modal-box.guide-box {
  max-width: 860px;
  display: flex;
  flex-direction: column;
  max-height: 88vh;
}

.guide-layout {
  display: flex;
  min-height: 0;
  flex: 1;
}

.guide-nav {
  width: 220px;
  flex-shrink: 0;
  border-right: 1px solid var(--border-subtle);
  padding: 0.75rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  overflow-y: auto;
  background: var(--bg-tertiary);
}

.guide-nav-btn {
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.45rem 0.65rem;
  border-radius: 6px;
  cursor: pointer;
}

.guide-nav-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.guide-nav-btn.active {
  background: var(--accent-cyan-glow);
  border-color: rgba(6, 182, 212, 0.4);
  color: var(--text-primary);
}

.guide-nav-select {
  display: none;
}

.guide-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.5rem;
  min-height: 0;
  max-height: 64vh;
  user-select: text;
}

.guide-section {
  display: none;
  line-height: 1.6;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.guide-section.active {
  display: block;
}

.guide-section h3 {
  font-size: 1.15rem;
  color: var(--text-primary);
  margin-bottom: 0.6rem;
}

.guide-section h4 {
  font-size: 0.95rem;
  color: var(--text-primary);
  margin: 1.1rem 0 0.4rem;
}

.guide-section p {
  margin-bottom: 0.75rem;
}

.guide-section ul,
.guide-section ol {
  padding-left: 1.3rem;
  margin-bottom: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.guide-section strong {
  color: var(--text-primary);
}

.guide-section code {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  background: var(--bg-tertiary);
  padding: 0.05rem 0.3rem;
  border-radius: 4px;
}

.guide-section kbd {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0.02rem 0.35rem;
  color: var(--text-primary);
  white-space: nowrap;
}

.guide-tip {
  background: rgba(6, 182, 212, 0.08);
  border: 1px solid rgba(6, 182, 212, 0.25);
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  font-size: 0.84rem;
}

.guide-keys {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 0.9rem;
}

.guide-keys td {
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: top;
}

.guide-keys td:first-child {
  white-space: nowrap;
  width: 42%;
}

.guide-footer {
  justify-content: space-between;
}

.guide-progress {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   Updates (Hilfe-Dialog) & Update-Banner
   -------------------------------------------------------------------------- */
.update-box {
  border: 1px solid var(--border-default);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.update-box-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
}

.update-current {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

#updateDesktopSettings {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

#updateDesktopSettings[hidden],
.update-box [hidden] {
  display: none !important;
}

.update-checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.84rem;
  color: var(--text-secondary);
  cursor: pointer;
}

.update-checkbox input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent-cyan);
}

.update-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.update-status {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.update-status[data-state="error"] { color: var(--accent-rose); }
.update-status[data-state="available"],
.update-status[data-state="downloaded"] { color: var(--accent-amber); }
.update-status[data-state="uptodate"] { color: var(--accent-emerald); }

.update-banner {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  z-index: 120;
  width: min(560px, calc(100vw - 2rem));
  background: var(--bg-elevated);
  border: 1px solid var(--accent-cyan);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 0.8rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  animation: toastIn 0.25s ease forwards;
}

.update-banner-text {
  flex: 1;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.84rem;
  color: var(--text-secondary);
}

.update-banner-text strong {
  color: var(--text-primary);
}

.update-banner-actions {
  display: flex;
  gap: 0.5rem;
}

/* --------------------------------------------------------------------------
   Mittlere Bildschirmbreiten: Kopfzeile entlasten (Logo bleibt sichtbar)
   -------------------------------------------------------------------------- */
.brand-name {
  white-space: nowrap;
}

@media (max-width: 1600px) {
  .brand-title,
  .brand-logo {
    display: none;
  }
}

@media (min-width: 769px) and (max-width: 1500px) {
  .header-actions .btn-secondary > span {
    display: none;
  }
}

/* --------------------------------------------------------------------------
   Handy-Elemente: auf dem Desktop ausgeblendet
   -------------------------------------------------------------------------- */
.mobile-tabbar,
.mobile-backdrop {
  display: none;
}

/* --------------------------------------------------------------------------
   Handy-Layout
   Muss zu MOBILE_QUERY in js/mobile.js passen.
   -------------------------------------------------------------------------- */
@media (max-width: 768px), (pointer: coarse) and (max-height: 520px) {
  :root {
    --header-height: 52px;
    --tabbar-height: 58px;
  }

  .app-container {
    height: 100vh;
    height: 100dvh;
    padding-bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom, 0px));
  }

  /* Eingabefelder ab 16px verhindern das automatische Hineinzoomen auf iOS */
  input, select, textarea, [contenteditable="true"] {
    font-size: 16px !important;
  }

  /* ---- Kopfzeile ---- */
  .app-header {
    padding: 0 0.5rem;
    padding-top: env(safe-area-inset-top, 0px);
    height: calc(var(--header-height) + env(safe-area-inset-top, 0px));
    gap: 0.4rem;
    overflow: visible !important;
  }

  .brand-section {
    gap: 0.25rem;
  }

  .brand-logo,
  .brand-title {
    display: none;
  }

  .header-meta {
    flex: 1;
    min-width: 0;
    padding: 0.25rem 0.4rem;
    gap: 0.35rem;
    max-width: none;
  }

  .doc-name,
  .type-pill-label,
  #headerColorModeLabel {
    display: none !important;
  }

  .active-type-pill {
    flex: 1;
    min-width: 0;
  }

  .header-type-select {
    width: 100%;
    max-width: none;
    font-size: 16px;
  }

  #btnOpenConfigModal {
    padding: 0 !important;
    width: 38px;
    height: 38px;
    flex-shrink: 0;
  }

  /* Kopfzeilen-Aktionen werden zum "Mehr"-Menü über der unteren Leiste */
  .header-actions {
    display: none;
    position: fixed;
    left: 0.5rem;
    right: 0.5rem;
    bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom, 0px) + 0.5rem);
    z-index: 95;
    background: var(--bg-secondary);
    border: 1px solid var(--border-default);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 0.5rem;
    flex-direction: column;
    align-items: stretch;
    gap: 0.25rem;
    max-height: 70vh;
    overflow-y: auto;
  }

  body.mobile-more-open .header-actions {
    display: flex;
  }

  /* Die Kopfzeile bildet eine eigene Ebene – für das Menü über die Abdunklung heben */
  body.mobile-more-open .app-header {
    z-index: 95;
  }

  .header-actions .btn,
  .header-actions .btn-icon {
    width: 100%;
    height: auto;
    min-height: 46px;
    justify-content: flex-start;
    padding: 0.6rem 0.85rem;
    gap: 0.75rem;
    font-size: 0.95rem;
    background: transparent;
    border: none;
    box-shadow: none;
    color: var(--text-primary);
  }

  .header-actions .btn:active {
    background: var(--bg-hover);
  }

  .header-actions .btn-icon::after {
    content: attr(title);
    font-weight: 600;
  }

  #btnShortcutsModal {
    display: none !important;
  }

  /* ---- Seitenleiste als Schublade ---- */
  .sidebar-panel,
  .sidebar-panel.collapsed {
    position: fixed;
    top: calc(var(--header-height) + env(safe-area-inset-top, 0px));
    bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom, 0px));
    left: 0;
    height: auto;
    width: min(86vw, 340px);
    z-index: 90;
    box-shadow: var(--shadow-lg);
  }

  .sidebar-panel.collapsed {
    transform: translateX(-105%);
    box-shadow: none;
  }

  .mobile-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 85;
  }

  body.mobile-sidebar-open .mobile-backdrop,
  body.mobile-more-open .mobile-backdrop {
    display: block;
  }

  /* ---- Ansicht: Plan oder Tabelle ---- */
  body.mobile-view-plan .bottom-panel {
    display: none;
  }

  body.mobile-view-table .main-body {
    display: none;
  }

  body.mobile-view-table .bottom-panel,
  body.mobile-view-table .bottom-panel.collapsed {
    flex: 1;
    height: auto !important;
    min-height: 0;
  }

  .panel-resize-handle,
  #btnToggleTable {
    display: none;
  }

  /* ---- Werkzeuge im Plan ---- */
  .cad-toolbar {
    top: 0.5rem;
    left: 0.5rem;
    right: auto;
    flex-direction: row;
    padding: 0.25rem;
    gap: 0.2rem;
    max-width: calc(100% - 1rem);
  }

  .cad-toolbar .tooltip-container::after {
    display: none;
  }

  .tool-btn {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
  }

  .tool-divider {
    width: 1px;
    height: auto;
    margin: 0.2rem 0.1rem;
  }

  .viewport-hud {
    top: 4.25rem;
    left: 0.5rem;
    right: auto;
    font-size: 0.72rem;
    gap: 0.5rem;
    padding: 0.2rem 0.5rem;
  }

  .zoom-controls {
    bottom: 0.5rem;
    right: 0.5rem;
  }

  .zoom-controls .btn-icon {
    width: 40px;
    height: 40px;
  }

  #btnExportImage,
  #btnZoomFitWidth,
  .zoom-label {
    display: none;
  }

  .empty-state {
    padding: 1rem;
  }

  .drop-zone {
    padding: 1.75rem 1rem;
  }

  /* ---- Tabellen-Kopf ---- */
  .table-toolbar {
    height: auto;
    flex-wrap: wrap;
    padding: 0.5rem;
    gap: 0.5rem;
  }

  .table-title-group {
    width: 100%;
    justify-content: space-between;
  }

  .table-filters {
    width: 100%;
    flex-wrap: wrap;
  }

  .table-search-input,
  .table-search-input:focus {
    flex: 1 1 100%;
    width: 100%;
    min-height: 40px;
  }

  .table-filter-select {
    flex: 1 1 0;
    min-width: 0;
    min-height: 40px;
  }

  #btnTablePrint {
    display: none;
  }

  /* ---- Tabelle als Karten ---- */
  .table-scroll-container {
    padding: 0.5rem;
    -webkit-overflow-scrolling: touch;
  }

  .measure-table,
  .measure-table tbody {
    display: block;
    white-space: normal;
  }

  .measure-table thead {
    display: none;
  }

  .measure-table tbody tr {
    display: grid;
    grid-template-columns: 44px 1fr 1fr 1fr 1fr 92px;
    grid-template-areas:
      "status id   ref  ref  ref  actions"
      "name   name name name name name"
      "type   type type type type type"
      "dx     dx   dy   dy   dd   dd"
      "notes  notes notes notes notes notes";
    align-items: center;
    gap: 0.35rem 0.5rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    padding: 0.6rem 0.65rem;
    margin-bottom: 0.6rem;
  }

  .measure-table tbody tr:hover {
    background: var(--bg-tertiary);
  }

  .measure-table tbody tr.selected {
    outline: 2px solid var(--accent-cyan);
  }

  .measure-table td {
    display: block;
    padding: 0 !important;
    border: none;
    width: auto;
    min-width: 0;
  }

  .measure-table td.table-empty {
    grid-column: 1 / -1;
    padding: 2rem 1rem !important;
  }

  .measure-table td.col-status { grid-area: status; text-align: left; }
  .measure-table td.col-id { grid-area: id; white-space: nowrap; font-size: 0.85rem; }
  .measure-table td.col-ref { grid-area: ref; min-width: 0; overflow: hidden; }
  .measure-table td.col-actions { grid-area: actions; display: flex; justify-content: flex-end; gap: 0.25rem; }
  .measure-table td.col-type { grid-area: type; }
  .measure-table td.col-notes { grid-area: notes; }

  .measure-table td.col-name {
    grid-area: name;
    font-size: 1rem;
    padding: 0.2rem 0 !important;
  }

  .measure-table td.col-ref .room-badge {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-flex;
  }

  .measure-table .status-checkbox {
    width: 28px;
    height: 28px;
  }

  .measure-table .col-actions .btn-icon {
    width: 40px;
    height: 40px;
  }

  .measure-table .table-type-select {
    max-width: none;
    width: 100%;
    min-height: 40px;
  }

  .measure-table td.col-type > div {
    display: flex !important;
    width: 100%;
  }

  /* Die wichtigsten Werte auf der Baustelle: groß und gut lesbar */
  .measure-table td.col-dist-x,
  .measure-table td.col-dist-y,
  .measure-table td.col-dist-diag {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    padding: 0.35rem 0.5rem !important;
    font-family: var(--font-mono);
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
  }

  .measure-table td.col-dist-x { grid-area: dx; color: var(--accent-cyan); }
  .measure-table td.col-dist-y { grid-area: dy; color: var(--accent-amber); }
  .measure-table td.col-dist-diag { grid-area: dd; font-size: 0.85rem; font-weight: 600; color: var(--text-secondary); }

  .measure-table td.col-dist-x::before,
  .measure-table td.col-dist-y::before,
  .measure-table td.col-dist-diag::before {
    display: block;
    font-family: var(--font-sans);
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
  }

  .measure-table td.col-dist-x::before { content: 'Wand X'; }
  .measure-table td.col-dist-y::before { content: 'Wand Y'; }
  .measure-table td.col-dist-diag::before { content: 'Diagonale'; }

  .measure-table td.col-notes {
    font-size: 0.88rem;
    color: var(--text-secondary);
    border-top: 1px dashed var(--border-subtle);
    padding-top: 0.4rem !important;
    min-height: 1.8em;
    user-select: text;
  }

  .measure-table td.col-notes:empty::before {
    content: 'Bemerkung hinzufügen …';
    color: var(--text-muted);
    font-style: italic;
  }

  .measure-table td.col-name:empty::before {
    content: 'Bezeichnung …';
    color: var(--text-muted);
    font-style: italic;
    font-weight: 400;
  }

  /* ---- Untere Navigationsleiste ---- */
  .mobile-tabbar {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(var(--tabbar-height) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-default);
    z-index: 96;
  }

  .mobile-tab {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font: inherit;
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-tab.active {
    color: var(--accent-cyan);
  }

  .mobile-tab-badge {
    position: absolute;
    top: 5px;
    left: calc(50% + 6px);
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--accent-amber);
    color: #111827;
    font-size: 0.65rem;
    font-weight: 800;
    line-height: 18px;
    text-align: center;
  }

  .mobile-tab-badge[hidden] {
    display: none;
  }

  /* ---- Dialoge als Blatt von unten ---- */
  .modal-overlay {
    align-items: flex-end;
  }

  .modal-box,
  .modal-box[style] {
    width: 100%;
    max-width: none !important;
    border-radius: 14px 14px 0 0;
    max-height: 92vh;
    max-height: 92dvh;
    display: flex;
    flex-direction: column;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .modal-header {
    padding: 0.85rem 1rem;
  }

  .modal-header > div[style*="display: flex"] {
    flex-wrap: wrap;
  }

  .modal-body {
    max-height: none;
    flex: 1;
    min-height: 0;
    padding: 1rem;
  }

  .modal-footer {
    flex-wrap: wrap;
    padding: 0.75rem 1rem;
  }

  .modal-footer .btn {
    flex: 1 1 auto;
    min-height: 44px;
  }

  .guide-footer .btn {
    flex: 0 0 auto;
  }

  .modal-box.guide-box {
    max-height: 92dvh;
  }

  .guide-layout {
    flex-direction: column;
  }

  .guide-nav {
    display: none;
  }

  .guide-nav-select {
    display: block;
    margin: 0.75rem 1rem 0;
    width: auto;
  }

  .guide-content {
    max-height: none;
    padding: 1rem;
  }

  .config-add-type-row {
    flex-wrap: wrap;
  }

  /* ---- Hinweise über der unteren Leiste ---- */
  .toast-container {
    bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom, 0px) + 0.75rem);
    width: calc(100vw - 2rem);
    align-items: center;
  }

  .update-banner {
    bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom, 0px) + 0.75rem);
  }
}
