:root {
  color-scheme: light;
  --bg: #eef4f8;
  --panel: #ffffff;
  --panel-soft: #f7fafc;
  --text: #122033;
  --muted: #60718a;
  --accent: #167f78;
  --accent-dark: #0f5f5a;
  --accent-soft: #e3f6f3;
  --border: #d6e1eb;
  --danger: #b42318;
  --warning: #9a6700;
  --shadow: 0 16px 40px rgba(31, 50, 73, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 0%, rgba(30, 148, 139, 0.10), transparent 26rem),
    linear-gradient(180deg, #f8fbfd 0%, var(--bg) 100%) fixed;
}

.container {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 22px 28px 54px;
}

.header {
  margin-bottom: 14px;
  text-align: center;
}
.brand-row, .title-row, .session-bar, .section-heading, .row-space, .inline-controls {
  display: flex;
  align-items: center;
}
.brand-row, .session-bar, .section-heading, .row-space { justify-content: space-between; }
.brand-row {
  flex-direction: column;
  justify-content: center;
  gap: 9px;
}
.title-row {
  justify-content: center;
  gap: 12px;
}
.title-row h1 { margin: 0; font-size: 29px; letter-spacing: -0.035em; }
.title-row p, .page-heading p, .section-heading p { margin: 3px 0 0; color: var(--muted); }
.brand-logo { width: 42px; height: 42px; }

.version-pill, .runtime-badge, .badge {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.version-pill { padding: 4px 9px; color: var(--accent-dark); background: var(--accent-soft); }
.runtime-badge { padding: 7px 12px; background: rgba(255,255,255,.8); color: var(--muted); }

.card, .admin-section {
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.card { border-radius: 16px; padding: 18px; }
.admin-section {
  border-radius: 14px;
  margin: 14px 0;
  padding: 17px;
  box-shadow: 0 7px 22px rgba(31, 50, 73, 0.045);
}
.admin-section summary {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  list-style: none;
}
.admin-section summary::-webkit-details-marker { display: none; }
.admin-section h3 { margin: 0 0 10px; font-size: 18px; }
.page-heading { margin: 4px 2px 18px; }
.page-heading h2, .section-heading h2 { margin: 0; font-size: 24px; }

.login-card { width: min(460px, 100%); margin: 7vh auto 0; padding: 32px; }
.login-card h2 { margin: 0; font-size: 25px; }
.session-bar {
  min-height: 46px;
  margin: 0 2px 10px;
  padding: 7px 4px;
  gap: 16px;
}
.session-bar .muted { margin-left: 8px; }

.tabs {
  display: flex;
  gap: 7px;
  padding: 5px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: rgba(255,255,255,.72);
  width: fit-content;
}
.tab {
  border: 0;
  background: transparent;
  color: #40516a;
  border-radius: 9px;
  padding: 9px 15px;
}
.tab.active { background: var(--accent); color: #fff; }
.tab:hover:not(.active) { background: #edf4f8; }

.view { min-height: 420px; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--danger) !important; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 13px;
}
.one-column { grid-template-columns: 1fr; }
label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: #34445b;
  font-size: 13px;
  font-weight: 600;
}
input, select, textarea {
  width: 100%;
  border: 1px solid #cbd8e4;
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-weight: 400;
  padding: 10px 11px;
}
input:focus, select:focus, textarea:focus {
  border-color: #45a9a0;
  box-shadow: 0 0 0 3px rgba(22,127,120,.12);
  outline: none;
}
input[readonly] { background: #f2f6f9; color: var(--muted); }
textarea { resize: vertical; min-height: 88px; line-height: 1.42; }
.checkbox-label { flex-direction: row; align-items: center; align-self: end; min-height: 41px; }
.checkbox-label input { width: 17px; height: 17px; margin: 0; }

button {
  border: 0;
  border-radius: 9px;
  padding: 10px 15px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}
button:hover { background: var(--accent-dark); }
button:disabled { opacity: .55; cursor: wait; }
button.ghost { border: 1px solid var(--border); background: #fff; color: #34445b; }
button.ghost:hover { background: #edf4f8; }
button.danger { background: #fff1f0; border: 1px solid #f5b7b1; color: var(--danger); }
.tiny { padding: 6px 9px; font-size: 12px; }
.row-actions, .composer-actions, .inline-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.row-actions { margin-top: 13px; }
.composer-actions { justify-content: flex-end; }
.inline-controls select { min-width: 220px; }

.status-inline { min-height: 20px; margin-top: 9px; color: var(--accent-dark); font-size: 13px; }
.callout {
  border-left: 4px solid #4faea6;
  border-radius: 8px;
  padding: 10px 12px;
  background: #f0faf8;
  color: #3c5267;
  font-size: 13px;
  line-height: 1.45;
}

.setup-progress {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  list-style: none;
  padding: 0;
  margin: 0 0 18px;
}
.setup-progress li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.setup-progress li span {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #edf2f6;
}
.setup-progress li.complete { color: #0c6b54; border-color: #a9dfcf; background: #f0fbf7; }
.setup-progress li.complete span { color: #fff; background: #16845f; }

.badge { padding: 3px 8px; text-transform: uppercase; letter-spacing: .02em; }
.badge.neutral { background: #edf2f6; color: #53657c; }
.badge.healthy, .badge.succeeded, .badge.pass, .badge.processed { background: #dff7ed; color: #0b684b; border-color: #a8dfcc; }
.badge.warning, .badge.queued, .badge.running, .badge.partial { background: #fff6d8; color: #7b5700; border-color: #ecd990; }
.badge.critical, .badge.failed, .badge.block { background: #ffe8e6; color: #9b2018; border-color: #f2b6b0; }
.badge.disabled, .badge.archived, .badge.stub, .badge.none { background: #edf2f6; color: #53657c; }
.badge.connected, .badge.configured, .badge.reported { background: #dff7ed; color: #0b684b; border-color: #a8dfcc; }
.badge.pending { background: #fff6d8; color: #7b5700; border-color: #ecd990; }

.chat-log {
  min-height: 370px;
  max-height: 57vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: #fbfdfe;
}
.msg {
  max-width: 88%;
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 12px 14px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.msg.user { align-self: flex-end; background: #dcf6f2; border-color: #b8e5df; }
.msg.assistant { align-self: flex-start; background: #fff; }
.msg .meta { display: block; color: var(--muted); font-size: 11px; font-weight: 700; margin-bottom: 6px; text-transform: uppercase; }
.msg .follow-ups { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.msg .follow-ups button { font-size: 12px; padding: 6px 9px; }
.quick-prompts { display: flex; flex-wrap: wrap; gap: 7px; margin: 12px 0; }
.chip { background: #fff; border: 1px solid var(--border); color: #34445b; border-radius: 999px; font-size: 12px; padding: 8px 11px; }
.chip:hover { background: var(--accent-soft); color: var(--accent-dark); }
.composer { display: grid; gap: 9px; }

.task-context { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px; margin-bottom: 14px; border: 1px solid var(--border); border-radius: 12px; background: linear-gradient(110deg, var(--accent-soft), #f8fbff); font-size: 12px; }
.task-context select { width: auto; min-width: 190px; max-width: 100%; }
.operations-conversation { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 360px); gap: 18px; }
.conversation-main { min-width: 0; }
.operations-conversation .chat-log { min-height: 250px; height: clamp(250px, 42vh, 500px); }
.task-rail { min-width: 0; padding: 15px; border: 1px solid var(--border); border-radius: 14px; background: #f8fbfe; max-height: 760px; overflow: auto; }
.task-rail h3 { margin: 0; font-size: 15px; }
.task-rail h4 { margin: 14px 0 8px; }
.task-rail p, .task-rail small { overflow-wrap: anywhere; }
.task-rail p { font-size: 13px; margin: 8px 0; }
.task-rail small { display: block; font-size: 11px; }
.task-state { display: inline-block; margin-top: 14px; padding: 5px 9px; border-radius: 6px; background: var(--accent-soft); color: var(--accent-dark); font-size: 12px; font-weight: 700; text-transform: capitalize; }
.task-state.failed, .task-state.partial, .task-state.awaiting_input { color: #7e4515; background: #fff0db; }
.task-step, .task-finding { padding: 10px 0; border-top: 1px solid var(--border); margin-top: 12px; }
.task-step strong, .task-finding strong { font-size: 12px; }
.task-blocker { padding: 9px; border-left: 3px solid #bf7c23; background: #fff4e6; color: #704415; }
.task-approve { margin: 8px 6px 8px 0; }
.attachment-button { display: inline-flex; align-items: center; position: relative; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; font-size: 12px; font-weight: 700; }
.attachment-button:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.attachment-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.upload-row { flex-wrap: wrap; }
@media (max-width: 1000px) { .operations-conversation { grid-template-columns: 1fr; } .task-rail { max-height: 460px; } }
.upload-row { display: flex; align-items: center; gap: 8px; }
.upload-row input[type=file] { flex: 1; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
  gap: 9px;
  margin-top: 11px;
}
.metric {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-soft);
  padding: 11px;
}
.metric small { display: block; color: var(--muted); margin-bottom: 4px; }
.metric strong { font-size: 21px; }


.work-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.work-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: linear-gradient(180deg, #ffffff 0%, #f6fafc 100%);
  padding: 13px;
}
.work-card p { margin: 8px 0; line-height: 1.45; }
.work-card small { color: var(--muted); font-weight: 700; }

.table-wrap { overflow-x: auto; margin-top: 12px; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 10px 8px; border-bottom: 1px solid #e4ebf1; text-align: left; vertical-align: top; }
.table th { color: #52647b; font-size: 11px; text-transform: uppercase; letter-spacing: .035em; }
.table td .row-actions { margin-top: 0; min-width: 210px; }
.empty-cell { text-align: center !important; color: var(--muted); padding: 22px !important; }

.result-panel {
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #0f1b2a;
  color: #d8e7f3;
  padding: 13px;
  white-space: pre-wrap;
  font-size: 12px;
  line-height: 1.45;
}
.qr-code { width: 180px; height: 180px; margin: 12px 12px 12px 0; border: 8px solid #fff; box-shadow: 0 3px 14px rgba(0,0,0,.12); }
#totpSecret { display: inline-block; padding: 8px; background: #edf2f6; border-radius: 7px; }

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: 380px;
  padding: 12px 15px;
  border-radius: 10px;
  background: #142336;
  color: #fff;
  box-shadow: var(--shadow);
  z-index: 50;
}

@media (max-width: 900px) {
  .setup-progress { grid-template-columns: 1fr 1fr; }
  .section-heading { align-items: flex-start; flex-direction: column; gap: 10px; }
}

@media (max-width: 640px) {
  .container { padding: 13px; }
  .title-row { align-items: center; flex-wrap: wrap; }
  .tabs { width: 100%; overflow-x: auto; }
  .tab { flex: 1; white-space: nowrap; padding-inline: 10px; }
  .session-bar { align-items: flex-start; }
  .session-bar .muted { display: block; margin: 3px 0 0; }
  .setup-progress { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .inline-controls, .upload-row { align-items: stretch; flex-direction: column; width: 100%; }
  .inline-controls select { min-width: 0; }
  .msg { max-width: 96%; }
  .row-space { align-items: flex-start; gap: 10px; }
}
