:root {
    color-scheme: dark;
    --bg: #090b10;
    --panel: #11151d;
    --panel-2: #151a24;
    --line: rgba(255,255,255,.08);
    --line-strong: rgba(255,255,255,.14);
    --text: #eef2ff;
    --muted: #8e99ad;
    --green: #4ee3a5;
    --violet: #8d72ff;
    --danger: #ff6b83;
    --shadow: 0 24px 60px rgba(0,0,0,.28);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; min-height: 100%; background: var(--bg); color: var(--text); }
button, input, textarea, select { font: inherit; }

body.app-page {
    height: 100vh;
    overflow: hidden;
    background:
        radial-gradient(circle at 6% 8%, rgba(141,114,255,.13), transparent 26rem),
        radial-gradient(circle at 92% 90%, rgba(78,227,165,.08), transparent 30rem),
        var(--bg);
}

#app { height: 100vh; display: flex; flex-direction: column; }

.topbar {
    height: 66px;
    flex: 0 0 66px;
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 0 20px;
    border-bottom: 1px solid var(--line);
    background: rgba(11,14,20,.92);
    backdrop-filter: blur(18px);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.brand strong { display: block; font-size: 17px; letter-spacing: -.02em; }
.brand small { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }

.brand-mark {
    width: 58px;
    height: 58px;
    border-radius: 18px;
    display: grid;
    place-items: center;
    font-weight: 800;
    font-size: 30px;
    color: #fff;
    background: linear-gradient(135deg, #765cff, #4ee3a5);
    box-shadow: 0 12px 35px rgba(118,92,255,.25);
}
.brand-mark-small { width: 38px; height: 38px; border-radius: 12px; font-size: 20px; }

.topbar-status { display: flex; align-items: center; gap: 8px; flex: 1; justify-content: center; }
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--line);
    background: rgba(255,255,255,.03);
    color: var(--muted);
    border-radius: 999px;
    padding: 7px 10px;
    font-size: 12px;
}
.status-pill b { color: var(--text); font-weight: 600; }
.status-pill i { width: 7px; height: 7px; border-radius: 50%; background: #687184; }
.status-pill i.ok { background: var(--green); box-shadow: 0 0 12px rgba(78,227,165,.65); }
.status-pill i.bad { background: var(--danger); }

.topbar-user { min-width: 220px; display: flex; justify-content: flex-end; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; }
.topbar-link { color: #bcb4ff; text-decoration: none; }

.workspace {
    flex: 1;
    min-height: 0;
    display: flex;
    gap: 10px;
    padding: 10px;
}

.panel {
    background: linear-gradient(180deg, rgba(19,24,34,.96), rgba(14,18,26,.96));
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: var(--shadow);
    overflow: hidden;
    min-width: 0;
    min-height: 0;
}

.chat-panel {
    width: 46%;
    min-width: 360px;
    display: flex;
    flex-direction: column;
}

.right-column {
    flex: 1;
    min-width: 380px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.terminal-panel { height: 52%; min-height: 220px; display: flex; flex-direction: column; }
.browser-panel { flex: 1; min-height: 200px; display: flex; flex-direction: column; }

.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    min-height: 68px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
    background: rgba(255,255,255,.018);
}
.panel-head.compact { min-height: 58px; padding: 11px 14px; }
.panel-head h2 { margin: 0; font-size: 14px; font-weight: 700; }
.panel-head p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }

.panel button,
.composer button,
.login-card button {
    border: 1px solid rgba(141,114,255,.4);
    background: rgba(141,114,255,.15);
    color: #eae7ff;
    border-radius: 10px;
    padding: 8px 12px;
    cursor: pointer;
}
.panel button:hover,
.composer button:hover,
.login-card button:hover { background: rgba(141,114,255,.24); }

.lock-badge {
    color: #aeb6c7;
    font-size: 11px;
    padding: 6px 9px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255,255,255,.03);
}

.conversation-row {
    padding: 9px 12px;
    border-bottom: 1px solid var(--line);
}
.conversation-row select {
    width: 100%;
    color: var(--text);
    background: #0d1118;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    padding: 8px 10px;
}

.messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 18px;
    scroll-behavior: smooth;
}

.message {
    margin: 0 0 14px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.message.user { align-items: flex-end; }
.message.assistant { align-items: flex-start; }
.message-meta { color: var(--muted); font-size: 10px; }
.message-bubble {
    max-width: 88%;
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.55;
    font-size: 13px;
    padding: 11px 13px;
    border-radius: 14px;
    border: 1px solid var(--line);
}
.message.user .message-bubble {
    background: linear-gradient(135deg, rgba(118,92,255,.23), rgba(118,92,255,.12));
    border-color: rgba(141,114,255,.28);
}
.message.assistant .message-bubble {
    background: rgba(255,255,255,.035);
}

.generation-progress { height: 3px; border: 0 !important; background: transparent !important; }
.generation-progress .ui-progressbar-value {
    background: linear-gradient(90deg, var(--violet), var(--green));
    border: 0;
    margin: 0;
}

.composer {
    flex: 0 0 auto;
    padding: 12px;
    border-top: 1px solid var(--line);
}
.composer textarea {
    width: 100%;
    resize: none;
    min-height: 72px;
    max-height: 180px;
    color: var(--text);
    background: #0b0f16;
    border: 1px solid var(--line-strong);
    border-radius: 13px;
    padding: 11px 12px;
    outline: none;
}
.composer textarea:focus { border-color: rgba(141,114,255,.58); box-shadow: 0 0 0 3px rgba(141,114,255,.09); }
.composer-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.composer-footer span { color: var(--muted); font-size: 10px; }

#terminal {
    flex: 1;
    min-height: 0;
    padding: 8px 10px 10px;
    background: #07090d;
}

.browser-placeholder { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.browser-toolbar {
    flex: 0 0 44px;
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 7px 9px;
    border-bottom: 1px solid var(--line);
    background: #0d1118;
}
.browser-toolbar button { width: 30px; height: 30px; padding: 0; opacity: .55; }
.browser-address {
    flex: 1;
    min-width: 0;
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: 9px;
    color: var(--muted);
    background: #080b10;
    font-size: 11px;
}
.browser-empty {
    flex: 1;
    display: grid;
    place-content: center;
    text-align: center;
    gap: 8px;
    color: var(--muted);
    padding: 30px;
}
.browser-empty strong { color: #dce2ee; font-size: 15px; }
.browser-empty span { max-width: 420px; font-size: 12px; line-height: 1.6; }

.ui-resizable-e { width: 8px !important; right: -5px !important; cursor: col-resize !important; }
.ui-resizable-s { height: 8px !important; bottom: -5px !important; cursor: row-resize !important; }
.ui-dialog {
    background: #131823 !important;
    border: 1px solid var(--line-strong) !important;
    border-radius: 16px !important;
    box-shadow: var(--shadow) !important;
}
.ui-dialog-titlebar { background: transparent !important; border: 0 !important; color: var(--text) !important; }
.ui-dialog-content { color: var(--text) !important; }
.ui-widget-overlay { background: #000 !important; opacity: .62 !important; }

.dialog-label { display: grid; gap: 7px; }
.dialog-label span { color: var(--muted); font-size: 12px; }
.dialog-label input {
    width: 100%;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    padding: 9px 10px;
    background: #090c12;
    color: var(--text);
}
.hidden-dialog { display: none; }

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background:
        radial-gradient(circle at 20% 20%, rgba(141,114,255,.18), transparent 28rem),
        radial-gradient(circle at 82% 78%, rgba(78,227,165,.1), transparent 26rem),
        var(--bg);
}
.login-card {
    width: min(390px, calc(100% - 32px));
    padding: 30px;
    border-radius: 22px;
    border: 1px solid var(--line);
    background: rgba(17,21,29,.96);
    box-shadow: var(--shadow);
}
.login-card .brand-mark { margin: 0 auto 16px; }
.login-card h1 { text-align: center; margin: 0; }
.login-card > p { text-align: center; color: var(--muted); margin: 6px 0 24px; }
.login-card form { display: grid; gap: 14px; }
.login-card label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.login-card input {
    width: 100%;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    padding: 11px;
    background: #090c12;
    color: var(--text);
    outline: none;
}
.login-card button { margin-top: 4px; padding: 11px; }
.login-error {
    margin-bottom: 14px;
    padding: 10px 11px;
    border: 1px solid rgba(255,107,131,.25);
    background: rgba(255,107,131,.08);
    color: #ffafbc;
    border-radius: 10px;
    font-size: 12px;
}

@media (max-width: 980px) {
    body.app-page { overflow: auto; height: auto; }
    #app { min-height: 100vh; height: auto; }
    .topbar-status { display: none; }
    .topbar-user { min-width: auto; }
    .workspace { flex-direction: column; }
    .chat-panel { width: 100% !important; height: 72vh; min-width: 0; }
    .right-column { min-width: 0; height: 90vh; }
}

/* ALTARI TERMINAL V1 */
#terminalConnection {
    margin-left: 6px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 500;
}
#terminalLockBtn.ai-lock {
    color: #f3d38a;
    border-color: rgba(243,211,138,.3);
    background: rgba(243,211,138,.08);
}
#terminal .xterm {
    height: 100%;
}
#terminal .xterm-viewport {
    scrollbar-color: rgba(141,114,255,.42) transparent;
}

/* ALTARI BROWSER V1 */
#browserConnection {
    margin-left: 6px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 500;
}
#browserLockBtn.ai-lock {
    color: #f3d38a;
    border-color: rgba(243,211,138,.3);
    background: rgba(243,211,138,.08);
}
.browser-toolbar {
    display: flex;
}
.browser-toolbar .browser-address {
    min-width: 0;
    height: 32px;
    outline: none;
}
.browser-toolbar .browser-address:focus {
    border-color: rgba(141,114,255,.5);
}
.browser-viewport {
    position: relative;
    flex: 1;
    min-height: 0;
    overflow: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    background:
        linear-gradient(45deg, rgba(255,255,255,.015) 25%, transparent 25%),
        #090c11;
}
#browserScreenshot {
    display: none;
    width: 100%;
    height: auto;
    max-width: 1280px;
    cursor: crosshair;
    user-select: none;
}
.browser-typebar {
    min-height: 42px;
    padding: 6px 8px;
    border-top: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: 6px;
    background: #0d1118;
}
.browser-typebar input {
    flex: 1;
    min-width: 0;
    color: var(--text);
    background: #080b10;
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 7px 9px;
    outline: none;
}
.browser-typebar #browserTitle {
    max-width: 30%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: var(--muted);
    font-size: 10px;
}


/* ALTARI UPLOADS V1 */
.composer.drag-over {
    background: rgba(141, 114, 255, .07);
    box-shadow: inset 0 0 0 1px rgba(141, 114, 255, .35);
}

.composer-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.attachment-btn {
    flex: 0 0 auto;
    padding: 7px 10px !important;
    border-radius: 9px !important;
    font-size: 11px !important;
}

.pending-attachments,
.message-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.pending-attachments {
    display: none;
    margin-bottom: 8px;
    padding: 8px;
    border: 1px dashed rgba(141, 114, 255, .28);
    border-radius: 11px;
    background: rgba(141, 114, 255, .035);
}

.message-attachments {
    margin-top: 9px;
}

.attachment-chip {
    display: flex;
    align-items: stretch;
    min-width: 0;
    max-width: 100%;
    border: 1px solid var(--line-strong);
    border-radius: 9px;
    overflow: hidden;
    background: rgba(255, 255, 255, .025);
}

.attachment-chip > a {
    display: flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
    padding: 6px 9px;
    color: var(--text);
    text-decoration: none;
}

.attachment-chip > a:hover {
    background: rgba(255, 255, 255, .035);
}

.attachment-chip strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11px;
    font-weight: 600;
}

.attachment-chip span {
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 9px;
}

.attachment-remove {
    width: 28px;
    padding: 0 !important;
    border: 0 !important;
    border-left: 1px solid var(--line) !important;
    border-radius: 0 !important;
    background: transparent !important;
    color: var(--muted) !important;
    font-size: 16px !important;
}

.attachment-remove:hover {
    color: #ff9a9a !important;
    background: rgba(255, 80, 80, .08) !important;
}

.message-text {
    white-space: pre-wrap;
}


/* ALTARI ATTACHMENT AGENT V1 */
.message-activity {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-top: 10px;
    padding-top: 9px;
    border-top: 1px solid var(--line);
}

.activity-item {
    display: flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
    color: var(--muted);
    font-size: 10px;
}

.activity-dot {
    width: 6px;
    height: 6px;
    flex: 0 0 6px;
    border-radius: 50%;
    background: #7f8a9b;
}

.activity-item.ok .activity-dot {
    background: #6fd39a;
}

.activity-item.error .activity-dot {
    background: #ef7f7f;
}

.activity-label {
    flex: 0 0 auto;
    font-weight: 600;
    color: var(--text-soft, #b9c3d0);
}

.activity-item code {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 2px 5px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: rgba(255, 255, 255, .025);
    color: var(--muted);
    font-size: 9px;
}


/* ALTARI AGENT CONTROL V1 */
.agent-control {
    margin: 8px 10px 0;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(255, 255, 255, .018);
    overflow: hidden;
}

.agent-control.active {
    border-color: rgba(141, 114, 255, .38);
    box-shadow: inset 0 0 0 1px rgba(141, 114, 255, .06);
}

.agent-control.stopping {
    border-color: rgba(236, 179, 91, .38);
}

.agent-control.error {
    border-color: rgba(239, 127, 127, .38);
}

.agent-control-main {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 45px;
    padding: 7px 9px;
}

.agent-state-dot {
    width: 8px;
    height: 8px;
    flex: 0 0 8px;
    border-radius: 50%;
    background: #66717f;
}

.agent-control.active .agent-state-dot {
    background: #8d72ff;
    box-shadow: 0 0 0 4px rgba(141, 114, 255, .11);
    animation: altari-agent-pulse 1.4s ease-in-out infinite;
}

.agent-control.stopping .agent-state-dot {
    background: #ecb35b;
}

.agent-control.error .agent-state-dot {
    background: #ef7f7f;
}

@keyframes altari-agent-pulse {
    0%, 100% { opacity: .6; }
    50% { opacity: 1; }
}

.agent-control-text {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
    flex: 1;
}

.agent-control-text strong {
    color: var(--text);
    font-size: 11px;
}

.agent-control-text span {
    min-width: 0;
    color: var(--muted);
    font-size: 9px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.agent-step-badge {
    flex: 0 0 auto;
    padding: 4px 6px;
    border: 1px solid var(--line);
    border-radius: 7px;
    color: var(--muted);
    font-size: 9px;
    font-variant-numeric: tabular-nums;
}

#agentToolsLockBtn,
#agentStopBtn {
    flex: 0 0 auto;
    padding: 6px 8px !important;
    border-radius: 8px !important;
    font-size: 10px !important;
}

#agentToolsLockBtn.ai-lock {
    border-color: rgba(141, 114, 255, .45) !important;
    color: #c6b9ff !important;
}

.agent-stop-btn:not(:disabled) {
    border-color: rgba(239, 127, 127, .38) !important;
    color: #ffabab !important;
}

.agent-activity {
    display: none;
    max-height: 116px;
    overflow-y: auto;
    padding: 6px 9px 8px 26px;
    border-top: 1px solid var(--line);
}

.agent-activity-row {
    display: flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
    min-height: 20px;
    color: var(--muted);
    font-size: 9px;
}

.agent-activity-marker {
    width: 5px;
    height: 5px;
    flex: 0 0 5px;
    border-radius: 50%;
    background: #77808e;
}

.agent-activity-row.ok .agent-activity-marker {
    background: #6fd39a;
}

.agent-activity-row.bad .agent-activity-marker {
    background: #ef7f7f;
}

.agent-activity-row strong {
    flex: 0 0 auto;
    color: var(--text-soft, #bbc4d1);
    font-size: 9px;
}

.agent-activity-row code {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 1px 4px;
    border-radius: 4px;
    background: rgba(255, 255, 255, .025);
    color: var(--muted);
    font-size: 8px;
}
