/* K.I.T. — Knight Rider Cockpit Dashboard v0.5.1 */

:root {
    --bg: #0a0a0a;
    --surface: #0d0d0d;
    --surface-raised: #141414;
    --border: #1e1e1e;
    --border-bright: #2a2a2a;
    --text: #d4d4d4;
    --text-dim: #666;
    --text-muted: #444;
    --red: #e00000;
    --red-bright: #ff1a1a;
    --red-glow: rgba(255, 0, 0, 0.25);
    --red-dim: rgba(255, 0, 0, 0.08);
    --green: #00cc44;
    --yellow: #ccaa00;
    --amber: #ff8800;
    --panel-bg: rgba(13, 13, 13, 0.95);
}

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Courier New', monospace;
    height: 100dvh; /* dvh = dynamic viewport height, respekterer iOS browser bar */
    overflow: hidden;
    font-size: 15px;
    position: fixed; /* forhindrer iOS bounce/scroll */
    width: 100%;
}

/* === SCANNER BAR === */
.scanner-bar {
    height: 3px;
    background: var(--surface);
    position: relative;
    overflow: hidden;
    z-index: 100;
}

.scanner-light {
    position: absolute;
    width: 150px;
    height: 100%;
    background: linear-gradient(90deg, transparent, var(--red-bright), transparent);
    box-shadow: 0 0 30px var(--red), 0 0 80px var(--red-glow);
    animation: scan 3s ease-in-out infinite;
}

@keyframes scan {
    0%, 100% { left: -150px; }
    50% { left: calc(100% + 150px); }
}

/* === HEADER === */
.kit-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.kit-logo { display: flex; align-items: baseline; gap: 14px; }

.logo-text {
    font-size: 28px;
    font-weight: bold;
    color: var(--red);
    text-shadow: 0 0 20px var(--red-glow);
    letter-spacing: 8px;
}

.logo-sub {
    font-size: 10px;
    color: var(--text-muted);
    letter-spacing: 3px;
    text-transform: uppercase;
}

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

.status-dot {
    width: 8px; height: 8px;
    background: var(--green);
    border-radius: 50%;
    animation: pulse 2s infinite;
    box-shadow: 0 0 6px var(--green);
}

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

.status-text { font-size: 11px; color: var(--green); letter-spacing: 2px; }
.version-tag { font-size: 10px; color: var(--text-muted); }
.header-btn {
    background: none; border: 1px solid var(--border);
    color: var(--text-dim); font-family: inherit; font-size: 10px;
    padding: 4px 10px; border-radius: 3px; cursor: pointer;
    letter-spacing: 1px; transition: all 0.2s;
}
.header-btn:hover { border-color: var(--red); color: var(--red); }

/* === COCKPIT GRID — DESKTOP === */
.cockpit {
    display: grid;
    grid-template-columns: 260px 1fr 260px;
    height: calc(100dvh - 50px);
    gap: 1px;
    background: var(--border);
}

/* === PANELS === */
.panel {
    background: var(--panel-bg);
    overflow-y: auto;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.panel::-webkit-scrollbar { width: 3px; }
.panel::-webkit-scrollbar-track { background: transparent; }
.panel::-webkit-scrollbar-thumb { background: var(--border-bright); border-radius: 2px; }

.panel-section {
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 10px;
    background: var(--surface);
}

.panel-section h3 {
    font-size: 10px;
    color: var(--red);
    letter-spacing: 3px;
    text-transform: uppercase;
    margin-bottom: 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
}

/* Server list */
.server-list { display: flex; flex-direction: column; gap: 4px; }

.server-item {
    display: flex; align-items: center; gap: 8px;
    font-size: 13px; padding: 3px 0;
}
.server-item.loading { color: var(--text-dim); }

.dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.dot-green { background: var(--green); box-shadow: 0 0 4px var(--green); }
.dot-red { background: var(--red); box-shadow: 0 0 4px var(--red); }
.dot-yellow { background: var(--yellow); box-shadow: 0 0 4px var(--yellow); }
.dot-loading { background: var(--text-dim); animation: pulse 1s infinite; }

.server-name { color: var(--text); font-size: 12px; }
.server-val { color: var(--text-dim); font-size: 11px; margin-left: auto; }

/* Info blocks */
.info-block { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.info-value { font-size: 22px; font-weight: bold; color: var(--text); }
.info-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; }

/* Alerts */
.alerts-block { display: flex; flex-direction: column; gap: 4px; }
.alert-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-dim); }

/* GPU */
.gpu-item { display: flex; justify-content: space-between; font-size: 13px; padding: 2px 0; }

/* Mini list (mail, events) */
.mini-list { display: flex; flex-direction: column; gap: 3px; margin-top: 8px; }

.mini-item {
    font-size: 12px; color: var(--text-dim); padding: 4px 0;
    border-bottom: 1px solid var(--border);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mini-item.unread { color: var(--text); font-weight: bold; }

/* Conversations */
.conversation-list {
    display: flex; flex-direction: column; gap: 3px;
    max-height: 250px; overflow-y: auto;
}

.conv-item {
    padding: 8px 8px; font-size: 13px; color: var(--text-dim);
    cursor: pointer; border-radius: 3px; transition: all 0.15s;
    overflow: hidden; text-overflow: ellipsis;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    line-height: 1.4; border-bottom: 1px solid var(--border);
}
.conv-item:hover { background: var(--surface-raised); color: var(--text); }
.conv-item.active { color: var(--red); border-left: 2px solid var(--red); background: var(--red-dim); }

/* === CHAT PANEL === */
.chat-panel {
    display: flex;
    flex-direction: column;
    background: var(--bg);
    overflow: hidden;
    min-height: 0; /* kritisk for flex child i grid */
}

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

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: var(--bg); }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border-bright); border-radius: 2px; }

/* Messages */
.message {
    display: flex;
    gap: 12px;
    max-width: 90%;
    animation: fadeIn 0.3s ease;
    position: relative;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.user-message { align-self: flex-end; flex-direction: row-reverse; }

.message-avatar {
    width: 32px; height: 32px; border-radius: 4px;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; font-weight: bold; flex-shrink: 0;
}

.kit-message .message-avatar {
    background: var(--red-dim); color: var(--red);
    border: 1px solid rgba(255,0,0,0.3);
    text-shadow: 0 0 8px var(--red-glow);
}

.user-message .message-avatar {
    background: rgba(255,255,255,0.03); color: var(--text-dim);
    border: 1px solid var(--border);
}

.message-content {
    padding: 10px 14px; border-radius: 6px;
    font-size: 14px; line-height: 1.7;
    word-break: break-word; min-width: 0;
}

.kit-message .message-content {
    background: var(--surface-raised);
    border: 1px solid var(--border);
}

.user-message .message-content {
    background: var(--red-dim);
    border: 1px solid rgba(255,0,0,0.15);
}

/* Markdown in messages */
.message-content p { margin: 0 0 8px 0; }
.message-content p:last-child { margin-bottom: 0; }
.message-content h1, .message-content h2, .message-content h3 {
    color: var(--red); margin: 12px 0 6px 0; font-size: 16px;
}
.message-content h2 { font-size: 15px; }
.message-content h3 { font-size: 14px; }
.message-content ul, .message-content ol { padding-left: 20px; margin: 4px 0; }
.message-content li { margin: 2px 0; }
.message-content pre {
    background: #1a1a2e; border: 1px solid var(--border);
    border-radius: 4px; padding: 10px 12px; margin: 8px 0;
    overflow-x: auto; font-size: 13px;
}
.message-content code { font-family: inherit; font-size: 13px; }
.message-content :not(pre) > code {
    background: rgba(255,0,0,0.1); padding: 1px 5px;
    border-radius: 3px; color: var(--red-bright);
}
.message-content table {
    border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 13px;
}
.message-content th, .message-content td {
    border: 1px solid var(--border); padding: 5px 10px; text-align: left;
}
.message-content th { background: var(--surface); color: var(--red); font-size: 11px; text-transform: uppercase; }
.message-content strong { color: var(--text); }
.message-content a { color: var(--red); text-decoration: none; }
.message-content a:hover { text-decoration: underline; }
.message-content blockquote {
    border-left: 2px solid var(--red); padding-left: 12px;
    color: var(--text-dim); margin: 8px 0;
}

/* Message actions */
.message-actions {
    display: none; position: absolute; top: -4px; right: 0;
    gap: 2px; background: var(--surface); border: 1px solid var(--border);
    border-radius: 4px; padding: 2px;
}
.message:hover .message-actions { display: flex; }

.action-btn {
    background: none; border: none; color: var(--text-dim);
    font-size: 14px; padding: 4px 6px; cursor: pointer;
    border-radius: 2px; transition: all 0.15s;
}
.action-btn:hover { color: var(--red); background: var(--red-dim); }

/* Typing indicator */
.typing-indicator { display: flex; gap: 4px; padding: 4px 0; }
.typing-indicator span {
    width: 6px; height: 6px; background: var(--red);
    border-radius: 50%; animation: typing 1.4s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
    30% { opacity: 1; transform: scale(1); }
}

/* === INPUT AREA === */
.chat-input-area {
    padding: 10px 16px;
    border-top: 1px solid var(--border);
    background: var(--surface);
}

.file-indicator {
    display: none; font-size: 11px; color: var(--red);
    padding: 4px 8px; cursor: pointer;
}

.input-wrapper {
    display: flex; gap: 8px; align-items: flex-end;
}

.input-btn {
    border: 1px solid var(--border); border-radius: 4px;
    color: var(--text-dim); width: 40px; height: 40px;
    cursor: pointer; display: flex; align-items: center;
    justify-content: center; transition: all 0.2s;
    flex-shrink: 0; background: none;
}
.input-btn:hover { border-color: var(--red); color: var(--red); }

.send-btn {
    background: var(--red); border-color: var(--red); color: white;
}
.send-btn:hover {
    background: #cc0000; box-shadow: 0 0 12px var(--red-glow);
}

textarea {
    flex: 1; background: var(--bg); border: 1px solid var(--border);
    border-radius: 4px; color: var(--text); font-family: inherit;
    font-size: 15px; padding: 10px 14px; resize: none;
    max-height: 120px; outline: none; transition: border-color 0.2s;
}
textarea:focus { border-color: var(--red); box-shadow: 0 0 8px var(--red-dim); }

/* ===========================================================
   MOBIL — chatten er ALLTID synlig, paneler skjules
   =========================================================== */

@media (max-width: 1100px) {
    .cockpit { grid-template-columns: 220px 1fr 220px; }
}

/* Mobile menu */
.mobile-only { display: none; }
.desktop-only { display: inline-block; }

.mobile-menu {
    display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg); z-index: 1000; overflow-y: auto;
    flex-direction: column;
}
.mobile-menu.active { display: flex; }

.mobile-menu-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.mobile-menu-title { color: var(--red); font-size: 12px; letter-spacing: 3px; text-transform: uppercase; }
.mobile-menu-close { background: none; border: none; color: var(--text); font-size: 24px; cursor: pointer; }

.mobile-menu-items { display: flex; flex-direction: column; padding: 8px; }

.mobile-menu-item {
    display: flex; align-items: center; gap: 12px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
    color: var(--text); font-family: inherit; font-size: 15px;
    padding: 14px 16px; margin-bottom: 6px; cursor: pointer;
    transition: all 0.15s; text-align: left; width: 100%;
}
.mobile-menu-item:hover, .mobile-menu-item:active { border-color: var(--red); background: var(--surface-raised); }
.mobile-menu-icon { font-size: 18px; width: 24px; text-align: center; }
.mobile-menu-badge { margin-left: auto; background: var(--red); color: white; font-size: 11px; padding: 2px 6px; border-radius: 10px; }
.mobile-menu-logout { border-color: rgba(255,0,0,0.2); color: var(--red); margin-top: 8px; }
.mobile-menu-logout:hover { border-color: var(--red); }

.mobile-menu-convos {
    max-height: 200px; overflow-y: auto; margin: 4px 0;
}
.mobile-convo-item {
    display: block; width: 100%; text-align: left; background: none;
    border: none; border-bottom: 1px solid var(--border);
    color: var(--text-dim); font-family: inherit; font-size: 13px;
    padding: 10px 16px 10px 52px; cursor: pointer;
}
.mobile-convo-item:hover { color: var(--text); background: var(--surface-raised); }
.mobile-convo-item.active { color: var(--red); }

@media (max-width: 900px) {
    .mobile-only { display: inline-block; }
    .desktop-only { display: none !important; }
    .cockpit {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr;
        height: calc(100dvh - 44px);
    }
    .panel-left, .panel-right { display: none !important; }

    .kit-header { padding: 6px 10px; }
    .logo-text { font-size: 20px; letter-spacing: 4px; }
    .logo-sub { display: none; }

    .chat-messages { padding: 12px 14px; gap: 10px; }
    .message { max-width: 95%; }
    .message-content { font-size: 15px; padding: 10px 12px; }
    .message-avatar { width: 30px; height: 30px; font-size: 13px; }

    textarea { font-size: 16px; padding: 10px 12px; }
    .input-btn { width: 44px; height: 44px; }
    .send-btn { width: 44px; height: 44px; }
}

@media (max-width: 600px) {
    .kit-header { padding: 6px 10px; }
    .logo-text { font-size: 20px; letter-spacing: 4px; }
    .logo-sub { display: none; }
    .version-tag { display: none; }

    .chat-messages { padding: 8px 10px; gap: 8px; }
    .message { max-width: 100%; }
    .message-avatar { width: 26px; height: 26px; font-size: 11px; }
    .message-content { padding: 8px 10px; font-size: 15px; line-height: 1.6; }

    .chat-input-area {
        padding: 8px;
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }
    .input-wrapper { gap: 4px; }
    textarea { font-size: 16px; } /* forhindrer zoom pa iOS */
    .input-btn { width: 44px; height: 44px; }
}

@media (max-width: 380px) {
    .logo-text { font-size: 18px; letter-spacing: 3px; }
    .header-btn { font-size: 9px; padding: 3px 6px; }
}
