:root {
    color-scheme: light;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: #1d2733;
    background: #f4f6f8;
    font-size: 15px;
    line-height: 1.45;
}

* { box-sizing: border-box; }
body { margin: 0; background: #f4f6f8; }
a { color: #155f9a; text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; }

.topbar {
    min-height: 58px; padding: 0 28px; display: grid; grid-template-columns: auto 1fr auto;
    align-items: center; gap: 32px; background: #17212b; color: #fff; border-bottom: 3px solid #d4a72c;
}
.brand { color: #fff; font-weight: 750; font-size: 17px; }
.topbar nav { display: flex; gap: 8px; }
.topbar nav a { color: #c9d2db; padding: 17px 12px 14px; border-bottom: 3px solid transparent; }
.topbar nav a[aria-current="page"] { color: #fff; border-bottom-color: #45a36f; text-decoration: none; }
.account { display: flex; align-items: center; gap: 14px; font-size: 13px; color: #c9d2db; }
.account form { margin: 0; }

.page { width: min(1440px, calc(100% - 40px)); margin: 28px auto 60px; }
.page-heading, .dialog-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; margin-bottom: 22px; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: 30px; line-height: 1.15; margin-bottom: 4px; letter-spacing: 0; }
h2 { font-size: 18px; margin-bottom: 0; letter-spacing: 0; }
h3 { font-size: 14px; margin: 16px 0 6px; }
.eyebrow { margin-bottom: 5px; color: #687585; font-size: 12px; text-transform: uppercase; font-weight: 700; }
.muted { color: #687585; font-size: 13px; }

.button { display: inline-flex; align-items: center; justify-content: center; min-height: 38px; padding: 8px 14px; border: 1px solid #c9d1d9; border-radius: 5px; cursor: pointer; background: #fff; color: #273443; }
.button:hover { text-decoration: none; border-color: #8d99a6; }
.button-primary { background: #17689f; color: #fff; border-color: #17689f; }
.button-quiet { background: transparent; color: inherit; }

.heartbeat-band { padding: 20px 24px; display: grid; grid-template-columns: 220px 1fr; gap: 24px; align-items: center; border-left: 5px solid #798694; background: #fff; margin-bottom: 18px; }
.heartbeat-healthy { border-left-color: #278759; }
.heartbeat-delayed { border-left-color: #d4a72c; }
.heartbeat-error, .heartbeat-down { border-left-color: #c64f4f; }
.heartbeat-error { grid-column: 1 / -1; color: #8c2929; margin: 0; }
.inline-stats { display: grid; grid-template-columns: repeat(3, minmax(140px, 1fr)); gap: 16px; margin: 0; }
.inline-stats div, .definition-list div, .thread-facts div { min-width: 0; }
dt { color: #687585; font-size: 12px; }
dd { margin: 3px 0 0; font-weight: 650; overflow-wrap: anywhere; }

.metrics { display: grid; grid-template-columns: repeat(6, minmax(130px, 1fr)); gap: 12px; margin-bottom: 18px; }
.metric { min-height: 96px; display: flex; flex-direction: column; justify-content: space-between; padding: 16px; color: inherit; background: #fff; border-top: 3px solid #5d7489; border-radius: 4px; box-shadow: 0 1px 2px rgb(21 32 43 / 8%); }
.metric:hover { text-decoration: none; box-shadow: 0 2px 7px rgb(21 32 43 / 13%); }
.metric span { color: #5d6874; font-size: 13px; }
.metric strong { font-size: 27px; }
.metric-warning { border-top-color: #d4a72c; }
.metric-danger { border-top-color: #c64f4f; }

.dashboard-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; margin-bottom: 18px; }
.surface { background: #fff; border: 1px solid #dce2e8; border-radius: 5px; padding: 18px; margin-bottom: 18px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.compact-list { display: grid; }
.compact-list > a { display: flex; justify-content: space-between; gap: 18px; padding: 12px 0; border-top: 1px solid #e5e9ed; color: inherit; }
.compact-list > a:first-child { border-top: 0; }
.compact-list span:first-child { display: grid; gap: 2px; min-width: 0; }
.compact-list strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compact-list small, td small { color: #718090; display: block; }
.definition-list, .thread-facts { margin: 0; display: grid; gap: 10px; }
.definition-list div { display: flex; justify-content: space-between; gap: 16px; padding-bottom: 9px; border-bottom: 1px solid #e7ebef; }

.status, .channel { display: inline-flex; align-items: center; width: fit-content; min-height: 24px; padding: 3px 8px; border-radius: 4px; font-size: 12px; font-weight: 700; white-space: nowrap; background: #e8edf1; color: #42515f; }
.status-success { background: #dff2e7; color: #17633d; }
.status-active { background: #dcecf7; color: #185d89; }
.status-warning { background: #fff0c9; color: #735600; }
.status-danger { background: #fae0e0; color: #8d2929; }
.channel { border: 1px solid #b8c4ce; background: #fff; }
.attention-note { color: #8b6200; margin-top: 4px; }
.text-danger { color: #a22f2f; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 10px 12px; text-align: left; font-size: 12px; color: #647180; background: #f5f7f9; border-bottom: 1px solid #dbe1e6; }
td { padding: 12px; border-bottom: 1px solid #e7ebef; vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
td pre { max-width: 460px; margin: 0; }

.filters { display: grid; grid-template-columns: minmax(220px, 2fr) repeat(2, minmax(150px, 1fr)) auto auto auto; gap: 12px; align-items: end; margin-bottom: 16px; padding: 16px; background: #fff; border: 1px solid #dce2e8; }
.filters div { display: grid; gap: 5px; }
.filters label { color: #596675; font-size: 12px; font-weight: 650; }
input, select { width: 100%; min-height: 40px; border: 1px solid #bec8d1; border-radius: 4px; background: #fff; padding: 8px 10px; color: #1d2733; }
input:focus, select:focus, button:focus, a:focus { outline: 3px solid rgb(34 132 190 / 25%); outline-offset: 1px; }
.checkbox { min-height: 40px; display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.checkbox input { width: 17px; min-height: 17px; }
.dialog-list { padding: 0; }
.dialog-link { font-weight: 700; }
.pagination { display: flex; flex-wrap: wrap; gap: 5px; }
.pagination a { min-width: 35px; min-height: 35px; display: grid; place-items: center; border: 1px solid #c9d1d9; background: #fff; border-radius: 4px; }
.pagination a[aria-current="page"] { background: #17689f; color: #fff; border-color: #17689f; }

.back-link { display: inline-block; margin-bottom: 8px; font-size: 13px; }
.dialog-header p { margin: 0; color: #687585; }
.dialog-header-meta { display: flex; gap: 8px; }
.thread-facts { grid-template-columns: repeat(4, 1fr); padding: 14px 18px; background: #fff; border: 1px solid #dce2e8; margin-bottom: 16px; }
.tabs { display: flex; gap: 22px; border-bottom: 1px solid #ccd5dc; margin-bottom: 18px; }
.tabs a { padding: 10px 2px; color: #566472; border-bottom: 3px solid transparent; }
.tabs a[aria-current="page"] { color: #145f94; border-bottom-color: #1e7db5; font-weight: 700; text-decoration: none; }
.chat { max-width: 980px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.message { width: min(76%, 720px); padding: 14px 16px; border: 1px solid #d5dde4; background: #fff; border-radius: 6px; }
.message-agent, .message-manager { align-self: flex-end; background: #eaf4fa; border-color: #bed9e9; }
.message-system { width: 100%; align-self: stretch; background: #fff6d8; border-color: #e6cf7c; }
.message header { display: flex; justify-content: space-between; gap: 12px; color: #536171; font-size: 12px; }
.message header > span:first-child { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.session-badge, .attempt-badge { display: inline-flex; align-items: center; min-height: 22px; padding: 2px 7px; border-radius: 4px; background: #e2e8ed; color: #435260; font-size: 11px; font-weight: 700; }
.session-badge:hover { text-decoration: none; background: #d5e0e8; }
.message-address { margin: 3px 0 10px; color: #758291; font-size: 12px; overflow-wrap: anywhere; }
.message-body, .diagnostic-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.message details { margin-top: 12px; }
.message pre, .audit-list pre, td pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; background: #f4f6f8; padding: 10px; border: 1px solid #dce2e8; }
.attachments { margin: 10px 0 0; padding-left: 18px; }

.diagnostics-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.diagnostics-wide { grid-column: 1 / -1; }
.audit-list details { border-top: 1px solid #e1e6ea; padding: 10px 0; }
.audit-list details:first-child { border-top: 0; }
.audit-list summary { cursor: pointer; display: flex; justify-content: space-between; gap: 12px; }
.audit-list .definition-list { margin-top: 12px; }
.empty-state { color: #718090; padding: 20px; text-align: center; margin: 0; }
.alert { padding: 11px 13px; border-radius: 4px; }
.alert-danger { background: #fae0e0; color: #842626; border: 1px solid #e3aaaa; }

.session-timeline-list { display: grid; gap: 26px; }
.session-block { scroll-margin-top: 20px; background: #fff; border: 1px solid #d6dee5; border-radius: 5px; overflow: hidden; }
.session-header { display: flex; justify-content: space-between; gap: 24px; padding: 20px 22px; border-bottom: 1px solid #e1e6ea; background: #f8fafb; }
.session-header h2 { margin-bottom: 7px; }
.session-header p:last-child { max-width: 900px; margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.session-metrics { display: grid; grid-template-columns: repeat(6, minmax(110px, 1fr)); gap: 1px; margin: 0; background: #e1e6ea; border-bottom: 1px solid #e1e6ea; }
.session-metrics div { min-width: 0; padding: 12px 14px; background: #fff; }
.reasoning-unavailable { margin: 16px 22px 0; padding: 10px 12px; color: #5d6874; background: #f4f6f8; border-left: 3px solid #94a1ad; font-size: 13px; }
.agent-timeline { list-style: none; margin: 0; padding: 18px 22px 24px 52px; }
.timeline-entry { position: relative; padding: 0 0 18px 18px; border-left: 2px solid #d9e0e6; }
.timeline-entry:last-child { padding-bottom: 0; border-left-color: transparent; }
.timeline-marker { position: absolute; width: 12px; height: 12px; left: -7px; top: 5px; border: 3px solid #fff; border-radius: 50%; background: #6d7f8e; box-shadow: 0 0 0 1px #aeb9c2; }
.timeline-level-success .timeline-marker { background: #278759; }
.timeline-level-error .timeline-marker { background: #c64f4f; }
.timeline-entry article { min-width: 0; padding: 0 0 0 4px; }
.timeline-entry article > header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.timeline-entry article > header > span { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.timeline-entry time { flex: 0 0 auto; color: #718090; font-size: 12px; }
.timeline-duration { margin: 3px 0 0; color: #718090; font-size: 12px; }
.timeline-summary { max-width: 980px; margin-top: 8px; white-space: pre-wrap; overflow-wrap: anywhere; }
.timeline-entry details { margin-top: 8px; }
.timeline-entry details summary, .raw-diagnostics > summary { cursor: pointer; color: #155f9a; }
.timeline-entry pre { max-width: 100%; white-space: pre-wrap; overflow-wrap: anywhere; background: #f4f6f8; border: 1px solid #dce2e8; padding: 10px; font-size: 12px; }
.timeline-retry article, .timeline-error article { padding: 10px 12px; background: #fff2f2; border: 1px solid #efcaca; }
.raw-diagnostics { margin-top: 28px; padding: 16px 18px; background: #fff; border: 1px solid #d6dee5; border-radius: 5px; }
.raw-diagnostics > summary { font-weight: 700; color: #273443; }
.raw-diagnostics > .muted { margin: 10px 0 18px; }

.login-page { width: min(420px, calc(100% - 32px)); min-height: 100vh; margin: 0 auto; display: grid; place-items: center; }
.login-panel { width: 100%; padding: 28px; background: #fff; border: 1px solid #d7dee4; border-top: 4px solid #17689f; box-shadow: 0 10px 35px rgb(20 34 48 / 10%); }
.form-stack { display: grid; gap: 8px; }
.form-stack .button { margin-top: 12px; width: 100%; }

@media (max-width: 1050px) {
    .metrics { grid-template-columns: repeat(3, 1fr); }
    .filters { grid-template-columns: repeat(2, 1fr); }
    .filter-search { grid-column: 1 / -1; }
    .session-metrics { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 720px) {
    .topbar { padding: 10px 16px; grid-template-columns: 1fr auto; gap: 10px; }
    .topbar nav { grid-column: 1 / -1; grid-row: 2; }
    .topbar nav a { padding: 8px 10px; }
    .account > span { display: none; }
    .page { width: min(100% - 24px, 1440px); margin-top: 18px; }
    .page-heading, .dialog-header { align-items: flex-start; flex-direction: column; }
    .heartbeat-band { grid-template-columns: 1fr; }
    .inline-stats, .thread-facts { grid-template-columns: 1fr 1fr; }
    .metrics { grid-template-columns: 1fr 1fr; }
    .dashboard-grid, .diagnostics-grid { grid-template-columns: 1fr; }
    .diagnostics-wide { grid-column: auto; }
    .filters { grid-template-columns: 1fr; }
    .filter-search { grid-column: auto; }
    .message { width: 92%; }
    .session-header { align-items: flex-start; flex-direction: column; }
    .session-metrics { grid-template-columns: 1fr 1fr; }
    .agent-timeline { padding-left: 34px; padding-right: 14px; }
    h1 { font-size: 25px; }
}

@media (max-width: 430px) {
    .metrics, .inline-stats, .thread-facts { grid-template-columns: 1fr; }
    .message { width: 100%; }
    .login-panel { padding: 22px; }
    .session-metrics { grid-template-columns: 1fr; }
    .timeline-entry article > header { flex-direction: column; gap: 4px; }
}
