* { box-sizing: border-box; }
* { scrollbar-width: thin; scrollbar-color: #96a8bc #edf2f7; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: #edf2f7; border-radius: 999px; }
*::-webkit-scrollbar-thumb { background: #96a8bc; border: 2px solid #edf2f7; border-radius: 999px; }
*::-webkit-scrollbar-thumb:hover { background: #758aa1; }
body { margin: 0; font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: #f5f7fa; color: #1f2933; }
button, input, select { font: inherit; }
button { border: 0; border-radius: 6px; padding: 9px 14px; cursor: pointer; background: #dde5ee; color: #162231; }
button:hover:not(:disabled) { background: #ccd8e3; }
button:disabled { cursor: not-allowed; opacity: 0.6; }
input, select { width: 100%; border: 1px solid #c8d3df; border-radius: 6px; padding: 9px 10px; background: #fff; color: #162231; }
label { display: grid; gap: 6px; font-size: 13px; color: #52616f; }
.hidden { display: none !important; }
.primary { background: #0f62fe; color: #fff; }
.primary:hover:not(:disabled) { background: #0b4fd0; }
.danger { background: #fee2e2; color: #b42318; }
.danger:hover:not(:disabled) { background: #fecaca; }
.ghost { background: transparent; border: 1px solid #c8d3df; }
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(420px, 100%); background: #fff; border: 1px solid #d7e0ea; border-radius: 8px; padding: 22px; display: grid; gap: 14px; }
.auth-card h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: 0; }
.shell { min-height: 100vh; height: 100vh; display: grid; grid-template-rows: auto minmax(0, 1fr); overflow: hidden; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 14px 22px; background: #fff; border-bottom: 1px solid #d7e0ea; }
.brand { min-width: 0; display: flex; align-items: baseline; gap: 10px; }
.brand h1 { margin: 0; font-size: 20px; letter-spacing: 0; }
.brand span { color: #66788a; font-size: 13px; }
.nav { display: flex; gap: 8px; }
.nav button { background: #edf2f7; }
.nav button.active { background: #0f62fe; color: #fff; }
.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-left: auto; }
.icon-button { width: 38px; height: 38px; display: inline-grid; place-items: center; padding: 0; font-size: 20px; line-height: 1; }
.icon-button svg { width: 18px; height: 18px; stroke: currentColor; }
.user-menu { position: relative; }
.user-button { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: #edf2f7; }
.user-dropdown { position: absolute; top: calc(100% + 8px); right: 0; z-index: 15; width: 168px; padding: 6px; display: grid; gap: 4px; background: #fff; border: 1px solid #d7e0ea; border-radius: 8px; box-shadow: 0 12px 28px rgba(15, 23, 42, 0.14); }
.user-dropdown button { width: 100%; text-align: left; background: transparent; }
.user-dropdown button:hover { background: #edf2f7; }
main { min-height: 0; overflow: hidden; display: grid; grid-template-rows: auto minmax(0, 1fr); }
.page { min-height: 0; padding: 0 18px 18px; display: flex; flex-direction: column; overflow: hidden; }
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.menu-header { padding: 18px 18px 0; }
.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 370px minmax(0, 1fr); gap: 18px; }
.panel { min-height: 0; overflow: hidden; display: flex; flex-direction: column; background: #fff; border: 1px solid #d7e0ea; border-radius: 8px; }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid #e4eaf1; }
.mailbox-header { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; }
.mailbox-header-title { display: flex; align-items: center; gap: 4px; min-width: 0; }
.collapse-toggle { display: none; width: 30px; height: 30px; font-size: 16px; flex-shrink: 0; }
.collapse-toggle svg { width: 16px; height: 16px; transition: transform 160ms ease; }
.mailbox-panel.collapsed .collapse-icon { transform: rotate(180deg); }
.mail-detail-header { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
.mail-detail-heading { min-width: 0; display: grid; gap: 4px; }
.mail-title-row { min-width: 0; display: flex; align-items: center; gap: 12px; }
.mail-detail-heading .panel-title { min-width: 0; overflow: hidden; }
.mail-detail-heading .item-meta { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-folder-controls { min-width: 200px; max-width: 320px; flex: 0 1 280px; }
.mail-folder-controls label { min-width: 0; display: flex; align-items: center; gap: 8px; font-size: 12px; white-space: nowrap; }
.mail-folder-controls select { padding: 6px 8px; font-size: 13px; }
.panel-title { margin: 0; font-size: 16px; letter-spacing: 0; white-space: nowrap; flex-shrink: 0; }
.panel-body { flex: 1; min-height: 0; padding: 16px; overflow: hidden; }
.panel-body.stack { display: flex; flex-direction: column; gap: 12px; }
.page > .panel { flex: 1; }
.stack { display: grid; gap: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.input-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: end; }
.input-row button { white-space: nowrap; }
.status { min-height: 22px; color: #52616f; font-size: 14px; }
.status.error { color: #b42318; }
.toast-container { position: fixed; top: 76px; left: 50%; transform: translateX(-50%); z-index: 60; display: grid; gap: 10px; width: min(360px, calc(100vw - 32px)); pointer-events: none; }
.toast { pointer-events: auto; padding: 12px 14px; border: 1px solid #d7e0ea; border-left: 4px solid #0f62fe; border-radius: 8px; background: #fff; color: #263646; box-shadow: 0 12px 28px rgba(15, 23, 42, 0.14); overflow-wrap: anywhere; transition: opacity 160ms ease, transform 160ms ease; }
.toast.success { border-left-color: #16a34a; }
.toast.error { border-left-color: #dc2626; }
.toast.exiting { opacity: 0; transform: translateY(-6px); }
.list { display: grid; align-content: start; gap: 10px; }
.item { border: 1px solid #d7e0ea; border-radius: 8px; padding: 12px; background: #fff; }
.item.clickable { cursor: pointer; }
.item.clickable:hover { border-color: #8bb7ff; background: #f8fbff; }
.item.active { border-color: #0f62fe; box-shadow: inset 3px 0 0 #0f62fe; }
.item-main { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.item-title { font-weight: 650; overflow-wrap: anywhere; }
.item-meta { margin-top: 5px; color: #66788a; font-size: 13px; overflow-wrap: anywhere; }
.item-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.floating-tooltip { position: fixed; z-index: 100; max-width: min(320px, calc(100vw - 16px)); padding: 6px 8px; border-radius: 6px; background: #162231; color: #fff; font-size: 12px; font-weight: 500; line-height: 1.35; white-space: nowrap; pointer-events: none; opacity: 0; transform: translateY(2px); box-shadow: 0 12px 28px rgba(15, 23, 42, 0.18); transition: opacity 140ms ease, transform 140ms ease; }
.floating-tooltip.visible { opacity: 1; transform: translateY(0); }
.floating-tooltip.below { transform: translateY(-2px); }
.floating-tooltip.below.visible { transform: translateY(0); }
.mailbox-item .item-main { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
.mailbox-item .item-main > div { min-width: 0; }
.mailbox-email-title { max-width: 100%; }
.mailbox-item { touch-action: pan-y; user-select: none; }
.mailbox-item.dragging { opacity: 0.72; border-color: #0f62fe; background: #eef4ff; box-shadow: 0 12px 28px rgba(15, 23, 42, 0.14); cursor: grabbing; }
.mailbox-item.pinned { border-color: #7db0ff; background: #f8fbff; }
.mailbox-item-side { display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0; }
.drag-handle { width: 28px; height: 28px; display: inline-grid; place-items: center; border-radius: 999px; color: #8a9aaa; cursor: grab; touch-action: none; }
.drag-handle:hover { background: #edf2f7; color: #0f62fe; }
.drag-handle:focus-visible { outline: 2px solid #0f62fe; outline-offset: 2px; }
.drag-handle svg { width: 16px; height: 16px; stroke: currentColor; }
.mailbox-item.dragging .drag-handle { cursor: grabbing; color: #0f62fe; background: #dbeafe; }
.pin-button { width: 28px; height: 28px; display: inline-grid; place-items: center; padding: 0; border-radius: 999px; background: #edf2f7; color: #66788a; }
.pin-button:hover:not(:disabled) { background: #dbeafe; color: #0f62fe; }
.pin-button.active { background: #dbeafe; color: #0f62fe; }
.pin-button svg { width: 15px; height: 15px; stroke: currentColor; }
#mailboxList.drag-active { cursor: grabbing; }
#mailboxList.drag-active .mailbox-item:not(.dragging) { transition: transform 120ms ease; }
.provider-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px; align-items: start; }
.provider-content { min-width: 0; }
.provider-main { display: block; }
.provider-side { display: grid; justify-items: end; align-content: start; gap: 18px; }
.provider-actions { margin-top: 0; justify-content: flex-end; flex-wrap: nowrap; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 3px 8px; background: #edf2f7; color: #52616f; font-size: 12px; white-space: nowrap; }
.badge.ok { background: #dcfce7; color: #166534; }
.badge.off { background: #f1f5f9; color: #64748b; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.panel-header > .toolbar { flex-wrap: nowrap; flex-shrink: 0; }
.search-input { min-width: 0; padding: 8px 10px; }
.message-list { display: grid; align-content: start; gap: 8px; }
#mailboxList, #messageList, #providerList { flex: 1; min-height: 0; overflow: auto; padding-right: 4px; scrollbar-gutter: stable; }
#mailboxList { overflow-x: hidden; }
.message-button { width: 100%; text-align: left; background: #f8fafc; border: 1px solid #d7e0ea; border-left: 3px solid #0f62fe; }
.message-button:hover { background: #eef4fb; }
.title-copy { display: inline; padding: 0; border: 0; background: transparent; color: #0f62fe; font-size: inherit; font-weight: 650; text-align: left; overflow-wrap: anywhere; }
.mail-detail-heading .title-copy { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.title-copy:hover:not(:disabled) { background: transparent; text-decoration: underline; }
.empty { color: #66788a; text-align: center; padding: 24px 10px; border: 1px dashed #c8d3df; border-radius: 8px; }
.modal { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(15, 23, 42, 0.46); padding: 18px; z-index: 20; }
.modal.active { display: flex; }
.modal-card { width: min(820px, 100%); max-height: 88vh; min-height: 0; overflow: hidden; display: flex; flex-direction: column; background: #fff; border-radius: 8px; border: 1px solid #d7e0ea; }
.modal-head { display: flex; justify-content: space-between; gap: 12px; padding: 16px; border-bottom: 1px solid #e4eaf1; }
.modal-title { margin: 0; font-size: 18px; letter-spacing: 0; overflow-wrap: anywhere; }
.modal-body { min-height: 0; padding: 16px; overflow: auto; scrollbar-gutter: stable; }
.confirm-modal { z-index: 30; }
.confirm-card { width: min(440px, 100%); }
.confirm-message { color: #263646; line-height: 1.55; }
.confirm-detail { padding: 10px 12px; border: 1px solid #e4eaf1; border-radius: 8px; background: #f8fafc; color: #52616f; overflow-wrap: anywhere; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }
.confirm-actions button { min-width: 92px; }
.preview-box { padding: 10px 12px; border: 1px solid #d7e0ea; border-radius: 8px; background: #f8fafc; color: #263646; overflow-wrap: anywhere; }
.body-text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; margin-top: 14px; }
.mode-toggle { display: inline-flex; gap: 6px; padding: 4px; border-radius: 8px; background: #edf2f7; }
.mode-toggle button { padding: 6px 10px; background: transparent; }
.mode-toggle button.active { background: #0f62fe; color: #fff; }
.html-frame { width: 100%; min-height: 360px; border: 1px solid #d7e0ea; border-radius: 8px; background: #fff; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 14px; color: #52616f; }
.checkbox-row input { width: auto; }
@media (max-width: 920px) {
  .topbar { align-items: center; flex-direction: row; gap: 10px; padding: 12px 14px; }
  .brand h1 { font-size: 18px; }
  .user-button { max-width: 150px; }
  .toast-container { top: 68px; width: calc(100vw - 28px); }
  .layout { grid-template-columns: 1fr; grid-template-rows: minmax(260px, 40%) minmax(320px, 60%); }
  .layout.mailbox-list-collapsed { grid-template-rows: auto minmax(0, 1fr); }
  .collapse-toggle { display: inline-grid; }
  .mailbox-panel.collapsed #mailboxPanelBody { display: none; }
  .mail-title-row { align-items: stretch; flex-direction: column; gap: 6px; }
  .mail-folder-controls { min-width: 0; max-width: none; flex: none; }
  .mail-folder-controls label { align-items: stretch; flex-direction: column; gap: 4px; white-space: normal; }
  .panel-body { overflow: auto; scrollbar-gutter: stable; }
  #mailboxList { flex: 0 0 auto; min-height: auto; overflow: visible; padding-right: 0; }
  .provider-item { display: block; }
  .provider-side { display: contents; }
  .provider-actions { margin-top: 10px; justify-content: flex-start; flex-wrap: wrap; }
  .grid-2 { grid-template-columns: 1fr; }
}
