:root {
  color-scheme: dark;
  --bg: #0b0f15;
  --sidebar: #090c12;
  --panel: #10151d;
  --panel-2: #151c27;
  --border: #263246;
  --border-soft: #1c2635;
  --text: #e4ebf5;
  --muted: #8798b1;
  --subtle: #647b9c;
  --accent: #2583ff;
  --accent-hover: #4b98ff;
  --accent-wash: #12233a;
  --success: #56a4ff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f2f4f7;
  --sidebar: #ffffff;
  --panel: #f8f9fb;
  --panel-2: #f0f2f5;
  --border: #d8dee7;
  --border-soft: #e8ebf0;
  --text: #242c38;
  --muted: #677589;
  --subtle: #8290a4;
  --accent: #1769d2;
  --accent-hover: #0d58ba;
  --accent-wash: #e5f0ff;
  --success: #1769d2;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; }
body { overflow: hidden; background: var(--bg); color: var(--text); font-size: 13px; }
button, input, select { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hidden { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.app-shell { display: grid; grid-template-columns: 280px minmax(330px, 380px) minmax(360px, 1fr); grid-template-rows: 62px auto minmax(0, 1fr); width: 100%; height: 100dvh; border-top: 4px solid #173866; }
.app-shell.empty-inboxes { grid-template-columns: 280px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
.app-shell.empty-inboxes .address-bar,
.app-shell.empty-inboxes .mail-column { display: none; }
.app-shell.empty-inboxes .reader-column { grid-column: 2; grid-row: 1; }
.sidebar { grid-column: 1; grid-row: 1 / -1; display: flex; flex-direction: column; min-width: 0; background: var(--sidebar); border-right: 1px solid var(--border); }
.brand-row { height: 68px; padding: 0 21px; display: flex; align-items: center; gap: 11px; border-bottom: 1px solid var(--border); }
.brand-mark, .modal-icon { display: grid; place-items: center; color: #fff; background: var(--accent); border-radius: 12px; }
.brand-mark { position: relative; width: 36px; height: 36px; overflow: hidden; background: #090c12; }
.brand-mark img { position: absolute; top: -7px; left: -25px; width: 86px; height: 86px; max-width: none; }
.brand-name { font-size: 16px; font-weight: 750; letter-spacing: -.35px; }
.theme-button { margin-left: auto; }
.sidebar-actions { padding: 17px 13px 10px; display: grid; gap: 8px; }
.button { min-height: 39px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; border-radius: 10px; padding: 0 14px; cursor: pointer; font-weight: 650; transition: background .15s ease, border-color .15s ease, transform .15s ease; white-space: nowrap; }
.button:active { transform: translateY(1px); }
.button-primary { background: var(--accent); color: white; }
.button-primary:hover { background: var(--accent-hover); }
.button-secondary { background: var(--panel-2); color: var(--text); border-color: var(--border); }
.button-secondary:hover { border-color: #42618a; background: #1b2738; }
.button:disabled { cursor: default; opacity: .4; }
.button-wide { width: 100%; height: 46px; font-size: 14px; }
.button-plus { font-size: 18px; line-height: 1; font-weight: 400; }
.button svg, .icon-button svg, .search-box svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
.quick-form input { width: 100%; height: 42px; padding: 0 13px; border: 1px solid var(--border); border-radius: 10px; color: var(--text); background: #111720; outline: none; }
.quick-form input::placeholder, .search-box input::placeholder { color: #70819a; }
.quick-form input:focus, .search-box:focus-within { border-color: #397bc9; }
.inbox-heading { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 12px; color: #8297b3; text-transform: uppercase; font-size: 10px; font-weight: 700; letter-spacing: .6px; }
.muted { color: var(--muted); }
.text-button { padding: 3px 0 3px 10px; color: #8ba0ba; border: 0; background: transparent; cursor: pointer; text-transform: none; font-size: 11px; font-weight: 450; letter-spacing: 0; }
.text-button:hover { color: #d6e7ff; }
.inbox-list { padding: 0 9px; overflow: auto; }
.inbox-item { min-width: 0; min-height: 46px; display: flex; align-items: center; gap: 5px; margin: 0 4px 5px; padding: 4px 6px 4px 11px; border: 1px solid transparent; border-radius: 10px; color: #aeb8c8; }
.inbox-item:hover { background: #111925; }
.inbox-item.active { color: #57a1ff; background: var(--accent-wash); border-color: #234a78; }
.inbox-select { min-width: 0; min-height: 34px; flex: 1; display: flex; align-items: center; gap: 9px; padding: 0; overflow: hidden; border: 0; background: transparent; color: inherit; text-align: left; cursor: pointer; }
.inbox-item svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.7; flex: 0 0 auto; }
.inbox-item-name { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.inbox-delete { width: 27px; height: 27px; flex: 0 0 27px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 7px; background: transparent; color: #8b96a7; font-size: 20px; line-height: 1; cursor: pointer; opacity: 0; visibility: hidden; transition: opacity .15s ease, background .15s ease, color .15s ease, visibility .15s ease; }
.inbox-item:hover .inbox-delete, .inbox-item:focus-within .inbox-delete { opacity: 1; visibility: visible; }
.inbox-delete:hover { color: #ff7768; background: #442722; }
.inbox-item.active .inbox-delete { color: #c08a69; }
.inbox-item.active .inbox-delete:hover { color: #ff9385; }
.sidebar-empty { margin: 38px 28px; color: #71819a; text-align: center; line-height: 1.55; }
.sidebar-empty p { margin: 2px 0; }
.sidebar-empty strong { color: var(--text); font-weight: 650; }
.sidebar-footer { margin-top: auto; height: 43px; display: grid; place-items: center; border-top: 1px solid var(--border); color: #7396c4; font-size: 9px; font-weight: 700; letter-spacing: .8px; }

.address-bar { grid-column: 2 / 4; grid-row: 1; min-width: 0; display: flex; align-items: center; gap: 9px; padding: 10px 14px 10px 20px; border-bottom: 1px solid var(--border); background: var(--bg); }
.mail-column { grid-column: 2; grid-row: 2 / 4; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--panel); border-right: 1px solid var(--border); }
.address-pill { display: flex; align-items: center; gap: 11px; min-width: 0; flex: 1; height: 39px; padding: 0 13px; border: 1px solid #234a78; border-radius: 10px; color: #57a1ff; background: #111d2d; }
.small-mail-icon { display: flex; }
.small-mail-icon svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.active-address { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; }
.copy-button { min-height: 38px; }
.icon-button { width: 34px; height: 34px; display: inline-grid; place-items: center; border: 1px solid transparent; border-radius: 9px; background: transparent; color: #8795a9; cursor: pointer; }
.icon-button:hover { border-color: #355273; color: var(--text); background: #172235; }
.inbox-info { padding: 15px 16px 12px; border-bottom: 1px solid var(--border); }
.inbox-info-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 39px; margin-bottom: 7px; }
.inbox-info-title #refreshButton.is-refreshing svg { animation: refresh-spin .8s linear infinite; }
@keyframes refresh-spin { to { transform: rotate(360deg); } }
.inbox-info-title strong { display: block; overflow: hidden; color: var(--text); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.inbox-info-title small { display: block; margin-top: 6px; color: #71849e; font-size: 10px; }
.search-box { height: 37px; display: flex; align-items: center; gap: 9px; padding: 0 10px; border: 1px solid var(--border); border-radius: 9px; color: #8797ad; background: #111720; }
.search-box svg { width: 15px; height: 15px; }
.search-box input { min-width: 0; flex: 1; border: 0; outline: 0; color: var(--text); background: transparent; }
.message-list { flex: 1; overflow: auto; }
.message-list-empty { padding: 90px 18px; color: #788ba4; text-align: center; }
.message-card { width: 100%; min-height: 74px; display: flex; align-items: center; gap: 12px; padding: 13px 17px; border: 0; border-bottom: 1px solid var(--border-soft); background: transparent; text-align: left; cursor: pointer; }
.message-card:hover { background: #141e2c; }
.message-card.selected { background: #14243a; box-shadow: inset 3px 0 var(--accent); }
.message-avatar, .sender-avatar { flex: 0 0 auto; display: grid; place-items: center; border-radius: 50%; color: white; background: #256fe5; font-weight: 700; }
.message-avatar { width: 38px; height: 38px; }
.message-card-content { min-width: 0; flex: 1; }
.message-card-top, .message-card-bottom { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.message-card-from { min-width: 0; overflow: hidden; color: var(--text); font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.message-card time { flex: 0 0 auto; color: #72839a; font-size: 10px; }
.message-card-subject { margin-top: 7px; overflow: hidden; color: #8290a4; text-overflow: ellipsis; white-space: nowrap; }
.attachment-dot { color: var(--accent); font-size: 12px; }

.reader-column { grid-column: 3; grid-row: 2 / 4; min-width: 0; min-height: 0; overflow: hidden; background: var(--panel); }
.reader-empty { height: 100%; min-height: 440px; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 28px; text-align: center; }
.empty-icon { width: 96px; height: 96px; display: grid; place-items: center; margin-bottom: 26px; border-radius: 20px; background: #14243a; color: #58a2ff; }
.empty-icon svg { width: 42px; height: 42px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }
.reader-empty h1 { margin: 0 0 10px; color: #edf0f4; font-size: 17px; letter-spacing: -.2px; }
.reader-empty p { margin: 0 0 22px; color: #8091a8; line-height: 1.7; }
.features { margin-top: 26px; color: #71849d; }
.feature-title { display: block; margin-bottom: 11px; text-transform: uppercase; font-size: 10px; font-weight: 700; letter-spacing: .6px; }
.feature-list { display: flex; justify-content: center; gap: 16px; flex-wrap: wrap; font-size: 11px; }
.feature-list b { padding-right: 4px; color: var(--success); }
.message-reader { height: 100%; min-height: 0; display: flex; flex-direction: column; }
.reader-toolbar { display: flex; align-items: center; gap: 12px; padding: 18px 24px 16px; border-bottom: 1px solid var(--border); }
.reader-toolbar, .reader-actions, .attachment-list { flex: 0 0 auto; }
.reader-subject-wrap { min-width: 0; flex: 1; }
.reader-toolbar h1 { margin: 0 0 11px; overflow-wrap: anywhere; color: #eef1f4; font-size: 17px; line-height: 1.4; }
.sender-line { display: flex; align-items: center; gap: 11px; color: #a8b3c2; font-size: 11px; }
.sender-avatar { width: 40px; height: 40px; }
.sender-meta { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.sender-meta #messageFrom { overflow-wrap: anywhere; color: var(--text); font-size: 13px; font-weight: 650; }
.sender-to { color: #74859c; font-size: 11px; }
.reader-toolbar time { flex: 0 0 auto; padding: 6px 10px; border-radius: 18px; color: #77889f; background: var(--panel-2); font-size: 10px; }
.reader-actions { min-height: 54px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 24px; border-bottom: 1px solid var(--border); }
.reader-actions .button { min-height: 34px; padding: 0 12px; font-size: 11px; }
.button-danger { color: #ff6860; }
.button-danger:hover { border-color: #713a39; color: #ff8b83; background: #2a1b1d; }
.attachment-list { display: flex; gap: 8px; padding: 14px 26px 0; flex-wrap: wrap; }
.attachment-chip { min-height: 35px; display: inline-flex; align-items: center; gap: 8px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; color: #c9d2df; background: #1d2128; cursor: pointer; font-size: 11px; }
.attachment-chip:hover { border-color: #616b79; }
.attachment-chip span { max-width: 210px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-content { min-height: 0; flex: 1 1 auto; display: flex; padding: 20px 26px 24px; overflow: hidden; }
.message-content iframe { display: block; width: 100%; height: 100%; min-height: 0; flex: 1 1 auto; border: 0; border-radius: 7px; background: #fff; }
.message-content pre { min-width: 0; flex: 1 1 auto; margin: 0; overflow: auto; color: #d9dee7; font: 13px/1.65 ui-monospace, SFMono-Regular, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.reader-placeholder { max-width: 740px; margin: auto; padding: 15vh 20px; color: #66758a; text-align: center; }
.reader-placeholder svg { width: 42px; height: 42px; margin-bottom: 10px; fill: none; stroke: #556070; stroke-width: 1.5; }
.reader-placeholder p { margin: 0; }
.mobile-back { display: none; }

.modal-backdrop { position: fixed; z-index: 10; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(0, 0, 0, .62); backdrop-filter: blur(3px); }
.modal { width: min(100%, 460px); padding: 24px; border: 1px solid #373c46; border-radius: 17px; background: #111319; box-shadow: 0 24px 80px #0008; }
.modal-heading { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.modal-icon { width: 40px; height: 40px; flex: 0 0 auto; border-radius: 12px; color: #58a2ff; background: #14243a; }
.modal-icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.modal-heading h2 { margin: 0 0 4px; font-size: 14px; }
.modal-heading p { margin: 0; color: #7e8a9b; font-size: 11px; }
.modal-close { margin-left: auto; align-self: flex-start; font-size: 22px; }
.address-fields { display: grid; grid-template-columns: minmax(0, 1fr) 18px minmax(0, 1fr); align-items: center; gap: 5px; }
.address-fields input, .address-fields select { width: 100%; min-width: 0; height: 42px; padding: 0 11px; border: 1px solid #2b3d56; border-radius: 10px; background: #111923; color: var(--text); }
.address-fields select { padding-right: 25px; }
.at-sign { color: #99a5b5; text-align: center; font-weight: 700; }
.address-preview { margin-top: 11px; padding: 12px 10px; overflow: hidden; border: 1px solid #234a78; border-radius: 10px; color: #58a2ff; background: #111d2d; text-align: center; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; }
.form-error { min-height: 16px; margin: 8px 0 0; color: #ff927e; font-size: 11px; }
.modal-actions { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.cancel-button { color: #8992a0; }
.use-address { min-width: 138px; margin-left: auto; }
.privacy-note { margin: 15px 0 0; color: #6f7e92; font-size: 10px; line-height: 1.45; text-align: center; }
.toast { position: fixed; z-index: 20; left: 50%; bottom: 25px; max-width: calc(100% - 32px); padding: 10px 15px; border: 1px solid #2c405b; border-radius: 9px; color: var(--text); background: #172235; box-shadow: 0 7px 28px #0007; opacity: 0; transform: translate(-50%, 10px); pointer-events: none; transition: opacity .2s ease, transform .2s ease; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

:root[data-theme="light"] .quick-form input,
:root[data-theme="light"] .search-box,
:root[data-theme="light"] .address-fields input,
:root[data-theme="light"] .address-fields select { background: #fff; color: var(--text); }
:root[data-theme="light"] .address-pill { color: #1769d2; background: #eaf3ff; border-color: #bfd9fb; }
:root[data-theme="light"] .inbox-item:hover,
:root[data-theme="light"] .message-card:hover { background: #edf0f4; }
:root[data-theme="light"] .message-card.selected { background: #e5f0ff; box-shadow: inset 3px 0 #1769d2; }
:root[data-theme="light"] .message-card-subject,
:root[data-theme="light"] .reader-empty h1,
:root[data-theme="light"] .reader-toolbar h1 { color: #202a37; }
:root[data-theme="light"] .modal { background: #fff; border-color: #d8dee7; }
:root[data-theme="light"] .message-content pre { color: #303b49; }
:root[data-theme="light"] .attachment-chip { color: #354052; background: #fff; }
:root[data-theme="light"] .empty-icon { background: #e5f0ff; color: #1769d2; }

@media (max-width: 970px) {
  .app-shell { grid-template-columns: 250px minmax(300px, 360px) minmax(320px, 1fr); }
  .app-shell.empty-inboxes { grid-template-columns: 250px minmax(0, 1fr); }
  .brand-row { padding: 0 15px; }
  .address-bar { padding-left: 12px; }
  .reader-toolbar { padding: 20px 17px 15px; }
  .message-content, .attachment-list { padding-right: 17px; padding-left: 17px; }
}

@media (max-width: 880px) {
  html, body { min-height: 100%; }
  body { overflow: hidden; }
  .app-shell { display: block; position: relative; width: 100%; height: 100vh; height: 100dvh; min-height: 100svh; overflow: hidden; }
  .sidebar, .reader-column { position: absolute; inset: 0; width: 100%; height: 100%; }
  .address-bar { position: absolute; z-index: 4; top: 0; right: 0; left: 0; height: 62px; min-height: 62px; transform: translateX(100%); transition: transform .2s ease; }
  .mail-column { position: absolute; inset: 62px 0 0; width: 100%; height: auto; z-index: 2; transform: translateX(100%); transition: transform .2s ease; }
  .sidebar { z-index: 3; transform: translateX(-100%); transition: transform .2s ease; }
  .reader-column { z-index: 1; transform: translateX(100%); transition: transform .2s ease; }
  .app-shell.view-inboxes .sidebar { transform: translateX(0); }
  .app-shell.view-inboxes .address-bar,
  .app-shell.view-inboxes .mail-column,
  .app-shell.view-inboxes .reader-column { transform: translateX(100%); }
  .app-shell.view-messages .sidebar { transform: translateX(-100%); }
  .app-shell.view-messages .address-bar { transform: translateX(0); }
  .app-shell.view-messages .mail-column { z-index: 3; transform: translateX(0); }
  .app-shell.view-messages .reader-column { transform: translateX(100%); }
  .app-shell.view-reader .sidebar,
  .app-shell.view-reader .address-bar,
  .app-shell.view-reader .mail-column { transform: translateX(-100%); }
  .app-shell.view-reader .reader-column { z-index: 3; transform: translateX(0); }
  .mobile-back { display: inline-grid; flex: 0 0 auto; }
  .address-bar { gap: 4px; padding: 9px; }
  .address-bar .mobile-back { order: -1; }
  .copy-button { min-width: 40px; padding: 0 9px; font-size: 0; }
  .copy-button svg { width: 17px; }
  .reader-toolbar { padding: 15px 13px; }
  .reader-toolbar h1 { font-size: 15px; }
  .reader-toolbar time { font-size: 9px; }
  .message-content, .attachment-list { padding-right: 14px; padding-left: 14px; }
  .modal { padding: 20px; }
}

@media (hover: none) {
  .inbox-delete { opacity: 1; visibility: visible; }
}

@media (max-width: 380px) {
  .address-fields { grid-template-columns: minmax(0, 1fr) 14px minmax(0, .9fr); gap: 3px; }
  .address-fields input, .address-fields select { padding-right: 7px; padding-left: 8px; font-size: 12px; }
  .feature-list { gap: 9px 12px; }
  .reader-empty { padding: 15px; }
}
