/**
 * Clu:Kennwort — Mobile Darstellung
 *
 * Copyright (c) 2026 Clu:Swiss Security AG. Alle Rechte vorbehalten.
 *
 * Wird NACH style.css geladen und ueberschreibt nur, was auf dem Handy anders
 * sein muss. Alle Farben kommen weiterhin aus den Theme-Variablen (themes.css),
 * damit die sechs Designs auch mobil unveraendert funktionieren.
 *
 *   - Hoehe per 100dvh (die Adressleiste mobiler Browser frisst sonst Platz)
 *   - Safe Areas (Notch, Dynamic Island, Home-Indikator)
 *   - Navigation als Tab-Leiste am unteren Rand
 *   - Dialoge als Bottom-Sheets
 *   - Eingabefelder mit 16 px, sonst zoomt iOS beim Antippen hinein
 */

:root {
  --clu-safe-top: env(safe-area-inset-top, 0px);
  --clu-safe-right: env(safe-area-inset-right, 0px);
  --clu-safe-bottom: env(safe-area-inset-bottom, 0px);
  --clu-safe-left: env(safe-area-inset-left, 0px);
  --clu-tabbar-h: 62px;
}

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

body {
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

.app,
.screen {
  height: 100vh;
  height: 100dvh;
}

/* Fensterknoepfe gibt es auf dem Handy nicht. */
.titlebar-controls {
  display: none;
}
.titlebar-drag {
  -webkit-app-region: no-drag;
}

/* Touch: groessere Schrift in Feldern (iOS-Zoom), kein Hover-Versatz. */
@media (pointer: coarse) {
  input[type='text'],
  input[type='password'],
  input[type='search'],
  input[type='number'],
  textarea,
  select,
  .text-input,
  .select-input {
    font-size: 16px;
  }
}
@media (hover: none) {
  .account-card:hover,
  .social-btn:hover {
    transform: none;
  }
}
@media (pointer: coarse) {
  /* Fingerfreundliche Symbolknoepfe (Desktop: 32 px). */
  .btn-icon {
    width: 36px;
    height: 36px;
  }
  .btn-icon svg {
    width: 18px;
    height: 18px;
  }
  /* Mobile Browser blenden Scrollbalken selbst ein. */
  ::-webkit-scrollbar {
    width: 0;
    height: 0;
  }
}

/* Splash: "Ueberspringen" nicht unter dem Home-Indikator verstecken. */
.splash-skip {
  margin-bottom: var(--clu-safe-bottom);
  margin-right: var(--clu-safe-right);
}

/* ======================================================================
   Handy und kleines Tablet (Hochformat)
   ====================================================================== */

@media (max-width: 860px) {
  /* ---------------------------------------------------- Titelleiste */
  .titlebar {
    height: auto;
    min-height: 44px;
    padding-top: var(--clu-safe-top);
    padding-left: var(--clu-safe-left);
    padding-right: var(--clu-safe-right);
  }
  .titlebar-drag {
    height: 44px;
  }

  /* ---------------------------------------------------- Anmeldung */
  .login-screen {
    justify-content: flex-start;
    padding: calc(var(--space-5) + var(--clu-safe-top)) calc(var(--space-4) + var(--clu-safe-right))
      calc(var(--space-5) + var(--clu-safe-bottom)) calc(var(--space-4) + var(--clu-safe-left));
  }
  .login-card {
    margin-top: auto;
    padding: var(--space-5);
  }
  .login-lang-switch {
    margin-bottom: auto;
  }

  /* ---------------------------------------------------- Layout */
  .dashboard-layout {
    padding: var(--space-3) calc(var(--space-3) + var(--clu-safe-right)) 0 calc(var(--space-3) + var(--clu-safe-left));
  }
  .main-content {
    padding-right: 0;
    padding-bottom: calc(var(--clu-tabbar-h) + var(--clu-safe-bottom) + var(--space-5));
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  /* Nur Einblenden, kein Verschieben: ein transform wuerde den schwebenden
     Knopf (position: fixed) waehrend der Animation mitnehmen. */
  .tab-panel {
    animation: cluFade var(--transition-base) var(--ease-out);
  }

  /* ---------------------------------------------------- Tab-Leiste unten */
  .sidebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: var(--z-sticky);
    width: auto;
    flex-direction: row;
    align-items: stretch;
    gap: 0;
    padding: 4px calc(4px + var(--clu-safe-right)) calc(4px + var(--clu-safe-bottom)) calc(4px + var(--clu-safe-left));
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    background: var(--bg-elevated);
  }
  .sidebar-nav {
    flex: 4;
    flex-direction: row;
    gap: 0;
  }
  .nav-btn,
  .btn-lock {
    flex: 1;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    min-height: 54px;
    padding: 6px 2px;
    border-radius: var(--radius-sm);
    text-align: center;
    position: relative;
  }
  .nav-btn span,
  .btn-lock span {
    display: block;
    font-size: 10.5px;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }
  .nav-btn svg,
  .btn-lock svg {
    width: 21px;
    height: 21px;
  }
  .nav-btn.active {
    background: var(--accent-soft);
    color: var(--accent);
  }
  .nav-badge {
    position: absolute;
    top: 3px;
    left: calc(50% + 6px);
    margin: 0;
    min-width: 17px;
    padding: 0 4px;
    font-size: 10px;
    line-height: 16px;
  }
  .sidebar-lock {
    flex: 1;
    display: flex;
    margin: 0;
  }
  .btn-lock {
    width: auto;
    border: 0;
    background: transparent;
    color: var(--text-secondary);
  }
  .btn-lock:hover {
    background: var(--danger-soft);
  }

  /* ---------------------------------------------------- Tresorliste */
  .tab-header {
    align-items: stretch;
    gap: var(--space-3);
    margin-bottom: var(--space-3);
  }
  .tab-actions {
    width: 100%;
    flex-wrap: nowrap;
  }
  .search-bar {
    flex: 1;
    min-width: 0;
  }
  .search-bar input {
    width: 100%;
  }
  .custom-select-trigger.select-input {
    min-width: 0;
  }

  /* "Konto hinzufuegen" als schwebender Knopf ueber der Tab-Leiste. */
  #btn-add-account {
    position: fixed;
    right: calc(var(--space-4) + var(--clu-safe-right));
    bottom: calc(var(--clu-tabbar-h) + var(--clu-safe-bottom) + var(--space-4));
    z-index: var(--z-sticky);
    width: 56px;
    height: 56px;
    padding: 0;
    border-radius: 50%;
    justify-content: center;
    box-shadow: var(--shadow-lg);
  }
  #btn-add-account span {
    display: none;
  }
  #btn-add-account svg {
    width: 24px;
    height: 24px;
    margin: 0;
  }

  .filter-row {
    flex-wrap: nowrap;
    overflow-x: auto;
    margin: 0 calc(-1 * var(--space-3)) var(--space-3);
    padding: 2px var(--space-3);
    scrollbar-width: none;
  }
  .filter-row::-webkit-scrollbar {
    display: none;
  }
  .chip {
    flex-shrink: 0;
    padding: 6px 14px;
  }
  .filter-sep {
    flex-shrink: 0;
  }

  /* ---------------------------------------------------- Dialoge als Sheets */
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }
  .modal,
  .modal-sm,
  .modal-lg {
    max-width: none;
    max-height: calc(100dvh - var(--clu-safe-top) - var(--space-4));
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-bottom: 0;
    background: var(--bg-elevated);
    animation: cluSheetIn var(--transition-base) var(--ease-out);
  }
  .modal-header {
    padding-left: calc(var(--space-4) + var(--clu-safe-left));
    padding-right: calc(var(--space-4) + var(--clu-safe-right));
  }
  .modal-close {
    width: 40px;
    height: 40px;
  }
  .modal-body {
    padding-left: calc(var(--space-4) + var(--clu-safe-left));
    padding-right: calc(var(--space-4) + var(--clu-safe-right));
    overscroll-behavior: contain;
  }
  .modal-footer {
    padding-bottom: calc(var(--space-4) + var(--clu-safe-bottom));
  }
  .modal-footer .btn {
    flex: 1;
    justify-content: center;
    min-height: 44px;
  }
  .modal select,
  .modal .select-input {
    width: 100%;
    min-width: 0;
    text-overflow: ellipsis;
  }

  /* ---------------------------------------------------- Kontenkarten */
  .account-card {
    align-items: flex-start;
  }
  .account-icon {
    margin-top: 2px;
  }
  .account-actions {
    display: grid;
    grid-template-columns: repeat(3, 36px);
    gap: 2px;
    max-width: none;
  }
  .account-totp {
    flex-wrap: wrap;
  }
  .totp-code {
    white-space: nowrap;
  }

  /* ---------------------------------------------------- Schnell hinzufuegen */
  .clu-quickadd {
    margin-bottom: var(--space-3);
    border-radius: var(--radius-md);
    padding: 0 var(--space-3);
  }
  .clu-quickadd > summary {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 44px;
    list-style: none;
    cursor: pointer;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--text-secondary);
  }
  .clu-quickadd > summary::-webkit-details-marker {
    display: none;
  }
  .clu-quickadd > summary::after {
    content: '';
    margin-left: auto;
    width: 8px;
    height: 8px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    transition: transform var(--transition-fast);
  }
  .clu-quickadd[open] > summary::after {
    transform: rotate(-135deg);
  }
  .clu-quickadd .sidebar-social {
    display: flex;
    padding-bottom: var(--space-3);
  }
  .clu-quickadd .sidebar-label {
    display: none;
  }
  .clu-quickadd .social-grid {
    grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
    max-height: 208px;
  }

  /* ---------------------------------------------------- Rueckmeldungen */
  /* Oben statt unten: unten liegen Tab-Leiste und der schwebende Knopf. */
  .toast-container {
    top: calc(44px + var(--clu-safe-top) + var(--space-2));
    bottom: auto;
    left: calc(var(--space-3) + var(--clu-safe-left));
    right: calc(var(--space-3) + var(--clu-safe-right));
    max-width: none;
  }
  .toast {
    transform: translateY(-12px);
  }
  .toast-in {
    transform: none;
  }
}

/* ======================================================================
   Schmale Handys
   ====================================================================== */

@media (max-width: 620px) {
  .setting-item {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-3);
  }
  .setting-control {
    justify-content: flex-start;
    flex-wrap: wrap;
  }
  .setting-control input[type='range'] {
    width: 100%;
  }
  .setting-control .btn {
    min-height: 40px;
  }
  .theme-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .generator-actions {
    flex-wrap: wrap;
  }
  .generator-actions .btn {
    flex: 1 1 140px;
    justify-content: center;
  }
}

@keyframes cluFade {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes cluSheetIn {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* ======================================================================
   Eigene Bausteine der Mobilversion (mobile-ui.js, platform-web.js)
   ====================================================================== */

/* Aktionsblatt: Teilen/Herunterladen, Kopieren bestaetigen, Installieren */
/* Ueber der Ladeanzeige der App (--z-tooltip: 700): Export und Kopieren
   warten auf den Nutzer, waehrend renderer.js die Anzeige noch offen hat. */
.clu-sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 800;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: var(--overlay);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: cluFade var(--transition-fast) var(--ease-standard);
}
.clu-sheet {
  width: 100%;
  max-width: 480px;
  max-height: calc(100dvh - var(--clu-safe-top) - var(--space-4));
  overflow-y: auto;
  padding: var(--space-5) calc(var(--space-5) + var(--clu-safe-right)) calc(var(--space-5) + var(--clu-safe-bottom))
    calc(var(--space-5) + var(--clu-safe-left));
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: var(--bg-elevated);
  animation: cluSheetIn var(--transition-base) var(--ease-out);
}
@media (min-width: 861px) {
  .clu-sheet-overlay {
    align-items: center;
  }
  .clu-sheet {
    border-radius: var(--radius-lg);
  }
}
.clu-sheet h3 {
  margin: 0 0 var(--space-2);
  font-size: var(--font-size-md);
}
.clu-sheet-body {
  margin: 0 0 var(--space-3);
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  line-height: 1.5;
  word-break: break-word;
}
.clu-sheet-warn {
  margin: 0 0 var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--warning);
  background: var(--warning-soft, transparent);
  font-size: var(--font-size-xs);
  line-height: 1.5;
  color: var(--text-primary);
}
.clu-sheet-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-4);
}
.clu-sheet-actions .btn {
  justify-content: center;
  min-height: 46px;
}

/* Installationshinweis */
.clu-install-overlay {
  z-index: 900;
}
.clu-install-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.clu-install-head h3 {
  margin: 0;
}
.clu-install-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  flex-shrink: 0;
}
.clu-install-steps {
  margin: 0 0 var(--space-3);
  padding-left: 1.3em;
  font-size: var(--font-size-sm);
  line-height: 1.55;
}
.clu-install-steps li + li {
  margin-top: var(--space-2);
}

/* Update-Hinweis oben */
.clu-banner {
  position: fixed;
  top: calc(var(--space-2) + var(--clu-safe-top));
  left: calc(var(--space-3) + var(--clu-safe-left));
  right: calc(var(--space-3) + var(--clu-safe-right));
  z-index: 650;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-lg);
  font-size: var(--font-size-sm);
  animation: cluFade var(--transition-base) var(--ease-out);
}
@media (min-width: 861px) {
  .clu-banner {
    left: auto;
    max-width: 460px;
  }
}
.clu-banner-text {
  flex: 1;
}

/* Sicherungserinnerung in der Tresoransicht */
.clu-reminder {
  flex-wrap: wrap;
  align-items: flex-start;
  margin-bottom: var(--space-3);
}
.clu-reminder-text {
  flex: 1 1 220px;
}
.clu-reminder-text p {
  margin: 2px 0 0;
}
.clu-reminder-actions {
  display: flex;
  gap: var(--space-2);
  margin-left: auto;
}

/* Speicherstatus unter Einstellungen > Speicherort */
.clu-storage-status .setting-hint {
  margin-top: 2px;
}
.clu-storage-status .clu-hint-warn {
  color: var(--warning);
}
