:root {
  --page: #d4dcea;
  --header: #e0e7f3;
  --footer: #e2e8f3;
  --canvas: #f1f5fa;
  --surface: #fdfdfe;
  --card: #fcfcfd;
  --text: #101c30;
  --muted: #364a66;
  --accent: #0d2c64;
  --accent-hover: #09234f;
  --focus: #395b89;
  --tint: #e3e9f2;
  --hover: #d5dfed;
  --selected: #dae1ec;
  --own-message: #cad6e8;
  --own-message-line: #aebfd7;
  --line: #c4d0e2;
  --input-line: #7486a0;
  --divider: #3d5677;
  --disabled: #e9edf2;
  --disabled-text: #5b6b81;
  --danger: #a12c2c;
  --backdrop: #101c3099;
  --shadow: #101c3040;
  --reading-width: 48rem;
  --bubble-width: 42rem;
  --bubble-share: 92%;
  --control-height: 36px;
  --reading-inset: 20px;
  font-family: "Segoe UI", "Yu Gothic UI", Meiryo, system-ui, sans-serif;
  color: var(--text);
  background: var(--page);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; overflow: hidden; }
h1, h2, h3, p { margin: 0; overflow-wrap: anywhere; }
h1 { font-size: 1.25rem; line-height: 1.625rem; font-weight: 700; }
h2, .add-preview-header h3 { font-size: 1.25rem; line-height: 1.75rem; font-weight: 700; }
h3, .sidebar-title h2 { font-size: 1rem; line-height: 1.375rem; font-weight: 650; }
p, dd { line-height: 1.6; overflow-wrap: anywhere; }
a { color: var(--accent); }
.label { color: var(--muted); font-size: .875rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.narrow-only { display: none; }

button {
  min-height: var(--control-height);
  padding: 4px 12px;
  font-family: inherit;
  font-size: .875rem;
  line-height: 1.25rem;
  font-weight: 600;
  color: var(--surface);
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
}
button:hover:not(:disabled) { background: var(--accent-hover); }
.secondary, .conversation-action-list button { color: var(--text); background: var(--tint); }
.secondary:hover:not(:disabled), .conversation-action-list button:hover:not(:disabled) { background: var(--hover); }
.text-action, .v2-forward-toggle {
  color: var(--accent);
  background: transparent;
  padding: 4px;
  font-size: .8125rem;
}
.text-action:hover:not(:disabled), .v2-forward-toggle:hover:not(:disabled) { background: var(--tint); text-decoration: underline; }
button:disabled { color: var(--disabled-text); background: var(--disabled); cursor: default; }
:where(button, a, input, summary, [tabindex]):focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
input {
  min-height: var(--control-height);
  min-width: 0;
  padding: 4px 10px;
  font: inherit;
  font-size: .875rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--input-line);
  border-radius: 6px;
}
input::placeholder { color: var(--muted); }
label { font-size: .8125rem; line-height: 1.125rem; }

.app-shell { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
.app-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "brand legal";
  align-items: center;
  gap: 0 16px;
  min-height: 56px;
  padding: 4px 16px;
  background: var(--header);
  border-bottom: 1px solid var(--line);
}
.signed-in .app-header {
  grid-template-columns: minmax(0, 1fr) auto minmax(0, max-content) auto;
  grid-template-areas: "brand legal account logout";
}
.brand { grid-area: brand; display: flex; align-items: baseline; flex-wrap: wrap; gap: 0 12px; min-width: 0; }
.legal-links { grid-area: legal; display: flex; flex-wrap: wrap; align-items: center; gap: 0 12px; font-size: .8125rem; line-height: 1.125rem; }
#display-language {
  min-height: 28px;
  max-width: 100%;
  padding: 0 6px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
}
#display-language:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#account { grid-area: account; min-width: 0; max-width: 14rem; padding-left: 16px; border-left: 1px solid var(--line); }
#account p { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .8125rem; line-height: 1.125rem; }
#account-name { font-weight: 650; }
#account-username { color: var(--muted); }
#logout { grid-area: logout; }
.app-feedback { font-size: .8125rem; color: var(--muted); }
.app-feedback p:empty, #signed-in-feedback:not(:has(p:not(:empty))) { display: none; }
#signed-in-feedback { padding: 4px 16px; max-height: 5rem; overflow-y: auto; }
#sign-in-feedback p:not(:empty) { margin-top: 8px; }

.workspace-viewport { flex: 1; min-height: 0; padding: 12px; }
.workspace { height: 100%; display: grid; grid-template-columns: minmax(260px, var(--left-column-width, 3fr)) 12px minmax(480px, 7fr); }
#column-resizer { cursor: col-resize; touch-action: none; position: relative; }
#column-resizer::after, #column-resizer::before { content: ""; position: absolute; background: var(--divider); border-radius: 2px; }
#column-resizer::after { inset: 8px 5px; background: var(--line); }
#column-resizer::before { top: 50%; left: 4px; width: 4px; height: 32px; transform: translateY(-50%); }
#column-resizer:hover::before, #column-resizer:focus-visible::before, .resizing-columns #column-resizer::before { background: var(--accent); }
.resizing-columns, .resizing-columns * { cursor: col-resize !important; user-select: none !important; }
.sidebar, .chat-main, .mail-tools { min-width: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.sidebar { display: flex; flex-direction: column; min-height: 0; padding: 8px 12px 0; }
.sidebar-header { flex-shrink: 0; max-height: 55%; overflow-y: auto; padding: 4px 3px; margin: 0 -3px; }
.sidebar-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sidebar-title h2 { min-width: 0; }
#registration-count {
  display: inline-block;
  margin-left: 2px;
  padding: 0 4px;
  border-radius: 4px;
  background: var(--tint);
  color: var(--muted);
  white-space: nowrap;
  font-size: .75rem;
  line-height: 1rem;
  font-weight: 400;
}
#add-conversation { flex: none; padding-inline: 9px; }
.sidebar-header p, #registered-empty, #registration-no-results { margin-top: 8px; color: var(--muted); font-size: .8125rem; line-height: 1.125rem; }
.sidebar-header p:empty { display: none; }
#registration-search-controls { margin-top: 8px; }
.registration-search-actions { position: relative; margin-top: 4px; }
#registration-search { width: 100%; padding-right: calc(var(--control-height) + 4px); }
#registration-search::-webkit-search-cancel-button { appearance: none; }
#clear-registration-search { position: absolute; inset: 0 0 0 auto; width: var(--control-height); font-size: 1rem; }
#reload-registrations { display: block; margin: 0 0 0 auto; }
.conversation-list-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 4px 2px 12px; margin: 0 -2px; }
#registered-list, #add-mail-list, #mail-list { padding: 0; margin: 0; list-style: none; }
#registered-list li {
  --row-action: 32px;
  position: relative;
  min-height: 64px;
  margin-bottom: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
}
#registered-list li:hover { background: var(--canvas); }
#registered-list li.selected, #add-mail-list .select-mail[aria-pressed="true"] {
  background: var(--selected);
  border-color: var(--accent);
  box-shadow: inset 3px 0 var(--accent);
}
#registered-list .open-registration {
  display: block;
  width: 100%;
  min-height: 62px;
  padding: 8px calc(var(--row-action) + 8px);
  color: var(--text);
  background: transparent;
  text-align: left;
  overflow-wrap: anywhere;
}
#registered-list .open-registration:hover:not(:disabled) { background: transparent; }
#registered-list .open-registration:focus-visible, #add-mail-list .select-mail:focus-visible { outline-offset: -3px; }
.conversation-name { display: block; font-size: .9375rem; line-height: 1.3125rem; }
.open-registration[aria-pressed="true"] { font-weight: 700; }
.conversation-meta { display: flex; flex-wrap: wrap; gap: 0 6px; margin-top: 4px; }
.conversation-last-sent, .pinned-label { color: var(--muted); font-size: .8125rem; line-height: 1.125rem; font-weight: 400; }
.pinned-label { color: var(--accent); }
.conversation-drag-handle, .conversation-actions summary {
  position: absolute;
  top: 4px;
  width: var(--row-action);
  min-height: var(--row-action);
  padding: 0;
  color: var(--muted);
  background: transparent;
  border-radius: 6px;
}
.conversation-drag-handle { left: 4px; cursor: grab; }
.conversation-drag-handle:active:not(:disabled) { cursor: grabbing; }
.conversation-drag-handle:hover:not(:disabled), .conversation-actions summary:hover { background: var(--tint); }
.conversation-drag-handle:disabled { color: var(--disabled-text); background: transparent; }
.conversation-actions summary { right: 4px; display: grid; place-items: center; list-style: none; cursor: pointer; font-weight: 700; }
.conversation-actions summary::-webkit-details-marker { display: none; }
.conversation-actions[open] { padding: 0 8px 8px; }
.conversation-action-list { display: flex; flex-wrap: wrap; gap: 4px; }
.conversation-action-list button { font-size: .8125rem; overflow-wrap: anywhere; }
.conversation-name-editor label { display: block; }
.conversation-name-editor input { display: block; width: 100%; margin: 4px 0 8px; }
.conversation-name-editor button, .conversation-remove-confirmation button { margin-right: 4px; }
.conversation-remove-confirmation p { margin-bottom: 8px; font-size: .875rem; }
button.confirm-remove-registration { color: var(--danger); background: var(--surface); border-color: var(--danger); }
button.confirm-remove-registration:hover:not(:disabled) { color: var(--surface); background: var(--danger); }
#registered-list .dragging { opacity: .5; outline: 2px dashed var(--accent); }
#registered-list .drop-before { border-top: 4px solid var(--accent); }
#registered-list .drop-after { border-bottom: 4px solid var(--accent); }

.chat-column { display: flex; flex-direction: column; gap: 12px; min-width: 0; min-height: 0; }
.chat-main { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.empty-state {
  width: 100%;
  max-width: 496px;
  min-height: 0;
  margin: auto;
  padding: 16px;
  overflow-y: auto;
}
.empty-state p { margin-top: 8px; font-size: .875rem; color: var(--muted); }
.sign-in { max-width: 528px; }
.sign-in h2 { font-size: 1.5rem; line-height: 2rem; }
#login-permission-note { padding: 12px; margin: 16px 0 12px; border-radius: 8px; background: var(--tint); }
#login-permission-note p { margin: 0; font-size: .8125rem; line-height: 1.125rem; color: var(--text); }
#login-permission-note p + p { margin-top: 4px; }
#login { min-height: 40px; }
html:not(.signed-in) :is(#conversation-empty, #first-conversation, .chat-navigation) { display: none; }
#conversation-panel, #add-conversation-panel { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.conversation-header, .add-preview-header {
  flex-shrink: 0;
  max-height: 35%;
  overflow-y: auto;
  scrollbar-gutter: stable both-edges;
  padding: 12px var(--reading-inset);
  border-bottom: 1px solid var(--line);
}
.reading-heading { max-width: var(--reading-width); margin-inline: auto; }
.conversation-title-row { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 12px; }
.conversation-title-row h2 { flex: 1; min-width: 0; }
.reading-heading p { margin-top: 4px; font-size: .8125rem; line-height: 1.125rem; color: var(--muted); }
.reading-heading p:empty { display: none; }
.reading-heading .conversation-warning { padding: 6px 8px; border-left: 3px solid var(--divider); background: var(--tint); }
.conversation-details { margin-top: 4px; font-size: .8125rem; color: var(--muted); }
.conversation-details summary { width: fit-content; cursor: pointer; }
#conversation-messages, #add-conversation-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-gutter: stable both-edges;
  overscroll-behavior: contain;
  margin: 0;
  padding: 16px var(--reading-inset);
  list-style: none;
  background: var(--canvas);
}
.v2-message { display: flex; justify-content: flex-start; max-width: var(--reading-width); margin-inline: auto; }
.v2-message + .v2-message { margin-top: 12px; }
.v2-message.self { justify-content: flex-end; }
.v2-bubble {
  max-width: min(var(--bubble-width), var(--bubble-share));
  min-width: 0;
  padding: 12px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow-wrap: anywhere;
}
.self .v2-bubble { background: var(--own-message); border-color: var(--own-message-line); }
.v2-message-meta { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 4px 12px; margin-bottom: 6px; }
.v2-message-meta .v2-sender { font-size: .875rem; line-height: 1.25rem; font-weight: 650; }
.v2-timestamp { color: var(--muted); font-size: .8125rem; line-height: 1.125rem; font-variant-numeric: tabular-nums; }
.v2-body, .v2-forward-content { white-space: pre-wrap; line-height: 1.6; font-size: 1rem; }
.v2-forward-content { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.v2-forward { margin-bottom: 8px; color: var(--muted); }
.v2-forward-toggle { margin-top: 4px; }
[role="alert"] { color: var(--danger) !important; }

.app-footer, .add-modal-footer { background: var(--footer); box-shadow: inset 0 1px var(--line); }
.feedback-links { display: flex; flex-wrap: wrap; align-items: center; gap: 0 16px; min-height: 36px; padding: 0 16px; font-size: .8125rem; line-height: 1.125rem; }
.feedback-links a { display: inline-flex; align-items: center; min-height: 24px; max-width: 100%; color: var(--muted); overflow-wrap: anywhere; }
.feedback-links .feedback-primary { color: var(--accent); font-weight: 600; }
.app-shell:has(+ .add-modal[open]) .app-footer .feedback-links { visibility: hidden; }

.add-modal {
  width: min(1120px, calc(100vw - 32px));
  height: min(720px, calc(100dvh - 32px));
  max-width: none;
  max-height: none;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 8px 32px var(--shadow);
}
.add-modal::backdrop { background: var(--backdrop); }
.add-modal-shell { height: 100%; display: flex; flex-direction: column; }
.add-modal-header, .add-modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 76px;
  padding: 8px 16px;
}
.add-modal-header { border-bottom: 1px solid var(--line); background: var(--header); }
.add-modal-header p { margin-top: 4px; font-size: .875rem; color: var(--muted); }
#add-close { flex-shrink: 0; }
.add-modal-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 44fr) minmax(0, 56fr); }
.add-mail-picker { display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 0; margin: 0; border: 0; border-right: 1px solid var(--line); }
.add-picker-header { flex-shrink: 0; max-height: 70%; overflow-y: auto; padding: 12px 16px 8px; }
.add-picker-header form { margin: 8px 0; }
.search-actions { display: flex; gap: 8px; margin-top: 4px; }
.search-actions input { flex: 1; }
.add-results-heading { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0 8px; }
.add-picker-header p { margin-top: 4px; font-size: .8125rem; color: var(--muted); }
.add-picker-header p:empty { display: none; }
#add-retry-mail { margin-top: 8px; }
.add-mail-results { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 4px 16px 12px; }
#add-mail-list li { margin-bottom: 6px; }
.select-mail {
  display: block;
  width: 100%;
  min-height: 68px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: left;
  background: var(--card);
  color: var(--text);
  overflow-wrap: anywhere;
}
.select-mail:hover:not(:disabled) { background: var(--canvas); }
.select-mail strong { font-size: .9375rem; font-weight: 600; }
.mail-candidate-meta { display: block; font-size: .8125rem; line-height: 1.125rem; font-weight: 400; color: var(--muted); }
.add-preview { --reading-inset: 16px; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.add-preview-toolbar { padding: 12px var(--reading-inset) 0; }
#add-conversation-empty { text-align: center; }
#add-retry-preview { margin-top: 8px; }
.add-modal-footer { flex-shrink: 0; }
.add-modal-actions { min-height: 64px; max-height: 24dvh; overflow-y: auto; }
.add-modal-actions p { font-size: .8125rem; line-height: 1.125rem; color: var(--muted); }
.add-modal-actions p:empty { display: none; }
#add-register-conversation { flex-shrink: 0; }
.add-modal-footer .feedback-links { border-top: 1px solid var(--line); }

.mail-tools { flex-shrink: 0; overflow: hidden; }
.mail-tools summary { padding: 8px 12px; cursor: pointer; font-weight: 600; }
.mail-tools-content { max-height: min(40vh, 24rem); overflow-y: auto; padding: 0 12px 12px; overscroll-behavior: contain; }
.mail-tools-content p { font-size: .875rem; }
#mail-search, #mail-list li { margin: 8px 0; }
#mail-search .search-actions { flex-wrap: wrap; }
dt { font-weight: 600; margin-top: 8px; }
dd { margin: 4px 0; white-space: pre-wrap; }

@media (width < 800px) {
  :root { --bubble-share: 96%; --reading-inset: 12px; --control-height: 44px; }
  .narrow-only { display: block; }
  .app-header, .signed-in .app-header {
    grid-template-columns: minmax(0, 1fr) minmax(0, max-content);
    grid-template-areas: "brand logout" "account legal";
    min-height: 84px;
    padding: 0 12px;
    gap: 0 8px;
  }
  html:not(.signed-in) .app-header { grid-template-areas: "brand brand" "legal legal"; }
  .brand .label, #account-username { display: none; }
  #account { padding: 0; border: 0; }
  .legal-links { gap: 0 8px; }
  #display-language { min-height: 32px; }
  .signed-in .legal-links { justify-content: flex-end; max-width: 64vw; }
  .workspace-viewport { padding: 8px; }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  #column-resizer, html:not(.signed-in) .sidebar, .signed-in [data-pane="chat"] .sidebar,
  .signed-in .workspace:not([data-pane="chat"]) .chat-column { display: none; }
  #login { min-height: 44px; }
  .chat-navigation { padding: 0 var(--reading-inset); }
  #registered-list li { --row-action: 44px; }
  #conversation-messages, #add-conversation-messages { padding-block: 12px; }
  .v2-bubble { padding: 10px 12px; }
  .feedback-links { gap: 0 12px; min-height: 44px; padding-inline: 12px; }
  .feedback-links a { min-height: 44px; }
  .add-modal { width: calc(100vw - 16px); height: calc(100dvh - 16px); }
  .add-modal-header { min-height: auto; padding: 12px; }
  .add-modal-body { grid-template-columns: minmax(0, 1fr); }
  .add-modal[data-pane="preview"] .add-mail-picker, .add-modal:not([data-pane="preview"]) .add-preview { display: none; }
  .add-mail-picker { border-right: 0; }
  .add-picker-header, .add-mail-results { padding-inline: 12px; }
  .add-preview { --reading-inset: 12px; }
  .add-preview-toolbar { padding-top: 0; }
  .add-modal-actions { flex-direction: column; align-items: stretch; justify-content: start; gap: 4px; padding: 8px 12px; min-height: 76px; }
}
