:root { color-scheme: light dark; }
* { box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  margin: 0; background: #0f1115; color: #e6e6e6;
}
button { cursor: pointer; font-family: inherit; }
input, select, textarea, button {
  font-size: 1rem; padding: 10px 12px; border-radius: 8px;
  border: 1px solid #333; background: #1a1d23; color: #e6e6e6; font-family: inherit;
}
textarea { width: 100%; resize: vertical; }
button.primary { background: #2b6cff; border: none; color: white; font-weight: 600; }
button.primary:hover { background: #1f56d6; }
button.secondary { background: #333; border: none; color: #e6e6e6; }
button.secondary:hover { background: #444; }
button.danger { background: #a33; border: none; color: white; }
button.danger:hover { background: #822; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
a { color: #6ea8ff; }
label { font-size: 0.82rem; color: #9aa0a6; display: block; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.hint { font-size: 0.78rem; color: #9aa0a6; margin-top: 4px; }
.error-banner {
  background: #3a1a1a; border: 1px solid #7a2e2e; color: #ff9b9b;
  padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; font-size: 0.9rem;
}
.success-banner {
  background: #1a3a22; border: 1px solid #2e7a45; color: #9bffb0;
  padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; font-size: 0.9rem;
}

/* ---- App shell ---- */
#login-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 16px;
}
.login-box { max-width: 320px; width: 100%; display: flex; flex-direction: column; gap: 10px; }
.login-box h1 { margin: 0 0 4px; font-size: 1.4rem; }
.login-box .sub { color: #9aa0a6; font-size: 0.85rem; margin-bottom: 12px; }

#app-shell { display: none; min-height: 100vh; }
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; border-bottom: 1px solid #262a33; position: sticky; top: 0;
  background: #0f1115; z-index: 5;
}
#topbar .brand { font-weight: 700; }
#topbar .who { font-size: 0.82rem; color: #9aa0a6; }
#layout { display: flex; }
#sidebar {
  width: 190px; flex-shrink: 0; padding: 14px 8px; border-right: 1px solid #262a33;
  position: sticky; top: 49px; height: calc(100vh - 49px); overflow-y: auto;
}
#sidebar button {
  display: block; width: 100%; text-align: left; background: none; border: none;
  color: #c7cbd1; padding: 10px 12px; border-radius: 8px; margin-bottom: 2px; font-size: 0.92rem;
}
#sidebar button:hover { background: #1a1d23; }
#sidebar button.active { background: #2b6cff22; color: #6ea8ff; font-weight: 600; }
#content { flex: 1; min-width: 0; padding: 20px; max-width: 900px; }
input[type=file] { max-width: 100%; }

h2 { margin-top: 0; font-size: 1.2rem; }
.card {
  background: #171a20; border: 1px solid #262a33; border-radius: 10px;
  padding: 14px 16px; margin-bottom: 12px;
}
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat { text-align: center; }
.stat .n { font-size: 1.6rem; font-weight: 700; }
.stat .l { font-size: 0.78rem; color: #9aa0a6; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid #262a33; }
th { color: #9aa0a6; font-weight: 600; font-size: 0.78rem; text-transform: uppercase; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #1a1d23; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.72rem; font-weight: 600; }
.badge.green { background: #1a3a22; color: #9bffb0; }
.badge.yellow { background: #3a331a; color: #ffe89b; }
.badge.red { background: #3a1a1a; color: #ff9b9b; }
.badge.gray { background: #262a33; color: #9aa0a6; }

.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; background: #262a33;
  border-radius: 999px; padding: 4px 10px; font-size: 0.82rem;
}
.chip button { background: none; border: none; color: #9aa0a6; padding: 0; font-size: 0.9rem; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid #262a33; margin-bottom: 14px; overflow-x: auto; }
.tabs button { flex: none; white-space: nowrap; }
.tabs button { background: none; border: none; border-radius: 0; padding: 8px 4px; margin-right: 16px; color: #9aa0a6; border-bottom: 2px solid transparent; }
.tabs button.active { color: #e6e6e6; border-bottom-color: #2b6cff; }

.wizard-steps { display: flex; gap: 4px; margin-bottom: 16px; font-size: 0.82rem; color: #9aa0a6; }
.wizard-steps .step.active { color: #6ea8ff; font-weight: 600; }
.wizard-steps .step.done { color: #9bffb0; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px;
}
.modal { background: #171a20; border: 1px solid #333; border-radius: 12px; padding: 20px; max-width: 480px; width: 100%; max-height: 85vh; overflow-y: auto; }

.loading { color: #9aa0a6; font-size: 0.9rem; padding: 12px 0; }

/* chat view reuses the earlier design */
#chat-messages { display: flex; flex-direction: column; gap: 12px; min-height: 200px; margin-bottom: 16px; }
.msg { padding: 12px 14px; border-radius: 10px; font-size: 0.92rem; white-space: pre-wrap; word-break: break-word; }
.msg.user { background: #2b6cff22; border: 1px solid #2b6cff55; align-self: flex-end; max-width: 85%; margin-left: auto; }
.msg.agent { background: #1a1d23; border: 1px solid #333; }
.msg.pending { background: #3a2f1a; border: 1px solid #7a5c1e; }
.msg .label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: #9aa0a6; margin-bottom: 6px; }
.msg pre { background: #0f1115; padding: 8px; border-radius: 6px; overflow-x: auto; font-size: 0.82rem; margin-top: 8px; }
.confirm-row { display: flex; gap: 8px; margin-top: 10px; }

#alert-bell-count {
  position: absolute; top: -4px; right: -4px; background: #a33; color: white;
  border-radius: 999px; font-size: 0.68rem; padding: 1px 5px; font-weight: 700;
}
#alert-panel {
  position: absolute; right: 0; top: calc(100% + 8px); width: 320px; max-height: 400px;
  overflow-y: auto; background: #1a1d23; border: 1px solid #333; border-radius: 10px;
  padding: 8px; z-index: 20; box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.alert-item { padding: 10px; border-bottom: 1px solid #262a33; }
.alert-item:last-child { border-bottom: none; }
.alert-item .sev-HIGH { color: #ff8080; font-weight: 700; }
.alert-item .sev-MEDIUM { color: #ffc266; font-weight: 700; }
.alert-item .msg { margin: 4px 0; font-size: 0.88rem; }
.alert-item button { font-size: 0.75rem; padding: 4px 8px; }
.alert-empty { padding: 14px; color: #9aa0a6; font-size: 0.85rem; text-align: center; }

@media (max-width: 700px) {
  #menu-toggle { display: inline-block !important; }
  #sidebar {
    position: fixed; left: -220px; transition: left 0.2s; height: 100vh; top: 0;
    background: #0f1115; z-index: 11; width: 220px; border-right: 1px solid #262a33;
  }
  #sidebar.open { left: 0; }
  #sidebar-backdrop {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 10;
  }
  #sidebar-backdrop.open { display: block; }
  #content { padding: 14px; }
}
