:root {
  color-scheme: light;
  --bg: #f5f6f4;
  --surface: #ffffff;
  --line: #dfe3df;
  --line-strong: #c7cec8;
  --text: #1f2521;
  --muted: #69736c;
  --green: #216e4e;
  --green-soft: #e7f4ed;
  --amber: #9b5d0a;
  --amber-soft: #fff3d9;
  --blue: #315f9b;
  --blue-soft: #e9f0fa;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { font-size: 15px; letter-spacing: 0; }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
a { color: inherit; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 220px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 24px 16px; background: #eef0ed; border-right: 1px solid var(--line); }
.brand { display: flex; gap: 11px; align-items: center; margin: 0 8px 32px; text-decoration: none; min-width: 0; }
.brand-mark, .avatar, .connection-icon { display: grid; place-items: center; flex: 0 0 auto; color: white; background: var(--green); font-weight: 700; }
.brand-mark { width: 34px; height: 34px; border-radius: 7px; }
.brand span:last-child { min-width: 0; }
.brand strong, .brand small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand strong { font-size: 14px; }
.brand small { margin-top: 1px; color: var(--muted); font-size: 12px; }
.sidebar nav { display: grid; gap: 3px; }
.sidebar nav a { padding: 9px 11px; border-radius: 6px; color: #4d5750; font-weight: 600; text-decoration: none; }
.sidebar nav a:hover { background: #e4e8e4; }
.sidebar nav a[aria-current="page"] { color: var(--text); background: var(--surface); box-shadow: 0 1px 2px rgb(31 37 33 / 8%); }
.account-menu { position: absolute; right: 16px; bottom: 20px; left: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.account-menu span { display: block; overflow: hidden; margin-bottom: 4px; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.account-menu button { padding: 4px 0; color: #4d5750; background: transparent; border: 0; cursor: pointer; font-weight: 650; }
.account-menu button:hover { color: var(--text); }

.login-page { display: grid; min-height: 100vh; place-items: center; padding: 24px; }
.login-shell { width: min(360px, 100%); }
.login-shell .brand-mark { margin-bottom: 22px; }
.login-shell h1 { margin: 0 0 8px; font-size: 26px; }
.login-shell > p { margin: 0 0 24px; color: var(--muted); }
.google-login { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; min-height: 44px; padding: 8px 14px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 6px; font-weight: 680; text-decoration: none; }
.google-login:hover { border-color: #9ca69f; background: #fafbf9; }
.google-login span { color: #315f9b; font-weight: 750; }
.form-error { padding: 10px 12px; color: #8f3028 !important; background: #faeae8; border-radius: 5px; }

.main { width: min(1120px, 100%); padding: 36px 44px 80px; }
.page-header { min-height: 58px; display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
.page-header h1 { margin: 2px 0 0; font-size: 28px; line-height: 1.15; }
.eyebrow { margin: 0; color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; }
.subtle { margin: 5px 0 0; color: var(--muted); }
.back-link { display: inline-block; margin-bottom: 10px; color: var(--blue); font-size: 13px; text-decoration: none; }

.tabs { display: flex; gap: 22px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.tabs a { display: flex; gap: 7px; padding: 0 1px 11px; color: var(--muted); font-size: 14px; font-weight: 650; text-decoration: none; border-bottom: 2px solid transparent; }
.tabs a[aria-current="page"] { color: var(--text); border-bottom-color: var(--green); }
.tabs span { color: #8a938d; font-variant-numeric: tabular-nums; }

.notice { margin: 0 0 18px; padding: 11px 13px; border: 1px solid; border-radius: 6px; font-size: 14px; }
.notice.warning { color: #704307; background: var(--amber-soft); border-color: #ead5a7; }
.notice.success { color: #17573d; background: var(--green-soft); border-color: #bfdfcc; }

.conversation-list, .connection-list { overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; }
.conversation-row { display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; gap: 13px; align-items: center; min-height: 72px; padding: 12px 15px; text-decoration: none; border-bottom: 1px solid var(--line); }
.conversation-row:last-child { border-bottom: 0; }
.conversation-row:hover { background: #fafbf9; }
.avatar, .connection-icon { width: 36px; height: 36px; border-radius: 50%; background: var(--blue); }
.conversation-copy, .row-title, .row-preview, .connection-copy { display: block; min-width: 0; }
.row-title { margin-bottom: 4px; font-weight: 680; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-preview { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-meta { display: grid; justify-items: end; gap: 8px; min-width: 112px; color: var(--muted); font-size: 12px; }
.attention-dot { width: 8px; height: 8px; border-radius: 50%; background: #c47a12; }
.empty-state { padding: 64px 28px; text-align: center; color: var(--muted); }
.empty-state h2 { margin: 0 0 6px; color: var(--text); font-size: 18px; }
.empty-state p { margin: 0; }

.conversation-header { margin-bottom: 20px; }
.owner-question { margin-bottom: 20px; padding: 18px; background: var(--amber-soft); border: 1px solid #ead5a7; border-radius: 7px; }
.owner-question h2 { margin: 5px 0 16px; max-width: 760px; font-size: 18px; line-height: 1.4; }
.answer-row { display: flex; align-items: end; gap: 10px; }
.answer-row textarea { flex: 1; min-height: 44px; }
.option-list { display: grid; gap: 8px; }
.option-button { display: grid; gap: 2px; width: 100%; padding: 10px 12px; text-align: left; background: white; border: 1px solid #dec89a; border-radius: 5px; cursor: pointer; }
.option-button:hover { border-color: var(--amber); }
.option-button span { color: var(--muted); font-size: 13px; }
.option-answer { margin-top: 10px; }
.chat-thread { min-height: 460px; padding: 26px; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; }
.message { display: flex; margin-bottom: 14px; }
.message.outbound { justify-content: flex-end; }
.message-bubble { max-width: min(640px, 78%); padding: 10px 12px 7px; background: #eff2ef; border-radius: 7px 7px 7px 2px; }
.message.outbound .message-bubble { background: var(--green-soft); border-radius: 7px 7px 2px 7px; }
.message-bubble p { margin: 0; line-height: 1.5; white-space: pre-wrap; }
.message-bubble time { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; text-align: right; }
.delivery-status { display: inline-block; margin-top: 6px; font-size: 12px; font-weight: 700; }
.delivery-status.failed { color: #9a372f; }
.delivery-status.pending { color: var(--amber); }

.primary-button, .text-button, .remove-button { border: 0; cursor: pointer; }
.primary-button { min-height: 38px; padding: 8px 14px; color: white; background: var(--green); border-radius: 6px; font-weight: 680; }
.primary-button:hover { background: #185c40; }
.text-button { padding: 6px 0; color: var(--blue); background: transparent; font-weight: 650; }
.remove-button { align-self: end; width: 34px; height: 38px; color: var(--muted); background: transparent; font-size: 22px; line-height: 1; border-radius: 5px; }
.remove-button:hover { color: #8f3028; background: #faeae8; }

.settings-form { display: grid; gap: 16px; }
.form-section { padding: 22px; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; }
.form-section h2 { margin: 0 0 17px; font-size: 17px; }
.section-heading { display: flex; justify-content: space-between; gap: 20px; align-items: start; margin-bottom: 17px; }
.section-heading h2 { margin-bottom: 3px; }
.section-heading p { margin: 0; color: var(--muted); }
.form-grid { display: grid; gap: 16px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.span-two { grid-column: span 2; }
label { display: grid; gap: 6px; color: #545f57; font-size: 12px; font-weight: 680; }
input, textarea, select { width: 100%; padding: 9px 10px; color: var(--text); background: white; border: 1px solid var(--line-strong); border-radius: 5px; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
textarea { resize: vertical; line-height: 1.45; }
.hours-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 26px; }
.hours-grid label { grid-template-columns: 92px 1fr; align-items: center; }
.editable-list, .rule-list { display: grid; gap: 9px; }
.editable-row { display: grid; grid-template-columns: minmax(150px, 1fr) minmax(110px, .55fr) minmax(220px, 1.4fr) 34px; gap: 10px; align-items: end; }
.rule-row { display: grid; grid-template-columns: minmax(150px, .8fr) 150px minmax(260px, 1.5fr) 34px; gap: 10px; align-items: end; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.rule-row:last-child { border-bottom: 0; }
.template-list { display: grid; gap: 14px; }
.template-row { display: grid; grid-template-columns: minmax(150px, .7fr) minmax(220px, 1fr) minmax(300px, 1.5fr) 34px; gap: 10px; align-items: start; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.template-row:last-child { border-bottom: 0; }
.template-row textarea { resize: vertical; }

.connection-row { display: grid; grid-template-columns: 38px minmax(0, 1fr) 120px 140px; gap: 13px; align-items: center; min-height: 72px; padding: 12px 15px; border-bottom: 1px solid var(--line); }
.owner-route-setup { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 18px; padding: 17px 18px; background: var(--blue-soft); border: 1px solid #cbd9ec; border-radius: 7px; }
.owner-route-setup h2 { margin: 0 0 4px; font-size: 17px; }
.owner-route-setup p { margin: 0; color: var(--muted); }
.connection-row:last-child { border-bottom: 0; }
.connection-copy strong, .connection-copy span { display: block; }
.connection-copy span, .connection-count { margin-top: 3px; color: var(--muted); font-size: 13px; }
.connection-state { color: var(--green); font-size: 13px; font-weight: 650; }
.connection-state i { display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: var(--green); }
.connection-count { text-align: right; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 800px) {
  .app-shell { display: block; }
  .sidebar { position: static; width: auto; height: auto; padding: 13px 16px 0; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { margin: 0 0 12px; }
  .sidebar nav { display: flex; gap: 16px; overflow-x: auto; }
  .sidebar nav a { padding: 8px 1px 11px; border-radius: 0; background: transparent !important; box-shadow: none !important; white-space: nowrap; border-bottom: 2px solid transparent; }
  .sidebar nav a[aria-current="page"] { border-bottom-color: var(--green); }
  .account-menu { position: static; display: flex; align-items: center; justify-content: space-between; padding: 10px 0; }
  .account-menu span { margin: 0; }
  .main { padding: 24px 16px 56px; }
  .page-header { align-items: center; }
  .form-grid.two, .hours-grid { grid-template-columns: 1fr; }
  .span-two { grid-column: auto; }
  .editable-row, .rule-row, .template-row { grid-template-columns: 1fr 1fr 34px; }
  .template-text { grid-column: 1 / 3; }
  .editable-row .grow, .rule-guidance { grid-column: 1 / span 2; }
  .remove-button { grid-column: 3; grid-row: 1; }
  .connection-row { grid-template-columns: 38px minmax(0, 1fr) auto; }
  .connection-count { display: none; }
}

@media (max-width: 520px) {
  .brand-mark { display: none; }
  .page-header h1 { font-size: 24px; }
  .tabs { gap: 16px; overflow-x: auto; }
  .conversation-row { grid-template-columns: 34px minmax(0, 1fr); }
  .avatar { width: 34px; height: 34px; }
  .row-meta { display: none; }
  .form-section { padding: 17px; }
  .hours-grid label { grid-template-columns: 78px 1fr; }
  .editable-row, .rule-row, .template-row { grid-template-columns: 1fr 34px; }
  .editable-row label, .editable-row .grow, .rule-row label, .rule-guidance, .template-row label, .template-text { grid-column: 1; }
  .remove-button { grid-column: 2; grid-row: 1; }
  .message-bubble { max-width: 90%; }
}
