/* ============================================================
   KI-Tutor – Stylesheet
   Warm, freundlich, altersgerecht
   ============================================================ */

:root {
    --bg:           #f5f0eb;
    --surface:      #ffffff;
    --primary:      #2b7a78;
    --primary-light:#d4eceb;
    --accent:       #f2a154;
    --text:         #2d3436;
    --text-light:   #636e72;
    --border:       #e0dbd5;
    --radius:       12px;
    --shadow:       0 2px 8px rgba(0,0,0,.06);
    --font:         'Segoe UI', system-ui, -apple-system, sans-serif;
}

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

html, body { height: 100%; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
}

/* ---- Login ---- */

.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: linear-gradient(135deg, var(--primary-light), var(--bg));
}

.login-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 48px 36px;
    width: 100%;
    max-width: 380px;
    text-align: center;
}

.login-icon { font-size: 48px; margin-bottom: 8px; }

.login-card h1 {
    font-size: 24px;
    color: var(--primary);
    margin-bottom: 4px;
}

.login-subtitle {
    color: var(--text-light);
    margin-bottom: 28px;
}

.login-card label {
    display: block;
    text-align: left;
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 4px;
    color: var(--text-light);
}

.login-card input {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
    margin-bottom: 16px;
    transition: border-color .15s;
    font-family: var(--font);
}

.login-card input:focus {
    outline: none;
    border-color: var(--primary);
}

.login-card button {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
    font-family: var(--font);
}

.login-card button:hover { background: #236462; }

.error-msg {
    background: #fee;
    color: #c0392b;
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
}

/* ---- App Layout (Chat) ---- */

.app-layout {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 280px;
    min-width: 280px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--border);
}

.sidebar-logo { font-size: 24px; }

.sidebar-title {
    font-weight: 700;
    font-size: 18px;
    color: var(--primary);
}

.btn-new-chat {
    margin: 12px 16px;
    padding: 10px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
    font-family: var(--font);
}

.btn-new-chat:hover { background: #236462; }

.conv-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px;
}

.conv-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--text);
    font-size: 14px;
    margin-bottom: 2px;
    transition: background .1s;
}

.conv-item .conv-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.conv-item .conv-icon {
    flex-shrink: 0;
    font-size: 16px;
}

.conv-item:hover { background: var(--primary-light); }

.conv-item.active {
    background: var(--primary-light);
    font-weight: 600;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.user-badge {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-light);
}

.btn-logout {
    font-size: 13px;
    color: var(--text-light);
    text-decoration: none;
}

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

.sidebar-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 100;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 18px;
    cursor: pointer;
}

/* Chat main */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-header {
    padding: 12px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

#chat-title {
    font-weight: 600;
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.header-badges {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-subject {
    background: var(--primary-light);
    color: var(--primary);
}

.badge-mode {
    background: #fef3e2;
    color: #b87514;
}

/* ---- Selector Panel ---- */

.selector-panel {
    padding: 16px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    overflow-y: auto;
    max-height: 50vh;
}

.selector-section {
    margin-bottom: 16px;
}

.selector-section:last-child {
    margin-bottom: 0;
}

.selector-section h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-light);
    margin-bottom: 10px;
}

.selector-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.selector-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    border: 1.5px solid var(--border);
    border-radius: 20px;
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    font-family: var(--font);
    cursor: pointer;
    transition: all .15s;
    white-space: nowrap;
}

.selector-btn:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.selector-btn.active {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

.selector-icon {
    font-size: 14px;
}

.selector-label {
    font-weight: 500;
}

/* Mode buttons */
.mode-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.mode-btn {
    flex: 1;
    min-width: 140px;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    cursor: pointer;
    transition: all .15s;
    text-align: left;
    font-family: var(--font);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.mode-btn:hover {
    border-color: var(--accent);
    background: #fef8f0;
}

.mode-btn.active {
    border-color: var(--accent);
    background: #fef3e2;
}

.mode-icon {
    font-size: 18px;
}

.mode-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.mode-desc {
    font-size: 12px;
    color: var(--text-light);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-light);
}

.empty-icon { font-size: 48px; margin-bottom: 12px; }

/* Messages */
.message {
    display: flex;
}

.message.user { justify-content: flex-end; }

.message.assistant { justify-content: flex-start; }

.bubble {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 15px;
    line-height: 1.55;
    word-break: break-word;
}

.message.user .bubble {
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.message.assistant .bubble {
    background: var(--surface);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.bubble pre {
    background: #f4f3f0;
    padding: 10px;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 13px;
    margin: 8px 0;
}

.bubble code {
    font-family: 'Cascadia Code', 'Fira Code', monospace;
    font-size: 13px;
}

.bubble pre code {
    background: none;
    padding: 0;
}

.bubble code:not(pre code) {
    background: rgba(0,0,0,.06);
    padding: 2px 5px;
    border-radius: 4px;
}

.msg-meta {
    font-size: 12px;
    color: var(--text-light);
    margin-bottom: 6px;
    font-weight: 600;
}

.typing {
    display: inline-block;
    animation: pulse 1.2s infinite;
    color: var(--text-light);
    letter-spacing: 3px;
}

@keyframes pulse {
    0%, 100% { opacity: .3; }
    50% { opacity: 1; }
}

/* Input area */
.chat-input-area {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    background: var(--surface);
}

.chat-form {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.chat-form textarea {
    flex: 1;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: 12px;
    font-size: 15px;
    font-family: var(--font);
    resize: none;
    line-height: 1.5;
    max-height: 150px;
}

.chat-form textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.chat-form button {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--primary);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .15s;
}

.chat-form button:hover { background: #236462; }

.chat-form .btn-tool {
    background: var(--primary-light);
    color: var(--primary);
}

.chat-form .btn-tool:hover { background: #bfe2e0; }
.chat-form .btn-tool:disabled { opacity: .5; cursor: wait; }

.chat-form .btn-tool.recording {
    background: #c0392b;
    color: #fff;
    animation: pulse-mic 1.4s infinite;
}

@keyframes pulse-mic {
    0%, 100% { box-shadow: 0 0 0 0 rgba(192,57,43,.45); }
    50% { box-shadow: 0 0 0 8px rgba(192,57,43,0); }
}

@media (prefers-reduced-motion: reduce) {
    .chat-form .btn-tool.recording { animation: none; }
}

.input-status {
    font-size: 13px;
    color: var(--text-light);
    margin-bottom: 8px;
}

.input-status.error { color: #c0392b; }

.attachment-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.attachment-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 240px;
    padding: 4px 6px 4px 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
}

.attachment-chip img {
    width: 36px;
    height: 36px;
    object-fit: cover;
    border-radius: 4px;
    flex-shrink: 0;
}

.attachment-chip span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attachment-chip button {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    border: none;
    border-radius: 50%;
    background: none;
    color: var(--text-light);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
}

.attachment-read {
    margin-top: 8px;
    font-size: 13px;
}

.attachment-read:first-child { margin-top: 0; }
.attachment-read summary { cursor: pointer; font-weight: 600; }

.attachment-read div {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid rgba(128,128,128,.35);
    white-space: pre-wrap;
    max-height: 260px;
    overflow-y: auto;
}

.typing-status { color: var(--text-light); font-size: 14px; }

/* ---- Dashboard (Eltern) ---- */

.dashboard {
    min-height: 100vh;
}

.dash-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.dash-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.dash-header-left h1 {
    font-size: 20px;
    color: var(--primary);
}

.dash-header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.back-link {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
}

.back-link:hover { text-decoration: underline; }

.dash-content {
    max-width: 900px;
    margin: 0 auto;
    padding: 32px 24px;
}

.student-section {
    margin-bottom: 40px;
}

.student-section h2 {
    font-size: 18px;
    margin-bottom: 16px;
    color: var(--primary);
}

.conv-table {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.conv-table-header {
    display: grid;
    grid-template-columns: 1fr 100px 100px 140px 80px;
    padding: 12px 20px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-light);
    border-bottom: 1px solid var(--border);
}

.conv-table-row {
    display: grid;
    grid-template-columns: 1fr 100px 100px 140px 80px;
    padding: 14px 20px;
    text-decoration: none;
    color: var(--text);
    font-size: 14px;
    border-bottom: 1px solid var(--border);
    transition: background .1s;
    align-items: center;
}

.conv-table-row:last-child { border-bottom: none; }

.conv-table-row:hover { background: var(--primary-light); }

.conv-table-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.conv-table-count { text-align: center; }

.conv-table-subject,
.conv-table-mode {
    text-align: center;
    font-size: 13px;
}

.conv-table-action {
    text-align: right;
    color: var(--primary);
    font-weight: 600;
}

.no-data {
    color: var(--text-light);
    font-style: italic;
}

/* Verlauf */
.verlauf-content {
    max-width: 700px;
    margin: 0 auto;
    padding: 32px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ---- Mobile ---- */

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -290px;
        top: 0;
        height: 100vh;
        z-index: 99;
        transition: left .25s ease;
        box-shadow: 4px 0 16px rgba(0,0,0,.1);
    }
    .sidebar.open { left: 0; }
    .sidebar-toggle { display: block; }
    .chat-header { padding-left: 56px; }
    .bubble { max-width: 88%; }
    .selector-grid { gap: 4px; }
    .selector-btn { padding: 5px 8px; font-size: 12px; }
    .mode-btn { min-width: 100px; }
    .conv-table-header,
    .conv-table-row { grid-template-columns: 1fr 60px 80px; }
    .conv-table-subject,
    .conv-table-mode,
    .conv-table-action { display: none; }
    .header-badges { display: none; }
}

/* Mathe-Darstellungen */
.viz, .viz-pending { margin: 10px 0; }
.viz { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px; max-width: 100%; }
.viz-pending { min-height: 1.5em; color: var(--text-light); font-size: 13px; }
.viz-pending::before { content: "Aufgabe wird vorbereitet…"; }
.viz-fallback { margin: 8px 0; font-weight: 600; }
.viz-stage { overflow-x: auto; }
.viz-svg { display: block; width: 100%; max-width: 560px; height: auto; max-height: 340px; font-family: var(--font); }
.viz-caption { margin: 10px 0 8px; min-height: 1.4em; font-size: 14px; color: var(--text); }
.viz-buttons { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.viz-buttons button { border: 1px solid var(--primary); border-radius: 8px; padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer; background: var(--surface); color: var(--primary); }
.viz-buttons .viz-next { background: var(--primary); color: #fff; }
.viz-buttons button:disabled { opacity: .45; cursor: default; }
.viz-count { font-size: 12px; color: var(--text-light); }
.viz-number { font-size: 18px; font-weight: 600; margin-bottom: 8px; }

/* Karopapier */
.kara { display: inline-grid; grid-auto-rows: 1.7em; font-size: 17px; background: #fff; border-top: 1px solid #cfe0e8; border-left: 1px solid #cfe0e8; font-family: 'Cascadia Code', 'Fira Code', monospace; }
.kara .k { display: flex; align-items: center; justify-content: center; border-right: 1px solid #cfe0e8; border-bottom: 1px solid #cfe0e8; color: #24344d; }
.kara .k-line { border-bottom: 2px solid #24344d; }
.kara .k-small { font-size: 11px; align-items: flex-end; color: #a33; }
.k-new { background: #fdeccf; font-weight: 700; }

.stellen { border-collapse: collapse; }
.stellen th, .stellen td { border: 1px solid #9fb6c2; min-width: 2.5em; height: 2.2em; text-align: center; font-size: 16px; }
.stellen th { background: var(--primary-light); font-size: 13px; }

.s-axis { stroke: #24344d; stroke-width: 2; }
.s-mark { stroke: #c0392b; stroke-width: 2; }
.s-tiny { font-size: 10px; text-anchor: middle; fill: #24344d; }
.s-label { font-size: 14px; font-weight: 600; text-anchor: middle; fill: #24344d; }
.s-new { font-size: 14px; font-weight: 700; text-anchor: middle; fill: #c0392b; }
.s-bar { font-size: 13px; text-anchor: end; fill: #24344d; }
.s-barv { font-size: 13px; fill: #24344d; }
.s-fill { fill: #8fd0ce; }
.s-edge { stroke: #24344d; stroke-width: 1.5; }
.s-newfill { fill: #f2a154; }
.s-given { fill: #c9d6df; }
.s-empty { fill: #fff; stroke: #24344d; stroke-width: 1.5; }
.s-slot { fill: none; stroke: #c9d6df; stroke-dasharray: 4 4; }
.s-grid { stroke: #cfe0e8; stroke-width: 1; }
.s-frame { fill: none; stroke: #24344d; stroke-width: 1.5; }
.s-frameline { stroke: #c0392b; stroke-width: 3; }
.s-mirror { stroke: #c0392b; stroke-width: 2; stroke-dasharray: 6 4; }
