:root {
  color-scheme: light;
  --rt-primary: #006ab5;
  --rt-primary-dark: #00538f;
  --rt-success: #009416;
  --rt-warning: #eda509;
  --rt-danger: #c22515;
  --rt-nav: #333333;
  --rt-bg: #f5f6f8;
  --rt-panel: #ffffff;
  --rt-border: #dfe3e8;
  --rt-text: #1f2933;
  --rt-muted: #66717f;
  --rt-hover: #eef5fb;
  --rt-selected: #dcecf8;
  --rt-shadow: 0 8px 28px rgba(0,0,0,.08);
  font-family: Mulish, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--rt-bg); color: var(--rt-text); }
body { min-height: 100vh; }
h1,h2,h3,strong,.brand { font-family: Sora, Arial, sans-serif; }
a { color: var(--rt-primary-dark); }
button,input,select,textarea { font: inherit; }
button { cursor: pointer; }
label { display: grid; gap: .45rem; font-weight: 700; }
label small { font-weight: 400; color: var(--rt-muted); }
input,select,textarea { width: 100%; border: 1px solid #cbd2d9; border-radius: .45rem; padding: .72rem .8rem; background: #fff; color: var(--rt-text); }
input:focus,select:focus,textarea:focus,button:focus-visible,a:focus-visible { outline: 3px solid rgba(0,106,181,.24); outline-offset: 2px; }
textarea { resize: vertical; }
code,pre { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.wrap { overflow-wrap: anywhere; white-space: normal; }

.topbar { height: 58px; display: flex; align-items: center; gap: 1.25rem; padding: 0 1rem; background: var(--rt-nav); color: #fff; border-bottom: 1px solid #262626; }
.brand { display: inline-flex; align-items: center; gap: .55rem; color: #fff; text-decoration: none; min-width: 120px; }
.brand-mark { display: grid; place-items: center; width: 44px; height: 44px; border-radius: .65rem; background: var(--rt-primary); color: #fff; font-family: Sora,Arial,sans-serif; font-weight: 800; }
.brand-mark.small { width: 32px; height: 32px; border-radius: .45rem; }
.brand-row { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.5rem; }
.brand-row h1 { margin: 0; font-size: 1.35rem; }
.brand-row p { margin: .2rem 0 0; color: var(--rt-muted); }
.topnav { display: flex; align-items: stretch; gap: .2rem; height: 100%; }
.topnav a { display: flex; align-items: center; padding: 0 .8rem; color: #e8edf2; text-decoration: none; border-bottom: 3px solid transparent; }
.topnav a:hover,.topnav a.active { background: rgba(255,255,255,.08); border-bottom-color: #fff; color: #fff; }
.userbox { margin-left: auto; display: flex; align-items: center; gap: .8rem; font-size: .9rem; }
.userbox form { margin: 0; }
.link-button { border: 0; background: transparent; color: #fff; text-decoration: underline; padding: .25rem; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 40px; padding: .58rem .85rem; border-radius: .45rem; border: 1px solid #b9c2cc; background: #fff; color: var(--rt-text); font-weight: 700; text-decoration: none; }
.btn:hover { background: #f6f8fa; }
.btn.primary { background: var(--rt-primary); border-color: var(--rt-primary); color: #fff; }
.btn.primary:hover { background: var(--rt-primary-dark); }
.btn.danger { background: var(--rt-danger); border-color: var(--rt-danger); color: #fff; }
.btn.full { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-action { display: grid; place-items: center; width: 40px; height: 40px; border-radius: .5rem; border: 0; background: transparent; color: inherit; font-size: 1.4rem; }

.auth-page,.installer-body { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: #eef2f6; }
.auth-card,.installer-card { width: min(100%, 560px); background: #fff; border: 1px solid var(--rt-border); border-radius: .9rem; padding: 1.5rem; box-shadow: var(--rt-shadow); }
.installer-card { width: min(100%, 880px); }
.auth-card form { display: grid; gap: 1rem; }
.recovery-codes { padding: 1rem; background: #f2f4f6; border-radius: .5rem; line-height: 1.8; }

.page { padding: 1.5rem; max-width: 1320px; margin: 0 auto; }
.page.narrow { max-width: 900px; }
.page-title { display: flex; justify-content: space-between; align-items: start; margin-bottom: 1rem; }
.page-title h1 { margin: 0; }
.page-title p { margin: .3rem 0 0; color: var(--rt-muted); }
.card { background: var(--rt-panel); border: 1px solid var(--rt-border); border-radius: .7rem; padding: 1.1rem; margin-bottom: 1rem; }
.card h2 { margin-top: 0; font-size: 1.05rem; }
.form-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 1rem; margin-bottom: 1rem; }
.form-grid.three { grid-template-columns: repeat(3,minmax(0,1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.account-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .8rem 0; border-bottom: 1px solid var(--rt-border); }
.account-row:last-child { border-bottom: 0; }
.account-row > div { display: grid; gap: .2rem; }
.account-row span,.account-row small { color: var(--rt-muted); }
.alert { border: 1px solid transparent; border-radius: .5rem; padding: .8rem 1rem; margin: 1rem 0; }
.alert.success { background: #eef9ef; border-color: #b4ddb9; }
.alert.danger { background: #fff0ed; border-color: #efb8ae; }
.alert.warning { background: #fff8e8; border-color: #f1d599; }
.alert.info { background: #eef6fc; border-color: #b8d8ef; }
.global-flash { position: fixed; z-index: 50; right: 1rem; top: 70px; max-width: 560px; box-shadow: var(--rt-shadow); }
.check-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: .45rem; margin-bottom: 1.2rem; }
.check { display: flex; gap: .55rem; align-items: center; padding: .55rem .7rem; background: #f6f8fa; border-radius: .4rem; }
.check.ok span { color: var(--rt-success); font-weight: 900; }
.check.bad span { color: var(--rt-danger); font-weight: 900; }
.danger-zone { border-color: #e3aca3; }
dl { display: grid; grid-template-columns: 150px 1fr; gap: .5rem 1rem; } dt { font-weight: 700; } dd { margin: 0; }

.mail-shell { height: calc(100vh - 58px); min-height: 520px; display: grid; grid-template-columns: 56px 240px minmax(300px, 390px) minmax(360px, 1fr); background: #fff; overflow: hidden; }
.account-rail { background: #f0f2f4; border-right: 1px solid var(--rt-border); display: flex; flex-direction: column; align-items: center; gap: .55rem; padding: .7rem .4rem; }
.account-rail .icon-action { background: var(--rt-primary); color: #fff; margin-bottom: .4rem; }
.account-chip { width: 38px; height: 38px; border-radius: 50%; border: 1px solid #c7ced6; background: #fff; color: var(--rt-primary-dark); font-weight: 800; }
.account-chip.active { background: var(--rt-primary-dark); color: #fff; border-color: var(--rt-primary-dark); }
.folder-pane,.message-pane,.reading-pane { min-width: 0; border-right: 1px solid var(--rt-border); overflow: hidden; background: #fff; }
.reading-pane { border-right: 0; }
.pane-head { height: 48px; padding: 0 .85rem; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--rt-border); background: #fafbfc; }
.folder-pane > div:last-child,.message-list { height: calc(100% - 48px); overflow: auto; }
.folder-item { width: 100%; border: 0; border-left: 3px solid transparent; background: transparent; padding: .62rem .8rem; display: flex; align-items: center; justify-content: space-between; text-align: left; }
.folder-item:hover { background: var(--rt-hover); }
.folder-item.active { background: var(--rt-selected); border-left-color: var(--rt-primary); }
.folder-item small { color: var(--rt-muted); }
.message-item { display: grid; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--rt-border); border-left: 3px solid transparent; background: #fff; gap: .35rem; padding: .72rem .85rem; }
.message-item:hover { background: var(--rt-hover); }
.message-item.active { background: var(--rt-selected); border-left-color: var(--rt-primary); }
.message-item.unread strong,.message-item.unread .subject { font-weight: 800; }
.message-row { display: flex; justify-content: space-between; gap: .7rem; min-width: 0; }
.message-row strong,.message-item .subject { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.message-row time { flex: none; font-size: .72rem; color: var(--rt-muted); }
.message-item .subject { color: #384552; font-size: .9rem; }
.empty-state,.reading-empty { padding: 2rem; color: var(--rt-muted); text-align: center; }
.reading-empty { height: 100%; display: grid; place-content: center; gap: .4rem; }
.reading-content { height: 100%; overflow: auto; padding: 1.5rem clamp(1rem,3vw,2.5rem); }
.reading-content header { padding-bottom: 1rem; border-bottom: 1px solid var(--rt-border); }
.reading-content h1 { font-size: 1.4rem; margin: 0 0 1rem; }
.sender-line { display: flex; justify-content: space-between; gap: 1rem; }
.sender-line span,.recipient-line { color: var(--rt-muted); font-size: .88rem; }
.recipient-line { margin-top: .35rem; }
.mail-body { margin: 1.4rem 0; font-family: Mulish,Arial,sans-serif; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; font-size: .95rem; }
.attachments { display: grid; gap: .35rem; border-top: 1px solid var(--rt-border); padding-top: 1rem; }
.attachments span { font-size: .85rem; color: var(--rt-muted); }

.compose-dialog { width: min(760px, calc(100% - 2rem)); height: min(720px, calc(100% - 2rem)); border: 0; border-radius: .8rem; padding: 0; box-shadow: 0 22px 80px rgba(0,0,0,.3); }
.compose-dialog::backdrop { background: rgba(15,23,42,.48); }
.compose-form { height: 100%; display: grid; grid-template-rows: auto auto auto auto 1fr auto; gap: .75rem; padding: 1rem; }
.compose-form header,.compose-form footer { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.compose-form h2 { margin: 0; }
.compose-form .grow textarea { height: 100%; min-height: 240px; }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th,td { padding: .7rem; text-align: left; border-bottom: 1px solid var(--rt-border); vertical-align: top; }
th { background: #f7f8fa; font-size: .85rem; }
.calendar-list { display: grid; gap: .2rem; }
.event { display: grid; grid-template-columns: 150px 1fr; gap: 1rem; padding: .8rem 0; border-bottom: 1px solid var(--rt-border); }
.event > div { display: grid; gap: .2rem; }.event span,.event small,.event time { color: var(--rt-muted); }

@media (max-width: 1100px) {
  .mail-shell { grid-template-columns: 52px 210px minmax(300px,1fr); }
  .reading-pane { position: fixed; inset: 58px 0 0 262px; z-index: 20; box-shadow: -10px 0 30px rgba(0,0,0,.08); }
  .reading-pane:has(.reading-content[hidden]) { display: none; }
  .form-grid.three { grid-template-columns: repeat(2,minmax(0,1fr)); }
}
@media (max-width: 760px) {
  .topbar { height: auto; min-height: 58px; flex-wrap: wrap; padding: .6rem; }
  .topnav { order: 3; width: 100%; overflow-x: auto; }
  .topnav a { min-height: 40px; }
  .userbox span { display: none; }
  .mail-shell { height: calc(100vh - 104px); grid-template-columns: 48px minmax(250px,1fr); }
  .folder-pane { display: none; }
  .reading-pane { inset: 104px 0 0 48px; }
  .form-grid,.form-grid.three { grid-template-columns: 1fr; }
  .account-row { align-items: stretch; flex-direction: column; }
  .check-grid { grid-template-columns: 1fr; }
  .page { padding: 1rem; }
}

/* Account management */
.account-actions { display: flex !important; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: .55rem !important; }
.account-actions form { margin: 0; }
.form-actions { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.form-note { margin: -.2rem 0 1rem; color: var(--rt-muted); }
.checkbox-label { display: flex; flex-direction: row; align-items: center; gap: .6rem; }
.checkbox-label input { width: auto; }
.danger-zone { margin-top: 1.5rem; border: 1px solid #e3aca3; border-radius: .6rem; padding: 1rem; background: #fff8f6; }
.danger-zone h3 { margin-top: 0; color: var(--rt-danger); }
.danger-zone form { max-width: 520px; display: grid; gap: .8rem; }
@media (max-width: 760px) {
  .account-actions { justify-content: flex-start; }
}
