/*
 * FagulhaMail desktop workspace.
 *
 * The layout uses the proven desktop-mail pattern: a compact command band,
 * a narrow folder tree, a dense message list, and a large reading surface.
 * It is an original FagulhaMail implementation; no third-party assets,
 * trademarks, code, or proprietary iconography are used.
 */
:root {
  font-family: "Segoe UI Variable Text", "Segoe UI", Arial, sans-serif;
  --fm-panel: #f6f7f9;
  --fm-surface: #ffffff;
  --fm-surface-muted: #f1f3f5;
  --fm-text: #1f1f1f;
  --fm-muted: #5d6269;
  --fm-line: #d7dce1;
  --fm-line-strong: #c2c9d0;
  --fm-radius: 3px;
}

html[data-theme="dark"] {
  --fm-panel: #161c23;
  --fm-surface: #10161d;
  --fm-surface-muted: #1a222b;
  --fm-text: #edf3f8;
  --fm-muted: #afbbc7;
  --fm-line: #303b47;
  --fm-line-strong: #465463;
}

body { font-family: "Segoe UI Variable Text", "Segoe UI", Arial, sans-serif; }

/* Application title bar: deliberately short so the workspace owns the screen. */
.app-titlebar {
  height: 36px;
  grid-template-columns: minmax(180px, 1fr) auto minmax(180px, 1fr);
  gap: 14px;
  padding: 0 12px;
  color: #fff;
  background: var(--color-accent);
  border-bottom: 0;
}
.brand { gap: 7px; font-size: 13px; color: #fff; }
.brand strong { font-weight: 600; }
.brand-mark { width: 20px; height: 20px; border: 0; background: transparent; color: #fff; }
.title-context {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: center;
  gap: 5px;
  overflow: hidden;
  color: #fff;
  font-size: 12px;
  white-space: nowrap;
}
.title-context strong,
.title-context span { overflow: hidden; text-overflow: ellipsis; }
.title-actions { gap: 4px; }
.app-titlebar .icon-button {
  width: 28px;
  min-width: 28px;
  min-height: 28px;
  border: 0;
  border-radius: 0;
  color: #fff;
  background: transparent;
}
.app-titlebar .icon-button:hover { color: #fff; background: rgba(255,255,255,.14); }
.global-search {
  height: 24px;
  min-height: 24px;
  border: 1px solid rgba(255,255,255,.55);
  border-radius: var(--fm-radius);
  background: rgba(255,255,255,.95);
  color: #252525;
}
.global-search input { font-size: 12px; color: #252525; }
.global-search .icon { color: #47769a; }
.identity-name { color: #fff; font-size: 12px; }
.app-titlebar > .identity-zone .secondary { color:#fff; border-color:rgba(255,255,255,.62); background:transparent; }

/* Command band follows an e-mail-client hierarchy rather than a dashboard. */
.workspace-frame {
  min-height: calc(100vh - 36px);
  display: grid;
  grid-template-rows: 94px minmax(0, 1fr) 22px;
  background: var(--fm-surface);
}
.app-ribbon {
  --ribbon-tab-height: 30px;
  --ribbon-action-height: 64px;
  --ribbon-group-height: var(--ribbon-action-height);
  min-height: 94px;
  display: grid;
  grid-template-rows: var(--ribbon-tab-height) var(--ribbon-group-height);
  color: var(--fm-text);
  background: var(--fm-surface-muted);
  border-bottom: 1px solid var(--fm-line-strong);
}
.ribbon-tabs {
  display: flex;
  align-items: stretch;
  gap: 0;
  padding: 0 10px;
  border-bottom: 1px solid var(--fm-line);
}
.ribbon-tab {
  min-width: 62px;
  height: 30px;
  padding: 0 14px;
  border: 0;
  border-radius: 0;
  color: var(--fm-text);
  background: transparent;
  font-size: 13px;
  font-weight: 400;
}
.ribbon-tab:hover { background: color-mix(in srgb, var(--color-accent) 9%, transparent); }
.ribbon-tab.active {
  color: var(--fm-text);
  background: var(--fm-surface);
  box-shadow: inset 0 -2px var(--color-accent);
}
.ribbon-commands {
  display: flex;
  align-items: center;
  gap: 0;
  overflow-x: auto;
  padding: 0 12px;
}
.ribbon-group {
  display: flex;
  min-width: max-content;
  height: var(--ribbon-group-height);
  align-items: center;
  padding: 0 14px;
  border-left: 1px solid var(--fm-line);
}
.ribbon-group:first-child { padding-left: 2px; border-left: 0; }
.ribbon-group-actions {
  display: flex;
  min-width: 0;
  height: var(--ribbon-action-height);
  align-items: center;
  gap: 8px;
}
.ribbon-command-grid {
  display: flex;
  min-width: max-content;
  height: var(--ribbon-action-height);
  align-items: center;
  gap: 8px;
}
.ribbon-secondary-stack {
  display: flex;
  min-width: max-content;
  height: var(--ribbon-action-height);
  align-items: center;
  gap: 8px;
}
.ribbon-secondary-stack .secondary {
  min-height: 40px;
  justify-content: center;
  padding: 0 12px;
}
.ribbon-command-large {
  display: inline-flex;
  min-width: max-content;
  width: max-content;
  height: 40px;
  box-sizing: border-box;
  min-height: 40px !important;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 12px !important;
}
.ribbon-command-large .icon { display: block; width: 18px; height: 18px; margin: 0; }
.ribbon-command-large span { display: block; max-width: none; font-size: 13px; line-height: 18px; text-align: left; white-space: nowrap; }
.ribbon-group .primary,
.ribbon-group .secondary {
  min-height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: 0;
  color: var(--fm-text);
  background: transparent;
  box-shadow: none;
  font-size: 13px;
  font-weight: 400;
  white-space: nowrap;
}
.ribbon-group .primary { color: var(--color-accent-contrast); background: var(--color-accent); border-radius: var(--fm-radius); }
.ribbon-group .secondary:hover { background: color-mix(in srgb, var(--color-accent) 10%, transparent); }
.ribbon-group .secondary.active { background: var(--color-accent-soft); box-shadow: inset 0 -2px var(--color-accent); }
.ribbon-group .icon { width: 16px; height: 16px; }
.ribbon-group .ribbon-secondary-stack .secondary {
  display: inline-flex;
  height: 40px;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 12px;
  text-align: left;
}
.ribbon-group .ribbon-secondary-stack .secondary .icon { display: block; width: 18px; height: 18px; margin: 0; }
.ribbon-group .ribbon-secondary-stack .secondary span { overflow: hidden; font-size: 13px; line-height: 16px; text-overflow: ellipsis; white-space: nowrap; }
.ribbon-group .ribbon-command-large .icon { width: 18px; height: 18px; }
.ribbon-divider { width: 1px; height: 32px; margin: 0 4px; background: var(--fm-line); }

/* Folder tree: stable, short rows, no dashboard-style cards. */
.workspace-shell { min-height: 0; grid-template-columns: var(--sidebar-width, 208px) 5px minmax(0, 1fr); background: var(--fm-surface); }
.workspace-shell:has(.workspace-sidebar.collapsed) { grid-template-columns: 46px 5px minmax(0, 1fr); }
.workspace-sidebar { padding: 9px 7px; background: var(--fm-panel); border-right: 1px solid var(--fm-line); }
.workspace-sidebar.collapsed { padding-inline: 5px; }
.workspace-sidebar.collapsed .nav-label,
.workspace-sidebar.collapsed .folder-item strong,
.workspace-sidebar.collapsed .folder-item em,
.workspace-sidebar.collapsed .department-row span:last-child { display: none; }
.workspace-sidebar.collapsed .folder-item,
.workspace-sidebar.collapsed .department-row { justify-content: center; padding-inline: 0; }
.sidebar-actions { grid-template-columns: minmax(0,1fr) 30px; gap: 6px; margin-bottom: 10px; }
.sidebar-actions .primary {
  justify-content: center;
  min-height: 30px;
  border-radius: var(--fm-radius);
  background: var(--color-accent);
  box-shadow: none;
  font-size: 12px;
  font-weight: 600;
}
.sidebar-actions .secondary { min-height: 30px; padding: 0; border-radius: var(--fm-radius); }
.folder-navigation { gap: 0; }
.folder-label { margin: 11px 7px 4px; color: var(--fm-muted); font-size: 10px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.folder-item {
  min-height: 28px;
  margin: 0;
  padding: 0 8px;
  border-radius: 0;
  color: var(--fm-text);
  font-size: 12px;
  font-weight: 400;
}
.folder-item .icon { width: 15px; height: 15px; }
.folder-item:hover { background: color-mix(in srgb, var(--color-accent) 9%, transparent); }
.folder-item.active { color: var(--fm-text); background: var(--color-accent-soft); box-shadow: inset 3px 0 var(--color-accent); }
.folder-item.active .icon { color: var(--color-accent-active); }
.folder-item strong { font-weight: 600; }
.sidebar-bottom { margin-top: auto; padding: 9px 5px 0; border-top: 1px solid var(--fm-line); }

/* Reading plane: the reader takes priority, the list remains dense and scannable. */
.workspace-main { min-height: 0; overflow: hidden; background: var(--fm-surface); }
.mail-workspace { min-height: 0; height: 100%; grid-template-columns: var(--message-list-width, 316px) 5px minmax(0, 1fr); background: var(--fm-surface); }
.mail-workspace:has(.operations-panel) { grid-template-columns: var(--message-list-width, 316px) 5px minmax(0, 1fr) 250px; }
.mail-workspace:has(.message-column.collapsed) { grid-template-columns: 46px 5px minmax(0, 1fr); }
.mail-workspace:has(.message-column.collapsed):has(.operations-panel) { grid-template-columns: 46px 5px minmax(0, 1fr) 250px; }
.pane-resizer {
  position: relative;
  z-index: 4;
  width: 5px;
  min-width: 5px;
  cursor: col-resize;
  touch-action: none;
  background: transparent;
}
.pane-resizer::after {
  position: absolute;
  inset: 0 2px;
  content: "";
  background: var(--fm-line);
  transition: background-color 120ms ease, inset 120ms ease;
}
.pane-resizer:hover::after,
.pane-resizer:focus-visible::after,
.pane-resizer.dragging::after {
  inset-inline: 1px;
  background: var(--color-accent);
}
.pane-resizer:focus-visible { outline: 2px solid var(--color-focus-ring); outline-offset: -2px; }
.workspace-shell:has(.workspace-sidebar.collapsed) > .sidebar-resizer,
.mail-workspace:has(.message-column.collapsed) > .message-resizer { cursor: default; pointer-events: none; }
.message-column { min-height: 0; grid-template-rows: auto auto auto minmax(0, 1fr); background: var(--fm-surface); border-right: 1px solid var(--fm-line); }
.message-column.collapsed { grid-template-rows: 46px; align-content: start; }
.message-column.collapsed .column-head > div:first-child,
.message-column.collapsed .message-search,
.message-column.collapsed .list-tabs,
.message-column.collapsed .message-rows,
.message-column.collapsed .column-tools .icon-button:last-child { display: none; }
.message-column.collapsed .column-head { min-height: 46px; justify-content: center; padding: 8px 4px; }
.message-column.collapsed .column-tools {
  display: flex;
  width: 34px;
  align-items: center;
  justify-content: center;
}
.message-column.collapsed .list-collapse-toggle { display: inline-flex; }
.column-head { min-height: 58px; padding: 10px 13px 8px; border-bottom: 1px solid var(--fm-line); }
.column-head h1 { margin: 0; color: var(--fm-text); font-size: 17px; font-weight: 600; }
.column-head p { margin-top: 1px; color: var(--fm-muted); font-size: 11px; }
.column-tools {
  display: flex;
  flex: 0 0 auto;
  align-self: center;
  align-items: center;
  gap: 8px;
}
.column-tools .icon-button {
  width: 34px;
  min-width: 34px;
  height: 34px;
}
.column-head .secondary { min-height: 28px; padding: 0 8px; border-radius: var(--fm-radius); }
.list-tabs { min-height: 32px; padding: 0 10px; border-bottom: 1px solid var(--fm-line); }
.list-tabs button { min-height: 30px; padding: 0 8px; border-radius: 0; font-size: 12px; font-weight: 400; }
.list-tabs button.active { color: var(--color-accent); background: transparent; box-shadow: inset 0 -2px var(--color-accent); }
.message-rows { min-height: 0; overflow: auto; }
.message-row { min-height: 58px; padding: 7px 12px; border-bottom: 1px solid var(--fm-line); border-radius: 0; color: var(--fm-text); }
.message-row:hover { background: color-mix(in srgb, var(--color-accent) 7%, transparent); }
.message-row.active { background: var(--color-accent-soft); box-shadow: inset 3px 0 var(--color-accent); }
.message-row.unread .message-line strong { font-weight: 700; }
.message-row.unread .message-subject { font-weight: 700; }
.message-line { font-size: 12px; }
.message-line strong { font-weight: 600; }
.message-subject { margin-top: 1px; font-size: 12px; font-weight: 400; }
.message-preview { margin-top: 1px; color: var(--fm-muted); font-size: 11px; }
.message-meta { display: inline-flex; align-items: center; gap: 4px; margin-top: 2px; color: var(--fm-muted); font-size: 10px; }
.message-meta .icon { width: 12px; height: 12px; color: var(--fm-warning); }

.reader-column { min-height: 0; overflow: auto; color: var(--fm-text); background: var(--fm-surface); }
.reader-content, .compose-view, .admin-view { max-width: none; min-height: 100%; padding: 16px 22px 32px; }
.reader-head { gap: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--fm-line); }
.reader-head h1, .compose-head h1, .admin-head h1 { margin: 0; color: var(--fm-text); font-size: 20px; font-weight: 400; letter-spacing: 0; }
.reader-actions { gap: 3px; flex-wrap: wrap; }
.reader-actions .secondary { min-height: 28px; padding: 0 8px; border-radius: var(--fm-radius); font-size: 12px; font-weight: 400; }
.reader-back { display: none; }
.sender-card { margin-top: 11px; padding: 9px 10px; border: 0; border-bottom: 1px solid var(--fm-line); border-radius: 0; background: transparent; }
.sender-card strong { font-size: 13px; font-weight: 600; }
.sender-card p, .sender-card time { color: var(--fm-muted); font-size: 11px; }
.sender-details {
  display: grid;
  flex-basis: 100%;
  gap: 4px;
  padding: 9px 0 2px 52px;
  color: var(--fm-muted);
  font-size: 12px;
}
.sender-details strong { color: var(--fm-text); }
.reader-attachments { display: flex; gap: 6px; overflow-x: auto; padding: 7px 0; border-bottom: 1px solid var(--fm-line); }
.attachment-card {
  display: grid;
  min-width: 220px;
  max-width: 300px;
  grid-template-columns: 32px minmax(0, 1fr) 28px;
  align-items: center;
  gap: 7px;
  padding: 6px 7px;
  border: 1px solid var(--fm-line-strong);
  background: var(--fm-surface-muted);
}
.attachment-icon { display: grid; width: 32px; height: 32px; place-items: center; color: var(--color-accent); background: var(--color-accent-soft); }
.attachment-icon .icon { width: 18px; height: 18px; }
.attachment-info { display: grid; min-width: 0; text-align: left; }
.attachment-info strong { overflow: hidden; color: var(--fm-text); font-size: 11px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.attachment-info small { color: var(--fm-muted); font-size: 10px; }
.attachment-card .icon-button { width: 28px; min-width: 28px; min-height: 28px; padding: 0; }
.reader-status { margin: 10px 0; padding: 0; border: 0; border-radius: 0; background: transparent; color: var(--fm-muted); font-size: 11px; }
.mail-body {
  max-width: none;
  min-height: 0;
  margin-top: 12px;
  padding: 18px 20px 28px;
  color: var(--fm-text);
  border: 1px solid var(--fm-line);
  border-radius: 0;
  background: var(--fm-surface);
  box-shadow: none;
  font-family: Calibri, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}
.mail-body img { max-width: min(100%, 1040px); height: auto; }
.mail-body a { color: var(--color-accent-active); }
.reader-footer { border-top: 1px solid var(--fm-line); padding-top: 12px; }

/* Optional service panel is secondary and never steals reader width by default. */
.operations-panel { min-height: 0; overflow: auto; background: var(--fm-panel); border-left: 1px solid var(--fm-line); }
.operations-panel > header { position: sticky; top: 0; z-index: 2; background: var(--fm-panel); border-bottom: 1px solid var(--fm-line); }
.operations-panel .service-card { border-radius: var(--fm-radius); }

.app-statusbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 22px; padding: 0 10px; color: var(--fm-muted); background: var(--fm-surface-muted); border-top: 1px solid var(--fm-line); font-size: 10px; }
.mobile-bottom-nav,
.mobile-sidebar-close,
.mobile-sidebar-scrim { display: none; }

/* Menus must win the stacking context over the reading plane. */
.floating-action-menu { position: fixed; z-index: 1000; display: grid; min-width: 215px; padding: 4px; color: var(--fm-text); background: var(--fm-surface); border: 1px solid var(--fm-line-strong); border-radius: var(--fm-radius); box-shadow: 0 8px 20px rgba(0,0,0,.22); }
.floating-action-menu button { display: flex; align-items: center; gap: 8px; min-height: 29px; padding: 0 8px; border-radius: 0; color: var(--fm-text); background: transparent; text-align: left; font-size: 12px; }
.floating-action-menu button:hover { background: var(--color-accent-soft); }
.floating-action-menu .icon { width: 15px; height: 15px; color: var(--color-accent); }

.admin-view { background: var(--fm-surface); }
.admin-head { margin-bottom: 16px; padding-bottom: 10px; border-bottom: 1px solid var(--fm-line); }
.admin-grid { gap: 10px; }
.admin-card { border-radius: var(--fm-radius); border-color: var(--fm-line); background: var(--fm-surface-muted); }
.admin-department { border-radius: var(--fm-radius); }

/* No SVG is allowed to inherit the browser default intrinsic size. */
svg.icon { display: block; width: 16px; height: 16px; max-width: 16px; max-height: 16px; flex: 0 0 16px; }
button > svg.icon,
button > span > svg.icon { align-self: center; margin-block: auto; }
button.icon-button { gap: 0; }
.brand-mark > svg.icon { width: 18px; height: 18px; max-width: 18px; max-height: 18px; }
.auth-brand-mark > svg.icon { width: 25px; height: 25px; max-width: 25px; max-height: 25px; }

@media (max-width: 1250px) {
  .mail-workspace, .mail-workspace:has(.operations-panel) { grid-template-columns: minmax(250px, var(--message-list-width, 292px)) 5px minmax(0, 1fr); }
  .operations-panel { display: none; }
}
@media (max-width: 900px) {
  .app-titlebar { grid-template-columns: 150px minmax(0,1fr) auto; }
  .identity-name { display: none; }
  .workspace-frame { grid-template-rows: 82px minmax(0, 1fr) 22px; }
  .app-ribbon {
    --ribbon-tab-height: 26px;
    --ribbon-action-height: 56px;
    min-height: 82px;
  }
  .ribbon-commands { padding: 0 6px; }
  .ribbon-command-large { min-height: 40px !important; }
  .ribbon-group .ribbon-command-large .icon { width: 18px; height: 18px; }
  .workspace-shell { grid-template-columns: 58px 0 minmax(0,1fr); }
  .sidebar-resizer { display: none; }
  .workspace-sidebar { padding: 8px 5px; }
  .workspace-sidebar .folder-item span, .workspace-sidebar .folder-label, .workspace-sidebar .sidebar-bottom span { display: none; }
  .sidebar-actions { grid-template-columns: 1fr; }
  .sidebar-actions .secondary { display: none; }
  .mail-workspace { grid-template-columns: minmax(265px, 42vw) 0 minmax(0,1fr); }
  .message-resizer { display: none; }
  .reader-content, .compose-view, .admin-view { padding: 14px; }
}
@media (max-width: 650px) {
  body { overflow: hidden; }
  .app-titlebar { height: 52px; padding: 0 14px; grid-template-columns: 1fr auto; }
  .title-context { display: none; }
  .workspace-frame {
    min-height: calc(100dvh - 52px);
    height: calc(100dvh - 52px);
    grid-template-rows: minmax(0, 1fr) auto;
  }
  .app-ribbon,
  .app-statusbar { display: none; }
  .workspace-shell { grid-template-columns: 1fr; }
  .workspace-sidebar {
    position: fixed;
    z-index: 1200;
    top: 52px;
    bottom: calc(64px + env(safe-area-inset-bottom));
    left: 0;
    display: flex;
    width: min(84vw, 320px);
    padding: 14px 10px;
    transform: translateX(-105%);
    transition: transform 180ms ease;
    box-shadow: 10px 0 28px rgba(0,0,0,.32);
  }
  .workspace-sidebar,
  .mobile-sidebar-scrim { display: none; }
  .workspace-sidebar.mobile-open,
  .workspace-sidebar.mobile-open.collapsed {
    width: min(84vw, 320px);
    align-items: stretch;
    padding: 14px 10px;
    transform: translateX(0);
  }
  .workspace-sidebar.mobile-open .nav-label { display: block; }
  .workspace-sidebar.mobile-open .department-section { display: grid; }
  .workspace-sidebar.mobile-open .folder-item strong,
  .workspace-sidebar.mobile-open .folder-item em,
  .workspace-sidebar.mobile-open .folder-item > span,
  .workspace-sidebar.mobile-open .sidebar-bottom strong,
  .workspace-sidebar.mobile-open .sidebar-bottom span,
  .workspace-sidebar.mobile-open .department-row span { display: block; }
  .workspace-sidebar.mobile-open .folder-item {
    display: grid;
    width: 100%;
    grid-template-columns: 22px minmax(0, 1fr) auto;
    justify-content: initial;
    justify-items: start;
    padding-inline: 9px;
  }
  .workspace-sidebar.mobile-open .department-row {
    display: grid;
    width: 100%;
    grid-template-columns: 22px minmax(0, 1fr);
    justify-content: initial;
    justify-items: start;
    padding-inline: 9px;
  }
  .sidebar-actions { display: none; }
  .mobile-sidebar-close {
    display: inline-flex;
    align-self: flex-end;
    margin-bottom: 4px;
  }
  .mobile-sidebar-scrim {
    position: fixed;
    z-index: 1190;
    inset: 52px 0 calc(64px + env(safe-area-inset-bottom));
    display: block;
    width: 100%;
    min-height: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: rgba(0,0,0,.46);
  }
  .mail-workspace, .mail-workspace:has(.operations-panel) { grid-template-columns: 1fr; }
  .workspace-main,
  .mail-workspace { height: 100%; }
  .reader-column { display: none; }
  .mail-workspace:has(.reader-content) .message-column,
  .mail-workspace:has(.compose-view) .message-column { display: none; }
  .mail-workspace:has(.reader-content) .reader-column,
  .mail-workspace:has(.compose-view) .reader-column { display: block; }
  .reader-back { display: inline-flex; }
  .message-column { grid-template-rows: auto auto minmax(0, 1fr); border-right: 0; }
  .column-head { min-height: 68px; padding: 12px 16px; }
  .message-column .list-collapse-toggle,
  .message-column .list-tabs { display: none; }
  .column-tools { align-self: center; }
  .message-row { min-height: 72px; padding: 10px 14px; }
  .message-line strong { font-size: 14px; }
  .message-subject { font-size: 13px; }
  .reader-content { height: 100%; overflow: auto; padding: 16px; }
  .reader-head {
    display: grid;
    min-width: 0;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }
  .reader-title { min-width: 0; }
  .reader-title h1 {
    display: block;
    overflow: hidden;
    width: 100%;
    max-width: 100%;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .reader-actions {
    display: flex;
    width: 100%;
    max-width: 100%;
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 7px;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .reader-actions::-webkit-scrollbar { display: none; }
  .reader-actions button { flex: 0 0 auto; min-height: 42px; }
  .sender-card { flex-wrap: wrap; }
  .sender-info { flex: 1 1 180px; }
  .sender-details { padding-left: 0; }
  .reader-footer { display: none; }
  .compose-view { height: 100%; overflow: auto; padding: 14px 12px 24px; }
  .compose-head { gap: 12px; padding-bottom: 14px; }
  .compose-head h1 { font-size: 20px; }
  .compose-form { margin-top: 14px; border-radius: 12px; }
  .compose-form > label { padding: 12px 14px; }
  .body-field textarea { min-height: 34dvh; padding: 12px 10px 16px 42px; }
  .compose-footer {
    position: sticky;
    z-index: 2;
    bottom: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 10px;
  }
  .compose-footer button { width: 100%; min-width: 0; min-height: 44px; }
  .compose-footer [data-action="send"] {
    grid-column: 1 / -1;
    grid-row: 1;
    min-height: 48px;
  }
  .reader-head h1 { font-size: 17px; }
  .mail-body { padding: 14px; font-size: 13px; }
  .list-empty { min-height: 100%; padding: 32px 22px; }
  .list-empty h2 { margin: 4px 0 0; color: var(--fm-text); font-size: 18px; }
  .list-empty p { max-width: 270px; margin: 0; line-height: 1.5; }
  .list-empty .primary { margin-top: 8px; }
  .settings-view { height: 100%; overflow: auto; padding: 14px 14px 28px; }
  .admin-view .admin-head {
    display: grid;
    gap: 14px;
    margin-bottom: 16px;
    padding-bottom: 16px;
  }
  .admin-view .admin-head h1 { font-size: 22px; }
  .admin-view .admin-head-actions {
    display: flex;
    width: 100%;
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 8px;
  }
  .admin-view .admin-head-actions button { min-width: 0; justify-content: center; }
  .settings-view .admin-layout { display: grid; grid-template-columns: 1fr; gap: 16px; }
  .settings-view .admin-nav {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
    padding: 0 0 14px;
    border-right: 0;
    border-bottom: 1px solid var(--fm-line);
  }
  .settings-view .admin-nav-item {
    width: 100%;
    min-height: 58px;
    padding: 9px 11px;
  }
  .settings-view .admin-nav-item > span > strong,
  .settings-view .admin-nav-item > span > small {
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
  }
  .settings-view .settings-cards { grid-template-columns: 1fr; gap: 10px; }
  .settings-view .settings-cards article { min-height: 0; padding: 16px; }
  .settings-view .choice-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .settings-view .choice-row button { min-width: 0; width: 100%; }
  .mobile-bottom-nav {
    z-index: 1100;
    display: flex;
    min-height: calc(64px + env(safe-area-inset-bottom));
    max-width: 100vw;
    padding: 4px 6px max(6px, env(safe-area-inset-bottom));
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    border-top: 1px solid var(--fm-line-strong);
    background: color-mix(in srgb, var(--fm-panel) 96%, transparent);
    box-shadow: 0 -8px 24px rgba(0,0,0,.16);
  }
  .mobile-bottom-nav::-webkit-scrollbar { display: none; }
  .mobile-bottom-nav button {
    flex: 0 0 84px;
    min-width: 84px;
    min-height: 56px;
    scroll-snap-align: start;
    flex-direction: column;
    gap: 3px;
    padding: 5px 2px;
    border: 0;
    border-radius: 8px;
    color: var(--fm-muted);
    background: transparent;
    font-size: 10px;
  }
  .mobile-bottom-nav button .icon { width: 21px; height: 21px; max-width: 21px; max-height: 21px; flex-basis: 21px; }
  .mobile-bottom-nav button.active {
    color: #fff;
    background: var(--color-accent);
    font-weight: 700;
  }
  .floating-action-menu { right: 8px; left: 8px !important; width: auto; }
}

/* Product layout contract — authoritative responsive layer (2026-07-30). */
.title-account {
  display: inline-flex;
  min-width: 44px;
  min-height: 44px;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 4px;
  border: 0;
  color: inherit;
  background: transparent;
}
.title-avatar {
  display: grid;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  place-items: center;
  border: 1px solid color-mix(in srgb, currentColor 35%, transparent);
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
}
.more-view {
  min-height: 100%;
  padding: 24px;
  color: var(--fm-text);
  background: var(--fm-surface);
}
.more-view > header {
  max-width: 760px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--fm-line);
}
.more-view h1 { margin: 2px 0 6px; font-size: 26px; }
.more-view h2 { margin: 0 0 8px; font-size: 13px; color: var(--fm-muted); text-transform: uppercase; letter-spacing: .06em; }
.more-groups { display: grid; max-width: 760px; gap: 20px; margin-top: 20px; }
.more-groups section { display: grid; gap: 2px; }
.more-groups button {
  display: grid;
  min-height: 58px;
  grid-template-columns: 28px minmax(0,1fr);
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 0;
  border-bottom: 1px solid var(--fm-line);
  border-radius: 0;
  color: var(--fm-text);
  background: transparent;
  text-align: left;
}
.more-groups button:hover { background: var(--color-accent-soft); }
.more-groups button > span { display: grid; gap: 2px; }
.more-groups button small { color: var(--fm-muted); font-size: 12px; font-weight: 400; }
.more-groups .danger-link { color: var(--color-danger, #c42b1c); }
.reader-actions { position: relative; }
.reader-more-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  right: 0;
  display: grid;
  min-width: 240px;
  padding: 6px;
  border: 1px solid var(--fm-line-strong);
  border-radius: 8px;
  background: var(--fm-surface);
  box-shadow: 0 10px 30px rgba(0,0,0,.24);
}
.reader-more-menu button {
  min-height: 42px;
  justify-content: flex-start;
  border: 0;
  background: transparent;
}
.compose-form > label:first-child {
  display: grid;
  grid-template-columns: 70px minmax(0,1fr) auto;
}
.compose-expand {
  min-width: 62px;
  min-height: 40px;
  padding: 0 8px;
  border: 0;
  color: var(--color-accent-active);
  background: transparent;
}
.compose-advanced { display: none; }
.compose-advanced.open { display: contents; }
.compose-file-list { display: grid; grid-column: 2 / -1; gap: 4px; margin-top: 6px; }
.compose-file {
  display: grid;
  min-height: 38px;
  grid-template-columns: 20px minmax(0,1fr) 36px;
  align-items: center;
  gap: 7px;
  padding: 4px 6px;
  border: 1px solid var(--fm-line);
  background: var(--fm-surface-muted);
}
.compose-file > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compose-file button { display: grid; width: 36px; height: 36px; place-items: center; padding: 0; }
.compose-save-state { margin-right: auto; color: var(--fm-muted); font-size: 11px; }
.theme-options button.selected { color: var(--color-accent-active); border-color: var(--color-accent); background: var(--color-accent-soft); }
.admin-row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.admin-row-actions button { min-width: max-content; min-height: 40px; padding-inline: 12px; }
.admin-row-actions button[data-admin-operation$="deactivate"] { color: var(--color-danger, #c42b1c); }
.mobile-compose-fab { display: none; }

@media (max-width: 650px) {
  html, body, #app { width: 100%; max-width: 100%; overflow-x: hidden; }
  body { font-size: 16px; }
  .app-titlebar {
    height: calc(56px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 12px 0;
  }
  .brand strong { font-size: 16px; }
  .identity-name { display: none; }
  .workspace-frame {
    width: 100%;
    min-width: 0;
    max-width: 100vw;
    min-height: calc(100dvh - 56px - env(safe-area-inset-top));
    height: calc(100dvh - 56px - env(safe-area-inset-top));
  }
  .workspace-shell { min-width: 0; }
  .workspace-sidebar, .sidebar-resizer { display: none !important; }
  .workspace-main, .mail-workspace, .message-column, .reader-column { width: 100%; min-width: 0; max-width: 100%; }
  .message-column { grid-template-rows: auto auto auto minmax(0,1fr); }
  .message-column .list-tabs {
    display: flex;
    min-height: 44px;
    padding-inline: 12px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .message-column .list-tabs::-webkit-scrollbar { display: none; }
  .list-tabs button { min-height: 44px; flex: 0 0 auto; font-size: 14px; }
  .column-head { min-height: 76px; padding: 12px 16px; }
  .column-head h1 { font-size: 22px; }
  .column-head small { font-size: 14px; }
  .column-tools .icon-button { width: 44px; min-width: 44px; height: 44px; }
  .message-search { min-height: 52px; padding: 6px 16px; }
  .message-search input { min-height: 44px; font-size: 16px; }
  .message-row { min-height: 84px; padding: 11px 16px; }
  .message-line strong { font-size: 16px; }
  .message-line time { font-size: 12px; }
  .message-subject { font-size: 15px; }
  .message-preview { font-size: 13px; }
  .reader-content { padding: 16px 16px calc(88px + env(safe-area-inset-bottom)); }
  .reader-title h1 {
    display: -webkit-box;
    overflow: hidden;
    font-size: 22px;
    line-height: 1.22;
    text-overflow: clip;
    white-space: normal;
    overflow-wrap: anywhere;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
  }
  .reader-actions { overflow: visible; }
  .reader-actions > button { min-height: 44px; }
  .reader-more-menu {
    position: fixed;
    right: 12px;
    bottom: calc(76px + env(safe-area-inset-bottom));
    top: auto;
    left: 12px;
  }
  .sender-card { padding: 12px 0; }
  .sender-info strong { font-size: 16px; }
  .sender-info span, .sender-info small { font-size: 13px; overflow-wrap: anywhere; }
  .reader-status { font-size: 13px; }
  .mail-body { padding: 16px; font-size: 16px; line-height: 1.55; overflow-wrap: anywhere; }
  .compose-view { padding: 16px 12px calc(88px + env(safe-area-inset-bottom)); }
  .compose-head h1 { font-size: 24px; }
  .compose-head small { font-size: 13px; }
  .compose-form > label,
  .compose-form > label:first-child,
  .compose-advanced > label {
    display: grid;
    grid-template-columns: 1fr;
    gap: 7px;
    padding: 12px 14px;
  }
  .compose-form input, .compose-form textarea { font-size: 16px; }
  .compose-expand { justify-self: start; min-height: 44px; }
  .compose-file-list { grid-column: 1; }
  .body-field textarea { min-height: 38dvh; }
  .compose-footer { grid-template-columns: 1fr 1fr; }
  .compose-save-state { grid-column: 1 / -1; font-size: 12px; }
  .compose-footer [data-action="send"] { grid-column: 1 / -1; }
  .mobile-bottom-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100vw;
    display: grid;
    min-height: calc(68px + env(safe-area-inset-bottom));
    grid-template-columns: repeat(4, minmax(0,1fr));
    overflow: hidden;
    padding: 4px 4px max(6px, env(safe-area-inset-bottom));
  }
  .mobile-bottom-nav button {
    width: 100%;
    min-width: 0;
    min-height: 60px;
    flex: initial;
    font-size: 11px;
  }
  .mobile-compose-fab {
    position: fixed;
    z-index: 1080;
    right: max(18px, env(safe-area-inset-right));
    bottom: calc(82px + env(safe-area-inset-bottom));
    display: inline-flex;
    min-width: 56px;
    min-height: 56px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 18px;
    border: 0;
    border-radius: 28px;
    color: #fff;
    background: var(--color-accent);
    box-shadow: 0 8px 24px rgba(0,0,0,.3);
    font-size: 15px;
    font-weight: 700;
  }
  .more-view { height: 100%; overflow-y: auto; padding: 20px 16px calc(92px + env(safe-area-inset-bottom)); }
  .more-view h1 { font-size: 26px; }
  .more-groups button { min-height: 64px; }
  .settings-view, .admin-view { padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
  .settings-view .choice-row.theme-options { grid-template-columns: 1fr; }
  .settings-form { grid-template-columns: 1fr !important; }
  .settings-form label, .settings-form button { width: 100%; min-width: 0; }
  .admin-department {
    grid-template-columns: 28px minmax(0,1fr) auto;
    align-items: start;
  }
  .admin-row-actions {
    grid-column: 1 / -1;
    width: 100%;
    margin-top: 8px;
  }
  .admin-row-actions button {
    flex: 1 1 150px;
    min-width: 0;
    min-height: 44px;
    white-space: normal;
  }
}

@media (max-width: 360px) {
  .mobile-bottom-nav button { font-size: 10px; }
  .mobile-compose-fab span { display: none; }
  .mobile-compose-fab { width: 56px; padding: 0; }
  .reader-actions > button:not(.reader-back) span { display: none; }
}
