:root {
  --sidebar-width: 260px;
  --app-bg: #f4f6f8;
  --app-border: #d8dee7;
  --app-ink: #111827;
}

body { min-width: 320px; background: var(--app-bg); color: #111827; }
a { text-decoration-thickness: 1px; text-underline-offset: 2px; }
.app-frame { min-height: 100vh; }
.app-sidebar { width: var(--sidebar-width); padding: 1rem .85rem; border-right: 1px solid #d5dce6; background: #e9edf3; }
.sidebar-brand { display: flex; align-items: center; justify-content: space-between; padding: .25rem .45rem 1.1rem; border-bottom: 1px solid var(--app-border); }
.brand-link, .login-brand { display: inline-flex; align-items: center; gap: .7rem; color: var(--app-ink); text-decoration: none; }
.brand-link strong, .brand-link small { display: block; }
.brand-link small { margin-top: .1rem; color: #667588; font-size: .8rem; }
.brand-icon { display: inline-grid; width: 2.5rem; height: 2.5rem; place-items: center; border-radius: .6rem; background: #e8f0ff; color: #2456a6; font-size: 1.25rem; }
.sidebar-nav { display: grid; gap: .2rem; padding-top: 1rem; }
.sidebar-nav .nav-link { display: flex; align-items: center; gap: .7rem; min-height: 2.7rem; border-left: 3px solid transparent; border-radius: .35rem; color: #111827; font-weight: 500; }
.sidebar-nav .nav-link:hover { background: #dde5ef; color: #111827; }
.sidebar-nav .nav-link.active { border-left-color: #0d6efd; background: #d5e3fb; color: #111827; font-weight: 700; }
.sidebar-nav .nav-link > i { width: 1.2rem; font-size: 1.05rem; }
.sidebar-nav .mailbox-nav-link { min-height: 2.35rem; padding-top: .35rem; padding-bottom: .35rem; font-size: .92rem; }
.mailbox-nav-link > span:first-of-type { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-nav .nav-section-label { padding: 1rem .7rem .35rem; color: #374151; font-size: .75rem; font-weight: 700; letter-spacing: .04em; }
.sidebar-empty { padding: .2rem .7rem .35rem; color: #4b5563; font-size: .9rem; }
.main-column { min-width: 0; }
.topbar { position: sticky; z-index: 10; top: 0; display: flex; align-items: center; min-height: 4rem; padding: .6rem 1.25rem; border-bottom: 1px solid var(--app-border); background: rgba(255,255,255,.96); }
.topbar-title { color: #111827; font-weight: 650; text-decoration: none; }
.text-secondary { color: #374151 !important; }
.top-notification { position: relative; color: #44536a; font-size: 1.25rem; text-decoration: none; }
.top-notification-count { position: absolute; top: -.4rem; right: -.55rem; min-width: 1.1rem; padding: .05rem .25rem; border-radius: 1rem; background: #dc3545; color: white; font-size: .7rem; line-height: 1.25; text-align: center; }
.page-content { max-width: 1560px; margin: 0 auto; padding: 1.35rem clamp(1rem, 2vw, 2rem) 2.5rem; }
.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.15rem; }
.page-heading h1 { margin: 0; font-size: clamp(1.4rem, 2vw, 1.8rem); font-weight: 650; }
.stat-card .card-body { min-height: 6.7rem; }
.stat-label { color: #65758a; }
.stat-value { margin-top: .35rem; color: #253446; font-size: 1.8rem; font-weight: 650; line-height: 1.15; }
.stat-total { color: #718096; font-size: 1rem; font-weight: 400; }
.message-list-row { display: grid; grid-template-columns: minmax(10rem, 1fr) minmax(12rem, 1.6fr) minmax(10rem, 2fr) auto; align-items: center; gap: 1rem; min-width: 0; }
.message-row-link { display: grid; min-width: 0; color: inherit; text-decoration: none; }
.message-row-link:hover .message-subject { color: #174c9a; text-decoration: underline; }
.message-list-row.unread, tr.unread { background: #f7faff; }
.message-sender, .message-subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-sender, .message-subject { color: #111827; }
.unread .message-sender, .unread .message-subject { font-weight: 700; }
.message-preview { overflow: hidden; color: #69788b; text-overflow: ellipsis; white-space: nowrap; }
.message-meta { color: #69788b; font-size: .88rem; white-space: nowrap; }
.mailbox-tags { display: flex; flex-wrap: wrap; gap: .3rem; }
.mailbox-tags .badge { font-weight: 500; }
.advanced-filters summary { color: #2456a6; cursor: pointer; }
.bulk-action { width: auto; min-width: 12rem; }
.check-col { width: 2.8rem; }
.message-detail-card .card-body { padding: clamp(1rem, 2vw, 1.5rem); }
.message-meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr)); gap: .85rem 1.4rem; }
.message-meta-grid > div { display: grid; gap: .2rem; min-width: 0; }
.message-meta-grid strong { color: #6a7889; font-size: .88rem; font-weight: 600; }
.message-meta-grid span { overflow-wrap: anywhere; }
.attachment-chip { display: inline-flex; align-items: center; gap: .45rem; max-width: 100%; padding: .5rem .7rem; border: 1px solid var(--app-border); border-radius: .45rem; color: #35445a; text-decoration: none; }
.attachment-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-chip small { color: #718096; white-space: nowrap; }
.email-frame { display: block; width: 100%; min-height: 28rem; height: min(70vh, 58rem); border: 0; background: white; }
.plain-message, .raw-headers { max-height: 70vh; margin: 0; padding: 1.25rem; overflow: auto; background: #fff; color: #263648; font: 1rem/1.6 ui-monospace, SFMono-Regular, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.empty-state { padding: 2.5rem 1rem; color: #68778a; text-align: center; }
.empty-state > i { display: block; margin-bottom: .5rem; color: #8291a4; font-size: 1.75rem; }
.empty-state p { margin: 0; }
.login-page { display: grid; min-height: 100vh; place-items: center; padding: 1rem; background: var(--app-bg); }
.login-card { width: min(100%, 27rem); border: 1px solid var(--app-border); border-radius: .75rem; }
.login-brand { font-size: 1rem; }
.login-card h1 { color: #29384c; }

@media (min-width: 992px) {
  .app-frame { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }
  .app-sidebar { position: sticky; top: 0; height: 100vh; visibility: visible !important; transform: none !important; }
}

@media (max-width: 767.98px) {
  .topbar { padding-inline: .75rem; }
  .page-content { padding-inline: .75rem; }
  .message-list-row { grid-template-columns: minmax(0, 1fr) auto; gap: .2rem .75rem; }
  .message-list-row .message-row-link { grid-column: 1 / -1; }
  .message-list-row .message-meta { grid-column: 2; grid-row: 1; }
  .message-list-row > .mailbox-tags, .message-list-row > i { display: none; }
  .bulk-action { min-width: 0; max-width: 12rem; }
  .email-frame { min-height: 22rem; height: 65vh; }
}
