:root {
  color-scheme: light;
  --canvas: #eef2f0;
  --surface: #fff;
  --soft: #f5f8f6;
  --hover: #eaf2ee;
  --ink: #17201d;
  --muted: #596661;
  --line: #dbe4df;
  --line-strong: #c4d1cb;
  --green: #087a55;
  --green-dark: #075d43;
  --green-soft: #e1f1e9;
  --blue: #2b65b3;
  --blue-soft: #e8f0fb;
  --red: #b33a3a;
  --red-soft: #fae9e9;
  --amber: #9b5a09;
  --shadow: 0 18px 52px rgba(22, 45, 36, .16);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { background: var(--canvas); color: var(--ink); }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { color: inherit; }
button, [role="button"] { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
svg { width: 18px; height: 18px; stroke-width: 1.8; }

.boot { min-height: 100dvh; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--green-dark); }
.wordmark { display: inline-flex; align-items: baseline; font-size: 27px; line-height: 1; font-weight: 850; }
.wordmark .eye { position: relative; margin: 0 1px; font-size: .76em; }
.wordmark .eye::before { content: ""; position: absolute; left: 0; right: 0; top: -4px; border-top: 2px solid currentColor; }

.auth-shell { min-height: 100dvh; display: grid; grid-template-columns: minmax(360px, 510px) 1fr; background: var(--surface); }
.auth-main { min-width: 0; display: flex; flex-direction: column; justify-content: center; padding: clamp(34px, 7vw, 88px); border-right: 1px solid var(--line); overflow-y: auto; }
.auth-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 42px; color: var(--green-dark); }
.auth-brand strong { font-size: 16px; }
.auth-main h1 { margin: 0 0 9px; font-size: 30px; line-height: 1.18; }
.auth-main > p { margin: 0 0 25px; color: var(--muted); line-height: 1.55; }
.auth-aside { display: grid; place-content: center; padding: 46px; background: #edf4f1; }
.agent-route { width: min(620px, 88%); display: grid; gap: 28px; }
.route-line { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr; align-items: center; gap: 14px; }
.route-node { min-height: 122px; display: grid; place-content: center; justify-items: center; gap: 9px; padding: 16px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); text-align: center; }
.route-node svg { width: 27px; height: 27px; color: var(--green); }
.route-node span { color: var(--muted); font-size: 11px; }
.route-line > svg { color: var(--blue); }
.route-facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.route-facts span { padding: 12px 4px; border-top: 2px solid var(--green); color: var(--muted); font-size: 12px; line-height: 1.4; }

.tabs { display: flex; gap: 3px; margin-bottom: 20px; padding: 4px; border: 1px solid var(--line); border-radius: 8px; background: var(--soft); }
.tabs button { flex: 1; min-height: 40px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; }
.tabs button.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 5px rgba(17, 36, 29, .1); font-weight: 700; }
.auth-form { display: grid; gap: 15px; }
.field { display: grid; gap: 7px; color: var(--muted); font-size: 13px; font-weight: 650; }
.field input, .field textarea, .field select { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: 7px; outline: 0; background: var(--surface); color: var(--ink); }
.field textarea { min-height: 104px; resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus, .editor:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(8, 122, 85, .12); }
.address-input { display: grid; grid-template-columns: 1fr auto; align-items: center; border: 1px solid var(--line-strong); border-radius: 7px; overflow: hidden; }
.address-input:focus-within { border-color: var(--green); box-shadow: 0 0 0 3px rgba(8, 122, 85, .12); }
.address-input input { border: 0; box-shadow: none !important; }
.address-input span { padding: 0 12px; color: var(--muted); }
.name-status { min-height: 18px; margin-top: -8px; color: var(--muted); font-size: 12px; }
.name-status.available { color: var(--green); }
.name-status.taken, .name-status.reserved, .name-status.invalid { color: var(--red); }
.auth-note { margin: 2px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }

.primary, .secondary, .danger, .text-button { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 15px; border: 1px solid transparent; border-radius: 7px; cursor: pointer; font-weight: 720; }
.primary { background: var(--green); color: #fff; }
.primary:hover { background: var(--green-dark); }
.secondary { border-color: var(--line-strong); background: var(--surface); }
.secondary:hover { background: var(--hover); }
.danger { border-color: #e4bcbc; background: var(--surface); color: var(--red); }
.danger:hover { background: var(--red-soft); }
.text-button { min-height: 34px; padding: 0 6px; border: 0; background: transparent; color: var(--green-dark); }
.primary:disabled, .secondary:disabled { opacity: .55; cursor: not-allowed; }
.icon-button { width: 38px; height: 38px; display: inline-grid; place-content: center; padding: 0; border: 0; border-radius: 50%; background: transparent; cursor: pointer; }
.icon-button:hover { background: var(--hover); }
.icon-button.active { background: var(--green-soft); color: var(--green-dark); }

.credential-card { display: grid; gap: 16px; }
.credential-card h1 { margin-bottom: 0; }
.secret-box { display: grid; grid-template-columns: 1fr 40px; align-items: center; gap: 6px; padding: 7px 8px 7px 12px; border: 1px solid var(--line-strong); border-radius: 7px; background: var(--soft); }
.secret-box code { min-width: 0; overflow-wrap: anywhere; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
.recovery-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; counter-reset: recovery; }
.recovery-grid code { counter-increment: recovery; padding: 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--soft); font-size: 12px; }
.recovery-grid code::before { content: counter(recovery) ". "; color: var(--muted); }
.confirm-row { display: flex; align-items: flex-start; gap: 9px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.confirm-row input { margin-top: 3px; }

.app-shell { height: 100dvh; padding-top: var(--safe-top); display: grid; grid-template-columns: 230px 370px minmax(0, 1fr); background: var(--surface); }
.sidebar { min-width: 0; display: flex; flex-direction: column; padding: 17px 12px calc(13px + var(--safe-bottom)); border-right: 1px solid var(--line); background: #f3f6f4; }
.brand-row { min-height: 45px; display: flex; align-items: center; justify-content: space-between; padding: 0 7px 13px; color: var(--green-dark); }
.brand-copy { display: flex; align-items: baseline; gap: 7px; }
.brand-copy .wordmark { font-size: 22px; }
.brand-copy em { font-size: 12px; font-style: normal; color: var(--muted); font-weight: 750; }
.compose { width: 100%; margin-bottom: 17px; }
.nav { display: grid; gap: 3px; }
.nav-button { width: 100%; height: 40px; display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: 9px; padding: 0 10px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); text-align: left; cursor: pointer; }
.nav-button:hover { background: #e8eeeb; color: var(--ink); }
.nav-button.active { background: var(--green-soft); color: var(--green-dark); font-weight: 760; }
.nav-button small { font-size: 11px; }
.nav-divider { height: 1px; margin: 12px 8px; background: var(--line); }
.connection-card { margin-top: auto; padding: 13px 8px 0; border-top: 1px solid var(--line); display: grid; gap: 9px; }
.connection-line { display: grid; grid-template-columns: 9px 1fr; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #9aa49f; }
.status-dot.online { background: #19a06e; box-shadow: 0 0 0 3px rgba(25, 160, 110, .12); }
.account-line { min-width: 0; display: grid; gap: 2px; padding-top: 4px; }
.account-line strong, .account-line span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-line strong { font-size: 12px; }
.account-line span { color: var(--muted); font-size: 10px; }

.list-pane { min-width: 0; display: flex; flex-direction: column; border-right: 1px solid var(--line); }
.pane-header { padding: 16px 15px 12px; border-bottom: 1px solid var(--line); }
.title-row { min-height: 37px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.title-row h1 { margin: 0; font-size: 20px; }
.title-actions { display: flex; gap: 3px; }
.mobile-menu { display: none; }
.search { height: 38px; display: grid; grid-template-columns: 19px 1fr; align-items: center; gap: 8px; margin-top: 10px; padding: 0 11px; border: 1px solid var(--line); border-radius: 7px; background: var(--soft); color: var(--muted); }
.search input { min-width: 0; border: 0; outline: 0; background: transparent; color: var(--ink); }
.message-list { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.message-row { width: 100%; min-height: 92px; display: grid; grid-template-columns: 38px minmax(0, 1fr); gap: 10px; padding: 13px 14px; border: 0; border-bottom: 1px solid #edf1ef; background: var(--surface); text-align: left; cursor: pointer; }
.message-row:hover { background: #f8faf9; }
.message-row.active { background: var(--green-soft); }
.message-row.unread .sender, .message-row.unread .subject { color: var(--ink); font-weight: 800; }
.avatar { width: 36px; height: 36px; display: grid; place-content: center; border-radius: 50%; background: var(--blue-soft); color: var(--blue); font-size: 12px; font-weight: 820; text-transform: uppercase; }
.row-main { min-width: 0; display: grid; gap: 4px; }
.row-line { min-width: 0; display: flex; align-items: center; gap: 8px; }
.sender, .subject, .preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sender { flex: 1; font-size: 13px; font-weight: 680; }
.time { color: var(--muted); font-size: 10px; white-space: nowrap; }
.subject { font-size: 13px; }
.preview { color: var(--muted); font-size: 11px; }
.empty { min-height: 240px; display: grid; place-content: center; justify-items: center; gap: 9px; padding: 28px; color: var(--muted); text-align: center; }
.empty svg { width: 30px; height: 30px; color: var(--green); }
.empty strong { color: var(--ink); }
.empty p { max-width: 320px; margin: 0; font-size: 12px; line-height: 1.5; }

.content-pane { min-width: 0; display: flex; flex-direction: column; background: var(--surface); }
.content-header { min-height: 66px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.content-header-copy { min-width: 0; }
.content-header h2 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 17px; }
.content-header p { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.content-actions { display: flex; gap: 4px; }
.mobile-back { display: none; }
.message-reader { flex: 1; min-height: 0; overflow-y: auto; padding: 24px clamp(18px, 4vw, 56px); }
.message-meta { display: grid; grid-template-columns: 42px minmax(0, 1fr); gap: 11px; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.meta-copy { min-width: 0; display: grid; gap: 3px; }
.meta-copy strong, .meta-copy span { overflow-wrap: anywhere; }
.meta-copy span { color: var(--muted); font-size: 11px; }
.message-body { padding: 24px 0; font-size: 14px; line-height: 1.65; overflow-wrap: anywhere; }
.message-body pre { white-space: pre-wrap; font: inherit; }
.message-body iframe { width: 100%; min-height: 320px; border: 0; background: #fff; }
.label-strip { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 18px; }
.label { display: inline-flex; align-items: center; gap: 5px; min-height: 25px; padding: 0 8px; border-radius: 6px; background: var(--soft); color: var(--muted); font-size: 10px; font-weight: 750; }
.reader-actions { display: flex; gap: 8px; padding-top: 14px; }

.view { flex: 1; min-height: 0; overflow-y: auto; padding: 25px clamp(18px, 4vw, 48px); }
.view-head { margin-bottom: 22px; }
.view-head h2 { margin: 0 0 6px; font-size: 20px; }
.view-head p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.settings-section { padding: 20px 0; border-top: 1px solid var(--line); }
.settings-section:first-of-type { border-top: 0; padding-top: 0; }
.settings-section h3 { margin: 0 0 5px; font-size: 14px; }
.settings-section > p { margin: 0 0 14px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.key-list { display: grid; }
.key-row { min-height: 62px; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; border-top: 1px solid var(--line); }
.key-copy { min-width: 0; display: grid; gap: 3px; }
.key-copy strong { font-size: 12px; }
.key-copy span { color: var(--muted); font-size: 10px; }
.integration-tabs { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 8px; }
.integration-tabs button { min-height: 35px; padding: 0 11px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); cursor: pointer; font-size: 11px; font-weight: 700; white-space: nowrap; }
.integration-tabs button.active { border-color: var(--green); background: var(--green-soft); color: var(--green-dark); }
.code-box { position: relative; margin-top: 9px; border: 1px solid #293933; border-radius: 7px; overflow: hidden; background: #16231f; color: #e7f1ec; }
.code-box pre { margin: 0; padding: 17px 52px 17px 17px; overflow-x: auto; font: 11px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre; }
.code-box .copy-code { position: absolute; top: 7px; right: 7px; color: #e7f1ec; }
.endpoint-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.endpoint-table th, .endpoint-table td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.endpoint-table th { color: var(--muted); font-weight: 700; }
.endpoint-table code { overflow-wrap: anywhere; }

.modal-layer { position: fixed; z-index: 50; inset: 0; display: none; place-items: center; padding: 18px; background: rgba(12, 24, 20, .48); backdrop-filter: blur(2px); }
.modal-layer.open { display: grid; }
.modal { width: min(620px, 100%); max-height: calc(100dvh - 36px); display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.modal.wide { width: min(760px, 100%); }
.modal-head { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px 10px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-body { min-height: 0; overflow-y: auto; padding: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
.compose-form { display: grid; gap: 12px; }
.compose-fields { display: grid; gap: 8px; }
.compose-field { display: grid; grid-template-columns: 60px 1fr; align-items: center; gap: 6px; border-bottom: 1px solid var(--line); }
.compose-field label { color: var(--muted); font-size: 11px; }
.compose-field input { min-width: 0; height: 39px; border: 0; outline: 0; }
.editor-toolbar { display: flex; gap: 2px; padding: 5px; border: 1px solid var(--line); border-bottom: 0; border-radius: 7px 7px 0 0; background: var(--soft); }
.editor-toolbar button { width: 34px; height: 32px; display: grid; place-content: center; border: 0; border-radius: 5px; background: transparent; cursor: pointer; }
.editor-toolbar button:hover { background: var(--surface); }
.editor { min-height: 210px; max-height: 42vh; padding: 13px; border: 1px solid var(--line); border-radius: 0 0 7px 7px; outline: 0; overflow-y: auto; line-height: 1.55; }
.permissions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; }
.permission { display: flex; align-items: center; gap: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); font-size: 11px; }

.toast-stack { position: fixed; z-index: 80; right: 16px; bottom: calc(16px + var(--safe-bottom)); display: grid; gap: 8px; pointer-events: none; }
.toast { max-width: 360px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); box-shadow: var(--shadow); font-size: 12px; line-height: 1.4; }
.toast.error { border-color: #e1b0b0; color: var(--red); }
.toast.success { border-color: #a8d5c1; color: var(--green-dark); }

@media (max-width: 980px) {
  .auth-shell { grid-template-columns: minmax(340px, 470px) 1fr; }
  .auth-aside { padding: 28px; }
  .route-line { grid-template-columns: 1fr auto 1fr; }
  .route-line .route-node:nth-of-type(3), .route-line > svg:nth-of-type(2) { display: none; }
  .app-shell { grid-template-columns: 210px 340px minmax(0, 1fr); }
}

@media (max-width: 760px) {
  html, body { overflow: hidden; }
  .auth-shell { display: block; overflow-y: auto; }
  .auth-main { min-height: 100dvh; padding: max(26px, var(--safe-top)) 22px calc(32px + var(--safe-bottom)); border-right: 0; }
  .auth-brand { margin-bottom: 32px; }
  .auth-aside { display: none; }
  .app-shell { position: relative; display: block; overflow: hidden; }
  .sidebar { position: fixed; z-index: 35; inset: var(--safe-top) auto 0 0; width: min(82vw, 300px); transform: translateX(-102%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .app-shell.nav-open .sidebar { transform: translateX(0); }
  .app-shell.nav-open::after { content: ""; position: fixed; z-index: 30; inset: 0; background: rgba(13, 27, 22, .35); }
  .list-pane, .content-pane { position: absolute; inset: 0; border: 0; background: var(--surface); }
  .content-pane { z-index: 10; transform: translateX(100%); transition: transform .22s ease; }
  .app-shell.content-open .content-pane { transform: translateX(0); }
  .mobile-menu, .mobile-back { display: inline-grid; }
  .pane-header { padding-top: 10px; }
  .title-row h1 { font-size: 19px; }
  .message-reader, .view { padding: 18px 16px calc(24px + var(--safe-bottom)); }
  .content-header { padding: 9px 10px; }
  .content-header h2 { font-size: 15px; }
  .content-actions .secondary-label { display: none; }
  .modal-layer { align-items: end; padding: 0; }
  .modal, .modal.wide { width: 100%; max-height: calc(100dvh - var(--safe-top)); border-radius: 8px 8px 0 0; border-bottom: 0; }
  .modal-body { padding: 14px; }
  .editor { min-height: 180px; max-height: 40vh; }
  .permissions { grid-template-columns: 1fr; }
  .toast-stack { left: 12px; right: 12px; bottom: calc(12px + var(--safe-bottom)); }
  .toast { max-width: none; }
}

@media (max-width: 390px) {
  .auth-main { padding-left: 17px; padding-right: 17px; }
  .auth-main h1 { font-size: 26px; }
  .recovery-grid { grid-template-columns: 1fr; }
  .message-row { padding-left: 11px; padding-right: 11px; }
  .content-header { gap: 5px; }
}
