@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700&family=Roboto+Slab:wght@600&display=swap');

:root {
    --blue: #175cd3;
    --blue-dark: #103f91;
    --blue-soft: #eaf2ff;
    --red: #c82e3a;
    --red-soft: #fff0f1;
    --gray-950: #172033;
    --gray-800: #344054;
    --gray-600: #667085;
    --gray-400: #98a2b3;
    --gray-300: #d0d5dd;
    --gray-200: #e4e7ec;
    --gray-100: #f2f4f7;
    --gray-50: #f8fafc;
    --white: #ffffff;
    --yellow: #f4c430;
    --shadow: 0 16px 48px rgb(23 32 51 / 16%);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    color: var(--gray-950);
    background: var(--gray-100);
    font-family: 'Manrope', sans-serif;
    font-size: 14px;
}
button, input, select { font: inherit; }
button { cursor: pointer; }

.topbar {
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 0 20px;
    color: var(--white);
    background: var(--gray-950);
    border-bottom: 3px solid var(--red);
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand strong { font-family: 'Roboto Slab', serif; font-size: 19px; }
.brand > span:last-child { color: var(--gray-300); }
.brand-mark {
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    background: var(--blue);
    font-family: 'Roboto Slab', serif;
    font-size: 19px;
}
.top-actions { display: flex; align-items: center; gap: 10px; }
.top-actions label { color: var(--gray-300); font-size: 12px; }
.top-actions select {
    min-width: 150px;
    color: var(--white);
    background: #273247;
    border: 1px solid #475467;
}

button, select, input {
    min-height: 36px;
    border: 1px solid var(--gray-300);
    border-radius: 4px;
}
button { padding: 7px 12px; background: var(--white); color: var(--gray-800); }
button:hover { border-color: var(--blue); }
.primary { color: var(--white); background: var(--blue); border-color: var(--blue); font-weight: 700; }
.primary:hover { background: var(--blue-dark); }
.secondary { background: var(--gray-100); }
.danger { color: var(--white); background: var(--red); border-color: var(--red); font-weight: 700; }
.danger:hover { background: #a9232e; border-color: #a9232e; }
.icon-button { width: 36px; padding: 0; font-size: 20px; }
.topbar .icon-button { color: var(--white); background: transparent; border-color: #475467; }
.monitoring-button { color: var(--white); background: #273247; border-color: #475467; }

.workspace {
    height: calc(100% - 64px);
    display: grid;
    grid-template-columns: 190px minmax(300px, 390px) minmax(420px, 1fr);
    overflow: hidden;
}
.sidebar { padding: 18px 10px; background: var(--gray-950); }
.sidebar nav { display: grid; gap: 4px; }
.nav-item {
    display: flex;
    justify-content: space-between;
    width: 100%;
    color: var(--gray-300);
    background: transparent;
    border-color: transparent;
    text-align: left;
}
.nav-item:hover, .nav-item.active { color: var(--white); background: #273247; border-color: #344054; }
.nav-item.active { box-shadow: inset 3px 0 var(--blue); }
.nav-item span { color: var(--gray-400); }

.conversation-list { min-width: 0; min-height: 0; overflow: hidden; background: var(--white); border-right: 1px solid var(--gray-200); }
.list-tools { height: 58px; display: flex; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--gray-200); }
.list-tools input { width: 100%; padding: 0 12px; background: var(--gray-50); }
.list-content { height: calc(100% - 58px); overflow-y: auto; }
.conversation-item {
    width: 100%;
    min-height: 104px;
    padding: 14px;
    display: grid;
    gap: 7px;
    background: var(--white);
    border: 0;
    border-bottom: 1px solid var(--gray-200);
    border-radius: 0;
    text-align: left;
}
.conversation-item:hover { background: var(--gray-50); }
.conversation-item.active { background: var(--blue-soft); box-shadow: inset 4px 0 var(--blue); }
.item-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.item-id { color: var(--blue-dark); font-size: 12px; font-weight: 700; }
.item-subject { overflow: hidden; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.item-meta { justify-content: flex-end; color: var(--gray-600); font-size: 12px; }
.item-customer { color: var(--blue-dark); font-size: 11px; font-weight: 700; }

.detail { min-width: 0; min-height: 0; background: var(--gray-50); overflow-y: auto; }
.empty-state { display: grid; place-items: center; color: var(--gray-600); text-align: center; }
.empty-state h1 { margin: 0 0 5px; color: var(--gray-800); font-family: 'Roboto Slab', serif; font-size: 22px; }
.detail-head {
    position: sticky;
    top: 0;
    z-index: 3;
    padding: 14px 18px;
    background: rgb(255 255 255 / 96%);
    border-bottom: 1px solid var(--gray-200);
    backdrop-filter: blur(10px);
}
.detail-title { display: flex; align-items: start; justify-content: space-between; gap: 14px; }
.detail-title h1 { margin: 4px 0; font-family: 'Roboto Slab', serif; font-size: 21px; }
.detail-id { color: var(--blue); font-size: 12px; font-weight: 700; }
.detail-customer { color: var(--gray-600); font-size: 12px; }
.detail-controls { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 11px; }
.detail-controls select { min-width: 130px; padding: 0 8px; background: var(--white); }
.identification-tools { display: grid; gap: 9px; padding: 14px 18px; background: #fff8e8; border-bottom: 1px solid #e6b85c; }
.identification-row { display: flex; gap: 7px; }
.identification-row input { min-width: 0; flex: 1; padding: 0 9px; }
.customer-picker { position: relative; min-width: 0; flex: 1; }
.customer-picker > input { width: 100%; }
.customer-search-results { position: absolute; z-index: 5; top: calc(100% + 3px); right: 0; left: 0; max-height: 280px; overflow-y: auto; background: var(--white); border: 1px solid var(--gray-300); box-shadow: var(--shadow); }
.customer-search-results:empty { display: none; }
.customer-search-results .customer-option { width: 100%; display: grid; gap: 2px; padding: 9px 11px; background: var(--white); border: 0; border-bottom: 1px solid var(--gray-200); border-radius: 0; text-align: left; }
.customer-option span, .customer-option small { color: var(--gray-600); overflow-wrap: anywhere; }
.customer-option small { font-size: 11px; }
.identification-results { display: grid; gap: 5px; color: var(--gray-600); font-size: 12px; }
.identification-results .candidate { min-height: 34px; color: var(--gray-800); background: var(--white); border-color: var(--gray-300); text-align: left; }
.back-button { display: none; }
.timeline { max-width: 940px; margin: 0 auto; padding: 22px; }
.message {
    margin-bottom: 16px;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-left: 4px solid var(--blue);
    box-shadow: 0 3px 12px rgb(23 32 51 / 5%);
}
.message.inbound { border-left-color: var(--red); }
.message-head { display: flex; justify-content: space-between; gap: 16px; padding: 12px 14px; border-bottom: 1px solid var(--gray-200); }
.message-head strong { overflow-wrap: anywhere; }
.message-head time, .message-route { color: var(--gray-600); font-size: 12px; }
.message-route { padding: 8px 14px 0; overflow-wrap: anywhere; }
.mailbox-warning, .message-mailbox-change { color: #8a4b00; background: #fff7d6; border: 1px solid #e6bd55; font-size: 12px; font-weight: 700; }
.mailbox-warning { margin-top: 7px; padding: 7px 9px; }
.message-mailbox-change { margin: 8px 14px 0; padding: 6px 8px; }
.message-body { padding: 16px; line-height: 1.55; overflow: hidden; overflow-wrap: anywhere; contain: paint; isolation: isolate; }
.message-body img { max-width: 100%; height: auto; }
.message-files { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 14px 14px; }
.message-files a { color: var(--blue-dark); background: var(--blue-soft); padding: 7px 9px; text-decoration: none; border: 1px solid #b9d1ff; }
.message-actions { display: flex; gap: 7px; padding: 0 14px 14px; }

.loading, .no-results, .fatal { padding: 30px 16px; color: var(--gray-600); text-align: center; }
.fatal { color: var(--red); }

#composer { width: min(860px, calc(100vw - 24px)); max-height: calc(100vh - 24px); padding: 0; border: 0; border-radius: 6px; box-shadow: var(--shadow); }
#composer::backdrop { background: rgb(23 32 51 / 58%); }
#monitoring-dashboard { width: min(1180px, calc(100vw - 24px)); max-height: calc(100vh - 24px); padding: 0; border: 0; border-radius: 6px; box-shadow: var(--shadow); }
#monitoring-dashboard::backdrop { background: rgb(23 32 51 / 58%); }
.monitoring-panel { min-height: min(680px, calc(100vh - 24px)); background: var(--gray-50); }
.monitoring-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 20px; color: var(--white); background: var(--gray-950); border-bottom: 3px solid var(--red); }
.monitoring-head h2 { margin: 2px 0 0; font-family: 'Roboto Slab', serif; font-size: 21px; }
.monitoring-eyebrow { color: #9fc2ff; font-size: 11px; font-weight: 700; text-transform: uppercase; }
.monitoring-actions { display: flex; gap: 7px; }
.monitoring-actions button { color: var(--white); background: transparent; border-color: #475467; }
.monitoring-summary { min-height: 70px; display: flex; align-items: center; gap: 18px; padding: 14px 20px; background: var(--white); border-bottom: 1px solid var(--gray-200); }
.monitoring-summary > time { margin-left: auto; color: var(--gray-600); font-size: 12px; }
.monitoring-overall { display: flex; align-items: center; gap: 8px; font-size: 16px; }
.health-indicator, .dependency-dot { width: 9px; height: 9px; display: inline-block; flex: 0 0 auto; border-radius: 50%; background: currentColor; }
.monitoring-counts { display: flex; flex-wrap: wrap; gap: 8px; }
.monitoring-counts span { font-size: 12px; font-weight: 700; }
.health-healthy, .health-connected { color: var(--blue); }
.health-degraded, .health-starting, .health-unknown { color: #b45f00; }
.health-failed, .health-stale, .health-missing, .health-disconnected { color: var(--red); }
.monitoring-error { min-height: 0; padding: 0 20px; color: var(--red); }
.monitoring-error:not(:empty) { padding-block: 12px; }
.monitoring-table-wrap { overflow: auto; }
.monitoring-table { width: 100%; min-width: 900px; border-collapse: collapse; background: var(--white); }
.monitoring-table th { position: sticky; top: 0; z-index: 1; padding: 11px 14px; color: var(--gray-600); background: var(--gray-100); border-bottom: 1px solid var(--gray-300); font-size: 11px; text-align: left; text-transform: uppercase; }
.monitoring-table td { padding: 14px; border-bottom: 1px solid var(--gray-200); vertical-align: top; }
.monitoring-table td:first-child { min-width: 190px; }
.monitoring-table strong, .monitoring-table small { display: block; }
.monitoring-table small { margin-top: 4px; color: var(--gray-600); font-size: 11px; overflow-wrap: anywhere; }
.health-badge { display: inline-block; min-width: 94px; padding: 5px 7px; background: var(--gray-100); border-left: 3px solid currentColor; font-size: 12px; font-weight: 700; }
.dependency-line { display: grid; grid-template-columns: 9px auto; align-items: center; gap: 5px 7px; margin-bottom: 7px; }
.dependency-line small { grid-column: 2; margin: 0; }
.muted { color: var(--gray-600); }
.service-error { max-width: 320px; color: var(--red) !important; }
.composer-form { display: grid; gap: 12px; padding: 18px; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--gray-200); padding-bottom: 12px; }
.dialog-head h2 { margin: 0; font-family: 'Roboto Slab', serif; font-size: 20px; }
.composer-form label { display: grid; gap: 5px; color: var(--gray-800); font-size: 12px; font-weight: 700; }
.composer-form input, .composer-form select { width: 100%; padding: 0 10px; background: var(--white); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.editor-wrap { border: 1px solid var(--gray-300); border-radius: 4px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 3px; padding: 6px; background: var(--gray-100); border-bottom: 1px solid var(--gray-300); }
.toolbar button { width: 34px; min-height: 32px; padding: 3px; }
.toolbar select { width: 120px; min-height: 32px; }
.toolbar input[type='color'] { width: 34px; min-height: 32px; padding: 3px; }
.editor { min-height: 210px; max-height: 350px; padding: 14px; overflow-y: auto; line-height: 1.5; outline: 0; }
.editor:focus { box-shadow: inset 0 0 0 2px var(--blue-soft); }
.attachments { display: flex; align-items: start; gap: 12px; }
.file-button { display: inline-flex !important; min-height: 36px; align-items: center; padding: 7px 12px; background: var(--gray-100); border: 1px solid var(--gray-300); border-radius: 4px; cursor: pointer; }
#attachment-list { display: flex; flex-wrap: wrap; gap: 6px; }
.attachment-chip { display: flex; align-items: center; gap: 5px; padding: 5px 7px; background: var(--blue-soft); border: 1px solid #b9d1ff; }
.attachment-chip button { min-height: 24px; padding: 0 5px; color: var(--red); background: transparent; border: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--gray-200); padding-top: 12px; }
.error { min-height: 18px; color: var(--red); font-size: 12px; }
#toast { position: fixed; right: 20px; bottom: 20px; z-index: 20; max-width: 360px; padding: 11px 14px; color: var(--white); background: var(--gray-950); box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translateY(8px); transition: 160ms ease; }
#toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 980px) {
    .workspace { grid-template-columns: 72px 330px minmax(360px, 1fr); }
    .sidebar { padding-inline: 6px; }
    .nav-item { justify-content: center; padding-inline: 5px; font-size: 11px; }
    .nav-item span { display: none; }
}

@media (max-width: 720px) {
    .topbar { height: auto; min-height: 64px; padding: 9px 12px; }
    .brand { min-width: 0; flex: 0 1 auto; }
    .brand strong { font-size: 17px; }
    .brand > span:last-child, .top-actions label, #refresh { display: none; }
    .top-actions { min-width: 0; gap: 6px; }
    .top-actions select { width: 100px; min-width: 0; max-width: 100px; }
    #new-message { font-size: 0; width: 38px; padding: 0; }
    #new-message::after { content: '+'; font-size: 22px; }
    .monitoring-button { width: 38px; padding: 0; overflow: hidden; font-size: 0; }
    .monitoring-button::after { content: '●'; color: #9fc2ff; font-size: 15px; }
    .monitoring-summary { align-items: flex-start; flex-direction: column; gap: 9px; }
    .monitoring-summary > time { margin-left: 0; }
    .workspace { height: calc(100% - 64px); grid-template-columns: 1fr; }
    .sidebar { display: none; }
    .conversation-list { border: 0; }
    .detail { display: none; }
    body.has-detail .conversation-list { display: none; }
    body.has-detail .detail { display: block; }
    .back-button { display: inline-block; }
    .timeline { padding: 12px; }
    .detail-head { padding: 12px; }
    .detail-title h1 { font-size: 17px; }
    .detail-controls select { min-width: 0; flex: 1 1 140px; }
    .detail-controls button { flex-shrink: 0; white-space: nowrap; }
    .message-head { display: grid; gap: 4px; }
    .field-row { grid-template-columns: 1fr; }
    .composer-form { padding: 12px; }
    .editor { min-height: 170px; }
}
