:root {
  color-scheme: light;
  --ink: #10243b;
  --muted: #65768b;
  --line: #d5dee8;
  --surface: #ffffff;
  --page: #f4f7fa;
  --teal-900: #064a51;
  --teal-700: #087f88;
  --teal-100: #e5f5f5;
  --red: #bb2f31;
  --amber: #a46400;
  --blue: #1e65bf;
  --green: #167d48;
  font-family: Inter, Aptos, Segoe UI, Arial, sans-serif;
  font-size: 16px;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; color: var(--ink); background: var(--page); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled, input:disabled, textarea:disabled { cursor: not-allowed; opacity: .58; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid #89cfd4; outline-offset: 2px; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.65rem; line-height: 1.2; }
h2 { font-size: 1.1rem; line-height: 1.25; }
h3 { font-size: .98rem; line-height: 1.3; }

.login-shell { display: grid; min-height: 100vh; place-items: center; padding: 24px; background: linear-gradient(135deg, #e5f5f5 0 32%, var(--page) 32% 100%); }
.login-panel { width: min(100%, 410px); padding: 36px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); box-shadow: 0 16px 40px rgb(16 36 59 / 12%); }
.brand-mark { display: grid; width: 48px; height: 48px; margin-bottom: 28px; place-items: center; border-radius: 5px; color: white; background: var(--teal-900); font-weight: 800; letter-spacing: 0; }
.login-panel > p { margin-top: 8px; color: var(--muted); }
.login-form { display: grid; gap: 8px; margin-top: 28px; }
.setup-link { display: inline-grid; margin-top: 28px; place-items: center; text-decoration: none; }
.login-form label, .record-form label { display: grid; gap: 6px; color: var(--muted); font-size: .78rem; font-weight: 700; text-transform: uppercase; }
input, select, textarea { width: 100%; min-height: 40px; border: 1px solid #aebdca; border-radius: 4px; padding: 8px 10px; color: var(--ink); background: white; }
textarea { min-height: 160px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .88rem; line-height: 1.55; }
.form-error { margin-top: 8px; color: var(--red); font-size: .88rem; }

.button { min-height: 38px; border: 1px solid transparent; border-radius: 4px; padding: 8px 14px; font-size: .86rem; font-weight: 700; }
.button-primary { color: white; background: var(--teal-700); }
.button-primary:hover { background: var(--teal-900); }
.button-secondary { border-color: #aebdca; color: var(--ink); background: white; }
.icon-button { min-height: 34px; border: 1px solid #b8c7d5; border-radius: 4px; padding: 6px 10px; color: var(--ink); background: white; font-size: .78rem; font-weight: 700; }

.app-shell { display: grid; min-height: 100vh; grid-template-columns: 230px minmax(0, 1fr); }
.sidebar { display: flex; min-height: 100vh; flex-direction: column; padding: 24px 14px 16px; color: white; background: var(--teal-900); }
.sidebar-brand { padding: 6px 10px 26px; border-bottom: 1px solid rgb(255 255 255 / 22%); font-size: 1.15rem; font-weight: 800; }
.nav-list { display: grid; gap: 4px; margin-top: 22px; }
.nav-item { width: 100%; border: 0; border-radius: 4px; padding: 12px 10px; color: white; background: transparent; text-align: left; font-weight: 700; }
.nav-item:hover, .nav-item.is-active { background: rgb(255 255 255 / 15%); }
.sidebar-status { display: grid; gap: 8px; margin: auto 0 18px; border: 1px solid rgb(255 255 255 / 32%); border-radius: 4px; padding: 14px; color: #d5f3f4; font-size: .82rem; }
.sidebar-status span { color: #b8dfe1; }
.sign-out { border-top: 1px solid rgb(255 255 255 / 22%); border-radius: 0; padding-top: 17px; }

.application-main { min-width: 0; }
.live-notes { position: fixed; z-index: 30; top: 14px; right: 20px; left: 250px; display: flex; justify-content: space-between; gap: 20px; min-height: 76px; border: 1px solid #efb8bb; border-radius: 5px; padding: 13px 16px; color: #752428; background: #fff5f5; box-shadow: 0 10px 28px rgb(16 36 59 / 17%); }
.live-notes[hidden] { display: none; }
.live-notes > div { display: grid; gap: 3px; }
.live-notes-label { color: var(--red); font-size: .7rem; font-weight: 800; text-transform: uppercase; }
.live-notes p { font-size: .85rem; }
.topbar { display: flex; min-height: 68px; align-items: center; justify-content: space-between; gap: 28px; border-bottom: 1px solid var(--line); padding: 12px 24px; background: var(--surface); }
.integration-status { display: flex; align-items: center; gap: 18px; }
.integration-indicator { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: .76rem; font-weight: 800; text-transform: uppercase; }
.status-light { width: 11px; height: 11px; border-radius: 50%; background: #b7c2ce; box-shadow: 0 0 0 3px #eef2f6; }
.integration-indicator.is-red .status-light { background: var(--red); box-shadow: 0 0 0 3px #ffebec; }
.integration-indicator.is-green .status-light { background: var(--green); box-shadow: 0 0 0 3px #e6f8ed; }
.integration-indicator.is-orange .status-light { background: #d88200; box-shadow: 0 0 0 3px #fff2dc; }
.mailbox-select { display: grid; min-width: 220px; gap: 4px; color: var(--muted); font-size: .72rem; font-weight: 700; text-transform: uppercase; }
.mailbox-select select { min-height: 36px; font-size: .88rem; font-weight: 600; text-transform: none; }
.account-summary { display: grid; gap: 3px; min-width: 160px; font-size: .85rem; }
.account-summary span { color: var(--muted); font-size: .76rem; text-transform: capitalize; }

.content-view { padding: 18px 20px 28px; }
.workspace-grid { display: grid; grid-template-columns: minmax(640px, 1.6fr) minmax(360px, .75fr); min-height: calc(100vh - 104px); gap: 16px; }
.queue-panel, .email-context, .admin-panel { border: 1px solid var(--line); border-radius: 5px; background: var(--surface); }
.queue-panel, .email-context { min-width: 0; }
.panel-heading { display: flex; min-height: 54px; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); padding: 0 14px; }
.panel-heading span { color: var(--muted); font-size: .8rem; font-weight: 700; }
.queue-tools { display: flex; align-items: end; gap: 10px; border-bottom: 1px solid var(--line); padding: 12px 14px; }
.search-control { flex: 1; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: .79rem; }
th, td { border-bottom: 1px solid #e1e7ee; padding: 11px 10px; text-align: left; vertical-align: top; }
th { position: sticky; top: 0; color: #566982; background: #f7f9fb; font-size: .68rem; text-transform: uppercase; }
tbody tr.is-selected { background: #e8f5f6; }
.empty-cell { padding: 32px 16px; color: var(--muted); text-align: center; }
.severity-high { color: var(--red); font-weight: 800; }
.severity-elevated { color: var(--amber); font-weight: 800; }
.severity-normal { color: var(--blue); font-weight: 800; }
.severity-low, .reviewed-yes { color: var(--green); font-weight: 800; }
.reviewed-no { color: var(--red); font-weight: 800; }
.truncate-cell { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-actions { display: flex; gap: 6px; align-items: center; }
.table-action { min-height: 30px; border: 1px solid var(--teal-700); border-radius: 4px; padding: 5px 8px; color: white; background: var(--teal-700); font-size: .75rem; font-weight: 800; }
.table-action:hover { border-color: var(--teal-900); background: var(--teal-900); }
.table-action-danger { border-color: var(--red); background: var(--red); }
.table-action-danger:hover { border-color: #8e2427; background: #8e2427; }
.status-pill { display: inline-flex; align-items: center; min-height: 24px; border: 1px solid #aebdca; border-radius: 3px; padding: 2px 7px; color: #42576f; background: #f4f7fa; font-size: .7rem; font-weight: 800; text-transform: uppercase; }
.status-active { border-color: #93cdb0; color: var(--green); background: #edfff5; }
.status-disabled { border-color: #d1d9e2; color: #627489; background: #f2f5f8; }

.email-context { display: grid; grid-template-rows: auto minmax(0, 1fr); max-height: calc(100vh - 104px); }
.email-context-content { min-height: 0; overflow-y: auto; padding: 16px; }
.context-fields { display: grid; gap: 11px; }
.context-field { display: grid; grid-template-columns: 112px 1fr; gap: 12px; font-size: .86rem; }
.context-field dt { color: var(--muted); font-weight: 800; }
.context-field dd { margin: 0; overflow-wrap: anywhere; }
.email-body { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 16px; }
.email-body h3 { margin-bottom: 10px; }
.email-body pre { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; color: #263a51; font: .86rem/1.55 ui-monospace, SFMono-Regular, Consolas, monospace; }
.attachment-list { display: grid; gap: 8px; margin-top: 18px; }
.attachment-row { border-left: 3px solid var(--teal-700); padding: 8px 10px; background: #f6fbfb; font-size: .83rem; }
.empty-state { color: var(--muted); font-size: .9rem; }

.view-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.admin-tabs { display: flex; gap: 8px; overflow-x: auto; border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.admin-tab { flex: 0 0 auto; min-height: 38px; border: 1px solid var(--teal-700); border-radius: 4px; padding: 8px 13px; color: white; background: var(--teal-700); font-size: .84rem; font-weight: 800; }
.admin-tab:hover { color: white; background: var(--teal-900); border-color: var(--teal-900); }
.admin-tab.is-active { color: white; background: var(--teal-700); border-color: var(--teal-700); }
.admin-panel { min-height: 380px; margin-top: 16px; }
.record-modal { width: min(100% - 32px, 640px); max-height: min(860px, calc(100vh - 32px)); border: 1px solid var(--line); border-radius: 6px; padding: 0; color: var(--ink); background: var(--surface); box-shadow: 0 24px 70px rgb(16 36 59 / 28%); }
.record-modal::backdrop { background: rgb(16 36 59 / 42%); }
.record-form { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; max-height: min(860px, calc(100vh - 32px)); }
.modal-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); padding: 14px 16px; }
.record-form-fields { display: grid; gap: 14px; overflow-y: auto; padding: 16px; }
.record-form-fields textarea { min-height: 420px; }
.form-grid-two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; border-top: 1px solid var(--line); padding: 14px 16px; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 20; max-width: 360px; border: 1px solid #84c8a5; border-radius: 4px; padding: 12px 14px; color: #0f5132; background: #edfff5; box-shadow: 0 8px 20px rgb(16 36 59 / 14%); font-size: .85rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 1240px) {
  .workspace-grid { grid-template-columns: 1fr; }
  .email-context { max-height: 640px; }
}
@media (max-width: 780px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { min-height: auto; padding: 10px; }
  .sidebar-brand { padding: 8px; border: 0; }
  .nav-list { display: flex; overflow-x: auto; margin-top: 8px; }
  .nav-item { min-width: max-content; padding: 9px 10px; }
  .sidebar-status, .sign-out { display: none; }
  .live-notes { top: 8px; right: 8px; left: 8px; }
  .topbar { gap: 12px; padding: 10px 14px; }
  .integration-status { gap: 12px; }
  .mailbox-select { min-width: 0; flex: 1; }
  .account-summary { min-width: 0; text-align: right; }
  .content-view { padding: 12px; }
  .workspace-grid { min-height: auto; }
  .queue-panel { overflow: hidden; }
  .queue-tools { display: grid; grid-template-columns: 1fr auto; align-items: end; }
  .queue-tools .mailbox-select { grid-column: 1 / -1; }
  .table-wrap { max-height: 460px; }
  .email-context { max-height: 560px; }
  .context-field { grid-template-columns: 1fr; gap: 3px; }
  .admin-panel { min-height: 0; }
  .admin-tabs { margin-right: -12px; }
  .truncate-cell { max-width: 180px; }
  .form-grid-two { grid-template-columns: 1fr; }
  .record-modal { width: min(100% - 16px, 640px); max-height: calc(100vh - 16px); }
  .record-form { max-height: calc(100vh - 16px); }
  .record-form-fields textarea { min-height: 320px; }
}
