/*
 * FagulhaMail visual foundation.
 * This stylesheet is intentionally independent of the API layer: every state
 * is rendered from existing semantic classes in assets/app.js.
 */
:root {
  color-scheme: dark;
  font-family: Calibri, Candara, "Segoe UI", Arial, system-ui, sans-serif;
  font-synthesis: none;
  --fm-canvas: #0b0e12;
  --fm-chrome: #12171e;
  --fm-surface: #171d24;
  --fm-surface-raised: #1e252e;
  --fm-surface-hover: #27323e;
  --fm-surface-selected: #183d62;
  --fm-border: #303b47;
  --fm-border-strong: #4c5b6b;
  --fm-text: #f2f5f8;
  --fm-text-muted: #b0bac5;
  --fm-text-subtle: #85919d;
  --color-accent: #0f73be;
  --color-accent-hover: #2488d4;
  --color-accent-active: #075a9f;
  --color-accent-soft: #193f63;
  --color-accent-contrast: #ffffff;
  --color-focus-ring: #69b4f6;
  --fm-orange: #ff7a1a;
  --fm-orange-hover: #ff934b;
  --fm-green: #47cc88;
  --fm-warning: #f4ba43;
  --fm-danger: #f26870;
  --fm-space-1: 4px;
  --fm-space-2: 8px;
  --fm-space-3: 12px;
  --fm-space-4: 16px;
  --fm-space-5: 20px;
  --fm-space-6: 24px;
  --fm-space-8: 32px;
  --fm-control-radius: 6px;
  --fm-panel-radius: 10px;
  --fm-shadow-float: 0 18px 45px rgb(0 0 0 / 38%);
  --fm-focus: 0 0 0 2px var(--fm-canvas), 0 0 0 4px var(--color-focus-ring);
}

/* The current client starts dark; this semantic override is ready for the
   existing/future theme toggle without duplicating component selectors. */
html[data-theme="light"], body[data-theme="light"], .app-shell[data-theme="light"] {
  color-scheme: light;
  --fm-canvas: #f3f5f7;
  --fm-chrome: #ffffff;
  --fm-surface: #ffffff;
  --fm-surface-raised: #f8fafb;
  --fm-surface-hover: #eaf0f5;
  --fm-surface-selected: var(--color-accent-soft);
  --fm-border: #d5dde5;
  --fm-border-strong: #aab8c5;
  --fm-text: #17212b;
  --fm-text-muted: #52616f;
  --fm-text-subtle: #758392;
  --color-accent-soft: #dceefc;
  --fm-orange: #d95f00;
  --fm-orange-hover: #b94f00;
  --fm-green: #177a45;
  --fm-warning: #946500;
  --fm-danger: #b92f3a;
  --fm-shadow-float: 0 16px 40px rgb(28 43 57 / 18%);
}

* { box-sizing: border-box; }
html, body { min-width: 320px; min-height: 100%; margin: 0; background: var(--fm-canvas); }
body { color: var(--fm-text); line-height: 1.4; }
button, input, textarea { font: inherit; }
button { -webkit-font-smoothing: antialiased; }
button, input, textarea { border: 1px solid var(--fm-border); color: var(--fm-text); background: var(--fm-surface-raised); }
button {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 12px;
  border-radius: var(--fm-control-radius);
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease, transform 140ms ease;
}
button:hover { border-color: var(--fm-border-strong); background: var(--fm-surface-hover); }
button:active { transform: translateY(1px); }
button:disabled { cursor: not-allowed; opacity: .44; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: none; box-shadow: var(--fm-focus); }
button.primary { border-color: var(--color-accent); color: var(--color-accent-contrast); background: var(--color-accent); }
button.primary:hover { border-color: var(--color-accent-hover); background: var(--color-accent-hover); }
button.secondary { color: var(--fm-text-muted); background: transparent; }
button.secondary:hover { color: var(--fm-text); background: var(--fm-surface-hover); }
button.icon-button { width: 34px; min-width: 34px; padding: 0; color: var(--fm-text-muted); background: transparent; }
button.icon-button:hover { color: var(--fm-text); }
input, textarea { width: 100%; border-radius: var(--fm-control-radius); font-size: 15px; line-height: 1.35; }
input { min-height: 40px; padding: 0 12px; }
textarea { min-height: 320px; padding: 12px; resize: vertical; line-height: 1.6; }
input::placeholder, textarea::placeholder { color: var(--fm-text-subtle); opacity: 1; }
small { color: var(--fm-text-muted); font-size: 12px; line-height: 1.4; }

.icon { display: block; width: 18px; height: 18px; flex: 0 0 auto; stroke: currentColor; }
.app-shell { min-height: 100vh; background: var(--fm-canvas); }

/* Global chrome */
.app-titlebar {
  position: relative;
  z-index: 5;
  display: grid;
  min-height: 52px;
  grid-template-columns: minmax(190px, 1fr) minmax(280px, 510px) minmax(190px, 1fr);
  align-items: center;
  gap: var(--fm-space-4);
  padding: 0 var(--fm-space-5);
  border-bottom: 1px solid var(--fm-border);
  background: linear-gradient(90deg, #10151b, #161d25);
}
.brand, .auth-brand { display: flex; align-items: center; gap: 9px; color: var(--fm-text); font-size: 16px; letter-spacing: -.1px; }
.brand strong, .auth-brand > span:last-child { font-weight: 700; }
.brand strong span, .auth-brand > span:last-child span { color: var(--fm-orange); }
.brand-mark, .auth-brand-mark {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 1px solid #6e4a31;
  border-color: color-mix(in srgb, var(--fm-orange) 52%, var(--fm-border));
  border-radius: 8px;
  color: var(--fm-orange);
  background: #1d222a;
}
.brand-mark .icon { width: 17px; height: 17px; }
.global-search {
  display: flex;
  min-width: 0;
  height: 36px;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid var(--fm-border-strong);
  border-radius: 8px;
  color: var(--fm-text-subtle);
  background: #1a222c;
}
.global-search:focus-within { border-color: var(--color-accent); box-shadow: var(--fm-focus); }
.global-search .icon { width: 16px; height: 16px; }
.global-search input { min-width: 0; min-height: 0; padding: 0; border: 0; outline: 0; box-shadow: none; background: transparent; }
.title-actions { display: flex; align-items: center; justify-content: flex-end; gap: var(--fm-space-2); min-width: 0; }
.identity-name { overflow: hidden; color: var(--fm-text-muted); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }

/* Safe, complete authentication page — works even before workspace styles load. */
.auth-page {
  display: grid;
  min-height: calc(100vh - 52px);
  place-items: center;
  padding: var(--fm-space-6);
  background:
    radial-gradient(680px 420px at 50% 12%, color-mix(in srgb, var(--color-accent) 20%, transparent), transparent 70%),
    var(--fm-canvas);
}
.auth-card {
  width: min(100%, 456px);
  padding: clamp(24px, 5vw, 38px);
  border: 1px solid var(--fm-border);
  border-radius: 14px;
  background: linear-gradient(145deg, #1b222a, #151a20);
  box-shadow: var(--fm-shadow-float);
}
.auth-brand { margin-bottom: var(--fm-space-6); }
.auth-brand-mark { width: 34px; height: 34px; }
.auth-brand-mark .icon { width: 20px; height: 20px; }
.auth-card h1 { margin: 0 0 8px; letter-spacing: -.45px; font-size: 27px; line-height: 1.18; }
.auth-card > p { margin: 0; color: var(--fm-text-muted); font-size: 15px; line-height: 1.5; }
.auth-form { display: grid; gap: var(--fm-space-4); margin-top: var(--fm-space-6); }
.auth-form label { display: grid; gap: 7px; color: var(--fm-text); font-size: 14px; font-weight: 600; }
.auth-form .primary { width: 100%; min-height: 42px; margin-top: 4px; }
.auth-form small { margin-top: -5px; }
.notice.error {
  display: flex;
  gap: 8px;
  margin-top: var(--fm-space-5);
  padding: 11px 12px;
  border: 1px solid rgb(242 104 112 / 60%);
  border-left: 3px solid var(--fm-danger);
  border-radius: var(--fm-control-radius);
  background: rgb(125 43 49 / 42%);
  color: #ffdde0;
  font-size: 14px;
  line-height: 1.45;
}
.notice.error::before { content: "!"; display: grid; width: 17px; height: 17px; flex: 0 0 17px; place-items: center; border: 1px solid currentColor; border-radius: 50%; font-size: 11px; font-weight: 700; }

/* Fallback for the richer auth shell. This prevents a broken login surface
   if a browser temporarily has only the base stylesheet in cache. */
.fm-auth-shell { display: grid; min-height: 100vh; grid-template-rows: minmax(0, 1fr) auto; color: var(--fm-text); background: radial-gradient(680px 430px at 12% 12%, color-mix(in srgb, var(--color-accent) 18%, transparent), transparent 70%), var(--fm-canvas); }
.fm-auth-stage { display: grid; width: min(1100px, calc(100% - 48px)); grid-template-columns: minmax(300px, .9fr) minmax(360px, 460px); gap: clamp(40px, 8vw, 120px); align-items: center; justify-content: center; margin: auto; padding: 48px 0; }
.fm-auth-context { display: grid; align-content: center; gap: 40px; min-width: 0; }
.fm-auth-logo, .fm-auth-card-brand { display: flex; align-items: center; gap: 10px; font-size: 18px; }
.fm-auth-logo > span, .fm-auth-card-brand > span { display: grid; width: 34px; height: 34px; place-items: center; border: 1px solid var(--fm-border-strong); border-radius: 10px; color: var(--color-accent); background: var(--fm-surface-raised); }
.fm-auth-logo strong, .fm-auth-card-brand strong { font-weight: 700; }.fm-auth-logo strong span, .fm-auth-card-brand strong span { color: var(--fm-orange); }
.fm-auth-copy { max-width: 470px; }.fm-auth-eyebrow, .fm-auth-step { margin: 0 0 10px; color: var(--color-accent); font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
.fm-auth-copy h2 { margin: 0; font-size: clamp(29px, 3vw, 42px); line-height: 1.12; letter-spacing: -.04em; }.fm-auth-copy p:not(.fm-auth-eyebrow) { margin: 18px 0 0; color: var(--fm-text-muted); font-size: 15px; line-height: 1.6; }
.fm-auth-features { display: grid; gap: 12px; margin: 0; padding: 0; color: var(--fm-text-muted); font-size: 13px; list-style: none; }.fm-auth-features li { display: flex; align-items: center; gap: 9px; }.fm-auth-features .icon { color: var(--color-accent); }
.fm-auth-card { width: 100%; padding: 36px; border: 1px solid var(--fm-border); border-radius: 16px; background: linear-gradient(145deg, var(--fm-surface-raised), var(--fm-surface)); box-shadow: var(--fm-shadow-float); }
.fm-auth-card-brand { display: none; margin-bottom: 24px; font-size: 16px; }.fm-auth-card h1 { margin: 0; font-size: 27px; line-height: 1.2; letter-spacing: -.035em; }.fm-auth-description { margin: 10px 0 0; color: var(--fm-text-muted); font-size: 13px; line-height: 1.55; }
.fm-auth-card .auth-form { margin-top: 26px; }.fm-auth-card .auth-form label { color: var(--fm-text); font-size: 12px; }.fm-auth-card .auth-form .primary { width: 100%; min-height: 42px; }.fm-auth-card .notice { margin-top: 17px; }
.fm-auth-card .auth-form.compact { margin-top: 0; }
.auth-passkey { display: flex; width: 100%; min-height: 42px; align-items: center; justify-content: center; gap: 8px; }
.auth-divider { display: flex; align-items: center; gap: 10px; color: var(--fm-text-subtle); font-size: 11px; text-transform: uppercase; }
.auth-divider::before, .auth-divider::after { content: ""; height: 1px; flex: 1; background: var(--fm-border); }
.text-button { min-height: 34px; border-color: transparent; background: transparent; color: var(--fm-text-muted); }
.fm-auth-footer { display: flex; justify-content: space-between; width: min(1100px, calc(100% - 48px)); margin: 0 auto; padding: 16px 0 20px; border-top: 1px solid var(--fm-border); color: var(--fm-text-subtle); font-size: 11px; }

/* Main frame: command ribbon, workspace and status bar. */
.workspace-frame { display: grid; min-height: calc(100vh - 52px); grid-template-rows: 94px minmax(0, 1fr) 30px; }
.app-ribbon { display: grid; min-width: 0; grid-template-rows: 32px 62px; border-bottom: 1px solid var(--fm-border); background: linear-gradient(180deg, #181e26, #141a21); }
.ribbon-tabs { display: flex; align-items: flex-end; gap: 3px; overflow-x: auto; padding: 0 18px; border-bottom: 1px solid rgb(255 255 255 / 6%); }
.ribbon-tab { height: 32px; flex: 0 0 auto; padding: 0 13px; border: 0; border-radius: 7px 7px 0 0; color: var(--fm-text-muted); background: transparent; font-size: 13px; font-weight: 600; }
.ribbon-tab:hover { background: rgb(255 255 255 / 7%); }
.ribbon-tab.active { color: var(--fm-text); background: #273442; box-shadow: inset 0 -2px var(--color-accent); }
.ribbon-commands { display: flex; min-width: 0; align-items: center; gap: 8px; overflow-x: auto; padding: 0 18px; scrollbar-width: thin; }
.ribbon-commands button { flex: 0 0 auto; min-height: 36px; border-radius: 8px; white-space: nowrap; font-size: 13px; font-weight: 600; }
.ribbon-commands .primary { color: var(--color-accent-contrast); background: var(--color-accent); border-color: var(--color-accent); }
.ribbon-divider { width: 1px; height: 28px; flex: 0 0 1px; margin: 0 2px; background: var(--fm-border); }

.workspace-shell { display: grid; min-height: 0; grid-template-columns: 252px minmax(0, 1fr); }
.workspace-sidebar { display: flex; min-height: 0; flex-direction: column; gap: 6px; overflow: auto; padding: 14px 12px; border-right: 1px solid var(--fm-border); background: #151b23; }
.sidebar-actions { display: grid; grid-template-columns: minmax(0, 1fr) 34px; gap: 8px; margin-bottom: 10px; }
.sidebar-actions .primary { min-height: 40px; justify-content: center; border-radius: 8px; }
.folder-navigation, .department-section { display: grid; gap: 2px; }
.nav-label { margin: 11px 8px 5px; color: var(--fm-text-subtle); font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.folder-item, .department-row {
  display: grid;
  min-height: 36px;
  grid-template-columns: 20px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 0 9px;
  border: 0;
  border-radius: 7px;
  color: var(--fm-text-muted);
  background: transparent;
  font-size: 14px;
  text-align: left;
}
.folder-item:hover { color: var(--fm-text); background: var(--fm-surface-hover); }
.folder-item.active { color: var(--fm-text); background: color-mix(in srgb, var(--color-accent) 24%, var(--fm-surface)); box-shadow: inset 3px 0 var(--color-accent); }
.folder-item strong { overflow: hidden; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.folder-item .icon, .department-row .icon { width: 17px; height: 17px; }
.folder-item em { color: var(--color-accent); font-size: 19px; font-style: normal; }
.department-row { color: var(--fm-text-subtle); font-size: 13px; }
.sidebar-bottom { display: grid; gap: 2px; margin-top: auto; padding-top: 12px; border-top: 1px solid var(--fm-border); }

.workspace-main { min-width: 0; min-height: 0; overflow: hidden; background: #10151b; }
.mail-workspace { display: grid; min-width: 0; min-height: 100%; grid-template-columns: 360px minmax(0, 1fr) 286px; }
.message-column { display: grid; min-width: 0; min-height: 0; grid-template-rows: auto auto auto minmax(0, 1fr); border-right: 1px solid var(--fm-border); background: #151b23; }
.column-head { display: flex; min-height: 90px; align-items: center; justify-content: space-between; gap: 12px; padding: 17px 18px; border-bottom: 1px solid var(--fm-border); }
.crumb, .reader-kicker { margin: 0 0 3px; color: var(--color-accent); font-size: 12px; font-weight: 700; }
.column-head h1 { margin: 0; letter-spacing: -.25px; font-size: 21px; line-height: 1.15; }
.column-tools { align-self: flex-start; }
.list-tabs { display: flex; min-height: 42px; align-items: center; gap: 6px; padding: 0 14px; border-bottom: 1px solid var(--fm-border); }
.list-tabs button { min-height: 28px; padding: 0 9px; border-color: transparent; color: var(--fm-text-muted); background: transparent; font-size: 13px; }
.list-tabs button:hover, .list-tabs button.selected { color: var(--fm-text); background: var(--fm-surface-hover); }
.list-tabs button.selected { box-shadow: inset 0 -2px var(--color-accent); }
.list-tabs .list-filter { margin-left: auto; }
.list-filter .icon { width: 15px; height: 15px; }
.message-rows { min-height: 0; overflow: auto; }
.message-row {
  display: grid;
  width: 100%;
  min-height: 80px;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 10px;
  padding: 11px 14px;
  border: 0;
  border-bottom: 1px solid var(--fm-border);
  border-radius: 0;
  background: transparent;
  color: var(--fm-text);
  text-align: left;
}
.message-row:hover { background: var(--fm-surface-hover); }
.message-row.active { padding-left: 11px; border-left: 3px solid var(--color-accent); background: color-mix(in srgb, var(--color-accent) 24%, var(--fm-surface)); }
.message-row.unread { background-color: rgb(255 255 255 / 1.5%); }
.message-avatar, .sender-avatar, .profile-avatar {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid #4e6174;
  border-radius: 50%;
  color: #d9ecff;
  background: #28445e;
  font-size: 12px;
  font-weight: 700;
}
.message-main { display: grid; min-width: 0; gap: 2px; }
.message-line { display: flex; min-width: 0; align-items: center; gap: 8px; }
.message-line strong { overflow: hidden; flex: 1; font-size: 14px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.message-row.unread .message-line strong, .message-row.unread b { font-weight: 700; }
.message-line time { flex: 0 0 auto; color: var(--fm-text-subtle); font-size: 11px; font-variant-numeric: tabular-nums; }
.message-main b { overflow: hidden; color: var(--fm-text); font-size: 13px; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.message-main small { display: flex; align-items: center; gap: 5px; overflow: hidden; color: var(--fm-text-subtle); text-overflow: ellipsis; white-space: nowrap; }
.message-main small .icon { width: 13px; height: 13px; color: var(--fm-warning); }
.list-empty { display: grid; min-height: 220px; place-content: center; justify-items: center; gap: 8px; padding: 24px; color: var(--fm-text-subtle); text-align: center; }
.list-empty .icon { width: 28px; height: 28px; color: var(--color-accent); }

/* Reading and composition surfaces */
.reader-column { min-width: 0; min-height: 0; overflow: auto; background: #10151b; }
.reader-content, .compose-view, .admin-view { min-height: 100%; padding: 26px clamp(24px, 3vw, 42px) 44px; }
.reader-head, .compose-head, .admin-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; padding-bottom: 20px; border-bottom: 1px solid var(--fm-border); }
.reader-head h1, .compose-head h1, .admin-head h1 { margin: 0; color: var(--fm-text); letter-spacing: -.35px; font-size: clamp(22px, 2vw, 28px); line-height: 1.18; }
.reader-actions { display: flex; flex: 0 0 auto; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.reader-actions button { min-height: 32px; padding: 0 10px; color: var(--fm-text-muted); background: transparent; font-size: 13px; }
.sender-card { display: flex; align-items: center; gap: 12px; margin: 18px 0 12px; padding: 14px; border: 1px solid var(--fm-border); border-radius: var(--fm-panel-radius); background: var(--fm-surface); }
.sender-info { display: grid; min-width: 0; gap: 1px; }
.sender-info strong, .sender-info span, .sender-info small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sender-info strong { font-size: 14px; }
.sender-info span { color: var(--fm-text-muted); font-size: 13px; }
.sender-info small { color: var(--fm-text-subtle); }
.sender-card > .icon-button { margin-left: auto; }
.reader-status { display: flex; align-items: center; gap: 7px; margin-bottom: 12px; color: #b2d8fc; font-size: 12px; }
.reader-status .icon { width: 15px; height: 15px; color: var(--color-accent); }
.reader-external-images { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; margin: 0 0 12px; padding: 10px 12px; border: 1px solid color-mix(in srgb, var(--color-accent) 48%, var(--fm-border)); border-radius: 8px; color: var(--fm-text); background: color-mix(in srgb, var(--color-accent) 9%, var(--fm-surface)); font-size: 13px; }
.reader-external-images .icon { width: 16px; height: 16px; color: var(--color-accent); }
.reader-external-images button { margin-left: auto; min-height: 32px; white-space: nowrap; }
.reader-external-images.loaded { color: var(--fm-muted); }
.mail-html-frame { display: block; width: 100%; min-height: 280px; max-width: 1080px; border: 1px solid var(--fm-border); border-radius: var(--fm-panel-radius); background: #fff; overflow: hidden; }
.mail-body { min-height: 44vh; max-width: 1080px; padding: 28px 30px; border: 1px solid var(--fm-border); border-radius: var(--fm-panel-radius); color: #eef3f8; background: var(--fm-surface); font-size: 15px; line-height: 1.62; overflow-wrap: anywhere; white-space: pre-wrap; }
.reader-footer { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--fm-border); }
.reader-footer button { min-height: 32px; color: var(--fm-text-muted); background: transparent; }
.reader-empty { display: grid; min-height: 58vh; place-content: center; justify-items: center; padding: 32px; color: var(--fm-text-muted); text-align: center; }
.empty-orb { display: grid; width: 60px; height: 60px; margin-bottom: 14px; place-items: center; border: 1px solid var(--fm-border-strong); border-radius: 18px; color: var(--fm-orange); background: #1a222c; }
.empty-orb .icon { width: 28px; height: 28px; }
.reader-empty h2 { margin: 0 0 5px; color: var(--fm-text); font-size: 22px; }
.reader-empty p { margin: 0; }

.compose-head { margin-bottom: 20px; }
.compose-head small { display: block; margin-top: 5px; }
.compose-form { display: grid; overflow: hidden; border: 1px solid var(--fm-border); border-radius: var(--fm-panel-radius); background: var(--fm-surface); }
.compose-form > label { display: grid; gap: 6px; padding: 12px 16px; border-bottom: 1px solid var(--fm-border); color: var(--fm-text-muted); font-size: 13px; font-weight: 700; }
.compose-form input, .compose-form textarea { border-color: transparent; background: transparent; }
.compose-form input:focus-visible, .compose-form textarea:focus-visible { border-color: var(--color-accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-focus-ring) 28%, transparent); }
.body-field { padding-bottom: 16px !important; }
.body-editor { position: relative; display: block; }
.body-field textarea { min-height: min(49vh, 510px); padding-left: 42px; }
.compose-writing-cue {
  position: absolute;
  z-index: 1;
  top: 14px;
  left: 13px;
  color: var(--color-accent);
  pointer-events: none;
}
.compose-writing-cue .icon { width: 18px; height: 18px; }
.body-editor:has(textarea:not(:placeholder-shown)) .compose-writing-cue { display: none; }
.compose-footer { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; padding: 12px 16px; background: var(--fm-surface-raised); }

/* Optional operational context panel. It never overlaps the reader. */
.operations-panel { min-height: 0; overflow: auto; border-left: 1px solid var(--fm-border); background: #151b23; }
.operations-panel > header { position: sticky; top: 0; z-index: 2; display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; padding: 18px 16px 14px; border-bottom: 1px solid var(--fm-border); background: rgb(21 27 35 / 96%); backdrop-filter: blur(10px); }
.operations-panel h2 { margin: 0; font-size: 18px; }
.profile-summary { display: flex; align-items: center; gap: 10px; padding: 16px; }
.profile-summary > div { display: grid; gap: 2px; min-width: 0; }
.profile-summary strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.metric-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 0 16px 16px; }
.metric-grid > div { display: grid; gap: 3px; padding: 12px; border: 1px solid var(--fm-border); border-radius: 8px; background: var(--fm-surface-raised); }
.metric-grid strong { color: var(--fm-text); font-size: 22px; font-variant-numeric: tabular-nums; }
.metric-grid span { color: var(--fm-text-subtle); font-size: 11px; }
.panel-section { display: grid; gap: 4px; padding: 16px; border-top: 1px solid var(--fm-border); }
.panel-section h3 { margin: 0 0 6px; font-size: 13px; }
.panel-section button { justify-content: flex-start; min-height: 32px; border-color: transparent; color: var(--fm-text-muted); background: transparent; font-size: 13px; }
.panel-section.subdued p { margin: 0; color: var(--fm-text-subtle); font-size: 12px; line-height: 1.5; }

/* Administration */
.admin-head { margin-bottom: 24px; }
.admin-head > div > p:not(.reader-kicker) { max-width: 620px; margin: 7px 0 0; color: var(--fm-text-muted); }
.admin-hero { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; padding: 18px; border: 1px solid var(--fm-border); border-radius: var(--fm-panel-radius); background: linear-gradient(100deg, #1b3348, #17212b); }
.admin-hero > div { display: flex; align-items: center; gap: 12px; }
.profile-avatar.large { width: 48px; height: 48px; font-size: 14px; }
.admin-hero strong { display: block; }
.admin-hero p { margin: 3px 0 0; color: var(--fm-text-muted); font-size: 13px; }
.status-chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 8px; border: 1px solid rgb(71 204 136 / 45%); border-radius: 999px; color: #b5f2d0; background: rgb(35 104 71 / 30%); font-size: 12px; white-space: nowrap; }
.status-chip .icon { width: 14px; height: 14px; color: var(--fm-green); }
.admin-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.admin-card { overflow: hidden; border: 1px solid var(--fm-border); border-radius: var(--fm-panel-radius); background: var(--fm-surface); }
.admin-card.full { grid-column: 1 / -1; }
.admin-card > header { display: flex; gap: 10px; padding: 18px; border-bottom: 1px solid var(--fm-border); }
.admin-card > header > .icon { width: 20px; height: 20px; color: var(--color-accent); }
.admin-card h2 { margin: 0; font-size: 16px; }
.admin-card header p { margin: 4px 0 0; color: var(--fm-text-muted); font-size: 13px; line-height: 1.45; }
.department-admin-list { display: grid; padding: 8px; }
.admin-department { display: grid; min-height: 52px; grid-template-columns: 21px minmax(0, 1fr) auto; align-items: center; gap: 9px; padding: 8px; border-radius: 7px; }
.admin-department:hover { background: var(--fm-surface-hover); }
.admin-department .icon { color: var(--fm-text-subtle); }
.admin-department div { display: grid; gap: 2px; }
.admin-department strong { font-size: 14px; }
.admin-department em { color: var(--color-accent); font-size: 12px; font-style: normal; }
.admin-department .admin-row-actions {
  display: flex;
  grid-column: 2 / -1;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}
.admin-department .admin-row-actions button {
  min-width: 0;
  min-height: 36px;
  white-space: nowrap;
}
.admin-readonly { display: grid; padding: 8px 18px 18px; }
.admin-readonly > div { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--fm-border); font-size: 13px; }
.admin-readonly > div:last-child { border-bottom: 0; }
.admin-readonly span { color: var(--fm-text-muted); }
.admin-readonly strong { text-align: right; }

.floating-action-menu { position: fixed; z-index: 30; right: calc(286px + 28px); top: 150px; display: grid; min-width: 235px; padding: 6px; border: 1px solid var(--fm-border-strong); border-radius: var(--fm-panel-radius); background: #242d38; box-shadow: var(--fm-shadow-float); }
.floating-action-menu button { justify-content: flex-start; min-height: 36px; padding: 0 10px; border-color: transparent; color: var(--fm-text); background: transparent; font-size: 13px; }
.floating-action-menu button:hover { background: #34465a; }
.floating-action-menu .icon { width: 16px; height: 16px; color: var(--color-accent-hover); }
.toast-stack { position: fixed; z-index: 40; right: 18px; bottom: 44px; display: grid; width: min(360px, calc(100vw - 32px)); gap: 8px; pointer-events: none; }
.toast { padding: 12px; border: 1px solid var(--fm-border-strong); border-left: 3px solid var(--color-accent); border-radius: 8px; background: #222b35; box-shadow: var(--fm-shadow-float); color: var(--fm-text); font-size: 13px; line-height: 1.4; }
.toast.warning { border-left-color: var(--fm-warning); }
.toast.error { border-left-color: var(--fm-danger); }
.app-statusbar { display: flex; min-width: 0; align-items: center; justify-content: space-between; gap: 16px; padding: 0 16px; border-top: 1px solid var(--fm-border); color: var(--fm-text-muted); background: #10151b; font-size: 11px; }

html[data-theme="light"] body,
body[data-theme="light"],
.app-shell[data-theme="light"] { background: var(--fm-canvas); }
html[data-theme="light"] .app-titlebar,
body[data-theme="light"] .app-titlebar,
.app-shell[data-theme="light"] .app-titlebar { color: var(--color-accent-contrast); background: var(--color-accent); }
html[data-theme="light"] .app-ribbon,
body[data-theme="light"] .app-ribbon,
.app-shell[data-theme="light"] .app-ribbon { background: linear-gradient(180deg, #fff, #f5f7f9); }
html[data-theme="light"] .workspace-sidebar,
html[data-theme="light"] .message-column,
html[data-theme="light"] .operations-panel,
html[data-theme="light"] .reader-column,
html[data-theme="light"] .workspace-main,
html[data-theme="light"] .app-statusbar,
body[data-theme="light"] .workspace-sidebar,
body[data-theme="light"] .message-column,
body[data-theme="light"] .operations-panel,
body[data-theme="light"] .reader-column,
body[data-theme="light"] .workspace-main,
body[data-theme="light"] .app-statusbar,
.app-shell[data-theme="light"] .workspace-sidebar,
.app-shell[data-theme="light"] .message-column,
.app-shell[data-theme="light"] .operations-panel,
.app-shell[data-theme="light"] .reader-column,
.app-shell[data-theme="light"] .workspace-main,
.app-shell[data-theme="light"] .app-statusbar { background: var(--fm-surface); }
html[data-theme="light"] .message-row.active,
body[data-theme="light"] .message-row.active,
.app-shell[data-theme="light"] .message-row.active { background: var(--color-accent-soft); }
html[data-theme="light"] .folder-item.active,
body[data-theme="light"] .folder-item.active,
.app-shell[data-theme="light"] .folder-item.active { color: var(--fm-text); background: var(--color-accent-soft); }
html[data-theme="light"] .global-search,
body[data-theme="light"] .global-search,
.app-shell[data-theme="light"] .global-search { background: #fff; }
html[data-theme="light"] .mail-body,
body[data-theme="light"] .mail-body,
.app-shell[data-theme="light"] .mail-body { color: var(--fm-text); }

@media (max-width: 1250px) {
  .mail-workspace { grid-template-columns: 336px minmax(0, 1fr); }
  .operations-panel { display: none; }
  .floating-action-menu { right: 24px; }
}
@media (max-width: 900px) {
  .app-titlebar { grid-template-columns: 1fr minmax(220px, 410px) auto; padding: 0 14px; }
  .identity-name { display: none; }
  .workspace-frame { grid-template-rows: 86px minmax(0, 1fr) 30px; }
  .app-ribbon { grid-template-rows: 30px 56px; }
  .ribbon-commands { padding: 0 10px; }
  .workspace-shell { grid-template-columns: 66px minmax(0, 1fr); }
  .workspace-sidebar { align-items: center; padding: 12px 7px; }
  .sidebar-actions { grid-template-columns: 42px; }
  .sidebar-actions .primary { width: 42px; padding: 0; font-size: 0; }
  .sidebar-actions .primary .icon { width: 19px; height: 19px; }
  .sidebar-actions .sidebar-panel-toggle { display: none; }
  .nav-label, .folder-item strong, .department-section, .sidebar-bottom strong, .folder-item em { display: none; }
  .folder-item { width: 42px; min-height: 42px; grid-template-columns: 1fr; justify-items: center; padding: 0; }
  .folder-item .icon { width: 19px; height: 19px; }
  .mail-workspace { grid-template-columns: minmax(280px, 42vw) minmax(0, 1fr); }
  .reader-content, .compose-view, .admin-view { padding: 22px; }
  .fm-auth-stage { width: min(500px, calc(100% - 32px)); grid-template-columns: 1fr; gap: 26px; padding: 30px 0; }
  .fm-auth-context { gap: 0; }.fm-auth-context .fm-auth-copy, .fm-auth-context .fm-auth-features, .fm-auth-logo { display: none; }
  .fm-auth-card-brand { display: flex; }.fm-auth-card { padding: 28px; }.fm-auth-footer { width: min(500px, calc(100% - 32px)); }
}
/* Preference workspace: visual-only controls; no authority is moved from the server. */
.admin-layout { display: grid; grid-template-columns: 232px minmax(0, 1fr); gap: 28px; align-items: start; }
.admin-nav { display: grid; gap: 8px; padding-right: 22px; border-right: 1px solid var(--fm-border); }
.admin-nav-item { display: flex; align-items: center; gap: 10px; min-height: 54px; padding: 10px 12px; color: var(--fm-text-muted); text-align: left; border: 1px solid transparent; border-radius: var(--fm-radius-md); background: transparent; }
.admin-nav-item > span { display: grid; min-width: 0; gap: 2px; align-content: center; }
.admin-nav-item > span > strong { display: block; overflow: hidden; color: inherit; font-size: 13px; font-weight: 650; line-height: 17px; text-overflow: ellipsis; white-space: nowrap; }
.admin-nav-item > span > small { display: block; overflow: hidden; color: var(--fm-text-muted); font-size: 11px; font-weight: 400; line-height: 15px; text-overflow: ellipsis; white-space: nowrap; }
.admin-nav-item:hover { color: var(--fm-text); background: var(--fm-surface-hover); }
.admin-nav-item.active { color: var(--fm-text); border-color: color-mix(in srgb, var(--fm-accent) 48%, var(--fm-border)); background: color-mix(in srgb, var(--fm-accent) 17%, var(--fm-surface)); box-shadow: inset 3px 0 0 var(--fm-accent); }
.settings-content { min-width: 0; }
.settings-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.settings-cards article { min-height: 136px; padding: 20px; border: 1px solid var(--fm-border); border-radius: var(--fm-radius-lg); background: var(--fm-surface); box-shadow: var(--fm-shadow-sm); }
.settings-cards article h2 { margin: 0 0 8px; font-size: 16px; font-weight: 600; }
.settings-cards article p { margin: 0; color: var(--fm-text-muted); line-height: 1.55; }
.settings-password-card { grid-column: 1 / -1; }
.settings-security-card { grid-column: 1 / -1; }
.settings-security-card > header { display: flex; gap: 18px; align-items: flex-start; justify-content: space-between; }
.settings-security-card > header > div { min-width: 0; }
.settings-security-card h3, .settings-password-card h3 { margin: 0 0 8px; }
.security-readiness { flex: 0 0 auto; padding: 6px 10px; border: 1px solid var(--fm-border); border-radius: var(--fm-radius-pill); color: var(--fm-text-muted); font-size: 12px; font-weight: 650; }
.security-readiness.ready { border-color: color-mix(in srgb, #2fb878 55%, var(--fm-border)); color: #2fb878; background: color-mix(in srgb, #2fb878 10%, transparent); }
.security-progress { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 18px; }
.security-progress > div { display: grid; gap: 4px; padding: 12px; border: 1px solid var(--fm-border); border-radius: var(--fm-radius-md); background: var(--fm-surface-raised); }
.security-progress span { color: var(--fm-text-muted); font-size: 11px; }
.security-progress strong { overflow-wrap: anywhere; font-size: 13px; }
.recovery-codes { margin-top: 18px; padding: 16px; border: 1px solid color-mix(in srgb, var(--fm-accent) 45%, var(--fm-border)); border-radius: var(--fm-radius-md); background: color-mix(in srgb, var(--fm-accent) 7%, var(--fm-surface)); }
.recovery-codes h4 { margin: 0 0 6px; }
.recovery-codes ol { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px 24px; margin: 14px 0; padding-left: 24px; }
.recovery-codes code { color: var(--fm-text); font-size: 13px; letter-spacing: .04em; }
.settings-form { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto; gap: 12px; align-items: end; margin-top: 18px; }
.settings-form label { display: grid; gap: 6px; min-width: 0; }
.settings-form label span { color: var(--fm-text-muted); font-size: 12px; font-weight: 600; }
.settings-form input { width: 100%; min-width: 0; height: 38px; padding: 0 10px; border: 1px solid var(--fm-border); border-radius: var(--fm-radius-sm); background: var(--fm-surface); color: var(--fm-text); }
.settings-form button { min-height: 38px; white-space: nowrap; }
.message-search { display: flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 10px; border-top: 1px solid var(--fm-border); border-bottom: 1px solid var(--fm-border); background: var(--fm-surface); color: var(--fm-text-muted); }
.message-search input { width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--fm-text); font: inherit; }
.choice-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.choice-row button { min-width: 112px; border-radius: var(--fm-radius-pill); }

@media (max-width: 900px) {
  .admin-layout { grid-template-columns: 1fr; gap: 18px; }
  .admin-nav { grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 0 0 14px; border-right: 0; border-bottom: 1px solid var(--fm-border); }
}
@media (max-width: 650px) {
  .app-titlebar { min-height: 52px; grid-template-columns: 1fr auto; }
  .global-search { display: none; }
  .workspace-frame { min-height: calc(100vh - 52px); grid-template-rows: 78px minmax(0, 1fr) 30px; }
  .settings-security-card > header { display: grid; }
  .security-readiness { justify-self: start; }
  .security-progress { grid-template-columns: 1fr; }
  .recovery-codes ol { grid-template-columns: 1fr; }
  .app-ribbon { grid-template-rows: 30px 48px; }
  .ribbon-tabs { padding: 0 8px; }
  .ribbon-tab { padding: 0 8px; font-size: 12px; }
  .ribbon-commands .secondary span, .ribbon-commands .primary span { display: none; }
  .ribbon-commands .secondary, .ribbon-commands .primary { min-width: 38px; padding: 0 9px; }
  .workspace-shell { grid-template-columns: 1fr; }
  .workspace-sidebar { display: none; }
  .mail-workspace { grid-template-columns: 1fr; }
  .reader-column { display: none; }
  .message-column { border-right: 0; }
  .app-statusbar span:nth-child(2) { display: none; }
  .app-statusbar { justify-content: center; }
  .floating-action-menu { top: 128px; right: 12px; left: 12px; }
  .auth-page { min-height: calc(100vh - 52px); padding: 16px; }
  .auth-card { padding: 24px; }
}
@media (max-width: 440px) {
  .brand { font-size: 15px; }
  .app-titlebar { padding: 0 12px; }
  .auth-card h1 { font-size: 24px; }
  .fm-auth-card { padding: 24px 20px; border-radius: 12px; }.fm-auth-card h1 { font-size: 24px; }.fm-auth-footer { font-size: 10px; }
  .compose-footer { justify-content: stretch; }
  .compose-footer button { flex: 1 1 auto; }
  .admin-grid { grid-template-columns: 1fr; }
  .admin-nav { grid-template-columns: 1fr; }
  .settings-cards { grid-template-columns: 1fr; }
  .settings-form { grid-template-columns: 1fr; }
  .admin-card.full { grid-column: auto; }
  .admin-hero { align-items: flex-start; flex-direction: column; }
  .admin-department .admin-row-actions {
    display: grid;
    width: 100%;
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-top: 8px;
  }
  .admin-department .admin-row-actions button {
    width: 100%;
    min-height: 44px;
    padding-inline: 10px;
    line-height: 1.2;
    white-space: normal;
  }
}
@media (max-width: 360px) {
  .admin-department .admin-row-actions { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
@media (forced-colors: active) {
  button, input, textarea, .auth-card, .mail-body, .sender-card, .admin-card { border: 1px solid CanvasText; }
  button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid Highlight; outline-offset: 2px; box-shadow: none; }
  .folder-item.active, .message-row.active { outline: 2px solid Highlight; outline-offset: -2px; }
}
