:root {
  --bg:       #0a0a0d;
  --bg2:      #111116;
  --bg3:      #18181f;
  --border:   #242430;
  --text:     #e4e4f0;
  --text2:    #7070a0;
  --accent:   #5b8af7;
  --success:  #3ecf8e;
  --warning:  #f5a623;
  --error:    #e53e3e;
  --critical: #ff4455;
  --high:     #ff8800;
  --medium:   #f5a623;
  --low:      #3ecf8e;
  --info:     #5b8af7;
  --sidebar-w: 220px;
  --radius: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

#app { display: flex; height: 100vh; overflow: hidden; }

/* Loading */
#loading-screen {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; width: 100%; gap: 16px;
  color: var(--text2); font-size: 13px;
}
.spinner {
  width: 26px; height: 26px;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Sidebar */
aside#sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.sidebar-header { padding: 20px 14px 12px; border-bottom: 1px solid var(--border); }
.logo { font-size: 14px; font-weight: 700; color: var(--accent); letter-spacing: 1px; display: block; margin-bottom: 12px; }
#org-selector { display: flex; gap: 6px; align-items: center; }
#org-select { flex: 1; min-width: 0; background: var(--bg3); border: 1px solid var(--border); color: var(--text); border-radius: var(--radius); padding: 6px 8px; font-size: 12px; cursor: pointer; }
#org-select:focus { outline: none; border-color: var(--accent); }

nav { flex: 1; padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; }
.nav-item { display: block; padding: 8px 10px; border-radius: var(--radius); color: var(--text2); text-decoration: none; font-size: 13px; transition: background 0.15s, color 0.15s; }
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: var(--accent); color: #fff; }

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

/* Main */
main#main { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.view { display: block; padding: 28px 32px; overflow-y: auto; height: 100%; }
.view.hidden { display: none !important; }
.view-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
h1 { font-size: 20px; font-weight: 700; margin-bottom: 24px; }
h2 { font-size: 15px; font-weight: 600; margin-bottom: 12px; color: var(--text); }

/* Stats grid */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 28px; }
.stat-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.stat-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text2); margin-bottom: 8px; }
.stat-value { font-size: 28px; font-weight: 700; line-height: 1; }
.stat-sub { font-size: 11px; color: var(--text2); margin-top: 4px; }
.stat-critical { border-left: 3px solid var(--critical); }
.stat-high     { border-left: 3px solid var(--high); }
.stat-alerts   { border-left: 3px solid var(--warning); }
.stat-assets   { border-left: 3px solid var(--accent); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }

/* Severity badges */
.sev { font-size: 10px; font-weight: 700; padding: 2px 8px; border-radius: 20px; text-transform: uppercase; letter-spacing: 0.5px; }
.sev-critical { background: rgba(255,68,85,0.15); color: var(--critical); }
.sev-high     { background: rgba(255,136,0,0.15); color: var(--high); }
.sev-medium   { background: rgba(245,166,35,0.15); color: var(--medium); }
.sev-low      { background: rgba(62,207,142,0.15); color: var(--low); }
.sev-info     { background: rgba(91,138,247,0.15); color: var(--info); }

/* Status badge */
.badge-status { font-size: 10px; font-weight: 600; padding: 2px 8px; border-radius: 20px; text-transform: uppercase; }
.badge-open            { background: rgba(255,68,85,0.1);  color: var(--critical); }
.badge-investigating   { background: rgba(245,166,35,0.1); color: var(--warning); }
.badge-resolved        { background: rgba(62,207,142,0.1); color: var(--success); }
.badge-false_positive  { background: rgba(112,112,160,0.1); color: var(--text2); }

/* Alert/Event items */
.alert-item, .event-item {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; margin-bottom: 10px; transition: border-color 0.15s;
}
.alert-item:hover, .event-item:hover { border-color: var(--accent); }
.item-header { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.item-title { font-weight: 600; font-size: 13px; flex: 1; }
.item-meta { font-size: 11px; color: var(--text2); }
.item-asset { font-size: 11px; color: var(--text2); margin-top: 2px; }
.item-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.ai-analysis { background: var(--bg3); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; margin-top: 10px; font-size: 12px; color: var(--text2); white-space: pre-wrap; line-height: 1.6; }

/* Asset cards */
.asset-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 10px; }
.asset-header { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.asset-name { font-weight: 600; font-size: 14px; flex: 1; }
.asset-id { font-size: 11px; color: var(--text2); font-family: monospace; }
.risk-bar-wrap { height: 4px; background: var(--border); border-radius: 2px; margin-top: 8px; }
.risk-bar { height: 4px; border-radius: 2px; transition: width 0.3s; }

/* ---- Agent chat ---- */
#view-agent { padding: 0; overflow: hidden; }
.agent-layout { display: flex; height: 100%; }

.chat-sidebar {
  width: 220px; min-width: 220px; border-right: 1px solid var(--border);
  padding: 16px 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px;
}
.chat-list-item {
  padding: 8px 10px; border-radius: var(--radius); cursor: pointer;
  font-size: 12px; color: var(--text2); border: 1px solid transparent;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background 0.15s;
}
.chat-list-item:hover { background: var(--bg3); color: var(--text); }
.chat-list-item.active { background: var(--bg3); border-color: var(--accent); color: var(--text); }

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

.chat-welcome {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 40px; text-align: center;
}
.welcome-icon { font-size: 40px; margin-bottom: 16px; color: var(--accent); }
.chat-welcome h2 { font-size: 18px; margin-bottom: 8px; }
.chat-welcome p  { color: var(--text2); font-size: 13px; margin-bottom: 24px; }
.welcome-suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 500px; }
.suggestion {
  background: var(--bg2); border: 1px solid var(--border); color: var(--text2);
  border-radius: 20px; padding: 7px 14px; font-size: 12px; cursor: pointer;
  font-family: inherit; transition: border-color 0.15s, color 0.15s;
}
.suggestion:hover { border-color: var(--accent); color: var(--text); }

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

.chat-msg { display: flex; gap: 12px; max-width: 820px; }
.chat-msg.user { flex-direction: row-reverse; align-self: flex-end; }

.msg-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; flex-shrink: 0; font-weight: 700;
}
.chat-msg.user .msg-avatar { background: var(--accent); color: #fff; }
.chat-msg.assistant .msg-avatar { background: var(--bg3); border: 1px solid var(--border); color: var(--accent); }

.msg-content {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px;
  font-size: 13px; line-height: 1.7; max-width: 100%;
  white-space: pre-wrap; word-break: break-word;
}
.chat-msg.user .msg-content { background: var(--accent); border-color: var(--accent); color: #fff; border-radius: 12px 2px 12px 12px; }
.chat-msg.assistant .msg-content { border-radius: 2px 12px 12px 12px; }

.msg-thinking { display: flex; align-items: center; gap: 8px; color: var(--text2); font-size: 12px; }
.dots span { animation: blink 1.4s infinite; display: inline-block; }
.dots span:nth-child(2) { animation-delay: 0.2s; }
.dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.2; } 40% { opacity: 1; } }

.chat-input-area {
  border-top: 1px solid var(--border); padding: 16px 24px;
  display: flex; gap: 10px; align-items: flex-end;
}
#chat-input {
  flex: 1; background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); padding: 10px 14px;
  font-size: 13px; font-family: inherit; resize: none;
  max-height: 120px; overflow-y: auto; line-height: 1.5;
}
#chat-input:focus { outline: none; border-color: var(--accent); }
.btn-send {
  width: 36px; height: 36px; background: var(--accent); color: #fff;
  border: none; border-radius: 50%; cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.btn-send:hover:not(:disabled) { background: #7ab0ff; }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* Buttons */
button, .btn-primary-sm, .btn-secondary, .btn-ghost, .btn-primary-modal {
  cursor: pointer; border: none; border-radius: var(--radius);
  font-size: 13px; font-family: inherit; font-weight: 500;
  transition: background 0.15s, opacity 0.15s; padding: 8px 14px;
}
button:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary-sm { background: var(--accent); color: #fff; width: 100%; text-align: center; }
.btn-primary-sm:hover:not(:disabled) { background: #7ab0ff; }

.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }

.btn-ghost { background: transparent; color: var(--text2); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { color: var(--text); border-color: var(--text2); }

.btn-sm { padding: 4px 10px; font-size: 11px; }

.btn-primary-modal { background: var(--accent); color: #fff; }
.btn-primary-modal:hover:not(:disabled) { background: #7ab0ff; }

.btn-icon { background: var(--bg3); border: 1px solid var(--border); color: var(--text2); border-radius: var(--radius); width: 26px; height: 26px; padding: 0; font-size: 16px; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.btn-icon:hover { color: var(--text); border-color: var(--text2); }

/* Forms */
.form-group { margin-bottom: 14px; }
label { display: block; font-size: 12px; font-weight: 500; color: var(--text2); margin-bottom: 5px; }
input, textarea, select { width: 100%; background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); padding: 8px 12px; font-size: 13px; font-family: inherit; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; }
.hint { font-size: 11px; color: var(--text2); }

/* Filter row */
.filter-row { display: flex; gap: 10px; margin-bottom: 18px; }
.filter-row select, .filter-row input { width: auto; flex: 1; }

/* Pagination */
.pagination { display: flex; align-items: center; gap: 12px; justify-content: center; margin-top: 16px; font-size: 13px; color: var(--text2); }

/* Empty state */
.empty-state { color: var(--text2); font-size: 13px; text-align: center; padding: 36px 0; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.65); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal.hidden { display: none; }
.modal-box { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; width: 100%; max-width: 420px; }
.modal-box h2 { margin-bottom: 20px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.modal-actions button { width: auto; }

/* Toast */
.toast { position: fixed; bottom: 24px; right: 24px; background: var(--bg3); border: 1px solid var(--border); color: var(--text); padding: 10px 16px; border-radius: var(--radius); font-size: 13px; z-index: 200; opacity: 0; transform: translateY(8px); transition: opacity 0.2s, transform 0.2s; pointer-events: none; max-width: 320px; }
.toast.show { opacity: 1; transform: translateY(0); pointer-events: auto; }
.toast.success { border-color: var(--success); color: var(--success); }
.toast.error   { border-color: var(--error);   color: var(--error); }

.hidden { display: none !important; }

/* Markdown-like in chat */
.msg-content strong { font-weight: 700; }
.msg-content em { font-style: italic; }
