:root {
  color-scheme: light;
  --bg: #eef3f7;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-strong: #ffffff;
  --line: rgba(29, 47, 68, 0.14);
  --text: #182435;
  --muted: #657486;
  --accent: #1d6f8f;
  --accent-2: #6c5ce7;
  --success: #21855f;
  --danger: #c53f58;
  --shadow: 0 20px 46px rgba(29, 47, 68, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "IBM Plex Sans KR", sans-serif;
  background:
    linear-gradient(135deg, rgba(29, 111, 143, 0.12), transparent 34%),
    linear-gradient(225deg, rgba(108, 92, 231, 0.12), transparent 32%),
    var(--bg);
  color: var(--text);
}

body {
  padding: 22px;
}

button,
input,
textarea {
  font: inherit;
}

select {
  font: inherit;
}

.lang-select {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--text);
  min-height: 42px;
  padding: 0 12px;
}

a {
  color: inherit;
  text-decoration: none;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 38px;
}

.hidden {
  display: none !important;
}

.app-shell {
  width: min(1520px, 100%);
  margin: 0 auto;
}

.top-bar,
.toolbar-card,
.card,
.summary-card,
.sidebar,
.guest-shell,
.compose-dialog {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.top-bar,
.toolbar-card,
.card,
.sidebar,
.guest-shell {
  border-radius: 24px;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  padding: 20px 22px;
}

.top-eyebrow {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.top-actions,
.toolbar-actions,
.submit-row,
.detail-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.icon-btn,
.primary-btn,
.ghost-btn,
.folder-btn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
  color: var(--text);
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.icon-btn:hover,
.primary-btn:hover,
.ghost-btn:hover,
.folder-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(29, 111, 143, 0.34);
}

.icon-btn {
  width: 42px;
  padding: 0;
  border-radius: 999px;
}

.primary-btn,
.ghost-btn {
  border-radius: 999px;
  padding: 0 16px;
}

.primary-btn {
  background: linear-gradient(135deg, var(--accent), #31a1b8);
  border-color: transparent;
  color: #fff;
}

.danger {
  color: var(--danger);
}

.status-line {
  min-height: 32px;
  padding: 12px 6px 0;
  color: var(--muted);
}

.guest-shell {
  margin-top: 18px;
  padding: 24px;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(260px, 0.8fr);
  gap: 22px;
}

.guest-copy,
.guest-highlights {
  display: grid;
  gap: 16px;
  align-content: start;
}

.guest-copy h2 {
  font-size: 28px;
}

.guest-text {
  color: var(--muted);
  line-height: 1.7;
}

.mail-view {
  display: grid;
  grid-template-columns: 220px minmax(360px, 0.9fr) minmax(420px, 1.1fr);
  gap: 16px;
  align-items: stretch;
  height: calc(100dvh - 150px);
  min-height: 560px;
  overflow: hidden;
}

.mail-view.list-collapsed {
  grid-template-columns: 220px minmax(0, 1fr);
}

.mail-view.list-collapsed .message-column {
  display: none;
}

.mail-view.list-collapsed .detail-card {
  grid-column: 2;
}

.sidebar {
  padding: 16px;
  display: grid;
  gap: 14px;
  align-content: start;
  min-height: 0;
  overflow-y: auto;
}

.compose-wide {
  width: 100%;
}

.folder-list {
  display: grid;
  gap: 8px;
}

.folder-btn {
  border-radius: 14px;
  min-height: 44px;
  padding: 0 12px;
  justify-content: space-between;
  text-align: left;
}

.folder-btn.active {
  background: rgba(29, 111, 143, 0.12);
  border-color: rgba(29, 111, 143, 0.28);
  color: var(--accent);
}

.folder-left {
  min-width: 0;
  display: inline-flex;
  gap: 8px;
  align-items: center;
}

.folder-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-count {
  color: var(--muted);
  font-size: 13px;
}

.message-column {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 14px;
  min-height: 0;
  overflow: hidden;
}

.toolbar-card {
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
}

.search-wrap {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
}

.search-wrap input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.summary-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.summary-card {
  border-radius: 18px;
  padding: 16px;
}

.summary-label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.summary-card strong {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 24px;
}

.card {
  padding: 18px;
}

.list-card {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.chip {
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(108, 92, 231, 0.1);
  color: var(--accent-2);
  font-size: 13px;
}

.message-list {
  display: grid;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
}

.mail-page-status { padding: 12px; text-align: center; color: var(--muted); font-size: 13px; }

.message-item {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.78);
  padding: 14px;
  text-align: left;
  cursor: pointer;
  display: grid;
  gap: 7px;
}

.message-item.active {
  border-color: rgba(29, 111, 143, 0.34);
  background: rgba(29, 111, 143, 0.08);
}

.message-item.unread .message-subject {
  font-weight: 700;
}

.message-subject-row {
  min-width: 0;
  display: flex;
  gap: 7px;
  align-items: center;
}

.message-subject-row .message-subject {
  flex: 1;
}

.message-row {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  min-width: 0;
}

.message-sender,
.message-subject,
.message-snippet {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-date,
.message-snippet {
  color: var(--muted);
  font-size: 13px;
}

.spam-badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid transparent;
}

.spam-spam {
  color: #9f1239;
  background: rgba(197, 63, 88, 0.12);
  border-color: rgba(197, 63, 88, 0.26);
}

.spam-suspicious {
  color: #9a5a00;
  background: rgba(245, 158, 11, 0.14);
  border-color: rgba(245, 158, 11, 0.28);
}

.spam-pass {
  color: #176649;
  background: rgba(33, 133, 95, 0.12);
  border-color: rgba(33, 133, 95, 0.24);
}

.spam-reasons {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.detail-card {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.empty-state {
  min-height: 260px;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.detail-panel {
  display: grid;
  align-content: start;
  gap: 18px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
}

.message-meta {
  display: grid;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
}

.message-meta h3 {
  font-size: 25px;
  line-height: 1.32;
}

.message-meta dl {
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr);
  gap: 8px 12px;
  margin: 0;
  color: var(--muted);
}

.message-meta dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--text);
}

.message-body {
  line-height: 1.75;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message-body.html-mode {
  white-space: normal;
}

.mail-thread {
  display: grid;
  gap: 12px;
}

.thread-message {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.72);
  white-space: pre-wrap;
}

.thread-message header,
.momotalk-participants {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.thread-message time {
  color: var(--muted);
  font-size: 12px;
}

.thread-toggle {
  display: flex;
  width: 100%;
  gap: 10px;
  align-items: center;
  text-align: left;
  color: inherit;
  background: transparent;
  border: 0;
  padding: 8px 0;
  cursor: pointer;
}
.thread-toggle strong { flex: 1; overflow-wrap: anywhere; }
.thread-toggle[aria-expanded="true"] { margin-bottom: 10px; }
.thread-content { overflow: visible; max-height: none; }
.thread-content .html-message { overflow: visible; max-height: none; }

.thread-attachments {
  margin: 12px 0 0;
}

.momotalk-participants {
  justify-content: flex-start;
  margin: 10px 0 0;
}

.remote-image-bar {
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid rgba(29, 111, 143, 0.18);
  border-radius: 14px;
  background: rgba(29, 111, 143, 0.08);
  color: var(--muted);
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.remote-image-bar .ghost-btn {
  min-height: 34px;
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.72);
}

.html-message {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  overflow-wrap: anywhere;
}

.html-message :is(h1, h2, h3, h4, p, ul, ol, blockquote, pre) {
  margin-top: 0;
  margin-bottom: 0.9rem;
}

.html-message a {
  color: var(--accent);
  text-decoration: underline;
}

.html-message img {
  max-width: 100%;
  height: auto;
  border-radius: 12px;
}

.html-message table {
  width: auto;
  max-width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  margin: 0;
  display: table;
}

.html-message th,
.html-message td {
  border: 0;
  padding: 0;
  vertical-align: top;
}

.html-message table:has(> thead th, > tbody > tr > th, > tr > th) {
  width: 100%;
  margin-bottom: 0.9rem;
}

.html-message table:has(> thead th, > tbody > tr > th, > tr > th) > thead > tr > th,
.html-message table:has(> thead th, > tbody > tr > th, > tr > th) > tbody > tr > th,
.html-message table:has(> thead th, > tbody > tr > th, > tr > th) > tbody > tr > td,
.html-message table:has(> thead th, > tbody > tr > th, > tr > th) > tr > th,
.html-message table:has(> thead th, > tbody > tr > th, > tr > th) > tr > td {
  border: 1px solid var(--line);
  padding: 6px 8px;
}

.html-message blockquote {
  margin: 8px 0;
  border-left: 3px solid rgba(29, 111, 143, 0.32);
  padding: 2px 0 2px 10px;
  color: var(--muted);
}

.html-message blockquote blockquote { margin: 4px 0; }
.mail-text-line { white-space: pre-wrap; min-height: 1.5em; }

.html-message pre {
  white-space: pre-wrap;
  padding: 12px;
  border-radius: 12px;
  background: rgba(24, 36, 53, 0.06);
}

.blocked-image {
  display: inline-flex;
  max-width: 100%;
  min-height: 38px;
  align-items: center;
  padding: 8px 10px;
  border: 1px dashed rgba(101, 116, 134, 0.45);
  border-radius: 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.58);
}

.text-fallback {
  margin-top: 16px;
  color: var(--muted);
}

.text-fallback pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text);
}

.compose-dialog {
  width: min(720px, calc(100vw - 28px));
  border-radius: 24px;
  padding: 0;
  color: var(--text);
}

.compose-dialog::backdrop {
  background: rgba(24, 36, 53, 0.42);
}

.compose-dialog form {
  display: grid;
  gap: 14px;
  padding: 22px;
}

.field-wrap {
  display: grid;
  gap: 8px;
}

.field-wrap .ql-toolbar.ql-snow {
  display: none;
}

body[data-compose-editor="rich"] .field-wrap .ql-toolbar.ql-snow {
  display: block;
}

.field-wrap span {
  color: var(--muted);
  font-size: 13px;
}

.field {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--text);
  padding: 12px 14px;
  outline: 0;
}

textarea.field {
  resize: vertical;
}

.compose-editor {
  display: block;
  min-height: 260px;
  width: 100%;
  border-radius: 14px;
  border: 1px solid var(--line);
  padding: 14px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  line-height: 1.65;
  resize: vertical;
  outline: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

#compose-body-rich {
  display: none;
}

.compose-body-input {
  display: none;
}

body[data-compose-editor="rich"] #compose-body-rich {
  display: block;
}

body[data-compose-editor="plain"] .compose-body-input {
  display: block;
}

#compose-body-rich.ql-container.ql-snow {
  min-height: 220px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
}

#compose-body-rich .ql-editor {
  min-height: 220px;
  line-height: 1.65;
}

#compose-body-rich .ql-editor.ql-blank::before {
  color: rgba(101, 116, 139, 0.72);
  font-style: normal;
}

.field-wrap .ql-toolbar.ql-snow {
  border: 1px solid var(--line);
  border-radius: 14px 14px 0 0;
  background: rgba(248, 250, 252, 0.92);
}

.compose-editor:focus,
.field:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(44, 104, 211, 0.12);
}

.compose-attachments {
  display: grid;
  gap: 8px;
}

.compose-attachment-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.attachment-picker {
  cursor: pointer;
}

.attachment-limit,
.attachment-size {
  color: var(--muted);
  font-size: 12px;
}

.compose-attachment-list,
.message-attachments ul {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.compose-attachment-list li,
.message-attachments li {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.72);
}

.attachment-name {
  min-width: 0;
  overflow: hidden;
  flex: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-attachments {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.message-attachments h4 {
  margin: 0 0 8px;
}

.plain-message {
  margin: 0;
  color: inherit;
  font: inherit;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.compose-status {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.compose-status.error {
  color: var(--danger);
}

.submit-row {
  justify-content: flex-end;
}

.callback-shell {
  min-height: calc(100vh - 44px);
  display: grid;
  place-items: center;
}

.callback-card {
  width: min(520px, 100%);
}

.mobile-mail-tabs,
.mobile-settings-view {
  display: none;
}

@media (max-width: 1120px) {
  .mail-view {
    grid-template-columns: 180px minmax(0, 1fr);
  }

  .mail-view.list-collapsed {
    grid-template-columns: 180px minmax(0, 1fr);
  }

  .detail-card {
    grid-column: 1 / -1;
    min-height: 420px;
    position: static;
  }

  .mail-view.list-collapsed .detail-card {
    grid-column: 2;
  }
}

@media (max-width: 760px) {
  html,
  body {
    min-height: 100dvh;
    overflow-x: clip;
  }

  body {
    padding: 8px 8px calc(84px + env(safe-area-inset-bottom));
  }

  h1 {
    font-size: 30px;
  }

  .top-bar,
  .guest-shell,
  .toolbar-card,
  .summary-row,
  .mail-view {
    grid-template-columns: 1fr;
  }

  .top-bar {
    position: sticky;
    z-index: 30;
    top: 8px;
    align-items: flex-start;
    padding: 14px;
    border-radius: 18px;
    backdrop-filter: blur(18px);
  }

  .top-actions {
    flex-wrap: nowrap;
    overflow-x: auto;
    max-width: 100%;
    scrollbar-width: none;
  }

  .top-actions::-webkit-scrollbar {
    display: none;
  }

  .top-actions .icon-btn,
  .top-actions .lang-select {
    flex: 0 0 44px;
    min-height: 44px;
  }

  #compose-btn {
    display: none;
  }

  .top-actions > .lang-select {
    display: none;
  }

  .sidebar {
    position: static;
  }

  .folder-list {
    display: flex;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

  .folder-list::-webkit-scrollbar {
    display: none;
  }

  .folder-btn {
    flex: 0 0 auto;
    min-height: 44px;
  }

  .summary-row {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
  }

  .summary-row::-webkit-scrollbar {
    display: none;
  }

  .summary-row .summary-card {
    flex: 0 0 min(70vw, 230px);
    scroll-snap-align: start;
  }

  .toolbar-card {
    display: grid;
  }

  .mail-view,
  .mail-view.list-collapsed {
    height: auto;
    min-height: 0;
    overflow: visible;
  }

  body[data-mobile-mail-view="mailbox"] .detail-card,
  body[data-mobile-mail-view="settings"] .mail-view {
    display: none;
  }

  body[data-mobile-mail-view="detail"] .sidebar,
  body[data-mobile-mail-view="detail"] .message-column {
    display: none;
  }

  body[data-mobile-mail-view="detail"] .mail-view,
  body[data-mobile-mail-view="detail"] .detail-card {
    display: block;
    grid-column: 1;
    width: 100%;
  }

  body[data-mobile-mail-view="detail"] .detail-card {
    min-height: calc(100dvh - 176px);
  }

  .mobile-mail-tabs {
    position: fixed;
    z-index: 1500;
    right: 8px;
    bottom: max(8px, env(safe-area-inset-bottom));
    left: 8px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 16px 38px rgba(29, 47, 68, 0.2);
    backdrop-filter: blur(18px);
  }

  .mobile-mail-tab {
    min-width: 0;
    min-height: 52px;
    padding: 5px 3px;
    border: 0;
    border-radius: 15px;
    background: transparent;
    color: var(--muted);
    display: grid;
    place-items: center;
    gap: 1px;
    font-size: 11px;
    font-weight: 600;
  }

  .mobile-mail-tab .material-symbols-rounded {
    font-size: 22px;
  }

  .mobile-mail-tab.active {
    background: rgba(29, 111, 143, 0.12);
    color: var(--accent);
  }

  .mobile-settings-view {
    min-height: calc(100dvh - 176px);
    padding: 18px;
    border-radius: 20px;
    align-content: start;
    gap: 10px;
  }

  .mobile-settings-view:not(.hidden) {
    display: grid;
  }

  .mobile-settings-head {
    padding: 4px 2px 14px;
  }

  .mobile-setting-row {
    width: 100%;
    min-height: 70px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.86);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    text-align: left;
  }

  .mobile-setting-row strong,
  .mobile-setting-row small {
    display: block;
  }

  .mobile-setting-row small {
    margin-top: 4px;
    color: var(--muted);
    line-height: 1.4;
  }

  .mobile-setting-row.danger {
    color: var(--danger);
  }

  .mail-view.list-collapsed {
    grid-template-columns: 1fr;
  }

  .mail-view.list-collapsed .detail-card {
    grid-column: 1;
  }

  .message-list,
  .detail-panel {
    max-height: none;
    overflow-y: visible;
    overscroll-behavior: auto;
  }

  .list-card,
  .detail-card {
    display: block;
    overflow: visible;
  }

  .compose-dialog {
    width: 100vw;
    max-width: none;
    height: 100dvh;
    max-height: none;
    margin: 0;
    border-radius: 0;
    overflow: hidden;
  }

  .compose-dialog form {
    height: 100dvh;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  }

  .compose-editor {
    min-height: 32dvh;
    resize: vertical;
  }

  #compose-body-rich .ql-editor {
    overflow-y: visible;
  }
}

/* Keep intrinsic editor/filename widths inside the composer grid. */
.compose-dialog, .compose-dialog form { box-sizing: border-box; }
.compose-dialog form { grid-template-columns: minmax(0, 1fr); }
.compose-dialog form > *, .field-wrap, .compose-editor, .compose-attachment-list li { min-width: 0; max-width: 100%; }
.compose-dialog { overflow-x: hidden; }
.compose-attachment-list .attachment-name { overflow-wrap: anywhere; }
.compose-dialog .submit-row { position: sticky; bottom: 0; background: var(--surface, white); padding-block: 8px; display: flex; justify-content: flex-end; flex-wrap: wrap; }
.transfer-progress { width: 100%; }
