:root {
  color-scheme: light;
  --ink: #161616;
  --muted: #707070;
  --line: #e9e9e9;
  --surface: #fafafa;
  --paper: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); }
button, input, select, textarea { font: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .45; }
a { color: inherit; text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 4px; }
::selection { background: #dedede; color: var(--ink); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.topbar { height: 76px; display: flex; justify-content: space-between; align-items: center; padding: 0 max(32px, calc((100vw - 1216px) / 2)); border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: 12px; text-decoration: none; font-size: 17px; font-weight: 600; letter-spacing: -.4px; }
.brand-icon { display: flex; flex-direction: column; justify-content: center; gap: 5px; width: 32px; height: 32px; padding: 9px; background: var(--ink); border-radius: 9px; }
.brand-icon i { display: block; height: 2px; background: #fff; border-radius: 2px; }
.brand-icon i:last-child { width: 9px; }
.top-actions { display: flex; align-items: center; gap: 24px; }
.connection { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.connection::before { content: ""; width: 6px; height: 6px; border: 1px solid #929292; border-radius: 50%; }
.connection.online::before { background: var(--ink); border-color: var(--ink); }

.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 38px; padding: 0 16px; border: 1px solid transparent; border-radius: 8px; font-size: 13px; font-weight: 550; text-decoration: none; white-space: nowrap; }
.button.primary { background: var(--ink); border-color: var(--ink); color: #fff; box-shadow: 0 1px 2px #00000012; }
.button.primary:hover:not(:disabled) { background: #333; border-color: #333; }
.button.secondary { color: var(--ink); background: #fff; border-color: #dfdfdf; }
.button.secondary:hover:not(:disabled) { background: var(--surface); border-color: #c9c9c9; }
.intro-actions .button > span:first-child { font-size: 17px; font-weight: 400; }

main { width: 100%; max-width: 1280px; margin: auto; padding: 48px 32px 40px; }
.intro { display: flex; align-items: center; justify-content: space-between; gap: 24px; }
h1 { margin: 0; font-size: 34px; line-height: 1.2; letter-spacing: -1.4px; font-weight: 600; }
.intro-actions { display: flex; align-items: center; gap: 8px; }
.summary { display: flex; margin: 36px 0; }
.metric { min-width: 160px; padding-right: 48px; margin-right: 48px; border-right: 1px solid var(--line); }
.metric:last-child { padding-right: 0; margin-right: 0; border-right: 0; }
.metric > span { display: block; margin-bottom: 12px; color: var(--muted); font-size: 12px; }
.metric > strong { font-size: 32px; line-height: 1; letter-spacing: -1px; font-weight: 550; font-variant-numeric: tabular-nums; }

.workspace { border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 0 24px; border-bottom: 1px solid var(--line); }
.filters { display: flex; align-items: stretch; gap: 24px; min-height: 68px; }
.filter { display: inline-flex; align-items: center; gap: 8px; padding: 0 0 1px; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; background: transparent; color: var(--muted); font-size: 13px; white-space: nowrap; }
.filter:hover { color: var(--ink); }
.filter.active { border-bottom-color: var(--ink); color: var(--ink); font-weight: 600; }
.filter span { min-width: 20px; padding: 3px 5px; border-radius: 5px; background: #eee; font-size: 10px; line-height: 1.1; font-weight: 600; text-align: center; font-variant-numeric: tabular-nums; }
.search { display: flex; align-items: center; gap: 10px; width: 220px; min-height: 36px; border: 1px solid #e3e3e3; border-radius: 8px; padding: 0 12px; background: #fff; }
.search:focus-within { border-color: #aaa; }
.search-icon { position: relative; display: block; flex: none; width: 12px; height: 12px; border: 1.5px solid #808080; border-radius: 50%; }
.search-icon::after { content: ""; position: absolute; width: 5px; height: 1.5px; right: -4px; bottom: -2px; background: #808080; transform: rotate(45deg); }
.search input { width: 100%; min-width: 0; padding: 8px 0; border: 0; background: transparent; color: var(--ink); font-size: 13px; }
.search input::placeholder { color: var(--muted); }
.search input:focus { outline: 0; }
.search:has(input:focus-visible) { outline: 2px solid var(--ink); outline-offset: 3px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; min-width: 760px; border-collapse: collapse; text-align: left; }
th { padding: 14px 24px; background: var(--surface); color: var(--muted); font-size: 12px; font-weight: 450; white-space: nowrap; }
th:nth-child(1) { width: 25%; }
th:nth-child(2) { width: 33%; }
th:nth-child(3) { width: 14%; }
th:nth-child(4) { width: 16%; }
td { padding: 22px 24px; border-top: 1px solid var(--line); vertical-align: middle; }
tbody tr:hover, tbody tr:focus-within { background: #fcfcfc; }
.person { display: flex; align-items: center; gap: 12px; min-width: 150px; }
.person > div:last-child { min-width: 0; }
.avatar { display: grid; place-items: center; flex: none; width: 40px; height: 40px; border: 1px solid #e6e6e6; border-radius: 12px; background: #f2f2f2; color: #545454; font-size: 12px; font-weight: 550; }
.avatar.tone1 { background: #ededed; }
.avatar.tone2 { background: #f8f8f8; }
.person-name { display: block; color: var(--ink); font-size: 13px; line-height: 1.4; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
button.person-name { max-width: 100%; padding: 0; border: 0; background: transparent; text-align: left; }
button.person-name:hover { text-decoration: underline; text-underline-offset: 4px; }
.person-handle { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview { max-width: 300px; color: #363636; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; line-height: 1.5; }
.date { margin-top: 6px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.wait { color: #4c4c4c; font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.wait.overdue { color: var(--ink); font-weight: 600; }
.wait-note { margin-top: 6px; color: var(--muted); font-size: 10px; }
.status { display: inline-flex; align-items: center; gap: 6px; padding: 5px 8px; border: 1px solid #e6e6e6; border-radius: 6px; background: #fff; color: #5c5c5c; font-size: 11px; line-height: 1.2; white-space: nowrap; }
.status.waiting { color: #333; background: #f8f8f8; }
.status.overdue { color: #fff; background: var(--ink); border-color: var(--ink); }
.status.answered { border-color: transparent; background: #f3f3f3; }
.row-actions { display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.open-chat { color: #565656; font-size: 11px; text-decoration: none; white-space: nowrap; }
.open-chat:hover { color: var(--ink); }
button.open-chat { padding: 6px 0; border: 0; background: transparent; }
.action-menu { position: relative; }
.action-menu summary { display: grid; place-items: center; width: 28px; height: 28px; list-style: none; cursor: pointer; border-radius: 6px; color: var(--muted); font-size: 20px; line-height: 1; }
.action-menu summary:hover { background: #efefef; color: var(--ink); }
.action-menu summary::-webkit-details-marker { display: none; }
.menu-items { position: absolute; z-index: 4; right: 36px; bottom: 0; width: 180px; padding: 4px; border: 1px solid #e1e1e1; border-radius: 8px; background: #fff; box-shadow: 0 8px 24px #00000012; }
.menu-items button { display: block; width: 100%; padding: 9px 8px; border: 0; border-radius: 4px; background: #fff; color: #333; font-size: 11px; text-align: left; }
.menu-items button:hover { background: #f3f3f3; }
.table-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 48px; padding: 12px 24px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
#sync-note { text-align: right; }
.empty { text-align: center; padding: 64px 24px; }
.empty-icon { display: inline-grid; place-items: center; width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 12px; color: #777; font-size: 18px; }
.empty h2 { margin: 16px 0 0; font-size: 16px; line-height: 1.4; font-weight: 550; letter-spacing: -.2px; }
.empty p { margin: 8px 0 0; color: var(--muted); font-size: 12px; }
.empty .button { margin-top: 20px; }
.notice.error { margin-bottom: 24px; padding: 12px 16px; border: 1px solid #ddd; border-radius: 8px; background: var(--surface); color: #333; font-size: 12px; line-height: 1.6; }

dialog { width: min(600px, calc(100% - 32px)); max-height: 88dvh; padding: 0; border: 1px solid #ddd; border-radius: 14px; background: #fff; color: var(--ink); box-shadow: 0 24px 80px #00000026; }
dialog::backdrop { background: #00000040; backdrop-filter: blur(4px); }
.dialog-head { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid var(--line); background: #fff; }
.dialog-head h2 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -.5px; }
.icon-button { display: grid; place-items: center; width: 28px; height: 28px; border: 0; border-radius: 6px; background: transparent; color: #777; font-size: 23px; }
.icon-button:hover { background: #f3f3f3; }
.dialog-content { padding: 0 24px 24px; }
.settings-section { padding: 24px 0; border-bottom: 1px solid var(--line); }
h3 { margin: 0 0 12px; font-size: 14px; font-weight: 600; }
.help { margin: 12px 0; color: var(--muted); font-size: 11px; line-height: 1.7; }
.inline-note { margin: 0 0 16px; color: var(--muted); font-size: 11px; line-height: 1.6; }
.inline-note:empty { display: none; }
label:not(.search) { display: block; margin-bottom: 16px; color: #555; font-size: 11px; }
label input:not([type=checkbox]), label select { display: block; width: 100%; margin-top: 8px; padding: 10px 12px; border: 1px solid #dedede; border-radius: 7px; background: #fff; color: var(--ink); font-size: 12px; }
label input[type=file] { padding: 9px; font-size: 11px; }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.check { display: flex !important; align-items: flex-start; gap: 8px; line-height: 1.6; }
.check input { margin: 2px 0 0; accent-color: var(--ink); }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
details:not(.action-menu) { margin: 16px 0 0; color: var(--muted); font-size: 11px; line-height: 1.7; }
details:not(.action-menu) summary { color: #555; cursor: pointer; }
ol { padding-left: 20px; }
li { margin: 8px 0; }
.storage-details { margin-top: 24px !important; }
.toast { position: fixed; z-index: 10; bottom: 24px; left: 50%; max-width: calc(100% - 32px); padding: 12px 16px; border: 1px solid #333; border-radius: 8px; background: #222; color: #fff; transform: translateX(-50%); font-size: 12px; box-shadow: 0 4px 16px #00000016; }

.reply-dialog { width: min(540px, 100%); max-width: 100%; height: 100dvh; max-height: 100dvh; margin: 0 0 0 auto; border: 0; border-left: 1px solid var(--line); border-radius: 0; overflow: hidden; }
.reply-dialog[open] { display: flex; flex-direction: column; }
.reply-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex: none; padding: 24px; border-bottom: 1px solid var(--line); }
.reply-person { display: flex; align-items: center; gap: 12px; min-width: 0; }
.reply-person > div { min-width: 0; }
.reply-person h2 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; font-weight: 600; letter-spacing: -.3px; }
.reply-head-actions { display: flex; align-items: center; gap: 16px; flex: none; }
.reply-history { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 24px; background: #fafafa; }
.reply-messages { display: flex; flex-direction: column; gap: 14px; }
.message { align-self: flex-start; max-width: 85%; padding: 12px 14px 8px; border: 1px solid #e6e6e6; border-radius: 12px 12px 12px 3px; background: #fff; }
.message.outgoing { align-self: flex-end; border-color: var(--ink); border-radius: 12px 12px 3px 12px; background: var(--ink); color: #fff; }
.message-text { font-size: 13px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-attachment { margin-bottom: 6px; font-size: 12px; color: var(--muted); }
.outgoing .message-attachment { color: #bbb; }
.message-date { margin-top: 6px; text-align: right; color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.outgoing .message-date { color: #bbb; }
.history-note { margin: 32px 0; text-align: center; color: var(--muted); font-size: 12px; }
.history-older { display: block; margin: 0 auto 20px; padding: 8px 16px; border: 1px solid #e4e4e4; border-radius: 20px; background: #fff; color: #555; font-size: 11px; }
.reply-composer { flex: none; padding: 20px 24px calc(20px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: #fff; }
.reply-composer textarea { display: block; width: 100%; min-height: 86px; max-height: 180px; resize: vertical; padding: 12px 14px; border: 1px solid #ddd; border-radius: 10px; background: #fff; color: var(--ink); font-size: 13px; line-height: 1.6; }
.reply-composer textarea::placeholder { color: #888; }
.reply-composer textarea:focus { border-color: #888; }
.reply-composer-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }
.reply-composer-footer > span { color: var(--muted); font-size: 10px; }
.reply-error { margin: 0 0 12px; color: #444; font-size: 12px; line-height: 1.6; }
.reply-dialog::backdrop { background: #00000026; backdrop-filter: blur(2px); }
.login-page { display: grid; place-items: center; min-height: 100dvh; padding: 32px 20px; background: var(--surface); }
main.login-panel { max-width: 380px; width: 100%; padding: 36px 32px; border: 1px solid var(--line); border-radius: 16px; background: #fff; }
.login-brand { margin-bottom: 24px; }
.login-panel h1 { margin-bottom: 32px; font-size: 27px; letter-spacing: -.8px; }
.login-panel .button { width: 100%; margin-top: 4px; }
.login-panel input { font-size: 16px !important; }
.login-panel .reply-error { margin-bottom: 16px; }

@media (min-width: 768px) { tbody tr.is-overdue td:first-child { box-shadow: inset 2px 0 var(--ink); } }
@media (max-width: 1024px) {
  .toolbar { flex-wrap: wrap; gap: 0 20px; }
  .filters { gap: 20px; min-height: 60px; }
  .search { width: 100%; margin-bottom: 16px; }
  td, th { padding-left: 20px; padding-right: 20px; }
  .metric { min-width: 140px; padding-right: 32px; margin-right: 32px; }
}
@media (max-width: 767px) {
  .topbar { height: 64px; padding: 0 24px; }
  main { padding: 32px 24px; }
  .top-actions { gap: 16px; }
  .connection { font-size: 11px; }
  h1 { font-size: 28px; letter-spacing: -1px; }
  .intro { align-items: flex-start; flex-direction: column; gap: 20px; }
  .summary { width: 100%; margin: 32px 0; }
  .metric { flex: 1; min-width: 0; margin-right: 24px; padding-right: 24px; }
  .metric > strong { font-size: 28px; }
  .metric > span { font-size: 11px; }
  .toolbar { padding: 0 16px; }
  .filters { width: 100%; gap: 20px; overflow-x: auto; }
  .table-footer { padding: 12px 16px; font-size: 10px; }
}
@media (max-width: 639px) {
  .topbar { padding: 0 20px; }
  .brand { gap: 10px; font-size: 15px; }
  .brand-icon { width: 28px; height: 28px; padding: 8px; border-radius: 8px; }
  .top-actions { gap: 12px; }
  .top-actions:has(#web-logout:not(.hidden)) { gap: 6px; }
  .top-actions .button { min-height: 34px; padding: 0 12px; font-size: 11px; }
  .connection { display: none; }
  main { padding: 28px 20px; }
  .metric { margin-right: 12px; padding-right: 12px; }
  .metric > span { margin-bottom: 10px; }
  .filter { font-size: 11px; }
  .filters { gap: 16px; }
  .table-wrap { overflow: visible; }
  table, tbody { display: block; min-width: 0; width: 100%; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
  tbody tr { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 16px 8px; padding: 20px 16px; border-top: 1px solid var(--line); }
  tbody tr:first-child { border-top: 0; }
  td { padding: 0; border: 0; }
  td:nth-child(1) { grid-column: 1; grid-row: 1; }
  td:nth-child(2) { grid-column: 1 / -1; grid-row: 2; }
  td:nth-child(3) { grid-column: 1; grid-row: 3; align-self: center; }
  td:nth-child(4) { grid-column: 2; grid-row: 3; justify-self: end; }
  td:nth-child(5) { grid-column: 2; grid-row: 1; align-self: center; }
  .preview { max-width: none; }
  .person { min-width: 0; }
  .avatar { width: 36px; height: 36px; border-radius: 10px; }
  .person-name { font-size: 13px; }
  .person-handle { font-size: 10px; }
  .open-chat { font-size: 10px; }
  .row-actions { gap: 6px; }
  .menu-items { bottom: auto; top: 0; right: 32px; width: 170px; }
  .table-footer { align-items: flex-start; flex-direction: column; gap: 6px; }
  #sync-note { text-align: left; }
  .empty { padding: 48px 16px; }
  .field-pair { grid-template-columns: 1fr; gap: 0; }
  .dialog-content { padding-left: 20px; padding-right: 20px; }
  .reply-head { padding: 20px; }
  .reply-head-actions { gap: 12px; }
  .reply-history { padding: 20px 16px; }
  .reply-composer { padding: 16px 20px calc(16px + env(safe-area-inset-bottom)); }
  .reply-composer textarea { font-size: 16px; }
}
@media (prefers-reduced-motion: no-preference) {
  .button, .filter, .search, .action-menu summary { transition: background .15s, border-color .15s, color .15s; }
  .toast { animation: toast-enter .18s ease-out; }
  .is-loading > span:first-child { animation: rotate 1s linear infinite; }
  @keyframes toast-enter { from { opacity: 0; transform: translate(-50%, 6px); } to { opacity: 1; transform: translate(-50%, 0); } }
  @keyframes rotate { to { transform: rotate(360deg); } }
}
