/* ============================================================
   Novatek Portal — Base Styles
   Brand tokens from /brand/brand_tokens.css (volume-mounted, no rebuild)
   All colors/fonts via CSS Custom Properties from brand_tokens.css
   Source: BrandBook 2026 v1.4 | Material Design elevation
   ============================================================ */


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

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* === HEADER === */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
.header-left {
    display: flex; align-items: center; gap: 12px;
}
.header-logo {
    height: 36px; width: auto; max-width: 110px; border-radius: 6px;
    object-fit: contain; flex-shrink: 0;
}
.header-left h1 {
    font-family: var(--font-heading);
    font-size: 18px; font-weight: 700; letter-spacing: -0.5px;
    color: var(--text);
}
.header-left .subtitle {
    font-family: var(--font-data);
    font-size: 12px; color: var(--accent);
    text-transform: uppercase; letter-spacing: 0.06em;
    margin-left: 4px;
}
.header-right { display: flex; align-items: center; gap: 12px; }

/* === STATUS BADGE === */
.status-badge {
    display: flex; align-items: center; gap: 6px;
    padding: 4px 12px; border-radius: 20px;
    font-family: var(--font-data);
    font-size: 12px; font-weight: 500;
    background: var(--surface-2);
    border: 1px solid var(--border);
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; }
.status-badge.online .status-dot {
    background: var(--accent);
    box-shadow: 0 0 6px var(--accent);
}
.status-badge.offline .status-dot { background: var(--red); }

/* === USER BADGE === */
.user-badge {
    display: flex; align-items: center; gap: 8px;
    padding: 4px 10px; border-radius: 20px;
    background: var(--surface-2); border: 1px solid var(--border);
    font-size: 12px;
}
.user-avatar {
    width: 24px; height: 24px; border-radius: 50%;
    background: var(--accent); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-family: var(--font-heading);
    font-weight: 700; font-size: 11px; flex-shrink: 0;
}
.user-name {
    max-width: 120px; overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap; color: var(--text);
}
.user-logout {
    background: none; border: none; color: var(--text-dim);
    cursor: pointer; font-size: 16px; line-height: 1; padding: 0 2px;
}
.user-logout:hover { color: var(--red); }

/* === MAIN LAYOUT === */
main {
    padding: 20px 24px;
    height: calc(100vh - 100px);
    overflow: hidden;
}
.main-row {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 16px;
    height: 100%;
}

/* === CARDS === */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.card-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}
.card-header h3 {
    font-family: var(--font-data);
    font-size: 13px; font-weight: 600; color: var(--text-dim);
    text-transform: uppercase; letter-spacing: 0.5px;
}
.card-body { padding: 16px; }

/* === SIDEBAR === */
.sidebar {
    display: flex; flex-direction: column; gap: 16px;
    overflow: hidden; min-height: 0;
}
.sidebar-item {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 12px; border-radius: 6px;
    font-size: 13px; color: var(--text-dim);
    cursor: pointer; transition: all 0.15s;
}
.sidebar-item:hover { background: var(--surface-2); color: var(--text); }
.sidebar-item.active { background: rgba(0, 173, 80, 0.12); color: var(--accent); }

/* === CHAT === */
.chat-card { display: flex; flex-direction: column; }
.chat-messages {
    flex: 1; overflow-y: auto; padding: 16px;
    display: flex; flex-direction: column; gap: 12px;
}

/* Message bubbles */
.msg {
    max-width: 85%; padding: 10px 14px; border-radius: var(--radius);
    font-size: 14px; line-height: 1.6; white-space: pre-wrap; word-break: break-word;
}
.msg.user {
    align-self: flex-end;
    background: var(--accent-dim);
    color: #fff;
}
.msg.agent {
    align-self: flex-start;
    background: var(--surface-2);
}
.msg.system {
    align-self: center; color: var(--text-dim);
    font-size: 12px; font-style: italic;
}
.msg.streaming {
    border-left: 2px solid var(--accent);
}

/* Tool call messages */
.msg.tool-call {
    align-self: flex-start;
    background: rgba(0, 173, 80, 0.08);
    border: 1px solid rgba(0, 173, 80, 0.15);
    border-left: 3px solid var(--accent);
    padding: 8px 12px; font-size: 12px;
    display: flex; align-items: center; gap: 8px; max-width: 90%;
}
.msg.tool-call.tool-ok { border-left-color: var(--green); }
.msg.tool-call.tool-err { border-left-color: var(--red); }
.tool-icon { font-size: 16px; flex-shrink: 0; }
.tool-name {
    font-family: var(--font-data);
    color: var(--accent); font-weight: 600; white-space: nowrap;
}
.tool-args {
    color: var(--text-dim); font-size: 11px; margin-left: 4px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 300px;
}
.tool-args::before { content: '('; }
.tool-args::after { content: ')'; }
.tool-spinner {
    width: 12px; height: 12px; border: 2px solid var(--border);
    border-top-color: var(--accent); border-radius: 50%;
    animation: tool-spin 0.8s linear infinite; flex-shrink: 0;
}
@keyframes tool-spin { to { transform: rotate(360deg); } }
.tool-badge {
    font-family: var(--font-data);
    font-size: 10px; padding: 1px 8px; border-radius: 3px;
    font-weight: 600; white-space: nowrap; margin-left: auto;
}
.tool-badge.ok { background: rgba(0, 173, 80, 0.15); color: var(--green); }
.tool-badge.err { background: rgba(239, 68, 68, 0.15); color: var(--red); }

/* Thinking indicator */
.msg.thinking {
    align-self: flex-start; background: var(--surface-2);
    border-left: 2px solid var(--accent);
    display: flex; align-items: center; gap: 8px;
    padding: 10px 14px; border-radius: var(--radius);
}
.thinking-dots { display: flex; gap: 4px; }
.thinking-dots span {
    width: 6px; height: 6px; background: var(--accent);
    border-radius: 50%; animation: thinking-bounce 1.4s infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes thinking-bounce {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-4px); }
}

.thinking-cancel { display: block; margin-top: 8px; background: none; border: 1px solid var(--text-dim); color: var(--text-dim); padding: 4px 12px; border-radius: 4px; cursor: pointer; font-size: 12px; transition: all 0.2s; }
.thinking-cancel:hover { color: var(--accent); border-color: var(--accent); }

/* Streaming animations */
.msg.agent.streaming:empty {
    min-height: 34px; display: flex; align-items: center; padding: 6px 0;
}
.msg.agent.streaming:empty::after {
    content: ""; width: 18px; height: 18px;
    border: 2px solid rgba(0, 173, 80, 0.2);
    border-top-color: var(--accent); border-radius: 50%;
    display: inline-block;
    animation: gp-msg-spin 0.75s linear infinite;
}
@keyframes gp-msg-spin { to { transform: rotate(360deg); } }

.msg.agent.streaming:not(:empty)::after {
    content: "\25CB"; display: inline-block;
    animation: gp-cursor-blink 0.75s step-end infinite;
    color: var(--accent); font-size: 0.85em; margin-left: 1px;
}
@keyframes gp-cursor-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

.gp-fade-in { animation: gp-fade-in 0.4s ease forwards; }
@keyframes gp-fade-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* === CHAT INPUT === */
.chat-input-row {
    display: flex; gap: 8px; padding: 12px 16px;
    border-top: 1px solid var(--border); align-items: flex-end;
}
#chat-input, .chat-input {
    flex: 1; background: var(--surface-2);
    border: 1px solid var(--border); color: var(--text);
    border-radius: 6px; padding: 10px 14px;
    font-family: var(--font-body); font-size: 14px; resize: none;
}
#chat-input:focus, .chat-input:focus { outline: none; border-color: var(--accent); }
#chat-input::placeholder, .chat-input::placeholder { color: var(--text-secondary); }
#chat-input, .chat-input, .auth-input, .form-input { caret-color: var(--text); }
input:-webkit-autofill,textarea:-webkit-autofill { -webkit-box-shadow: 0 0 0 1000px var(--surface-2) inset !important; -webkit-text-fill-color: var(--text) !important; caret-color: var(--text) !important; }

/* === BUTTONS === */
.btn-primary {
    padding: 10px 24px; background: var(--brand); color: #fff; border: none;
    border-radius: 6px; font-family: var(--font-data); font-weight: 600;
    cursor: pointer; font-size: 14px; transition: background 0.2s ease;
}
.btn-primary:hover { background: var(--accent-dim); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
    padding: 8px 16px; background: transparent;
    color: var(--text-dim); border: 1px solid var(--border);
    border-radius: 6px; font-family: var(--font-data); font-size: 13px;
    font-weight: 500; cursor: pointer; transition: all 0.15s;
}
.btn-secondary:hover { color: var(--text); border-color: var(--text-dim); }

.btn-danger {
    padding: 8px 16px; background: transparent;
    color: var(--red); border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 6px; font-family: var(--font-data); font-size: 13px;
    font-weight: 500; cursor: pointer;
}
.btn-danger:hover { background: rgba(239, 68, 68, 0.1); }

.btn-icon {
    display: flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; background: var(--surface-2);
    border: 1px solid var(--border); border-radius: 6px;
    color: var(--text-dim); cursor: pointer; flex-shrink: 0;
}
.btn-icon:hover { color: var(--text); border-color: var(--accent); }

.btn-small {
    font-family: var(--font-data);
    font-size: 11px; padding: 2px 8px; background: transparent;
    color: var(--text-dim); border: 1px solid var(--border);
    border-radius: 4px; cursor: pointer;
}
.btn-small:hover { color: var(--text); border-color: var(--text-dim); }

/* === AUTH MODAL (login) === */
.auth-overlay {
    position: fixed; inset: 0; z-index: 1000;
    background: rgba(16, 24, 32, 0.85);
    backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
    animation: auth-fade-in 0.2s ease;
}
@keyframes auth-fade-in { from { opacity: 0; } to { opacity: 1; } }

.auth-modal {
    background: var(--surface); border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg); padding: 32px; width: 380px; max-width: 90vw;
    position: relative;
}
.auth-title {
    font-family: var(--font-heading);
    font-size: 20px; font-weight: 700; color: var(--text);
    margin-bottom: 6px; text-align: center;
}
.auth-subtitle {
    font-size: 13px; color: var(--text-dim); text-align: center;
    margin-bottom: 24px;
}
.auth-step { display: flex; flex-direction: column; gap: 12px; }
.auth-input {
    width: 100%; padding: 10px 14px; background: var(--surface-2);
    border: 1px solid var(--border); border-radius: 6px;
    color: var(--text); font-family: var(--font-body); font-size: 14px;
}
.auth-input:focus { outline: none; border-color: var(--accent); }
.auth-btn {
    padding: 10px 20px; border-radius: 6px; border: none;
    font-family: var(--font-data); font-size: 14px; font-weight: 600;
    cursor: pointer;
}
.auth-btn-primary { background: var(--accent); color: #fff; }
.auth-btn-primary:hover { background: var(--accent-dim); }
.auth-btn-ghost {
    background: transparent; color: var(--text-dim);
    border: 1px solid var(--border);
}

/* === PILL SWITCHER (nav tabs) === */
.pill-switcher {
    display: flex; gap: 2px; background: var(--surface-2);
    border-radius: 8px; padding: 3px; border: 1px solid var(--border);
}
.pill {
    display: flex; align-items: center; gap: 6px;
    padding: 6px 14px; border: none; border-radius: 6px;
    background: transparent; color: var(--text-dim);
    font-family: var(--font-data); font-size: 12px; font-weight: 600;
    cursor: pointer; transition: all 0.2s ease; white-space: nowrap;
}
.pill:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }
.pill.active {
    background: var(--accent); color: #fff;
    box-shadow: 0 2px 8px rgba(0, 173, 80, 0.3);
}
.pill svg { flex-shrink: 0; }

/* === EMPTY STATE === */
.empty-state {
    color: var(--text-dim); font-size: 13px; text-align: center; padding: 24px;
}

/* === SCROLLBAR === */
.chat-messages::-webkit-scrollbar,
.sidebar::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-thumb,
.sidebar::-webkit-scrollbar-thumb { background: var(--surface-2); border-radius: 3px; }
.chat-messages::-webkit-scrollbar-thumb:hover,
.sidebar::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.15); }

/* === RESPONSIVE === */
@media (max-width: 768px) {
    .main-row { grid-template-columns: 1fr; }
    .sidebar { display: none; }
    .auth-modal { padding: 24px 20px; }
    .user-name { display: none; }
    .pill-switcher { gap: 1px; }
    .pill { padding: 6px 10px; font-size: 11px; }
    .pill span { display: none; }
}

/* Lang switcher (px-004) */
.lang-switcher{display:flex;gap:4px;justify-content:center;margin:8px 0 4px}
.lang-btn{padding:4px 12px;border:1px solid var(--text-secondary);border-radius:4px;background:transparent;color:var(--text-dim);cursor:pointer;font-size:13px;font-weight:500;font-family:var(--font-body);transition:all .2s}
.lang-btn:hover{border-color:var(--accent);color:var(--text)}
.lang-btn.active{background:var(--accent);color:#fff;border-color:var(--accent)}
.privacy-note{font-size:12px;color:var(--text-secondary);text-align:center;margin-top:16px}
