:root {
  color-scheme: light;
  --navy-950: #0b1d2e;
  --navy-900: #10283f;
  --navy-800: #173954;
  --blue-600: #176fd1;
  --blue-100: #ddecfb;
  --blue-050: #edf6ff;
  --ink-900: #14202b;
  --ink-600: #536270;
  --ink-400: #82909d;
  --line: #dbe3ea;
  --canvas: #edf2f6;
  --paper: #ffffff;
  --success: #2d9d78;
  --danger: #b53b48;
  font-family: Aptos, "Segoe UI", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  color: var(--ink-900);
  background: var(--canvas);
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(23, 111, 209, .28);
  outline-offset: 2px;
}

.login-page {
  display: grid;
  min-height: 100%;
  place-items: center;
  padding: 24px;
  background: #f4f6f8;
}

.login-shell {
  width: min(400px, 100%);
}

.brand-mark {
  display: grid;
  width: 50px;
  height: 50px;
  place-items: center;
  border-radius: 13px;
  color: white;
  background: var(--blue-600);
  font-size: 24px;
  font-weight: 750;
}

.brand-mark.small {
  width: 38px;
  height: 38px;
  margin: 0;
  border-radius: 11px;
  font-size: 18px;
}

.login-panel {
  display: grid;
  gap: 24px;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  box-shadow: 0 10px 30px rgba(11, 29, 46, .08);
}

.login-heading { display: flex; align-items: center; gap: 14px; }
.login-panel h1 { margin: 0 0 4px; font-size: 22px; }
.login-panel p { margin: 0; color: var(--ink-600); }
.login-form { display: grid; gap: 18px; }

label { display: grid; gap: 8px; color: var(--ink-600); font-size: 14px; font-weight: 650; }
input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--ink-900);
  background: white;
}
input:focus, textarea:focus { border-color: var(--blue-600); outline: none; box-shadow: 0 0 0 3px rgba(23, 111, 209, .12); }

.primary-button {
  border: 0;
  border-radius: 10px;
  padding: 13px 18px;
  color: white;
  background: var(--blue-600);
  font-weight: 700;
}
.primary-button:hover { background: #0f61ba; }
.form-error { padding: 11px 13px; border-radius: 8px; color: #8e2834; background: #fbe9eb; font-size: 14px; }

.inbox-shell {
  display: grid;
  grid-template-columns: 370px minmax(0, 1fr);
  height: 100vh;
  min-height: 620px;
  overflow: hidden;
}

.conversation-panel {
  position: relative;
  z-index: 2;
  display: flex;
  min-width: 0;
  flex-direction: column;
  background: var(--paper);
  border-right: 1px solid var(--line);
}

.inbox-brand {
  display: flex;
  min-height: 76px;
  align-items: center;
  justify-content: space-between;
  padding: 15px 18px;
  color: white;
  background: var(--navy-950);
}

.brand-lockup { display: flex; align-items: center; gap: 12px; }
.brand-lockup strong { display: block; font-size: 16px; }
.connection-state { display: flex; align-items: center; gap: 6px; margin-top: 3px; color: #afbfcd; font-size: 12px; }
.connection-state i { width: 7px; height: 7px; border-radius: 50%; background: var(--success); }
.header-actions { display: flex; gap: 5px; }

.icon-button {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 0;
  border-radius: 9px;
  color: inherit;
  background: transparent;
}
.icon-button:hover { background: rgba(255, 255, 255, .1); }
.icon-button svg, .search-wrap svg, .attachment-button svg, .send-button svg { width: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.search-wrap { position: relative; padding: 14px 16px 10px; }
.search-wrap svg { position: absolute; top: 26px; left: 29px; width: 17px; color: var(--ink-400); }
.search-wrap input { padding: 10px 12px 10px 38px; border: 0; background: #f1f4f7; }

.conversation-list { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.conversation-row {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  gap: 11px;
  width: 100%;
  padding: 11px 10px;
  border: 0;
  border-radius: 12px;
  color: inherit;
  background: transparent;
  text-align: left;
}
.conversation-row:hover { background: #f3f6f9; }
.conversation-row.active { background: var(--blue-050); }
.conversation-copy { min-width: 0; align-self: center; }
.conversation-name-line { display: flex; justify-content: space-between; gap: 10px; }
.conversation-name { overflow: hidden; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.conversation-time { flex: none; color: var(--ink-400); font-size: 12px; font-weight: 500; }
.conversation-preview { display: flex; min-width: 0; align-items: center; justify-content: space-between; gap: 8px; margin-top: 5px; color: var(--ink-600); font-size: 13px; }
.conversation-preview span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread-count { min-width: 20px; padding: 2px 6px; border-radius: 999px; color: white; background: var(--blue-600); font-size: 11px; font-weight: 750; text-align: center; }

.contact-avatar {
  display: grid;
  width: 44px;
  height: 44px;
  flex: none;
  place-items: center;
  border-radius: 50%;
  color: var(--navy-900);
  background: var(--blue-100);
  font-size: 15px;
  font-weight: 750;
}
.conversation-row .contact-avatar { width: 48px; height: 48px; }

.thread-panel { min-width: 0; background: var(--canvas); }
.active-thread { display: grid; height: 100%; grid-template-rows: auto minmax(0, 1fr) auto auto; }
.thread-header { display: flex; min-height: 76px; align-items: center; gap: 12px; padding: 12px 24px; background: rgba(255,255,255,.96); border-bottom: 1px solid var(--line); }
.thread-contact { min-width: 0; }
.thread-contact strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-contact span { display: block; margin-top: 3px; color: var(--ink-600); font-size: 13px; }

.empty-state { display: grid; height: 100%; place-content: center; justify-items: center; padding: 30px; text-align: center; }
.empty-symbol { display: grid; width: 82px; height: 82px; place-items: center; border-radius: 26px; color: var(--blue-600); background: var(--blue-100); transform: rotate(-3deg); }
.empty-symbol svg { width: 48px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.empty-state h1 { margin: 24px 0 8px; font-size: 26px; letter-spacing: -.02em; }
.empty-state p { margin: 0; color: var(--ink-600); }

.message-list { overflow-y: auto; padding: 28px clamp(18px, 5vw, 72px); }
.message-day { width: max-content; margin: 4px auto 20px; padding: 5px 10px; border-radius: 999px; color: var(--ink-600); background: rgba(255,255,255,.8); font-size: 12px; }
.message-row { display: flex; margin: 6px 0; }
.message-row.outgoing { justify-content: flex-end; }
.message-bubble { position: relative; max-width: min(72%, 680px); padding: 9px 12px 7px; border-radius: 14px 14px 14px 4px; background: white; box-shadow: 0 1px 1px rgba(18, 39, 57, .08); }
.outgoing .message-bubble { border-radius: 14px 14px 4px 14px; background: #dcecff; }
.message-bubble.deleted { color: var(--ink-400); font-style: italic; }
.reply-reference { margin: 0 0 7px; padding: 5px 8px; border-left: 3px solid var(--blue-600); color: var(--ink-600); background: rgba(255,255,255,.52); border-radius: 4px; font-size: 12px; }
.message-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.42; }
.message-media { display: flex; align-items: center; gap: 7px; margin-bottom: 7px; color: var(--ink-600); font-size: 13px; }
.message-meta { display: flex; justify-content: flex-end; gap: 6px; margin-top: 4px; color: #667686; font-size: 11px; }
.reply-action { position: absolute; top: 50%; right: calc(100% + 7px); opacity: 0; transform: translateY(-50%); border: 0; border-radius: 8px; padding: 5px 7px; color: var(--ink-600); background: white; box-shadow: 0 2px 8px rgba(18,39,57,.12); }
.incoming .reply-action { right: auto; left: calc(100% + 7px); }
.message-row:hover .reply-action, .reply-action:focus-visible { opacity: 1; }

.reply-banner { display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 9px 18px; border-top: 1px solid var(--line); background: white; }
.reply-banner strong, .reply-banner span { display: block; }
.reply-banner strong { color: var(--blue-600); font-size: 12px; }
.reply-banner span { max-width: 65ch; margin-top: 2px; overflow: hidden; color: var(--ink-600); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.reply-banner .icon-button { color: var(--ink-600); font-size: 25px; }

.composer { display: flex; align-items: flex-end; gap: 10px; padding: 13px 18px; background: white; border-top: 1px solid var(--line); }
.attachment-button { display: grid; width: 42px; height: 42px; flex: none; place-items: center; border-radius: 10px; color: var(--ink-600); cursor: pointer; }
.attachment-button:hover { background: #f0f4f7; }
.attachment-button input { display: none; }
.compose-field { flex: 1; min-width: 0; }
.compose-field textarea { display: block; max-height: 150px; min-height: 42px; resize: none; }
.attachment-name { display: block; margin: 5px 4px 0; overflow: hidden; color: var(--ink-600); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.send-button { display: grid; width: 44px; height: 44px; flex: none; place-items: center; border: 0; border-radius: 13px; color: white; background: var(--blue-600); }
.send-button:hover { background: #0f61ba; }

.new-message-dialog { width: min(500px, calc(100% - 32px)); padding: 0; border: 0; border-radius: 16px; box-shadow: 0 24px 70px rgba(11,29,46,.3); }
.new-message-dialog::backdrop { background: rgba(11,29,46,.6); backdrop-filter: blur(3px); }
.new-message-dialog form { display: grid; gap: 17px; padding: 25px; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; }
.dialog-heading h2 { margin: 0 0 5px; }
.dialog-heading p { margin: 0; color: var(--ink-600); font-size: 14px; }
.dialog-heading .icon-button { flex: none; color: var(--ink-600); font-size: 25px; }
label span { font-weight: 400; }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 10; max-width: 390px; padding: 12px 15px; border-radius: 10px; color: white; background: var(--navy-900); box-shadow: 0 12px 35px rgba(11,29,46,.25); opacity: 0; pointer-events: none; transform: translateY(8px); transition: opacity .18s ease, transform .18s ease; }
.toast.visible { opacity: 1; transform: translateY(0); }
.list-empty { padding: 45px 24px; color: var(--ink-600); text-align: center; }
.mobile-only { display: none; }

@media (max-width: 760px) {
  .login-page { padding: 18px; }
  .login-panel { padding: 26px 22px; }

  .inbox-shell { display: block; min-height: 100dvh; }
  .conversation-panel, .thread-panel { height: 100dvh; }
  .thread-panel { display: none; }
  .inbox-shell.thread-open .conversation-panel { display: none; }
  .inbox-shell.thread-open .thread-panel { display: block; }
  .mobile-only { display: grid; }
  .thread-header { padding-inline: 12px 18px; }
  .message-list { padding: 22px 14px; }
  .message-bubble { max-width: 84%; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
