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

:root {
    --bg:          #0f1117;
    --bg2:         #1a1d27;
    --bg3:         #22263a;
    --border:      #2e3347;
    --text:        #e2e8f0;
    --text-muted:  #8892a4;
    --accent:      #4f8ef7;
    --accent-dark: #3b6fd4;
    --green:       #34d399;
    --red:         #f87171;
    --radius:      10px;
    --sidebar-w:   260px;
    --font:        'Inter', 'Segoe UI', system-ui, sans-serif;
}

html { font-size: 15px; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }

/* ── Login ─────────────────────────────────────────── */
.login-page {
    display: flex; align-items: center; justify-content: center; padding: 2rem;
    background: linear-gradient(135deg, #0f1117 0%, #1a1d27 100%);
}

.login-box {
    background: var(--bg2); border: 1px solid var(--border); border-radius: 16px;
    padding: 2.5rem; width: 100%; max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,.4);
}

.login-logo {
    display: flex; align-items: center; gap: .6rem;
    font-size: 1.1rem; font-weight: 700; color: var(--accent); margin-bottom: 1.5rem;
}
.login-logo svg { width: 28px; height: 28px; stroke: var(--accent); }

.login-box h1 { font-size: 1.4rem; font-weight: 700; margin-bottom: .3rem; }
.login-subtitle { color: var(--text-muted); font-size: .9rem; margin-bottom: 1.5rem; }
.login-footer { color: var(--text-muted); font-size: .8rem; margin-top: 1.5rem; text-align: center; line-height: 1.6; }

/* ── Forms ─────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: .4rem; margin-bottom: 1rem; }
.form-group label { font-size: .8rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }

input[type=text], input[type=email], input[type=password], input[type=number],
select, textarea {
    background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius);
    color: var(--text); padding: .65rem .9rem; font-size: .95rem; width: 100%;
    transition: border-color .2s;
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(79,142,247,.15);
}
input::placeholder, textarea::placeholder { color: var(--text-muted); }

/* ── Buttons ───────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .6rem 1.2rem; border-radius: var(--radius); border: none;
    font-size: .9rem; font-weight: 600; cursor: pointer; transition: all .2s;
    text-decoration: none;
}
.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-block    { width: 100%; justify-content: center; padding: .8rem; font-size: 1rem; }
.btn-sm       { padding: .35rem .7rem; font-size: .8rem; }
.btn-danger   { background: rgba(248,113,113,.15); color: var(--red); border: 1px solid rgba(248,113,113,.3); }
.btn-danger:hover { background: rgba(248,113,113,.25); }
.btn-success  { background: rgba(52,211,153,.15); color: var(--green); border: 1px solid rgba(52,211,153,.3); }

/* ── Alerts ────────────────────────────────────────── */
.alert { padding: .8rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .9rem; }
.alert-error   { background: rgba(248,113,113,.1); border: 1px solid rgba(248,113,113,.3); color: var(--red); }
.alert-success { background: rgba(52,211,153,.1);  border: 1px solid rgba(52,211,153,.3);  color: var(--green); }

/* ── Badges ────────────────────────────────────────── */
.badge { display: inline-block; padding: .2rem .5rem; border-radius: 20px; font-size: .75rem; font-weight: 600; }
.badge-green { background: rgba(52,211,153,.15); color: var(--green); }
.badge-red   { background: rgba(248,113,113,.15); color: var(--red); }

/* ── Chat layout ───────────────────────────────────── */
.chat-page { display: flex; height: 100vh; overflow: hidden; }

/* Sidebar */
.sidebar {
    width: var(--sidebar-w); background: var(--bg2); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; flex-shrink: 0;
}
.sidebar-header {
    display: flex; align-items: center; gap: .6rem;
    padding: 1.2rem 1rem; border-bottom: 1px solid var(--border);
    font-weight: 700; font-size: .95rem; color: var(--accent);
}
.icon-drone { width: 22px; height: 22px; stroke: var(--accent); }
.app-title { font-size: .9rem; }

.btn-new-chat {
    display: flex; align-items: center; gap: .5rem;
    margin: .8rem; padding: .65rem 1rem; border-radius: var(--radius);
    background: var(--accent); color: #fff; border: none; cursor: pointer;
    font-size: .85rem; font-weight: 600; transition: background .2s;
}
.btn-new-chat:hover { background: var(--accent-dark); }

.session-list { flex: 1; overflow-y: auto; padding: .5rem; }
.session-item {
    display: flex; align-items: center; gap: .5rem;
    width: 100%; padding: .6rem .8rem; border-radius: 8px;
    background: none; border: none; color: var(--text-muted);
    cursor: pointer; font-size: .82rem; text-align: left;
    transition: background .15s, color .15s; white-space: nowrap; overflow: hidden;
}
.session-item span { overflow: hidden; text-overflow: ellipsis; }
.session-item:hover, .session-item.active { background: var(--bg3); color: var(--text); }

.sidebar-footer {
    display: flex; align-items: center; justify-content: space-between;
    padding: .8rem 1rem; border-top: 1px solid var(--border);
}
.user-info { display: flex; align-items: center; gap: .6rem; }
.user-avatar {
    width: 32px; height: 32px; border-radius: 50%; background: var(--accent);
    display: flex; align-items: center; justify-content: center;
    font-size: .8rem; font-weight: 700; color: #fff; flex-shrink: 0;
}
.user-name    { font-size: .82rem; font-weight: 600; }
.user-company { font-size: .72rem; color: var(--text-muted); }
.btn-logout   { color: var(--text-muted); padding: .4rem; border-radius: 6px; transition: color .15s, background .15s; }
.btn-logout:hover { color: var(--red); background: rgba(248,113,113,.1); }

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

.chat-messages {
    flex: 1; overflow-y: auto; padding: 1.5rem;
    display: flex; flex-direction: column; gap: 1.2rem;
}

/* Welcome */
.welcome-screen {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    text-align: center; height: 100%; gap: 1rem;
}
.welcome-icon svg { width: 60px; height: 60px; stroke: var(--accent); opacity: .7; }
.welcome-screen h2 { font-size: 1.4rem; font-weight: 700; }
.welcome-screen p  { color: var(--text-muted); font-size: .95rem; line-height: 1.6; }

.suggestions { display: flex; flex-wrap: wrap; gap: .6rem; justify-content: center; margin-top: .5rem; }
.suggestion {
    background: var(--bg2); border: 1px solid var(--border); border-radius: 20px;
    padding: .5rem 1rem; font-size: .82rem; color: var(--text-muted);
    cursor: pointer; transition: all .15s;
}
.suggestion:hover { border-color: var(--accent); color: var(--accent); }

/* Messages */
.message { display: flex; flex-direction: column; max-width: 780px; width: 100%; }
.message.user  { align-self: flex-end; align-items: flex-end; }
.message.assistant { align-self: flex-start; }

.message-bubble {
    padding: .8rem 1.1rem; border-radius: 14px; font-size: .92rem; line-height: 1.7;
    max-width: 100%;
}
.message.user .message-bubble {
    background: var(--accent); color: #fff; border-bottom-right-radius: 4px;
}
.message.assistant .message-bubble {
    background: var(--bg2); border: 1px solid var(--border); border-bottom-left-radius: 4px;
    white-space: pre-wrap;
}

/* Markdown-like styles inside assistant bubble */
.message.assistant .message-bubble strong { font-weight: 700; }
.message.assistant .message-bubble code {
    background: var(--bg3); padding: .1rem .35rem; border-radius: 4px;
    font-family: 'Courier New', monospace; font-size: .85em;
}

.message-time { font-size: .72rem; color: var(--text-muted); margin-top: .3rem; padding: 0 .3rem; }

/* Typing indicator */
.typing-indicator .message-bubble { display: flex; gap: .3rem; align-items: center; padding: .9rem 1.1rem; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted); animation: bounce .8s infinite; }
.dot:nth-child(2) { animation-delay: .15s; }
.dot:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%,80%,100% { transform: translateY(0); } 40% { transform: translateY(-6px); } }

/* Input area */
.chat-input-area {
    padding: 1rem 1.5rem 1.2rem;
    border-top: 1px solid var(--border); background: var(--bg);
}
.chat-form {
    display: flex; gap: .6rem; align-items: flex-end;
    background: var(--bg2); border: 1px solid var(--border); border-radius: 14px;
    padding: .6rem .6rem .6rem 1rem; transition: border-color .2s;
}
.chat-form:focus-within { border-color: var(--accent); }

.chat-form textarea {
    flex: 1; background: none; border: none; resize: none; color: var(--text);
    font-size: .95rem; line-height: 1.5; max-height: 160px; overflow-y: auto;
    padding: 0; font-family: var(--font);
}
.chat-form textarea:focus { outline: none; box-shadow: none; }

.chat-form button[type=submit] {
    width: 38px; height: 38px; border-radius: 10px; border: none;
    background: var(--accent); color: #fff; cursor: pointer; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center; transition: background .2s;
}
.chat-form button[type=submit]:disabled { background: var(--bg3); color: var(--text-muted); cursor: default; }
.chat-form button[type=submit]:not(:disabled):hover { background: var(--accent-dark); }

.chat-disclaimer { font-size: .72rem; color: var(--text-muted); text-align: center; margin-top: .6rem; }

/* ── Admin ─────────────────────────────────────────── */
.admin-page { background: var(--bg); }
.admin-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1rem 2rem; background: var(--bg2); border-bottom: 1px solid var(--border);
}
.admin-header h1 { font-size: 1.1rem; font-weight: 700; }
.admin-container { max-width: 1100px; margin: 0 auto; padding: 2rem; display: flex; flex-direction: column; gap: 1.5rem; }

.admin-card {
    background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem;
}
.admin-card h2 { font-size: 1rem; font-weight: 700; margin-bottom: 1.2rem; }

.admin-form .form-row { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; }
.admin-form .form-row .form-group { flex: 1; min-width: 160px; margin-bottom: 0; }

.admin-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.admin-table th { text-align: left; padding: .6rem .8rem; color: var(--text-muted); font-size: .75rem; text-transform: uppercase; border-bottom: 1px solid var(--border); }
.admin-table td { padding: .6rem .8rem; border-bottom: 1px solid rgba(255,255,255,.04); }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table code { background: var(--bg3); padding: .15rem .4rem; border-radius: 4px; font-size: .8rem; }
.row-inactive { opacity: .5; }

/* Scrollbar */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
