:root {
  --ink: #18233a;
  --muted: #667085;
  --line: #dbe3ef;
  --canvas: #f3f7fb;
  --surface: #ffffff;
  --navy: #14213d;
  --primary: #087f75;
  --primary-dark: #05645c;
  --primary-soft: #dff6f1;
  --amber: #c47a0a;
  --amber-soft: #fff3d6;
  --danger: #bd2c3b;
  --danger-soft: #fde8eb;
  --shadow: 0 14px 36px rgba(20, 33, 61, 0.08);
  font-family: Tahoma, "Segoe UI", sans-serif;
}

.connection-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(min(100%,310px),1fr)); gap:1rem; margin:1rem 0; }
.connection-account { min-width:0; overflow-wrap:anywhere; }
.connection-account .button-row { display:flex; flex-wrap:wrap; gap:.6rem; }
.connection-state { color:var(--primary-dark); font-weight:700; }
* { box-sizing: border-box; }
html { font-size: 16px; }
body { margin: 0; background: var(--canvas); color: var(--ink); line-height: 1.65; }
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.topbar {
  height: 76px; padding: 0 4vw; background: var(--navy); color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: .75rem; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 1.05rem; }
.brand small { color: #aebbd2; font-size: .78rem; }
.brand-mark {
  display: grid; place-items: center; width: 42px; height: 42px; border-radius: 14px;
  background: linear-gradient(145deg, #1bb5a6, #087f75); color: #fff; font-weight: 800;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
}
.brand-mark-large { width: 58px; height: 58px; margin: 0 auto 1rem; border-radius: 18px; font-size: 1.35rem; }
.quiet-button { background: transparent; border: 1px solid #41506c; color: #e8edf6; border-radius: 10px; padding: .55rem .9rem; cursor: pointer; }

.desktop-nav {
  width: min(1180px, 92vw); margin: -1px auto 0; padding: .6rem;
  display: flex; gap: .35rem; background: #1d2c4d; color: #d7dfec;
  border-radius: 0 0 16px 16px; position: sticky; top: 76px; z-index: 15;
}
.desktop-nav a { padding: .65rem 1rem; border-radius: 9px; font-size: .92rem; }
.desktop-nav a:hover { background: rgba(255,255,255,.08); color: #fff; }

.page-shell { width: min(1180px, 92vw); margin: 1.6rem auto 6rem; }
.auth-shell { width: min(440px, 91vw); margin-top: 7vh; }
.flash { padding: .85rem 1rem; margin-bottom: 1rem; border-radius: 12px; border: 1px solid; }
.flash-error { background: var(--danger-soft); border-color: #f5b7c0; color: #8c1f2c; }
.flash-success { background: var(--primary-soft); border-color: #a9ded4; color: #075e57; }

.auth-card, .panel-card, .control-deck, .action-strip, .metric-card {
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.auth-card { padding: 2rem; border-radius: 24px; text-align: center; }
.auth-card h1 { margin: 0; font-size: 1.6rem; }
.auth-card p { color: var(--muted); margin: .55rem 0 1.5rem; }
.stack-form { display: grid; gap: 1rem; text-align: right; }
label { color: #344054; font-weight: 700; font-size: .92rem; }
input, textarea, select {
  width: 100%; margin-top: .35rem; padding: .8rem .9rem; background: #fff;
  border: 1px solid #bdc9da; border-radius: 11px; color: var(--ink); min-height: 46px;
}
input:focus, textarea:focus, select:focus { outline: 3px solid rgba(8,127,117,.15); border-color: var(--primary); }

.primary-button, .secondary-button, .danger-button {
  border: 0; border-radius: 11px; padding: .75rem 1.1rem; font-weight: 800; cursor: pointer;
  min-height: 44px; display: inline-grid; place-items: center;
}
.primary-button { background: var(--primary); color: #fff; }
.primary-button:hover { background: var(--primary-dark); }
.secondary-button { background: #e8eef6; color: #263653; }
.danger-button { background: var(--danger-soft); color: var(--danger); border: 1px solid #f2bdc4; }
button:disabled { opacity: .48; cursor: not-allowed; }

.control-deck {
  border-radius: 22px; padding: 1.4rem 1.5rem; display: flex; align-items: center;
  justify-content: space-between; gap: 1rem; border-right: 5px solid var(--primary);
}
.eyebrow { margin: 0 0 .2rem; color: var(--primary); font-size: .78rem; font-weight: 900; letter-spacing: .02em; }
.control-deck h1 { margin: 0; font-size: clamp(1.35rem, 3vw, 2rem); }
.lead { margin: .3rem 0 0; color: var(--muted); }
.connection-pill { display: flex; align-items: center; gap: .5rem; white-space: nowrap; padding: .65rem .85rem; background: #eef2f7; border-radius: 999px; font-weight: 800; font-size: .86rem; }
.pulse-dot { width: 9px; height: 9px; border-radius: 50%; background: #8b98ab; }
.status-connected { color: #087f5b; background: #e4f7ef; }
.status-connected .pulse-dot { background: #16a56f; box-shadow: 0 0 0 5px rgba(22,165,111,.12); }
.status-error, .status-login_required { color: #9c6110; background: var(--amber-soft); }
.status-error .pulse-dot, .status-login_required .pulse-dot { background: var(--amber); }

.action-strip { margin-top: 1rem; padding: 1rem; border-radius: 16px; display: flex; align-items: center; flex-wrap: wrap; gap: .7rem; }
.action-strip small { margin-right: auto; color: var(--muted); }
.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin: 1rem 0; }
.metric-card { border-radius: 16px; padding: 1.1rem; display: grid; gap: .15rem; box-shadow: none; transition: transform .15s ease, box-shadow .15s ease; }
.metric-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.metric-card strong { font-size: 1.7rem; color: var(--navy); }
.metric-card span { color: var(--muted); font-size: .85rem; }
.metric-attention strong { color: var(--amber); }
.two-column { display: grid; grid-template-columns: 1.15fr .85fr; gap: 1rem; }
.panel-card { border-radius: 18px; padding: 1.25rem; box-shadow: none; }
.section-heading { display: flex; align-items: start; justify-content: space-between; gap: 1rem; }
.section-heading h2 { margin: 0; font-size: 1.15rem; }
.step-badge { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; color: var(--primary); background: var(--primary-soft); font-weight: 900; }
.clean-steps, .event-list { list-style: none; margin: 1.1rem 0; padding: 0; display: grid; gap: .8rem; }
.clean-steps li, .event-list li { display: flex; align-items: center; gap: .75rem; }
.clean-steps li > span { width: 28px; height: 28px; border: 1px solid var(--line); border-radius: 9px; display: grid; place-items: center; font-weight: 800; color: var(--primary); }
.clean-steps strong, .clean-steps small, .event-list small { display: block; }
.clean-steps small, .event-list small { color: var(--muted); }
.inline-button { width: fit-content; }
.event-dot { width: 9px; height: 9px; background: #8b98ab; border-radius: 50%; flex: 0 0 auto; }
.event-error { background: var(--danger); }
.event-warning { background: var(--amber); }
.event-info { background: var(--primary); }
.empty-state { min-height: 145px; display: grid; place-items: center; align-content: center; color: var(--muted); text-align: center; }
.empty-state span { font-size: 2rem; color: var(--primary); }
.empty-state p { margin: .35rem; }
.mobile-nav { display: none; }

.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin: .4rem 0 1.2rem; }
.page-heading h1 { margin: 0; font-size: clamp(1.45rem, 3vw, 2rem); }
.page-heading p:not(.eyebrow) { margin: .3rem 0 0; color: var(--muted); }
.workspace-grid { display: grid; grid-template-columns: minmax(270px, .72fr) minmax(0, 1.28fr); gap: 1rem; align-items: start; }
.sticky-form { position: sticky; top: 142px; }
.sticky-form h2, .panel-card > h2 { margin-top: 0; font-size: 1.1rem; }
.records-panel, .record-list, .response-list { display: grid; gap: .8rem; }
.record-card { background: #fff; border: 1px solid var(--line); border-radius: 15px; padding: 1rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.record-card h2 { font-size: 1rem; margin: 0; }
.record-card p { margin: .2rem 0; color: #344054; }
.record-card small { color: var(--muted); }
.record-card-block { display: block; }
.record-disabled { opacity: .58; }
.record-actions, .button-row { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip-button { border: 1px solid var(--line); background: #f8fafc; color: #475467; border-radius: 999px; padding: .4rem .65rem; font-size: .78rem; cursor: pointer; }
.channel-tag, .status-badge { display: inline-flex; padding: .2rem .5rem; border-radius: 999px; background: #e9eff7; color: #44516a; font-size: .72rem; font-weight: 800; }
.message-preview { white-space: pre-wrap; word-break: break-word; direction: rtl; font-family: inherit; background: #f5f8fc; border: 1px solid #e1e7ef; border-radius: 12px; padding: .9rem; margin: .7rem 0; }
code { background: #e8eef6; padding: .15rem .35rem; border-radius: 6px; direction: ltr; display: inline-block; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: .8rem; }
legend { padding: 0 .4rem; font-weight: 800; }
.compose-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; align-items: start; }
.compose-grid .panel-card { min-height: 100%; }
.compose-submit { grid-column: 1 / -1; display: flex; justify-content: end; }
.check-list { display: grid; gap: .5rem; max-height: 320px; overflow: auto; }
.check-row { display: flex; align-items: flex-start; gap: .65rem; border: 1px solid var(--line); border-radius: 11px; padding: .7rem; cursor: pointer; }
.check-row input, .switch-row input { width: 20px; min-height: 20px; margin: .15rem 0 0; flex: 0 0 auto; accent-color: var(--primary); }
.check-row span, .check-row small { display: block; }
.check-row small { color: var(--muted); }
.muted { color: var(--muted); }
.warning-card { border-right: 4px solid var(--amber); }
.approval-bar { position: sticky; bottom: 1rem; margin-top: 1rem; background: var(--navy); color: #fff; padding: 1rem 1.2rem; border-radius: 16px; display: flex; align-items: center; justify-content: space-between; gap: 1rem; box-shadow: 0 15px 40px rgba(20,33,61,.28); }
.approval-bar strong, .approval-bar small { display: block; }
.approval-bar small { color: #bdc8db; }
.status-draft { background: #eef2f7; }
.status-queued, .status-running { background: #fff1cf; color: #8a5706; }
.status-completed, .status-sent { background: var(--primary-soft); color: #075e57; }
.status-paused, .status-unknown, .status-failed { background: var(--danger-soft); color: var(--danger); }
.message-meta { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.message-meta span { color: var(--muted); font-size: .8rem; }
.response-card blockquote { margin: .8rem 0; padding: .8rem 1rem; background: #f6f8fb; border-right: 3px solid #a7b6ca; border-radius: 10px; white-space: pre-wrap; }
.response-attachments { display: flex; flex-wrap: wrap; gap: .7rem; margin: .8rem 0; }
.response-attachments a { display: block; width: min(280px, 100%); }
.response-image { display: block; width: 100%; max-height: 360px; object-fit: contain; background: #eef2f7; border: 1px solid var(--line); border-radius: 12px; }
.extraction-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: .6rem; margin: .8rem 0; }
.extraction-grid > span { padding: .65rem; border: 1px solid var(--line); border-radius: 10px; }
.extraction-grid small { display: block; color: var(--muted); }
.error-text { color: var(--danger); }
details { border-top: 1px solid var(--line); padding-top: .7rem; }
summary { cursor: pointer; font-weight: 800; color: var(--amber); }
.inline-review { display: grid; grid-template-columns: repeat(3, 1fr); gap: .7rem; }
.settings-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.settings-grid .panel-card { display: grid; gap: .8rem; align-content: start; }
.switch-row { display: flex; gap: .6rem; align-items: center; border: 1px solid var(--line); border-radius: 11px; padding: .7rem; }
.settings-submit { grid-column: 1 / -1; display: flex; justify-content: end; }
.security-note { margin-top: 1rem; border-right: 4px solid var(--primary); }
.device-pair-form { display: grid; grid-template-columns: minmax(220px, 1fr) auto; gap: .8rem; align-items: end; }
.trusted-device-list { display: grid; gap: .65rem; margin-top: 1rem; }
.trusted-device-list small { display: block; margin-top: .25rem; color: var(--muted); }
.pairing-card { display: grid; gap: 1rem; }
.pairing-card p { margin: 0; }
.pairing-code { padding: 1rem; border-radius: 14px; background: var(--navy); color: #fff; font-size: clamp(1.6rem, 8vw, 2.4rem); font-weight: 900; letter-spacing: .12em; }
.pairing-code-input { direction: ltr; text-align: center; letter-spacing: .1em; font-size: 1.25rem; font-weight: 800; text-transform: uppercase; }
.public-link { direction: ltr; overflow-wrap: anywhere; color: var(--primary); font-weight: 800; }
.auth-alt { margin: 1.1rem 0 0 !important; font-size: .86rem; }

/* Conversation workspace: account-scoped inbox, timeline, and follow-up profile. */
.inbox-heading { display:flex; justify-content:space-between; align-items:center; gap:1rem; margin-bottom:1rem; }
.inbox-heading h1 { margin:0; font-size:1.6rem; }
.inbox-heading p { margin:.25rem 0; font-size:.9rem; }
.inbox-access-warning { padding:.6rem .9rem; border:1px solid #edd5a0; border-radius:10px; background:var(--amber-soft); color:#735015; font-size:.85rem; }
.inbox-layout { display:grid; grid-template-columns:minmax(210px,.8fr) minmax(0,1.8fr) minmax(210px,.8fr); gap:.8rem; align-items:start; }
.inbox-layout > * { min-width:0; }
.inbox-list, .conversation-profile { padding:1rem; }
.inbox-filters { gap:.55rem; }
.inbox-filters input, .inbox-filters select { padding:.55rem; }
.conversation-list { margin:.9rem -.45rem; display:grid; gap:.3rem; }
.conversation-link { display:block; padding:.85rem .6rem; border:1px solid transparent; border-radius:12px; overflow-wrap:anywhere; }
.conversation-link:hover { background:var(--canvas); }
.conversation-link.is-active { background:var(--primary-soft); border-color:#85c8bf; }
.conversation-link small { display:block; color:var(--muted); font-size:.8rem; margin:.3rem 0; }
.conversation-line { display:flex; align-items:center; justify-content:space-between; gap:.5rem; }
.unread-badge { display:inline-grid; place-items:center; background:var(--primary); color:white; min-width:24px; padding:.1rem .4rem; border-radius:20px; font-size:.8rem; }
.inbox-manage { display:block; color:var(--primary); margin-top:.85rem; font-size:.9rem; }
.conversation-main { padding:0; overflow:hidden; }
.conversation-header { padding:1rem; display:flex; gap:.5rem; justify-content:space-between; align-items:center; border-bottom:1px solid var(--line); }
.conversation-header h2 { margin:0; font-size:1.15rem; }
.conversation-header p { margin:.25rem 0 0; color:var(--muted); font-size:.8rem; overflow-wrap:anywhere; }
.inbox-back { display:none; }
.inbox-receive-state { margin:0; padding:.6rem 1rem; background:#edf4fc; color:#365375; font-size:.8rem; }
.conversation-timeline { display:flex; flex-direction:column; gap:1rem; padding:1rem; max-height:580px; overflow:auto; background:#f7f9fc; scroll-behavior:smooth; }
.chat-message { width:90%; border:1px solid var(--line); border-radius:14px; padding:.75rem; background:white; overflow-wrap:anywhere; }
.chat-incoming { align-self:flex-start; border-start-start-radius:3px; }
.chat-outgoing { align-self:flex-end; background:var(--primary-soft); border-color:#b6dfd6; border-start-end-radius:3px; }
.chat-note { align-self:center; width:100%; background:var(--amber-soft); border-color:#edd5a0; }
.chat-meta { display:flex; flex-wrap:wrap; justify-content:space-between; gap:.3rem; color:var(--muted); font-size:.75rem; }
.chat-meta strong { font-size:.8rem; }
.chat-body { white-space:pre-wrap; overflow-wrap:anywhere; margin:.5rem 0; }
.chat-message small { display:block; color:#53627a; margin-top:.4rem; font-size:.8rem; }
.chat-message a:not(.chat-delivery) { color:var(--primary-dark); text-decoration:underline; }
.chat-delivery { display:inline-block; padding:.15rem .4rem; border-radius:8px; font-size:.8rem; }
.read-messages { padding:.8rem 1rem; display:flex; align-items:center; flex-wrap:wrap; gap:.5rem; border-top:1px solid var(--line); }
.read-messages small { color:var(--muted); font-size:.8rem; }
.reply-composer { padding:1rem; border-top:1px solid var(--line); }
.reply-composer h3 { margin:0 0 .6rem; font-size:1rem; }
.reply-composer .stack-form { margin-top:.6rem; }
.document-card { display:flex; align-items:center; gap:.75rem; max-width:100%; min-width:0; padding:.85rem; margin:.65rem 0; border:1px solid var(--line); border-radius:12px; background:white; color:var(--primary-dark); text-decoration:none !important; }
.document-card > span:last-child { min-width:0; }
.document-card strong, .document-card small, .document-card > span > span { display:block; overflow-wrap:anywhere; word-break:break-word; }
.document-card small { color:var(--muted); font-size:.8rem; margin:.35rem 0; }
.response-attachments .document-card { display:flex; }
.document-card > span > span { font-size:.85rem; }
.document-icon { flex:none; font-size:1.65rem; line-height:1; color:var(--primary); }
.file-selection { padding:.6rem; border-radius:8px; background:var(--primary-soft); overflow-wrap:anywhere; font-size:.85rem; }
#reply-attachment { max-width:100%; min-width:0; font-size:.85rem; }
#reply-attachment::file-selector-button { border:1px solid var(--line); border-radius:8px; padding:.5rem; margin-inline-end:.5rem; background:var(--canvas); cursor:pointer; }
.note-composer { padding:1rem; background:#fff9ec; }
.note-composer p { font-size:.85rem; }
.conversation-profile h2 { font-size:1.1rem; margin:0; }
.conversation-profile h3 { font-size:1rem; }
.conversation-profile p, .conversation-profile small { font-size:.85rem; }
.inbox-welcome { grid-column:2 / -1; min-height:340px; display:flex; flex-direction:column; justify-content:center; text-align:center; }
.history-pagination { display:flex; justify-content:space-between; padding:.4rem 1rem; color:var(--primary); gap:.8rem; font-size:.85rem; }
body[data-page="conversations"] .status-badge { font-size:.8rem; }
#inbox-confirm { width:min(92vw,480px); border:1px solid var(--line); border-radius:18px; padding:1.4rem; color:var(--ink); }
#inbox-confirm h2 { font-size:1.15rem; margin-top:0; }
#inbox-confirm::backdrop { background:rgba(20,33,61,.45); }
.desktop-nav { flex-wrap:wrap; }
@media (min-width:761px) and (max-width:1100px) {
  .inbox-layout { grid-template-columns:240px minmax(0,1fr); }
  .conversation-profile { grid-column:2; }
}
@media (max-width:760px) {
  .inbox-heading { align-items:stretch; flex-direction:column; }
  .inbox-layout { grid-template-columns:minmax(0,1fr); }
  .inbox-layout.has-conversation .inbox-list { display:none; }
  .inbox-back { display:block; margin-bottom:.5rem; color:var(--primary); font-size:.9rem; }
  .inbox-welcome { grid-column:1; min-height:180px; }
  .conversation-timeline { max-height:55vh; padding:.65rem; }
  .conversation-profile { grid-column:1; }
  .chat-message { width:95%; }
  .chat-note { width:100%; }
  .reply-composer, .note-composer { padding:.8rem; }
  .reply-composer .button-row > button { flex:1; }
}

@media (max-width: 760px) {
  .topbar { height: 66px; padding: 0 1rem; }
  .brand small, .desktop-nav { display: none; }
  .page-shell { width: min(100% - 1.2rem, 700px); margin-top: .8rem; padding-bottom: 5rem; }
  .auth-shell { width: min(100% - 1.5rem, 440px); margin-top: 4vh; }
  .auth-card { padding: 1.4rem; }
  .control-deck { align-items: flex-start; flex-direction: column; padding: 1.1rem; }
  .connection-pill { align-self: stretch; justify-content: center; }
  .action-strip { display: grid; grid-template-columns: 1fr 1fr; }
  .action-strip .danger-button, .action-strip small { grid-column: 1 / -1; margin: 0; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); gap: .7rem; }
  .metric-card { padding: .9rem; }
  .two-column { grid-template-columns: 1fr; }
  .page-heading { align-items: stretch; flex-direction: column; }
  .workspace-grid, .compose-grid, .settings-grid { grid-template-columns: 1fr; }
  .device-pair-form { grid-template-columns: 1fr; }
  .sticky-form { position: static; }
  .compose-submit, .settings-submit { grid-column: 1; }
  .compose-submit .primary-button, .settings-submit .primary-button { width: 100%; }
  .extraction-grid, .inline-review { grid-template-columns: 1fr 1fr; }
  .approval-bar { bottom: 5.2rem; align-items: stretch; flex-direction: column; }
  .approval-bar .button-row, .approval-bar form, .approval-bar button { width: 100%; }
  .mobile-nav {
    position: fixed; z-index: 30; bottom: 0; right: 0; left: 0; display: grid;
    grid-template-columns: repeat(5, 1fr); background: rgba(255,255,255,.96);
    border-top: 1px solid var(--line); padding: .4rem .3rem calc(.4rem + env(safe-area-inset-bottom));
    box-shadow: 0 -8px 24px rgba(20,33,61,.1); backdrop-filter: blur(12px);
  }
  .mobile-nav a { display: grid; place-items: center; gap: .05rem; font-size: .7rem; color: var(--muted); }
  .mobile-nav span { font-size: 1.15rem; line-height: 1; }
  .mobile-nav .mobile-primary span { width: 38px; height: 38px; margin-top: -1rem; border-radius: 14px; color: #fff; background: var(--primary); display: grid; place-items: center; box-shadow: 0 7px 18px rgba(8,127,117,.28); }
}
