/* ═══════════════════════════════════════════════════════════
   Otto Platform — Shared Stylesheet
   Administration dashboard, chat, bots, projects, logs
   ═══════════════════════════════════════════════════════════ */

/* ── Reset & Base ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg-primary: #1e1e2e;
    --bg-secondary: #181825;
    --bg-surface: #252537;
    --bg-hover: #2a2a3c;
    --bg-input: #313145;
    --bg-card: #1e1e30;
    --text-primary: #cdd6f4;
    --text-secondary: #a6adc8;
    --text-muted: #6c7086;
    --accent: #89b4fa;
    --accent-hover: #74c7ec;
    --mauve: #cba6f7;
    --green: #a6e3a1;
    --yellow: #f9e2af;
    --peach: #fab387;
    --red: #f38ba8;
    --teal: #94e2d5;
    --border: #313244;
    --error: #f38ba8;
    --success: #a6e3a1;
    --radius: 8px;
    --nav-width: 220px;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-primary);
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

.hidden { display: none !important; }

/* ── Platform Shell ───────────────────────────────────── */
.platform-shell {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ── Navigation Sidebar ───────────────────────────────── */
.nav-sidebar {
    width: var(--nav-width);
    min-width: var(--nav-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
}

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

.nav-brand-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.nav-brand-text {
    font-size: 20px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -0.5px;
}

.nav-brand-sub {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-left: auto;
}

.nav-menu {
    flex: 1;
    overflow-y: auto;
    padding: 12px 8px;
}

.nav-section-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-muted);
    padding: 16px 12px 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
    cursor: pointer;
    text-decoration: none;
}

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

.nav-item.active {
    background: var(--bg-surface);
    color: var(--accent);
}

.nav-icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.nav-badge {
    margin-left: auto;
    background: var(--accent);
    color: var(--bg-primary);
    font-size: 10px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 10px;
}

.nav-footer {
    padding: 12px 8px;
    border-top: 1px solid var(--border);
}

/* ── Main Content Area ────────────────────────────────── */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-primary);
}

/* ── Page Header ──────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    min-height: 56px;
}

.page-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.page-subtitle {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.page-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* ── Page Body ────────────────────────────────────────── */
.page-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

/* ── Cards ────────────────────────────────────────────── */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.card-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.card-icon {
    font-size: 20px;
}

.card-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.card-value.small { font-size: 18px; }

.card-change {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.card-change.up { color: var(--green); }
.card-change.down { color: var(--red); }

/* ── Status Indicators ─────────────────────────────────── */
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
}

.status-dot.online { background: var(--green); }
.status-dot.offline { background: var(--red); }
.status-dot.warning { background: var(--yellow); }
.status-dot.idle { background: var(--text-muted); }

.status-badge {
    display: inline-flex;
    align-items: center;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.status-badge.running { background: rgba(166,227,161,0.15); color: var(--green); }
.status-badge.stopped { background: rgba(243,139,168,0.15); color: var(--red); }
.status-badge.active { background: rgba(137,180,250,0.15); color: var(--accent); }
.status-badge.paused { background: rgba(249,226,175,0.15); color: var(--yellow); }
.status-badge.completed { background: rgba(166,227,161,0.15); color: var(--green); }

/* ── Tables ───────────────────────────────────────────── */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    text-align: left;
    padding: 10px 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

.data-table td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 13px;
}

.data-table tr:hover td {
    background: var(--bg-hover);
}

.data-table .mono {
    font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 12px;
}

/* ── Buttons ──────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid var(--border);
    transition: background 0.15s, border-color 0.15s;
}

.btn-primary {
    background: var(--accent);
    color: var(--bg-primary);
    border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-danger {
    background: transparent;
    color: var(--red);
    border-color: var(--red);
}
.btn-danger:hover { background: rgba(243,139,168,0.15); }

.btn-sm { padding: 5px 10px; font-size: 12px; }

.btn-icon {
    padding: 6px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius);
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ── Forms ────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s;
}

.form-input:focus { border-color: var(--accent); }

.form-error {
    color: var(--error);
    font-size: 12px;
    margin-top: 8px;
}

/* ── Empty State ──────────────────────────────────────── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-muted);
    text-align: center;
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 13px;
    max-width: 320px;
}

/* ── Section Panels ───────────────────────────────────── */
.section-panel {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 24px;
}

.section-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

.section-panel-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.section-panel-body {
    padding: 16px;
}

/* ── Service Status Cards ─────────────────────────────── */
.service-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}
.service-row:last-child { border-bottom: none; }

.service-name {
    font-weight: 500;
    color: var(--text-primary);
    font-size: 13px;
}

.service-detail {
    font-size: 12px;
    color: var(--text-muted);
}

/* ── Progress Bar ─────────────────────────────────────── */
.progress-bar {
    height: 6px;
    background: var(--bg-hover);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 8px;
}

.progress-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s ease;
}

.progress-fill.good { background: var(--green); }
.progress-fill.warn { background: var(--yellow); }
.progress-fill.danger { background: var(--red); }

/* ── Activity Log ─────────────────────────────────────── */
.activity-item {
    display: flex;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}
.activity-item:last-child { border-bottom: none; }

.activity-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    background: var(--bg-hover);
}

.activity-text {
    flex: 1;
}

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

.activity-time {
    font-size: 11px;
    color: var(--text-muted);
}

/* ── Chat Embed (inside platform) ─────────────────────── */
.chat-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.chat-sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

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

.chat-sidebar-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

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

.conversation-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--text-secondary);
    transition: background 0.15s;
    margin-bottom: 2px;
    font-size: 13px;
}

.conversation-item:hover { background: var(--bg-hover); }
.conversation-item.active { background: var(--bg-surface); color: var(--accent); }

.conversation-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 13px;
}

/* Three-dot menu */
.convo-menu-wrapper {
    position: relative;
}
.btn-convo-menu {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
    padding: 0 4px;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.15s;
}
.conversation-item:hover .btn-convo-menu { opacity: 1; }
.btn-convo-menu:hover { color: var(--text-primary); }

.convo-menu {
    position: absolute;
    right: 0;
    top: 100%;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-width: 130px;
    z-index: 200;
    padding: 4px 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.convo-menu-item {
    display: block;
    width: 100%;
    background: none;
    border: none;
    color: var(--text-primary);
    padding: 8px 14px;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
}
.convo-menu-item:hover { background: var(--bg-hover); }
.convo-menu-danger:hover { color: var(--error); }

/* Chat pane (main area) */
.chat-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    min-height: 48px;
}

.chat-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Messages */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
}

.welcome-icon { font-size: 48px; margin-bottom: 16px; }
.welcome-avatar { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; }
.otto-avatar-img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.welcome-screen h2 { font-size: 20px; color: var(--text-secondary); margin-bottom: 8px; }
.welcome-screen p { font-size: 14px; }

.message {
    display: flex;
    gap: 12px;
    padding: 16px 0;
    border-bottom: 1px solid var(--border);
}
.message:last-child { border-bottom: none; }

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    background: var(--bg-surface);
    flex-shrink: 0;
}

.message-user .message-avatar { background: var(--accent); color: var(--bg-primary); }

.message-body { flex: 1; min-width: 0; }

.message-role {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.message-content {
    white-space: pre-wrap;
    word-wrap: break-word;
    line-height: 1.6;
    color: var(--text-primary);
}

.message-content.error { color: var(--error); }

/* Reasoning panel */
.reasoning-panel {
    margin: 0 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-surface);
}

.btn-toggle-reasoning {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    width: 100%;
}

.reasoning-content {
    padding: 0 12px 12px;
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-muted);
    white-space: pre-wrap;
    max-height: 200px;
    overflow-y: auto;
}

.reasoning-content.collapsed { display: none; }

/* Input area */
.input-area {
    padding: 12px 20px 16px;
    border-top: 1px solid var(--border);
}

.attachment-preview {
    display: flex;
    gap: 8px;
    padding: 8px 0;
    flex-wrap: wrap;
}

.attachment-thumb {
    position: relative;
    width: 64px;
    height: 64px;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.attachment-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.attachment-thumb .remove-attachment {
    position: absolute;
    top: 2px;
    right: 2px;
    background: rgba(0,0,0,0.7);
    color: white;
    border: none;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.input-wrapper {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    transition: border-color 0.15s;
}

.input-wrapper:focus-within { border-color: var(--accent); }

.input-wrapper textarea {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    max-height: 200px;
    font-family: inherit;
}

.input-wrapper textarea::placeholder { color: var(--text-muted); }

.btn-attach {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
}
.btn-attach:hover { color: var(--accent); }

.btn-send {
    background: var(--accent);
    color: var(--bg-primary);
    border: none;
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: opacity 0.15s;
}
.btn-send:disabled { opacity: 0.3; cursor: default; }
.btn-send:not(:disabled):hover { background: var(--accent-hover); }

.input-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: 6px;
}

.model-badge {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    background: var(--bg-surface);
    color: var(--text-muted);
    letter-spacing: 0.3px;
    transition: background 0.2s, color 0.2s;
}

.model-badge-reasoner {
    background: rgba(203, 166, 247, 0.15);
    color: #cba6f7;
}

.status-indicator {
    font-size: 12px;
    color: var(--text-muted);
}

/* Message attachments */
.msg-attachments { margin-bottom: 8px; }
.msg-attachment-img img {
    max-width: 300px;
    max-height: 200px;
    border-radius: 6px;
    border: 1px solid var(--border);
}
.msg-attachment-file {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--bg-surface);
    border-radius: 4px;
    font-size: 12px;
}
.msg-attachment-file a { color: var(--accent); }

.stream-error-notice {
    margin-top: 8px;
    padding: 8px 12px;
    background: rgba(243,139,168,0.1);
    border: 1px solid rgba(243,139,168,0.3);
    border-radius: 6px;
    color: var(--red);
    font-size: 12px;
}

/* ── Login Page ───────────────────────────────────────── */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-container { width: 100%; max-width: 380px; padding: 20px; }

.login-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 32px;
}

.login-header { text-align: center; margin-bottom: 28px; }

.login-header h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--accent);
}

.login-subtitle {
    color: var(--text-muted);
    font-size: 14px;
    margin-top: 4px;
}

.btn-full { width: 100%; justify-content: center; padding: 10px; }

/* ── Responsive ───────────────────────────────────────── */
@media (max-width: 768px) {
    .nav-sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        bottom: 0;
        transition: left 0.2s ease;
        z-index: 1000;
    }
    .nav-sidebar.open { left: 0; }

    .chat-sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        bottom: 0;
        transition: left 0.2s ease;
        z-index: 900;
    }
    .chat-sidebar.open { left: 0; }

    .card-grid {
        grid-template-columns: 1fr;
    }
}

/* ── Scrollbar ──────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--bg-hover);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: var(--border); }

/* ── Animation helpers ────────────────────────────────── */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.fade-in { animation: fadeIn 0.2s ease; }

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

.animate-pulse { animation: pulse 2s infinite; }
