/*
  IFP Petro — enterprise UI theme (design tokens + base components)
  ------------------------------------------------------------
  Plain CSS, no build step. Every colour, radius and shadow used by
  theme-bridge.css, sidebar.css, home-dashboard.css and auth-login.css
  comes from the custom properties on :root below. The same palette is
  fed into CoreUI/Bootstrap via resources/sass/app.scss.

  Status semantics (keep consistent across modules):
    success  — available / completed / approved
    info     — informational / active / selected
    warning  — low stock / pending / needs attention
    danger   — critical / failed / rejected / destructive
    neutral  — inactive / draft / empty
*/

:root {
  /* Brand palette */
  --ifp-navy:        #0B1F3A;
  --ifp-navy-800:    #12294A;
  --ifp-navy-700:    #1B3557;
  --ifp-blue:        #1677D2;
  --ifp-blue-hover:  #0F63B3;
  --ifp-blue-50:     #EEF5FD;
  --ifp-blue-100:    #D3E6F8;
  --ifp-blue-200:    #A9CDF0;

  /* Surfaces & lines */
  --bg:            #F3F6FA;
  --surface:       #FFFFFF;
  --surface-muted: #F8FAFC;
  --border:        #DCE3EB;
  --border-light:  #E6EBF1;
  --border-strong: #C2CCD8;
  --divider:       #E9EEF4;
  --track:         #E6EBF1;
  --row-hover:     #F5F8FC;

  /* Text */
  --heading:        #0B1F3A;
  --text:           #172B4D;
  --text-secondary: #64748B;
  --text-muted:     #64748B;
  --text-placeholder: #8A97A8;

  /* Primary action colour */
  --accent:          var(--ifp-blue);
  --accent-hover:    var(--ifp-blue-hover);
  --accent-contrast: #ffffff;
  --focus-ring:      0 0 0 3px rgba(22, 119, 210, .28);

  /* Semantic status colours — solid, soft background, readable text, border */
  --success:        #16A34A;
  --success-strong: #15803D;
  --success-bg:     #E8F6EE;
  --success-text:   #166534;
  --success-border: #B7E2C6;

  --info:           var(--ifp-blue);
  --info-bg:        var(--ifp-blue-50);
  --info-text:      #0F5296;
  --info-border:    var(--ifp-blue-100);

  --warning:        #F59E0B;
  --warning-strong: #D97706;
  --warning-bg:     #FEF5E2;
  --warning-text:   #92400E;
  --warning-border: #F8D9A0;

  --danger:         #DC2626;
  --danger-strong:  #B91C1C;
  --danger-bg:      #FDECEC;
  --danger-text:    #B91C1C;
  --danger-border:  #F5C2C2;

  --neutral:        #64748B;
  --neutral-bg:     #EEF1F5;
  --neutral-text:   #475569;
  --neutral-border: #DCE3EB;

  /* Sidebar (styles live in sidebar.css) */
  --sidebar-bg:          var(--ifp-navy);
  --sidebar-border:      #1A3150;
  --sidebar-text:        #C8D3E1;
  --sidebar-text-muted:  #8C9BB0;
  --sidebar-hover-bg:    #13294A;
  --sidebar-active-bg:   var(--ifp-blue);
  --sidebar-active-text: #ffffff;
  --sidebar-active-icon: #ffffff;
  --sidebar-group-icon:  #7FB6EC;
  --sidebar-accent:      var(--ifp-blue);
  --sidebar-focus:       #7FB6EC;
  --sidebar-divider:     #1A3150;
  --sidebar-flyout-bg:   #102745;
  --sidebar-width:       256px;
  --sidebar-width-collapsed: 68px;

  /* Legacy status aliases (badge-good / badge-mid / badge-bad) */
  --status-good-bg: var(--success-bg); --status-good-fg: var(--success-text);
  --status-mid-bg:  var(--warning-bg); --status-mid-fg:  var(--warning-text);
  --status-bad-bg:  var(--neutral-bg); --status-bad-fg:  var(--neutral-text);

  /* Shape */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 10px;
  --shadow-sm: 0 1px 2px rgba(11, 31, 58, .05);
  --shadow-md: 0 8px 24px rgba(11, 31, 58, .12);
  --shadow-lg: 0 16px 40px rgba(11, 31, 58, .18);

  /* Layout */
  --topbar-height: 60px;
  --content-pad:   24px;
  --control-height: 38px;

  /* Type */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;

  /* Type scale — use these instead of hard-coded sizes */
  --fs-xs:   11px;  /* badges, table header captions, meta */
  --fs-sm:   12px;  /* help text, <small>, .form-text */
  --fs-md:   13px;  /* labels, buttons, table cells, card headers, sidebar */
  --fs-base: 14px;  /* body text, inputs */
  --fs-lg:   16px;  /* card titles, h5 / h6 */
  --fs-xl:   18px;  /* h4 */
  --fs-2xl:  20px;  /* h3 */
  --fs-3xl:  24px;  /* h2, page titles */
  --fs-4xl:  28px;  /* h1, KPI values */
  --fs-display: 32px; /* hero counters only */
  --lh-base: 1.5;

  /* Motion — see "animation" section at the bottom */
  --ease: cubic-bezier(.4,0,.2,1);
  --dur-fast: 120ms;
  --dur: 200ms;
  --dur-slow: 320ms;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* ---------- Layout shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.app-main  { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-topbar {
  height: var(--topbar-height); background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 var(--content-pad);
  position: sticky; top: 0; z-index: 5;
}
.app-content { padding: 20px var(--content-pad) var(--content-pad); flex: 1; }

/* Sidebar: see public/css/sidebar.css */

.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--ifp-blue-50); color: var(--ifp-navy);
  display: flex; align-items: center; justify-content: center; font-size: var(--fs-md); font-weight: 700; flex: none;
}

/* ---------- Buttons ---------- */
.btn {
  padding: 8px 14px; border-radius: var(--radius-md); font-size: var(--fs-md); font-weight: 600;
  border: 1px solid transparent; cursor: pointer; font-family: var(--font);
  transition: transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-muted); }

/* ---------- Cards & KPIs ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow-sm); }
.kpi-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px; box-shadow: var(--shadow-sm); }
.kpi-card .label { font-size: var(--fs-xs); color: var(--text-secondary); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.kpi-card .value { font-size: var(--fs-3xl); font-weight: 700; margin-top: 6px; letter-spacing: -.01em; color: var(--heading); font-variant-numeric: tabular-nums; }
.kpi-card .trend { font-size: var(--fs-md); margin-top: 6px; color: var(--text-secondary); }

/* ---------- Badges (status pills) ---------- */
.badge { display: inline-block; padding: 3px 8px; border-radius: var(--radius-sm); font-size: var(--fs-xs); font-weight: 600; line-height: 1.4; white-space: nowrap; border: 1px solid transparent; }
.badge-good { background: var(--status-good-bg); color: var(--status-good-fg); border-color: var(--success-border); }
.badge-mid  { background: var(--status-mid-bg);  color: var(--status-mid-fg);  border-color: var(--warning-border); }
.badge-bad  { background: var(--status-bad-bg);  color: var(--status-bad-fg);  border-color: var(--neutral-border); }

/* ---------- Tables ---------- */
.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-sm); }
table.data-table { width: 100%; border-collapse: collapse; font-size: var(--fs-md); font-variant-numeric: tabular-nums; }
.data-table thead tr { text-align: left; background: var(--surface-muted); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .04em; color: var(--text-secondary); }
.data-table th { padding: 10px 16px; font-weight: 600; border-bottom: 1px solid var(--border); }
.data-table td { padding: 11px 16px; }
.data-table tbody tr { border-top: 1px solid var(--divider); transition: background var(--dur-fast) var(--ease); }
.data-table tbody tr:hover { background: var(--row-hover); }
.data-table.compact td { padding: 7px 16px; }

/* ---------- Progress / gauges ---------- */
.bar-track { height: 8px; background: var(--track); border-radius: 4px; overflow: hidden; }
.gauge {
  width: 44px; height: 88px; border: 2px solid var(--border-light); border-radius: 6px;
  position: relative; overflow: hidden; background: var(--surface-muted);
}
.gauge-fill {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: var(--accent);
  height: 0;
  transition: height 900ms var(--ease);
}
.gauge-fill.is-animated { /* height set via JS or inline after mount */ }
.gauge-lg { width: 56px; height: 112px; }
.gauge-xl { width: 72px; height: 140px; }

.bar-fill {
  height: 100%; background: var(--accent); border-radius: 4px;
  width: 0;
  transition: width 900ms var(--ease);
}

/* ---------- Drawer (right-side detail panel) ---------- */
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(11, 31, 58, .32); z-index: 1040;
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity var(--dur) var(--ease), visibility var(--dur) var(--ease);
}
.drawer-backdrop.show {
  opacity: 1; visibility: visible; pointer-events: auto;
  animation: fadeIn var(--dur) var(--ease);
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(400px, 92vw);
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: var(--shadow-md); z-index: 1041; overflow-y: auto;
  transform: translateX(100%); visibility: hidden;
  transition: transform var(--dur-slow) var(--ease), visibility var(--dur-slow) var(--ease);
}
.drawer.show {
  transform: translateX(0); visibility: visible;
  animation: slideInRight var(--dur-slow) var(--ease);
}
/* Journey drawer: do not block the Record activity column on wide screens */
.drawer.drawer-journey {
  width: min(420px, 40vw);
  max-width: 480px;
}
@media (min-width: 992px) {
  .drawer-backdrop.drawer-journey-backdrop,
  body.drawer-open .drawer-backdrop {
    /* Allow interaction with left/main content while journey is open */
    pointer-events: none;
    background: transparent;
  }
  .drawer.drawer-journey.show {
    pointer-events: auto;
  }
  body.drawer-open {
    overflow: auto;
  }
}
.drawer-header {
  padding: 20px 22px 16px; border-bottom: 1px solid var(--divider);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.drawer-header h3 { margin: 0; font-size: var(--fs-lg); font-weight: 700; }
.drawer-body { padding: 20px 22px 28px; }
.drawer-close {
  border: none; background: var(--bg); color: var(--text);
  width: 32px; height: 32px; border-radius: var(--radius-md); cursor: pointer;
  font-size: 18px; line-height: 1;
}
.drawer-close:active { transform: scale(.95); }
body.drawer-open { overflow: hidden; }

/* ---------- Utility ---------- */
.text-muted { color: var(--text-secondary); }
.skeleton {
  position: relative; overflow: hidden; background: var(--divider);
  border-radius: var(--radius-sm); color: transparent !important; user-select: none;
}
.skeleton::after {
  content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.55), transparent);
  animation: shimmer 1.3s infinite;
}
.skeleton-text { height: 14px; margin-bottom: 8px; }
.skeleton-title { height: 28px; width: 60%; margin-bottom: 12px; }
.skeleton-chart { height: 280px; width: 100%; border-radius: var(--radius-lg); }
.skeleton-kpi { height: 96px; border-radius: var(--radius-lg); }
.skeleton-gauge { height: 140px; width: 72px; border-radius: var(--radius-md); margin: 0 auto; }

.is-loading .skeleton-panel { display: block; }
.is-loading .content-panel { display: none; }
.skeleton-panel { display: none; }
.content-panel { display: block; }
.content-panel.is-ready { animation: fadeInUp var(--dur) var(--ease) both; }

/* ---------- Buttons: press feedback ---------- */
.btn { transition: transform var(--dur-fast) var(--ease), opacity var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease); }
.btn:active, .theme-app button.btn-press:active { transform: scale(.96); }
.btn-press { transition: transform var(--dur-fast) var(--ease); }

/* ==========================================================
   Animation — small, purposeful, GPU-cheap. Apply the class;
   no JS required except toggling classes on mount/interaction.
   ========================================================== */
@keyframes fadeIn      { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeInUp    { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideInRight{ from { transform: translateX(24px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes scaleIn     { from { transform: scale(.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes shimmer     { 100% { transform: translateX(100%); } }
@keyframes pulseDot    { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

.fade-in    { animation: fadeIn var(--dur) var(--ease) both; }
.fade-in-up { animation: fadeInUp var(--dur) var(--ease) both; }
.scale-in   { animation: scaleIn var(--dur) var(--ease) both; }
.slide-in-right { animation: slideInRight var(--dur-slow) var(--ease) both; }

/* stagger a list's children: add .stagger to the parent */
.stagger > * { animation: fadeInUp var(--dur) var(--ease) both; }
.stagger > *:nth-child(1)  { animation-delay: 0ms; }
.stagger > *:nth-child(2)  { animation-delay: 40ms; }
.stagger > *:nth-child(3)  { animation-delay: 80ms; }
.stagger > *:nth-child(4)  { animation-delay: 120ms; }
.stagger > *:nth-child(5)  { animation-delay: 160ms; }
.stagger > *:nth-child(6)  { animation-delay: 200ms; }
.stagger > *:nth-child(7)  { animation-delay: 240ms; }
.stagger > *:nth-child(8)  { animation-delay: 280ms; }
.stagger > *:nth-child(9)  { animation-delay: 320ms; }
.stagger > *:nth-child(10) { animation-delay: 360ms; }
.stagger > *:nth-child(11) { animation-delay: 400ms; }
.stagger > *:nth-child(12) { animation-delay: 440ms; }

.live-dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--success); margin-right: 4px; vertical-align: middle;
  animation: pulseDot 1.6s ease-in-out infinite;
}

/* ==========================================================
   Email — responsive mail hub (sidebar unread badge: sidebar.css)
   ========================================================== */

/* —— Email hub (Gmail-style drawer + list; theme colors) —— */
body.mail-drawer-lock { overflow: hidden; }

.mail-page.container-fluid {
  max-width: 100%;
  padding-left: 0;
  padding-right: 0;
}

.mail-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 0;
  align-items: stretch;
  min-height: calc(100vh - 140px);
  position: relative;
  background: var(--surface, #fff);
}

.mail-aside,
.mail-main { min-width: 0; }

.mail-aside {
  background: var(--bg, #f6f6f6);
  border-right: 1px solid var(--border, #e6e6e6);
  padding: 0.75rem 0.65rem 1.25rem;
}

.mail-nav { position: sticky; top: 0.5rem; }

.mail-nav-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.25rem 0.5rem 0.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.mail-compose-rail {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  width: auto;
  min-width: 140px;
  min-height: 52px;
  margin: 0.15rem 0.35rem 1rem;
  padding: 0 1.35rem;
  border-radius: 1rem;
  background: var(--surface, #fff);
  color: inherit;
  text-decoration: none;
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 4px 10px rgba(0,0,0,.06);
}
.mail-compose-rail:hover { color: inherit; text-decoration: none; opacity: 0.95; }
.mail-compose-rail .bi { font-size: 1.1rem; }

.mail-nav-section {
  margin: 0.85rem 0.85rem 0.35rem;
  font-size: var(--fs-sm);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted, #777);
}

.mail-folder-list,
.mail-nav-actions {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.mail-folder-item {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.55rem;
  min-height: 44px;
  padding: 0.45rem 0.95rem 0.45rem 0.85rem;
  border-radius: 0 999px 999px 0;
  margin-right: 0.5rem;
  color: inherit;
  text-decoration: none;
  border: 0;
  background: transparent;
  width: calc(100% - 0.5rem);
  text-align: left;
  font-size: var(--fs-base);
  cursor: pointer;
}
.mail-folder-item:hover {
  background: rgba(0,0,0,.04);
  color: inherit;
  text-decoration: none;
}
.mail-folder-item.is-active {
  background: var(--ifp-blue-50);
  color: var(--info-text);
  font-weight: 700;
}
.mail-folder-icon { font-size: 1.15rem; line-height: 1; opacity: 0.9; }
.mail-folder-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-folder-count {
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--text-muted, #666);
  padding-left: 0.35rem;
}
.mail-folder-item--btn { font-family: inherit; }

.mail-drawer-backdrop {
  display: none;
}

.mail-topbar {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.65rem 0.75rem;
  position: sticky;
  top: 0;
  z-index: 6;
  background: var(--surface, #fff);
}

.mail-search-pill {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 44px;
  padding: 0.35rem 0.95rem;
  border-radius: 999px;
  background: var(--bg, #f1f1f1);
  min-width: 0;
}
.mail-search-icon { opacity: 0.55; }
.mail-search-label {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mail-search-meta {
  margin-left: auto;
  font-size: var(--fs-sm);
  color: var(--text-muted, #666);
  white-space: nowrap;
}

.mail-topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.15rem;
}

.mail-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 0;
  background: transparent;
  border-radius: 50%;
  color: inherit;
  text-decoration: none;
  font-size: 1.2rem;
  line-height: 1;
  padding: 0;
}
.mail-icon-btn:hover { background: rgba(0,0,0,.06); color: inherit; text-decoration: none; }

.mail-conn-banner {
  padding: 0.35rem 1rem 0.65rem;
  font-size: var(--fs-sm);
  color: var(--text-muted, #666);
}
.mail-conn-banner a { text-decoration: underline; }

.mail-list {
  background: var(--surface, #fff);
  border: 0;
  border-radius: 0;
}

.mail-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 0.85rem;
  align-items: start;
  padding: 0.95rem 1rem 0.95rem 0.85rem;
  border-bottom: 1px solid #eee;
  color: inherit;
  text-decoration: none;
  min-height: 76px;
}
.mail-row:last-child { border-bottom: 0; }
.mail-row:hover { background: rgba(0,0,0,.02); color: inherit; text-decoration: none; }
.mail-row.is-unread .mail-sender,
.mail-row.is-unread .mail-subject { font-weight: 700; color: var(--text); }
.mail-row.is-read .mail-sender { font-weight: 600; color: var(--text); }
.mail-row.is-read .mail-subject { font-weight: 500; color: var(--text); }

.mail-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--fs-lg);
  color: #fff;
  background: hsl(var(--mail-avatar-h, 210) 42% 46%);
  flex-shrink: 0;
  margin-top: 0.1rem;
}

.mail-row-main {
  min-width: 0;
  display: grid;
  gap: 0.12rem;
}
.mail-row-line1,
.mail-row-line2 {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  min-width: 0;
}
.mail-sender {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--fs-lg);
}
.mail-row-meta {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}
.mail-date {
  font-size: var(--fs-sm);
  color: var(--text-muted, #777);
}
.mail-unread-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent, #1a73e8);
  display: inline-block;
}
.mail-subject {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--fs-base);
  flex: 1;
  min-width: 0;
}
.mail-star {
  color: var(--text-muted, #999);
  font-size: 1rem;
  line-height: 1;
  flex-shrink: 0;
}
.mail-snippet {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--fs-md);
  color: var(--text-muted, #777);
  padding-right: 1.5rem;
}

.mail-attach-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.35rem;
}
.mail-attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  max-width: 100%;
  padding: 0.28rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border, #ddd);
  background: var(--bg, #f7f7f7);
  font-size: var(--fs-sm);
  color: inherit;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mail-attach-chip:hover { color: inherit; text-decoration: none; }

.mail-empty {
  padding: 3.5rem 1rem;
  text-align: center;
  color: var(--text-muted, #777);
}
.mail-empty .bi {
  font-size: 2.25rem;
  display: block;
  margin-bottom: 0.65rem;
  opacity: 0.45;
}

.mail-fab {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1.25rem, env(safe-area-inset-bottom));
  z-index: 40;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 56px;
  padding: 0 1.15rem 0 1rem;
  border-radius: 1rem;
  background: var(--surface, #fff);
  color: inherit;
  text-decoration: none;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(0,0,0,.14), 0 8px 20px rgba(0,0,0,.1);
}
.mail-fab:hover { color: inherit; text-decoration: none; }
.mail-fab .bi { font-size: 1.25rem; color: var(--accent); }
.mail-fab-label { padding-right: 0.15rem; }

.mail-pagination {
  padding: 0.75rem 1rem 5.5rem;
}

.mail-read-toolbar,
.mail-compose-toolbar {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.4rem 0.5rem;
  position: sticky;
  top: 0;
  background: var(--surface, #fff);
  z-index: 5;
  border-bottom: 1px solid #eee;
}
.mail-read-actions,
.mail-compose-actions {
  margin-left: auto;
  display: flex;
  gap: 0.35rem;
  align-items: center;
  flex-wrap: wrap;
}
.mail-read-card,
.mail-compose {
  border: 0;
  border-radius: 0;
  background: var(--surface, #fff);
  padding: 1rem 1rem 1.5rem;
  min-height: 55vh;
}
.mail-read-subject { font-size: var(--fs-3xl); font-weight: 700; letter-spacing: -0.02em; margin: 0 0 1rem; }
.mail-read-meta { display: grid; grid-template-columns: 42px 1fr; gap: 0.75rem; margin-bottom: 1.1rem; }
.mail-read-from { font-weight: 600; }
.mail-read-to,
.mail-read-when { font-size: var(--fs-md); }
.mail-read-body { font-size: var(--fs-lg); line-height: 1.55; overflow-wrap: anywhere; }
.mail-attachments { margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid #eee; }

.mail-compose-title { font-weight: 700; margin-left: 0.15rem; }
.mail-compose-form { margin: 0; padding: 0 0.35rem; }
.mail-compose-field {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  align-items: center;
  gap: 0.35rem;
  border-bottom: 1px solid #eee;
  padding: 0.2rem 0;
  min-height: 48px;
}
.mail-compose-field label {
  margin: 0;
  font-size: var(--fs-md);
  color: var(--text-muted, #666);
}
.mail-compose-field .form-control { padding-left: 0; padding-right: 0; }
.mail-compose-body-wrap { padding-top: 0.65rem; }
.mail-compose-body {
  min-height: 280px;
  resize: vertical;
  padding-left: 0 !important;
  padding-right: 0 !important;
}
.mail-compose-attach { grid-template-columns: 1fr; padding-top: 0.75rem; border-bottom: 0; }
.mail-compose-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 1rem 0 0.25rem;
  align-items: center;
}
.mail-compose-footer .btn { min-height: 44px; }

@media (max-width: 767.98px) {
  .mail-shell {
    grid-template-columns: 1fr;
    min-height: calc(100vh - 110px);
  }

  .mail-aside {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(86vw, 320px);
    z-index: 1050;
    transform: translateX(-105%);
    transition: transform .2s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,.18);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-top: max(0.75rem, env(safe-area-inset-top));
  }
  .mail-shell.mail-drawer-open .mail-aside {
    transform: translateX(0);
  }
  .mail-drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1040;
    background: rgba(0,0,0,.35);
  }
  .mail-drawer-backdrop[hidden] { display: none !important; }

  .mail-folder-item {
    border-radius: 0 999px 999px 0;
  }
  .mail-folder-item.is-active {
    background: var(--ifp-blue-50);
  }

  .mail-fab {
    /* Extended FAB like Gmail mobile when there's room */
    padding-right: 1.25rem;
  }

  .mail-compose-footer .btn-primary,
  .mail-compose-footer .btn-secondary {
    flex: 1 1 calc(50% - 0.5rem);
  }

  .mail-pagination { padding-bottom: 6rem; }
}

@media (min-width: 768px) {
  .mail-fab {
    /* On desktop the rail Compose is primary; keep a compact FAB for muscle memory */
    width: 56px;
    height: 56px;
    padding: 0;
    justify-content: center;
    border-radius: 1rem;
  }
  .mail-fab-label { display: none; }
  .mail-page.container-fluid { padding-left: 0; padding-right: 0; }
  .mail-shell { margin: 0 0.75rem; border: 1px solid var(--border, #e5e5e5); border-radius: 12px; overflow: hidden; }
}
