/* SINA – ergänzende Styles für Chat & Admin.
   Nutzt bewusst die SLT-Farbwelt aus style.css (#0082c3 / #2c3e50) und
   ergänzt nur Komponenten, die dort nicht existieren (Chat, Sidebar, Mobile). */

* { -webkit-tap-highlight-color: transparent; box-sizing: border-box; }
html, body { height: 100%; }
/* Kein horizontales Scrollen / „Verschieben" auf dem iPhone */
html, body { max-width: 100%; overflow-x: hidden; }

/* iOS zoomt automatisch rein, wenn Eingabefelder < 16px Schrift haben.
   Auf Touch-/Schmalgeräten daher mind. 16px erzwingen. */
@media (max-width: 820px) {
    input, select, textarea { font-size: 16px !important; }
    .login-box { width: min(350px, 92vw); }
    .container { padding: 16px; margin: 10px; }
    .header-container { height: 56px; }
    .brand-logo { height: 26px; }
    .header-right { flex: 0 0 auto; }
    .header-right .btn-slt-contact { padding: 5px 9px; font-size: 0.75rem; }
    /* Chat-Höhe an die tatsächliche (dynamische) Viewport-Höhe koppeln */
    .chat-layout { height: calc(100dvh - 58px); }
}

/* ---------- Logos ---------- */
.brand { display: flex; align-items: center; margin-right: 15px; }
.brand-logo { height: 40px; width: auto; display: block; }
.login-logo { max-width: 200px; width: 70%; height: auto; margin: 0 auto 20px auto; display: block; }

/* Hamburger + aktuelle Seite: nur auf dem Handy sichtbar */
.header-container { position: relative; }
.nav-toggle {
    display: none; background: transparent; color: #fff; border: none;
    font-size: 1.5rem; line-height: 1; height: 40px; width: 44px; padding: 0;
    cursor: pointer; border-radius: 6px; flex: 0 0 auto;
}
.nav-toggle:hover { background: rgba(255,255,255,0.12); }
.current-page { display: none; color: #fff; font-weight: bold; font-size: 1.05rem; }

.login-msg { margin-top: 12px; font-size: 0.9rem; min-height: 20px; }
.login-msg.error { color: #c0392b; }
.login-msg.ok { color: #27ae60; }

/* ---------- Chat-Layout ---------- */
.chat-layout {
    display: flex;
    height: calc(100vh - 70px);           /* Header = 70px */
    height: calc(100dvh - 70px);
    overflow: hidden;
}

.chat-sidebar {
    width: 260px;
    background: #2c3e50;
    color: #ecf0f1;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
}
.btn-new-chat {
    margin: 12px;
    background: #0082c3;
    height: auto;
    padding: 10px;
}
.btn-new-chat:hover { background: #006b9e; }
/* ---------- Listen-Panel in der Seitenleiste ---------- */
.lists-panel { border-top: 1px solid rgba(255,255,255,0.08); max-height: 45%; display: flex; flex-direction: column; }
.lists-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 12px 6px; color: #bdc3c7; font-size: 0.8rem; text-transform: uppercase;
    letter-spacing: 0.5px; font-weight: bold;
}
.lists-head button {
    background: #0082c3; color: #fff; border: none; width: 26px; height: 26px;
    border-radius: 6px; font-size: 1.1rem; line-height: 1; cursor: pointer; padding: 0;
}
.lists-head button:hover { background: #006b9e; }
.lists-container { overflow-y: auto; padding: 0 8px 8px; }
.list-block { margin-bottom: 8px; }
.list-title {
    display: flex; align-items: center; justify-content: space-between; gap: 6px;
    color: #fff; font-size: 0.9rem; font-weight: 600; padding: 6px 8px;
    border-radius: 6px; cursor: pointer; background: rgba(255,255,255,0.05);
}
.list-title:hover { background: rgba(255,255,255,0.1); }
.list-title .count { color: #9fb3c8; font-weight: normal; font-size: 0.8rem; }
.list-title .list-del { opacity: 0; background: none; border: none; color: #e74c3c; cursor: pointer; font-size: 0.9rem; }
.list-title:hover .list-del { opacity: 1; }
.list-items { padding: 4px 4px 2px 6px; }
.list-item {
    display: flex; align-items: center; gap: 8px; padding: 4px 4px; color: #ecf0f1; font-size: 0.88rem;
}
.list-item input[type=checkbox] { width: 16px; height: 16px; flex-shrink: 0; accent-color: #27ae60; }
.list-item.done label { text-decoration: line-through; color: #7f8c8d; }
.list-item label { flex: 1; cursor: pointer; word-break: break-word; text-transform: none; font-weight: normal; color: #ecf0f1; letter-spacing: 0; margin: 0; }
.list-item .item-del { opacity: 0; background: none; border: none; color: #e74c3c; cursor: pointer; }
.list-item:hover .item-del { opacity: 0.8; }
.list-additem { display: flex; gap: 4px; padding: 2px 4px 6px; }
.list-additem input {
    flex: 1; background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.15);
    color: #fff; border-radius: 5px; padding: 5px 8px; font-size: 0.85rem;
}
.list-additem input::placeholder { color: #9fb3c8; }
.list-additem button { background: #27ae60; border: none; color: #fff; border-radius: 5px; padding: 0 10px; cursor: pointer; }

.chat-history-head { padding: 10px 12px 4px; color: #bdc3c7; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; font-weight: bold; border-top: 1px solid rgba(255,255,255,0.08); }
.chat-history { flex: 1; overflow-y: auto; padding: 0 8px 12px 8px; }
.chat-history .chat-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 12px; border-radius: 6px; cursor: pointer;
    color: #bdc3c7; font-size: 0.9rem; margin-bottom: 4px;
}
.chat-history .chat-item.active { background: #0082c3; color: #fff; }
.chat-history .chat-item .title {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;
    pointer-events: none;
}
.chat-history .chat-item .del {
    opacity: 0; border: none; background: none; color: #fff; cursor: pointer;
    font-size: 1rem; padding: 0 4px;
}
/* Hover-Effekte nur mit echter Maus – auf dem Handy löst ein Hover-Effekt
   sonst beim ersten Tippen nur den Hover aus (Doppeltipp-Problem). */
@media (hover: hover) {
    .chat-history .chat-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
    .chat-history .chat-item.active:hover { background: #0082c3; }
    .chat-history .chat-item:hover .del { opacity: 0.8; }
}
@media (hover: none) {
    .chat-history .chat-item { padding: 13px 12px; touch-action: manipulation; }
    .chat-history .chat-item:active { background: rgba(255,255,255,0.14); }
    .chat-history .chat-item .del { opacity: 0.45; padding: 6px 10px; margin: -6px -8px -6px 0; }
    .list-title .list-del, .list-item .item-del { opacity: 0.6; }
}
.chat-loading { text-align: center; padding: 30px 0; color: #7f8c8d; }
.sidebar-backdrop { display: none; }

.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: #f4f7f6; }

.chat-toolbar {
    display: flex; gap: 10px; align-items: center; padding: 10px 16px;
    background: #fff; border-bottom: 1px solid #e9ecef; flex-wrap: wrap;
}
.chat-toolbar select { height: 38px; }
.chat-toolbar .toggle {
    display: flex; align-items: center; gap: 6px; font-size: 0.9rem;
    color: #2c3e50; text-transform: none; font-weight: 600; cursor: pointer; margin: 0;
}
.chat-toolbar .src-hint {
    font-size: 0.82rem; color: #7f8c8d; text-transform: none; font-weight: 600;
    white-space: nowrap;
}
@media (max-width: 640px) { .chat-toolbar .src-hint { display: none; } }
.sidebar-toggle {
    display: none; background: #ecf0f1; color: #2c3e50; height: 38px;
    padding: 0 12px; font-size: 1.1rem;
}
.sidebar-toggle:hover { background: #dfe6e9; }

.chat-messages { flex: 1; overflow-y: auto; padding: 20px; }
.chat-welcome { text-align: center; color: #7f8c8d; margin-top: 40px; }

.msg { display: flex; margin-bottom: 16px; }
.msg .bubble {
    max-width: 80%; padding: 12px 16px; border-radius: 12px;
    line-height: 1.5; white-space: pre-wrap; word-wrap: break-word;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: #0082c3; color: #fff; border-bottom-right-radius: 3px; }
.msg.assistant .bubble { background: #fff; color: #2c3e50; border-bottom-left-radius: 3px; }
.msg.assistant .bubble a { color: #0082c3; }
.msg .bubble .info-line { color: #7f8c8d; font-style: italic; font-size: 0.85rem; }

.typing-dots span {
    display: inline-block; width: 7px; height: 7px; margin: 0 2px; border-radius: 50%;
    background: #0082c3; animation: blink 1.2s infinite both;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.2; } 40% { opacity: 1; } }

.chat-input-bar {
    display: flex; gap: 10px; align-items: flex-end; padding: 12px 16px;
    background: #fff; border-top: 1px solid #e9ecef;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
}
#chat-input {
    flex: 1; resize: none; max-height: 160px; padding: 10px 12px;
    border: 1px solid #bdc3c7; border-radius: 8px; font-size: 1rem; font-family: inherit;
}
.btn-send, .btn-mic {
    height: 44px; width: 44px; padding: 0; border-radius: 50%; font-size: 1.2rem;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.btn-send { background: #0082c3; }
.btn-send:hover { background: #006b9e; }
.btn-mic { background: #95a5a6; }
.btn-mic:hover { background: #7f8c8d; }
.btn-mic.recording { background: #e74c3c; animation: pulse 1s infinite; }

/* ---------- Anhänge (Fotos/Dokumente) ---------- */
.visually-hidden {
    position: absolute !important; width: 1px; height: 1px; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; margin: -1px;
}
.btn-attach {
    height: 44px; width: 44px; border-radius: 50%; flex-shrink: 0; margin: 0;
    display: flex; align-items: center; justify-content: center; cursor: pointer;
    background: #ecf0f1; font-size: 1.2rem; text-transform: none; user-select: none;
}
.btn-attach:hover { background: #dfe6e9; }
.btn-camera { display: none; }            /* nur auf Touch-Geräten sinnvoll */
@media (pointer: coarse) { .btn-camera { display: flex; } }
.attach-preview {
    display: none; gap: 8px; padding: 8px 16px 0; background: #fff;
    border-top: 1px solid #e9ecef; overflow-x: auto; flex-shrink: 0;
}
.attach-preview.has-items { display: flex; }
.att-chip {
    position: relative; flex: 0 0 auto; height: 64px; min-width: 64px; max-width: 180px;
    border: 1px solid #dfe6e9; border-radius: 8px; background: #f8fafb;
    display: flex; align-items: center; overflow: hidden; font-size: 0.8rem; color: #2c3e50;
}
.att-chip img { height: 64px; width: 64px; object-fit: cover; display: block; }
.att-chip .doc { padding: 0 26px 0 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-chip.uploading { opacity: 0.55; }
.att-chip.uploading::after {
    content: "…"; position: absolute; inset: 0; display: flex; align-items: center;
    justify-content: center; font-size: 1.4rem; color: #0082c3; background: rgba(255,255,255,0.4);
}
.att-chip.failed { border-color: #e74c3c; }
.att-chip .att-remove {
    position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; padding: 0;
    border-radius: 50%; background: rgba(0,0,0,0.55); color: #fff; font-size: 0.7rem; line-height: 20px;
}
.msg-attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.msg-attachments img.att-thumb {
    max-width: 220px; max-height: 220px; border-radius: 8px; display: block; cursor: zoom-in;
}
.msg-attachments a.att-doc {
    display: inline-block; padding: 6px 10px; border-radius: 6px; font-size: 0.85rem;
    background: rgba(255,255,255,0.2); color: inherit; text-decoration: none;
}
.msg.assistant .msg-attachments a.att-doc { background: #f1f5f7; }
.chat-main.drop-active { outline: 3px dashed #0082c3; outline-offset: -8px; }
@media (max-width: 480px) {
    .chat-input-bar { gap: 6px; padding-left: 8px; padding-right: 8px; }
    .btn-attach, .btn-send, .btn-mic { height: 40px; width: 40px; font-size: 1.05rem; }
    .msg-attachments img.att-thumb { max-width: 160px; max-height: 160px; }
}
@keyframes pulse { 0%,100% { transform: scale(1);} 50% { transform: scale(1.1);} }

/* ---------- Gedächtnis ---------- */
.mem-btn { background: #8e44ad; height: 38px; padding: 0 12px; font-size: 0.9rem; }
.mem-btn:hover { background: #7d3c98; }
.mem-modal {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6);
    z-index: 3000; justify-content: center; align-items: center;
}
.mem-modal.open { display: flex; }
.mem-box {
    background: #fff; border-radius: 12px; width: 92%; max-width: 560px;
    max-height: 80vh; display: flex; flex-direction: column; overflow: hidden;
}
.mem-head {
    display: flex; justify-content: space-between; align-items: center;
    background: #2c3e50; color: #fff; padding: 12px 16px;
}
.mem-hint { color: #7f8c8d; font-size: 0.85rem; padding: 0 16px; margin: 12px 0 0; }
.mem-add { display: flex; gap: 8px; padding: 12px 16px; }
.mem-add input {
    flex: 1; padding: 8px 10px; border: 1px solid #bdc3c7; border-radius: 6px; font-size: 0.95rem;
}
.mem-list { padding: 0 16px 16px; overflow-y: auto; }
.mem-item {
    display: flex; justify-content: space-between; align-items: center; gap: 10px;
    padding: 10px 12px; border: 1px solid #e9ecef; border-radius: 6px; margin-bottom: 8px;
    background: #f8f9fa; color: #2c3e50; font-size: 0.92rem;
}
.mem-item .del {
    border: none; background: #e74c3c; color: #fff; border-radius: 4px;
    padding: 4px 9px; cursor: pointer; flex-shrink: 0;
}
.mem-item .del:hover { background: #c0392b; }

/* ---------- Admin-Tabelle Aktionen ---------- */
.btn-edit { background: #3498db; padding: 5px 10px; font-size: 0.85rem; height: auto; }
.btn-edit:hover { background: #2980b9; }

/* ---------- Daten-Browser ---------- */
.data-tabs { display: flex; gap: 4px; border-bottom: 2px solid #ecf0f1; margin-bottom: 20px; }
.data-tab {
    background: transparent; color: #7f8c8d; border: none; border-bottom: 3px solid transparent;
    border-radius: 0; height: auto; padding: 10px 18px; font-weight: bold; margin-bottom: -2px;
}
.data-tab:hover { background: #f4f7f6; color: #2c3e50; }
.data-tab.active { color: #0082c3; border-bottom-color: #0082c3; background: transparent; }

.data-message { min-height: 20px; margin: 6px 0 12px; font-size: 0.9rem; color: #7f8c8d; }
.data-message.error { color: #c0392b; }

.breadcrumb { margin: 8px 0 12px; font-size: 0.95rem; color: #7f8c8d; }
.breadcrumb a { color: #0082c3; text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

td a.nc-link { color: #0082c3; text-decoration: none; cursor: pointer; }
td a.nc-link:hover { text-decoration: underline; }
.hit-snippet { color: #7f8c8d; font-size: 0.82rem; margin-top: 4px; line-height: 1.4; }

.file-viewer { margin-top: 20px; border: 1px solid #bdc3c7; border-radius: 8px; overflow: hidden; }
.file-viewer-head {
    display: flex; justify-content: space-between; align-items: center;
    background: #34495e; color: #fff; padding: 10px 15px;
}
.file-viewer-body {
    margin: 0; padding: 15px; max-height: 480px; overflow: auto; background: #fff;
    white-space: pre-wrap; word-wrap: break-word; font-size: 0.9rem; line-height: 1.5; color: #2c3e50;
}

@media (max-width: 820px) {
    .data-tab { padding: 8px 10px; font-size: 0.9rem; }
    .container { padding: 16px; margin: 12px; }
}

/* ---------- Mobil ---------- */
@media (max-width: 820px) {
    .header-left { gap: 6px; min-width: 0; }
    .nav-toggle { display: flex; align-items: center; justify-content: center; }
    .brand { display: none; }  /* Logo auf dem Handy ausblenden – Hamburger + Titel genügt */
    .current-page {
        display: block; position: absolute; left: 50%; transform: translateX(-50%);
        max-width: 52%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
        pointer-events: none;
    }
    .slt-nav {
        position: absolute; top: 100%; left: 0; right: 0;
        flex-direction: column; gap: 2px; background: #0082c3;
        padding: 8px; display: none; z-index: 1500;
        box-shadow: 0 10px 24px rgba(0,0,0,0.25);
    }
    .slt-nav.open { display: flex; }
    .slt-nav a { padding: 12px 14px; font-size: 1rem; border-radius: 6px; }
    .chat-sidebar {
        position: fixed; top: 58px; left: 0; bottom: 0; z-index: 1200;
        transform: translateX(-100%); transition: transform 0.25s ease;
        box-shadow: 4px 0 20px rgba(0,0,0,0.25);
    }
    .chat-sidebar.open { transform: translateX(0); }
    .sidebar-toggle { display: inline-flex; }
    .msg .bubble { max-width: 90%; }
    .chat-toolbar { gap: 8px; }
    .chat-toolbar select { max-width: 42vw; }
    .header-right .header-user { display: none; }
}

@media (max-width: 480px) {
    .chat-toolbar .toggle span, .chat-toolbar .toggle { font-size: 0.82rem; }
}

/* ============ iOS Safe-Area + saubereres Mobile-Layout ============ */
/* Header unter Statusleiste/Dynamic Island schieben (verhindert Überlappung) */
.slt-header {
    padding-top: env(safe-area-inset-top);
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
}

/* Chat-Seite: Layout am sichtbaren Viewport verankert – nur die Nachrichtenliste
   scrollt, nie die Seite. Behebt „ganze Seite scrollt" und den leeren Rand nach
   dem Schließen der Tastatur (iOS). Höhe wird per JS an visualViewport gekoppelt. */
html { height: 100%; }
/* inset:0 statt fester Höhe: füllt in der Webapp immer den ganzen Bildschirm.
   Nur bei offener iOS-Tastatur setzt chat.js top/height auf den sichtbaren Bereich. */
body.page-chat {
    position: fixed; inset: 0;
    min-height: 0; overflow: hidden;
    display: flex; flex-direction: column;
    background: #fff;
}
/* Tastatur offen: kein Home-Indicator-Abstand unter der Eingabe (sonst Lücke) */
body.page-chat.kb-open .chat-input-bar { padding-bottom: 8px; }
body.page-chat main { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
body.page-chat .chat-layout { height: auto; flex: 1 1 auto; min-height: 0; }
/* min-height:0 auf jeder Flex-Ebene, sonst scrollt die innere Liste auf iOS nicht */
.chat-main { min-height: 0; }
.chat-messages { -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }

@media (max-width: 820px) {
    /* Höhe zuverlässig über Flex statt fester Rechnung – berücksichtigt Safe-Area */
    body { display: flex; flex-direction: column; min-height: 100dvh; }
    main { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
    .chat-layout { height: auto; flex: 1 1 auto; min-height: 0; }
    .chat-sidebar { top: calc(56px + env(safe-area-inset-top)); }

    .slt-header { padding-left: max(12px, env(safe-area-inset-left));
                  padding-right: max(12px, env(safe-area-inset-right)); }

    /* Toolbar: aufgeräumt, Selects flexibel, Umschalter als Chips */
    .chat-toolbar { padding: 8px 10px; gap: 8px; align-items: center; }
    .chat-toolbar select { flex: 1 1 40%; max-width: none; min-width: 0; height: 40px; }
    .sidebar-toggle { height: 40px; width: 44px; }
    .chat-toolbar .toggle {
        background: #f1f5f7; border: 1px solid #e2e8ea; border-radius: 20px;
        padding: 8px 12px; margin: 0; font-weight: 600; color: #2c3e50;
    }
    .chat-toolbar .toggle input { margin: 0 2px 0 0; }
    .mem-btn { border-radius: 20px; height: auto; padding: 8px 14px; }

    /* Toolbar in EINER Zeile halten – mehr Platz für die Nachrichten */
    .chat-toolbar { flex-wrap: nowrap; padding: 6px 8px; gap: 6px; }
    .chat-toolbar select { flex: 1 1 0; height: 38px; }
    .chat-toolbar .toggle { padding: 6px 10px; flex: 0 0 auto; }
    .chat-toolbar .toggle-text { display: none; }
    .chat-messages { padding: 12px 10px; }
    .chat-welcome { margin-top: 16px; }
    .chat-input-bar { padding-top: 8px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); }

    /* Abgedunkelter Hintergrund hinter der Unterhaltungsliste; Tippen schließt */
    .sidebar-backdrop {
        display: block; position: fixed; inset: 0; z-index: 1100;
        background: rgba(0,0,0,0.35); opacity: 0; pointer-events: none;
        transition: opacity 0.2s ease;
    }
    .sidebar-backdrop.open { opacity: 1; pointer-events: auto; }
    .chat-sidebar { width: min(300px, 84vw); padding-bottom: env(safe-area-inset-bottom); }
}
