:root {
  color-scheme: light;
  --ink: #202522;
  --muted: #69726d;
  --line: #dce2dd;
  --canvas: #f3f5f2;
  --surface: #ffffff;
  --sidebar: #252b27;
  --sidebar-muted: #aeb8b1;
  --green: #17885e;
  --green-dark: #0e6947;
  --green-soft: #e3f3eb;
  --blue: #356fa8;
  --red: #c7493f;
  --red-soft: #fdebea;
  --amber: #a96c18;
  --shadow: 0 16px 46px rgba(25, 34, 29, 0.12);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--canvas); color: var(--ink); }
body { min-width: 320px; font-size: 14px; letter-spacing: 0; }
button, input, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
img { display: block; }
.hidden { display: none !important; }
.mobile-only { display: none !important; }

.skip-link {
  position: fixed; left: 16px; top: -80px; z-index: 1000; padding: 10px 14px;
  color: white; background: var(--ink); border-radius: 4px;
}
.skip-link:focus { top: 16px; }

.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); font-size: 17px; font-weight: 750; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; background: var(--green); border-radius: 6px; }
.brand-mark img { width: 18px; height: 18px; filter: brightness(0) invert(1); }
.brand.compact { color: white; min-width: 220px; }

.auth-view { min-height: 100vh; display: grid; grid-template-rows: 72px 1fr 56px; background: var(--canvas); }
.auth-header, .auth-footer { width: min(1120px, calc(100% - 48px)); margin: 0 auto; display: flex; align-items: center; justify-content: space-between; }
.service-state { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.state-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px var(--green-soft); }
.auth-main { width: min(1040px, calc(100% - 48px)); margin: auto; display: grid; grid-template-columns: minmax(300px, 1fr) 420px; align-items: center; gap: 96px; padding: 48px 0 64px; }
.auth-context { align-self: center; }
.domain-label { margin: 0 0 14px; color: var(--green-dark); font-weight: 700; }
.auth-context h1 { margin: 0; max-width: 500px; font-size: 44px; line-height: 1.12; letter-spacing: 0; }
.trust-list { display: flex; flex-wrap: wrap; gap: 10px 24px; margin-top: 34px; color: var(--muted); }
.trust-list div { display: flex; align-items: center; gap: 8px; }
.trust-list img { width: 17px; height: 17px; filter: invert(40%) sepia(59%) saturate(610%) hue-rotate(104deg); }
.auth-card { padding: 28px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
.segmented { display: grid; grid-template-columns: 1fr 1fr; height: 40px; padding: 3px; background: #eef1ee; border-radius: 6px; }
.segment { border: 0; border-radius: 4px; color: var(--muted); background: transparent; font-weight: 700; }
.segment.active { color: var(--ink); background: white; box-shadow: 0 1px 5px rgba(20, 30, 24, 0.12); }
.auth-form { display: grid; gap: 18px; padding-top: 28px; }
.form-heading h2 { margin: 0 0 5px; font-size: 23px; }
.form-heading p, .dialog-header p { margin: 0; color: var(--muted); }
.field { display: grid; gap: 7px; color: #424a45; font-weight: 650; }
.field input, .search-box input {
  width: 100%; height: 44px; border: 1px solid #cbd3cd; border-radius: 6px; outline: none;
  padding: 0 12px; color: var(--ink); background: white;
}
.field input:focus, .search-box:focus-within { border-color: var(--green); box-shadow: 0 0 0 3px rgba(23, 136, 94, 0.13); }
.password-field { position: relative; display: block; }
.password-field input { padding-right: 46px; }
.password-toggle { position: absolute; top: 4px; right: 4px; }
.domain-input { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; border: 1px solid #cbd3cd; border-radius: 6px; overflow: hidden; background: #f4f6f4; }
.domain-input:focus-within { border-color: var(--green); box-shadow: 0 0 0 3px rgba(23, 136, 94, 0.13); }
.domain-input input { border: 0; border-radius: 0; box-shadow: none !important; }
.domain-input > span { padding: 0 11px; color: var(--muted); font-weight: 500; white-space: nowrap; }
.check-row { display: flex; align-items: flex-start; gap: 9px; color: var(--muted); line-height: 1.45; }
.check-row input { width: 17px; height: 17px; margin: 1px 0 0; accent-color: var(--green); }
.form-error { min-height: 20px; margin: -4px 0; color: var(--red); font-size: 13px; }
.primary-button { height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 9px; border: 0; border-radius: 6px; padding: 0 17px; color: white; background: var(--green); font-weight: 750; }
.primary-button:hover { background: var(--green-dark); }
.primary-button:disabled { cursor: wait; opacity: 0.62; }
.primary-button img { width: 17px; height: 17px; filter: brightness(0) invert(1); }
.secondary-button { height: 40px; display: inline-flex; align-items: center; gap: 8px; border: 1px solid #cbd3cd; border-radius: 6px; padding: 0 14px; color: var(--ink); background: white; font-weight: 700; }
.secondary-button:hover { border-color: #9eaaa2; background: var(--canvas); }
.secondary-button img { width: 17px; height: 17px; }
.submit-button { width: 100%; }
.auth-footer { border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }

.icon-button { width: 36px; height: 36px; display: inline-grid; place-items: center; padding: 0; border: 0; border-radius: 6px; color: inherit; background: transparent; }
.icon-button:hover { background: rgba(45, 58, 50, 0.08); }
.icon-button img { width: 18px; height: 18px; }
.icon-button.danger:hover { background: var(--red-soft); }
.icon-button.danger img { filter: invert(37%) sepia(70%) saturate(862%) hue-rotate(319deg); }

.mail-view { height: 100vh; overflow: hidden; background: var(--surface); }
.app-header { position: relative; z-index: 20; height: 58px; display: flex; align-items: center; gap: 18px; padding: 0 18px; color: white; background: var(--sidebar); border-bottom: 1px solid #373e39; }
.search-box { width: min(520px, 44vw); height: 38px; margin: 0 auto; display: grid; grid-template-columns: 22px 1fr 32px; align-items: center; gap: 5px; border: 1px solid #4a554d; border-radius: 6px; padding: 0 5px 0 11px; background: #343c36; }
.search-submit { width: 22px; height: 34px; display: grid; place-items: center; padding: 0; border: 0; background: transparent; }
.search-submit img { width: 17px; height: 17px; filter: invert(80%); }
.search-box input { height: 34px; padding: 0; color: white; border: 0; background: transparent; box-shadow: none; }
.search-box input::placeholder { color: #abb4ad; }
.search-box .icon-button img { filter: invert(90%); }
.account-button { height: 40px; max-width: 260px; display: flex; align-items: center; gap: 9px; border: 0; border-radius: 6px; padding: 0 8px; color: white; background: transparent; }
.account-button:hover { background: #343c36; }
.account-button > img { width: 15px; filter: invert(1); }
.account-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.avatar { flex: 0 0 auto; width: 29px; height: 29px; display: grid; place-items: center; border-radius: 50%; color: white; background: var(--blue); font-weight: 750; text-transform: uppercase; }
.avatar.large { width: 38px; height: 38px; }
.account-menu { position: absolute; right: 18px; top: 52px; width: 190px; padding: 6px; border: 1px solid var(--line); border-radius: 7px; background: white; box-shadow: var(--shadow); }
.account-menu button { width: 100%; height: 38px; display: flex; align-items: center; gap: 10px; border: 0; border-radius: 5px; padding: 0 10px; color: var(--ink); background: transparent; text-align: left; }
.account-menu button:hover { background: var(--canvas); }
.account-menu img { width: 16px; }

.mail-layout { height: calc(100vh - 58px); display: grid; grid-template-columns: 230px 370px minmax(0, 1fr); }
.mail-sidebar { display: flex; flex-direction: column; padding: 16px 12px; color: white; background: var(--sidebar); border-right: 1px solid #343b36; }
.compose-button { width: 100%; height: 44px; display: flex; align-items: center; justify-content: center; gap: 9px; margin-bottom: 14px; border: 0; border-radius: 6px; color: white; background: var(--green); font-weight: 750; }
.compose-button:hover { background: #1a9568; }
.compose-button img { width: 18px; height: 18px; filter: brightness(0) invert(1); }
.folder-list { display: grid; gap: 3px; }
.folder-button, .sidebar-action { width: 100%; height: 40px; display: grid; grid-template-columns: 25px 1fr auto; align-items: center; gap: 8px; border: 0; border-radius: 6px; padding: 0 10px; color: var(--sidebar-muted); background: transparent; text-align: left; }
.folder-button:hover, .folder-button.active, .sidebar-action:hover { color: white; background: #37413a; }
.folder-button.active { box-shadow: inset 3px 0 var(--green); }
.folder-button img, .sidebar-action img { width: 17px; height: 17px; filter: invert(78%); }
.folder-button.active img { filter: brightness(0) invert(1); }
.folder-count { min-width: 22px; padding: 2px 6px; border-radius: 8px; color: white; background: var(--green); font-size: 11px; text-align: center; }
.sidebar-footer { margin-top: auto; display: grid; gap: 16px; }
.sidebar-action { grid-template-columns: 25px 1fr; }
.quota-row { padding: 0 10px; display: grid; grid-template-columns: 1fr auto; gap: 7px; color: var(--sidebar-muted); font-size: 11px; }
.quota-track { grid-column: 1 / -1; height: 4px; overflow: hidden; border-radius: 2px; background: #4a534d; }
.quota-track span { display: block; width: 1%; height: 100%; background: var(--green); }

.message-column { min-width: 0; overflow: hidden; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: #f9faf9; }
.column-header { flex: 0 0 78px; display: flex; align-items: center; justify-content: space-between; padding: 0 16px 0 20px; border-bottom: 1px solid var(--line); background: white; }
.column-header p { margin: 0 0 3px; color: var(--green-dark); font-size: 11px; font-weight: 750; text-transform: uppercase; }
.column-header h1 { margin: 0; font-size: 20px; }
.message-list { overflow: auto; flex: 1; }
.message-item { width: 100%; min-height: 94px; display: grid; grid-template-columns: 10px 1fr; border: 0; border-bottom: 1px solid #e5e9e6; padding: 14px 16px 13px 8px; color: var(--ink); background: #f9faf9; text-align: left; }
.message-item:hover { background: #f1f5f2; }
.message-item.active { background: var(--green-soft); }
.message-item.unread { background: white; }
.message-item.unread .message-sender, .message-item.unread .message-item-subject { font-weight: 800; }
.unread-dot { width: 7px; height: 7px; margin-top: 6px; border-radius: 50%; background: transparent; }
.message-item.unread .unread-dot { background: var(--green); }
.message-item-main { min-width: 0; }
.message-line { display: flex; justify-content: space-between; gap: 12px; }
.message-sender, .message-item-subject, .message-preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-item-subject, .message-preview { display: block; }
.message-date-small { flex: 0 0 auto; color: var(--muted); font-size: 11px; }
.message-item-subject { margin-top: 6px; font-size: 13px; }
.message-preview { margin-top: 5px; color: var(--muted); font-size: 12px; }
.message-status { padding: 9px 16px; color: var(--muted); border-bottom: 1px solid var(--line); background: #fff8e9; font-size: 12px; }
.message-empty { display: grid; place-items: center; min-height: 260px; padding: 30px; color: var(--muted); text-align: center; }
.load-more { flex: 0 0 40px; border: 0; border-top: 1px solid var(--line); color: var(--green-dark); background: white; font-weight: 700; }

.reader { min-width: 0; overflow: hidden; background: white; }
.reader-empty { height: 100%; display: grid; place-content: center; justify-items: center; color: var(--muted); text-align: center; }
.reader-empty > span { width: 54px; height: 54px; display: grid; place-items: center; border-radius: 50%; background: var(--green-soft); }
.reader-empty img { width: 24px; filter: invert(39%) sepia(38%) saturate(1056%) hue-rotate(105deg); }
.reader-empty h2 { margin: 16px 0 4px; color: var(--ink); font-size: 17px; }
.reader-empty p { margin: 0; }
.reader-content { height: 100%; display: flex; flex-direction: column; }
.reader-toolbar { flex: 0 0 50px; display: flex; align-items: center; gap: 5px; padding: 0 14px; border-bottom: 1px solid var(--line); }
.toolbar-spacer { flex: 1; }
.reader-scroll { overflow: auto; padding: 30px clamp(24px, 5vw, 72px) 60px; }
.message-header { max-width: 900px; margin: 0 auto; padding-bottom: 24px; border-bottom: 1px solid var(--line); }
.message-date { margin: 0 0 8px; color: var(--muted); font-size: 12px; }
.message-header h2 { margin: 0 0 22px; overflow-wrap: anywhere; font-size: 24px; line-height: 1.3; }
.sender-row { display: flex; align-items: center; gap: 11px; }
.sender-row strong { display: block; overflow-wrap: anywhere; }
.sender-row p { margin: 3px 0 0; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.message-text, .message-html { width: 100%; max-width: 900px; margin: 26px auto 0; border: 0; color: #2b302d; background: white; white-space: pre-wrap; overflow-wrap: anywhere; font: 14px/1.7 ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
.message-html { min-height: 520px; }
.attachment-list { max-width: 900px; margin: 20px auto 0; display: flex; flex-wrap: wrap; gap: 8px; }
.attachment { height: 38px; display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 6px; padding: 0 11px; color: var(--ink); background: var(--canvas); text-decoration: none; }
.attachment img { width: 16px; }
.reader-reply-actions { max-width: 900px; margin: 30px auto 0; display: flex; gap: 8px; padding-top: 20px; border-top: 1px solid var(--line); }

.dialog { width: min(620px, calc(100% - 28px)); max-height: min(720px, calc(100vh - 40px)); padding: 0; border: 0; border-radius: 8px; box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(22, 28, 24, 0.54); }
.dialog-shell { display: grid; gap: 20px; padding: 22px; }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; }
.dialog-header h2 { margin: 4px 0 0; font-size: 20px; }
.invite-create { display: grid; grid-template-columns: 1fr 1fr auto; align-items: end; gap: 10px; }
.new-invite { display: flex; align-items: center; justify-content: space-between; padding: 12px; border: 1px solid #b7dec9; border-radius: 6px; background: var(--green-soft); }
.new-invite code { font-size: 16px; font-weight: 800; }
.invite-list { max-height: 340px; overflow: auto; display: grid; gap: 8px; }
.invite-row { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 12px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 6px; }
.invite-row p { margin: 0 0 3px; font-weight: 700; }
.invite-row span { color: var(--muted); font-size: 12px; }
.status-pill { padding: 4px 7px; border-radius: 8px; color: var(--green-dark) !important; background: var(--green-soft); font-weight: 700; }
.status-pill.inactive { color: var(--red) !important; background: var(--red-soft); }
.small-dialog { width: min(440px, calc(100% - 28px)); }
.compose-dialog { width: min(760px, calc(100% - 28px)); max-height: min(820px, calc(100vh - 28px)); }
.compose-shell { height: min(720px, calc(100vh - 56px)); display: grid; grid-template-rows: auto auto minmax(220px, 1fr) auto auto; padding: 0; }
.compose-header { display: flex; align-items: flex-start; justify-content: space-between; padding: 18px 20px 14px; border-bottom: 1px solid var(--line); }
.compose-header p { margin: 0 0 2px; color: var(--green-dark); font-size: 11px; font-weight: 750; text-transform: uppercase; }
.compose-header h2 { max-width: 600px; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 19px; }
.compose-fields { padding: 0 20px; }
.compose-address-row, .compose-subject-row { min-height: 45px; display: grid; grid-template-columns: 68px minmax(0, 1fr) auto; align-items: center; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.compose-address-row input, .compose-subject-row input { width: 100%; min-width: 0; height: 43px; padding: 0; border: 0; outline: 0; color: var(--ink); background: transparent; }
.compose-address-row button { height: 32px; border: 0; padding: 0 4px 0 12px; color: var(--green-dark); background: transparent; font-weight: 700; }
.compose-subject-row { grid-template-columns: 68px minmax(0, 1fr); }
#compose-body { width: calc(100% - 40px); min-height: 220px; resize: none; margin: 14px 20px; padding: 0; border: 0; outline: 0; color: var(--ink); background: white; line-height: 1.65; }
.compose-attachments { max-height: 92px; overflow: auto; display: flex; flex-wrap: wrap; gap: 7px; padding: 10px 20px; border-top: 1px solid var(--line); }
.compose-attachment { max-width: 100%; height: 34px; display: grid; grid-template-columns: 16px minmax(0, 1fr) 28px; align-items: center; gap: 7px; border: 1px solid var(--line); border-radius: 6px; padding-left: 9px; background: var(--canvas); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compose-attachment > img { width: 15px; }
.compose-attachment .icon-button { width: 28px; height: 28px; }
.compose-attachment .icon-button img { width: 14px; }
.compose-error { min-height: 0; margin: 0; padding: 0 20px; }
.compose-error:not(:empty) { min-height: 34px; padding-top: 7px; border-top: 1px solid var(--line); }
.compose-footer { min-height: 58px; display: flex; align-items: center; gap: 8px; padding: 8px 16px 8px 20px; border-top: 1px solid var(--line); background: #f9faf9; }
.compose-size { color: var(--muted); font-size: 12px; }
.toast-region { position: fixed; right: 18px; bottom: 18px; z-index: 100; display: grid; gap: 8px; }
.toast { min-width: 260px; max-width: 420px; padding: 12px 14px; border-radius: 6px; color: white; background: var(--ink); box-shadow: var(--shadow); }
.toast.error { background: var(--red); }

@media (max-width: 960px) {
  .auth-main { gap: 48px; }
  .auth-context h1 { font-size: 36px; }
  .mail-layout { grid-template-columns: 205px 340px minmax(0, 1fr); }
  .brand.compact { min-width: 185px; }
  .account-label { display: none; }
}

@media (max-width: 760px) {
  .mobile-only { display: inline-grid !important; }
  .auth-view { grid-template-rows: 64px 1fr 48px; }
  .auth-header, .auth-footer, .auth-main { width: min(100% - 28px, 460px); }
  .auth-main { display: block; padding: 20px 0 34px; }
  .auth-context { margin: 8px 4px 24px; }
  .auth-context h1 { font-size: 29px; }
  .trust-list { margin-top: 20px; gap: 8px 15px; font-size: 12px; }
  .auth-card { padding: 20px; }
  .auth-footer span:last-child { display: none; }
  .app-header { gap: 8px; padding: 0 10px; }
  .brand.compact { min-width: 0; }
  .brand.compact > span:last-child { display: none; }
  .search-box { width: auto; flex: 1; margin: 0; }
  .account-button > img { display: none; }
  .account-menu { right: 8px; }
  .mail-layout { position: relative; display: block; }
  .mail-sidebar { position: absolute; z-index: 15; inset: 0 auto 0 0; width: 250px; transform: translateX(-100%); transition: transform 180ms ease; box-shadow: var(--shadow); }
  .mail-sidebar.open { transform: translateX(0); }
  .message-column { width: 100%; height: 100%; border: 0; }
  .reader { position: absolute; z-index: 10; inset: 0; transform: translateX(100%); transition: transform 180ms ease; }
  .reader.open { transform: translateX(0); }
  .reader-scroll { padding: 22px 18px 48px; }
  .message-header h2 { font-size: 21px; }
  .invite-create { grid-template-columns: 1fr 1fr; }
  .invite-create .primary-button { grid-column: 1 / -1; }
  .compose-dialog { width: 100%; max-width: none; height: 100%; max-height: none; margin: 0; border-radius: 0; }
  .compose-shell { height: 100vh; }
  .compose-header { padding-top: max(14px, env(safe-area-inset-top)); }
  .compose-address-row, .compose-subject-row { grid-template-columns: 58px minmax(0, 1fr) auto; }
  .compose-subject-row { grid-template-columns: 58px minmax(0, 1fr); }
  #compose-body { min-height: 180px; }
  .reader-reply-actions { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .toast-region { left: 12px; right: 12px; bottom: 12px; }
  .toast { min-width: 0; max-width: none; }
}

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