/* IMEMS Modern Enterprise Design Tokens v3.0 (M17.02)
 * Crafted with Impeccable + Frontend-Design + Gestalt + UI/UX Pro Max.
 * Default Theme: Sandstone Aero (Warm Blue-Light-Friendly Command Theme).
 * 7 Built-in Modern Themes + Dynamic Custom Theme Support (via theme-engine.js).
 * Fonts: Self-hosted Sarabun (/fonts.css); TH Sarabun IT9 for official PDF exports.
 */

:root,
[data-imems-theme="sandstone-aero"] {
  color-scheme: light;
  --imems-font-sans: "Sarabun", system-ui, -apple-system, "Segoe UI", sans-serif;
  --imems-bg: #f4f1ea;
  --imems-surface: #fffefb;
  --imems-surface-muted: #f9f6f0;
  --imems-border: #e4ddd0;
  --imems-border-strong: #cec3b0;
  --imems-text: #1f1e1b;
  --imems-text-muted: #5e5a50;

  --imems-topbar-bg: #1d1f23;
  --imems-topbar-text: #faf7f0;
  --imems-hero-bg: radial-gradient(ellipse at 86% 10%, #4d3f2b 0%, transparent 64%), linear-gradient(124deg, #1b1d21 15%, #2c2d31 88%);
  --imems-hero-border: #3d3931;
  --imems-hero-cta-bg: #f0c97a;
  --imems-hero-cta-text: #1c1810;
  --imems-hero-pill-bg: rgba(255, 250, 240, 0.08);
  --imems-hero-pill-border: rgba(240, 201, 122, 0.28);
  --imems-hero-text: #fcf9f2;
  --imems-hero-sub: #d4cdc0;
  --imems-dot: #f0c97a;
  --imems-grid-rgba: rgba(240, 201, 122, 0.11);

  --imems-primary: #1f6b69;
  --imems-primary-hover: #175452;
  --imems-primary-soft: #e4f3f2;
  --imems-accent: #a86416;
  --imems-accent-soft: #fdf1dc;

  --imems-success: #1c7c54;
  --imems-success-soft: #e4f5ed;
  --imems-warning: #a86416;
  --imems-warning-soft: #fdf1dc;
  --imems-danger: #b42318;
  --imems-danger-soft: #fdecea;
  --imems-info: #1f6b69;
  --imems-info-soft: #e4f3f2;

  --imems-bar-1: #1f6b69;
  --imems-bar-2: #c9862c;
  --imems-bar-3: #2a9d6f;
  --imems-bar-4: #786f64;

  --imems-sidebar-bg: #1d1f23;
  --imems-sidebar-text: #faf7f0;
  --imems-sidebar-muted: #c6bfb2;
  --imems-sidebar-active: rgba(240, 201, 122, 0.20);
  --imems-sidebar-border: rgba(255, 255, 255, 0.10);

  --imems-radius-sm: 10px;
  --imems-radius-md: 16px;
  --imems-radius-lg: 20px;
  --imems-shadow-sm: 0 2px 4px rgba(31, 30, 27, 0.04), 0 8px 20px rgba(31, 30, 27, 0.05);
  --imems-shadow-md: 0 6px 24px rgba(31, 30, 27, 0.08);
  --imems-hero-shadow: 0 14px 30px rgba(27, 29, 33, 0.20);
  --imems-topbar-h: 60px;
}

/* 2. Nordic Command (Signature /personnel-strength/ Ocean-Slate + Mint Aqua) */
[data-imems-theme="nordic-command"] {
  color-scheme: light;
  --imems-bg: #edf1f6;
  --imems-surface: #ffffff;
  --imems-surface-muted: #f5f8fc;
  --imems-border: #dbe3ed;
  --imems-border-strong: #bfd0e3;
  --imems-text: #13243b;
  --imems-text-muted: #51637a;

  --imems-topbar-bg: #0f2035;
  --imems-topbar-text: #f4f8ff;
  --imems-hero-bg: radial-gradient(ellipse at 86% 8%, #245368 0%, transparent 66%), linear-gradient(122deg, #0f1f34 14%, #183656 88%);
  --imems-hero-border: #234061;
  --imems-hero-cta-bg: #7de1dc;
  --imems-hero-cta-text: #0c2233;
  --imems-hero-pill-bg: rgba(255, 255, 255, 0.08);
  --imems-hero-pill-border: rgba(196, 234, 250, 0.24);
  --imems-hero-text: #f5f9ff;
  --imems-hero-sub: #c3d6ea;
  --imems-dot: #7de1dc;
  --imems-grid-rgba: rgba(125, 225, 220, 0.12);

  --imems-primary: #1d6496;
  --imems-primary-hover: #154e77;
  --imems-primary-soft: #e7f2fb;
  --imems-accent: #b87414;
  --imems-accent-soft: #fff4df;

  --imems-success: #178577;
  --imems-success-soft: #e3f6f1;
  --imems-warning: #b87414;
  --imems-warning-soft: #fff4df;
  --imems-danger: #b42318;
  --imems-danger-soft: #fdecea;
  --imems-info: #1d6496;
  --imems-info-soft: #e7f2fb;

  --imems-bar-1: #3e7dbc;
  --imems-bar-2: #db9d42;
  --imems-bar-3: #28aa93;
  --imems-bar-4: #6f69a2;

  --imems-sidebar-bg: #0f2035;
  --imems-sidebar-text: #f4f8ff;
  --imems-sidebar-muted: #b5c9e0;
  --imems-sidebar-active: rgba(125, 225, 220, 0.18);
  --imems-shadow-sm: 0 2px 4px rgba(15, 34, 58, 0.04), 0 10px 24px rgba(15, 34, 58, 0.06);
  --imems-hero-shadow: 0 14px 30px rgba(15, 34, 58, 0.18);
}

/* 3. Sage Horizon (2026 Mineral Pine + Calm Jade) */
[data-imems-theme="sage-horizon"] {
  color-scheme: light;
  --imems-bg: #eef4f2;
  --imems-surface: #ffffff;
  --imems-surface-muted: #f5faf8;
  --imems-border: #d5e3de;
  --imems-border-strong: #b5ccc4;
  --imems-text: #112625;
  --imems-text-muted: #486361;

  --imems-topbar-bg: #0e2424;
  --imems-topbar-text: #f1faf7;
  --imems-hero-bg: radial-gradient(ellipse at 86% 8%, #1e5b54 0%, transparent 66%), linear-gradient(122deg, #0e2626 14%, #18423f 88%);
  --imems-hero-border: #235852;
  --imems-hero-cta-bg: #6ee7b7;
  --imems-hero-cta-text: #08231e;
  --imems-hero-pill-bg: rgba(255, 255, 255, 0.08);
  --imems-hero-pill-border: rgba(167, 243, 208, 0.24);
  --imems-hero-text: #f2fbf8;
  --imems-hero-sub: #bfe0d7;
  --imems-dot: #6ee7b7;
  --imems-grid-rgba: rgba(110, 231, 183, 0.11);

  --imems-primary: #0f766e;
  --imems-primary-hover: #0c5d57;
  --imems-primary-soft: #dff5f1;
  --imems-accent: #b46d11;
  --imems-accent-soft: #fef3dc;

  --imems-success: #059669;
  --imems-success-soft: #e2f7ee;
  --imems-warning: #b46d11;
  --imems-warning-soft: #fef3dc;
  --imems-danger: #b42318;
  --imems-danger-soft: #fdecea;
  --imems-info: #0f766e;
  --imems-info-soft: #dff5f1;

  --imems-bar-1: #0f766e;
  --imems-bar-2: #d9932c;
  --imems-bar-3: #10b981;
  --imems-bar-4: #4f6b9a;

  --imems-sidebar-bg: #0e2424;
  --imems-sidebar-text: #f1faf7;
  --imems-sidebar-muted: #b0cfc7;
  --imems-sidebar-active: rgba(110, 231, 183, 0.18);
  --imems-shadow-sm: 0 2px 4px rgba(14, 38, 38, 0.04), 0 10px 24px rgba(14, 38, 38, 0.06);
  --imems-hero-shadow: 0 14px 30px rgba(14, 38, 38, 0.18);
}

/* 4. Titanium Frost (Brushed Platinum + Graphite + Electric Teal) */
[data-imems-theme="titanium-frost"] {
  color-scheme: light;
  --imems-bg: #f1f3f6;
  --imems-surface: #ffffff;
  --imems-surface-muted: #f7f8fa;
  --imems-border: #dde1e8;
  --imems-border-strong: #c4cbd6;
  --imems-text: #161a20;
  --imems-text-muted: #555e6d;

  --imems-topbar-bg: #16191f;
  --imems-topbar-text: #f5f7fa;
  --imems-hero-bg: radial-gradient(ellipse at 85% 10%, #2d4a53 0%, transparent 62%), linear-gradient(125deg, #171a20 16%, #262c35 90%);
  --imems-hero-border: #323a46;
  --imems-hero-cta-bg: #2dd4bf;
  --imems-hero-cta-text: #0a201e;
  --imems-hero-pill-bg: rgba(255, 255, 255, 0.08);
  --imems-hero-pill-border: rgba(255, 255, 255, 0.18);
  --imems-hero-text: #f8fafc;
  --imems-hero-sub: #c6cdd8;
  --imems-dot: #2dd4bf;
  --imems-grid-rgba: rgba(45, 212, 191, 0.10);

  --imems-primary: #0f766e;
  --imems-primary-hover: #0d5e58;
  --imems-primary-soft: #e6f7f5;
  --imems-accent: #b45309;
  --imems-accent-soft: #fef3c7;

  --imems-success: #059669;
  --imems-success-soft: #e5f7ef;
  --imems-warning: #b45309;
  --imems-warning-soft: #fef3c7;
  --imems-danger: #b42318;
  --imems-danger-soft: #fdecea;
  --imems-info: #334155;
  --imems-info-soft: #eef1f5;

  --imems-bar-1: #334155;
  --imems-bar-2: #d97706;
  --imems-bar-3: #14b8a6;
  --imems-bar-4: #64748b;

  --imems-sidebar-bg: #16191f;
  --imems-sidebar-text: #f5f7fa;
  --imems-sidebar-muted: #b4bcc9;
  --imems-sidebar-active: rgba(45, 212, 191, 0.18);
  --imems-shadow-sm: 0 1px 3px rgba(22, 26, 32, 0.05), 0 10px 22px rgba(22, 26, 32, 0.05);
  --imems-hero-shadow: 0 14px 30px rgba(22, 26, 32, 0.20);
}

/* 5. Deep Fjord (Aerospace Petrol-Teal + Ice Mist + Coral Amber) */
[data-imems-theme="deep-fjord"] {
  color-scheme: light;
  --imems-bg: #ebf2f4;
  --imems-surface: #ffffff;
  --imems-surface-muted: #f3f8fa;
  --imems-border: #d2e2e7;
  --imems-border-strong: #b0cbd3;
  --imems-text: #0d222c;
  --imems-text-muted: #46616e;

  --imems-topbar-bg: #0a1f2b;
  --imems-topbar-text: #eff9fc;
  --imems-hero-bg: radial-gradient(ellipse at 86% 10%, #155e75 0%, transparent 65%), linear-gradient(122deg, #09202d 14%, #123c4f 88%);
  --imems-hero-border: #1b5066;
  --imems-hero-cta-bg: #67e8f9;
  --imems-hero-cta-text: #07222c;
  --imems-hero-pill-bg: rgba(255, 255, 255, 0.08);
  --imems-hero-pill-border: rgba(103, 232, 249, 0.25);
  --imems-hero-text: #f2fbfe;
  --imems-hero-sub: #b9dce6;
  --imems-dot: #67e8f9;
  --imems-grid-rgba: rgba(103, 232, 249, 0.12);

  --imems-primary: #0e7490;
  --imems-primary-hover: #0a586d;
  --imems-primary-soft: #e0f5fa;
  --imems-accent: #c26a19;
  --imems-accent-soft: #ffefe0;

  --imems-success: #0d9488;
  --imems-success-soft: #dff7f4;
  --imems-warning: #c26a19;
  --imems-warning-soft: #ffefe0;
  --imems-danger: #b42318;
  --imems-danger-soft: #fdecea;
  --imems-info: #0e7490;
  --imems-info-soft: #e0f5fa;

  --imems-bar-1: #0e7490;
  --imems-bar-2: #e0812d;
  --imems-bar-3: #14b8a6;
  --imems-bar-4: #4c6c9c;

  --imems-sidebar-bg: #0a1f2b;
  --imems-sidebar-text: #eff9fc;
  --imems-sidebar-muted: #a6cdd9;
  --imems-sidebar-active: rgba(103, 232, 249, 0.18);
  --imems-shadow-sm: 0 2px 4px rgba(10, 31, 43, 0.04), 0 10px 24px rgba(10, 31, 43, 0.06);
  --imems-hero-shadow: 0 14px 30px rgba(10, 31, 43, 0.19);
}

/* 6. Midnight Graphite (Pro Matte Carbon Dark + Soft Mint) */
[data-imems-theme="midnight-graphite"] {
  color-scheme: dark;
  --imems-bg: #111317;
  --imems-surface: #181b21;
  --imems-surface-muted: #20242c;
  --imems-border: #2a303b;
  --imems-border-strong: #3b4352;
  --imems-text: #f1f4f8;
  --imems-text-muted: #9aa4b5;

  --imems-topbar-bg: #0c0e12;
  --imems-topbar-text: #f1f4f8;
  --imems-hero-bg: radial-gradient(ellipse at 86% 10%, #154942 0%, transparent 62%), linear-gradient(124deg, #13171d 14%, #1a242c 88%);
  --imems-hero-border: #283740;
  --imems-hero-cta-bg: #5eead4;
  --imems-hero-cta-text: #071e1c;
  --imems-hero-pill-bg: rgba(255, 255, 255, 0.06);
  --imems-hero-pill-border: rgba(255, 255, 255, 0.16);
  --imems-hero-text: #f5f7fa;
  --imems-hero-sub: #b5c0cf;
  --imems-dot: #5eead4;
  --imems-grid-rgba: rgba(94, 234, 212, 0.11);

  --imems-primary: #5eead4;
  --imems-primary-hover: #2dd4bf;
  --imems-primary-soft: rgba(94, 234, 212, 0.13);
  --imems-accent: #fbbf24;
  --imems-accent-soft: rgba(251, 191, 36, 0.14);

  --imems-success: #4ade80;
  --imems-success-soft: rgba(74, 222, 128, 0.13);
  --imems-warning: #fbbf24;
  --imems-warning-soft: rgba(251, 191, 36, 0.14);
  --imems-danger: #f87171;
  --imems-danger-soft: rgba(248, 113, 113, 0.16);
  --imems-info: #5eead4;
  --imems-info-soft: rgba(94, 234, 212, 0.13);

  --imems-bar-1: #5eead4;
  --imems-bar-2: #fbbf24;
  --imems-bar-3: #4ade80;
  --imems-bar-4: #94a3b8;

  --imems-sidebar-bg: #0c0e12;
  --imems-sidebar-text: #f1f4f8;
  --imems-sidebar-muted: #9aa4b5;
  --imems-sidebar-active: rgba(94, 234, 212, 0.18);
  --imems-shadow-sm: 0 4px 18px rgba(0, 0, 0, 0.34);
  --imems-shadow-md: 0 8px 26px rgba(0, 0, 0, 0.44);
  --imems-hero-shadow: 0 16px 32px rgba(0, 0, 0, 0.46);
}

/* 7. Eclipse Bronze (Executive Command Dark + Brushed Champagne Gold) */
[data-imems-theme="eclipse-bronze"] {
  color-scheme: dark;
  --imems-bg: #101214;
  --imems-surface: #171a1e;
  --imems-surface-muted: #1f2329;
  --imems-border: #2c2f34;
  --imems-border-strong: #42413d;
  --imems-text: #f5f3ee;
  --imems-text-muted: #a39f96;

  --imems-topbar-bg: #0b0c0e;
  --imems-topbar-text: #f5f3ee;
  --imems-hero-bg: radial-gradient(ellipse at 86% 10%, #4d3c22 0%, transparent 62%), linear-gradient(124deg, #141619 14%, #24211c 88%);
  --imems-hero-border: #3d3528;
  --imems-hero-cta-bg: #e8c27a;
  --imems-hero-cta-text: #17130c;
  --imems-hero-pill-bg: rgba(255, 248, 235, 0.06);
  --imems-hero-pill-border: rgba(232, 194, 122, 0.25);
  --imems-hero-text: #fbf8f1;
  --imems-hero-sub: #cdc5b7;
  --imems-dot: #e8c27a;
  --imems-grid-rgba: rgba(232, 194, 122, 0.11);

  --imems-primary: #e8c27a;
  --imems-primary-hover: #d8ae62;
  --imems-primary-soft: rgba(232, 194, 122, 0.14);
  --imems-accent: #f59e0b;
  --imems-accent-soft: rgba(245, 158, 11, 0.15);

  --imems-success: #34d399;
  --imems-success-soft: rgba(52, 211, 153, 0.14);
  --imems-warning: #f59e0b;
  --imems-warning-soft: rgba(245, 158, 11, 0.15);
  --imems-danger: #f87171;
  --imems-danger-soft: rgba(248, 113, 113, 0.16);
  --imems-info: #e8c27a;
  --imems-info-soft: rgba(232, 194, 122, 0.14);

  --imems-bar-1: #e8c27a;
  --imems-bar-2: #f59e0b;
  --imems-bar-3: #34d399;
  --imems-bar-4: #94a3b8;

  --imems-sidebar-bg: #0b0c0e;
  --imems-sidebar-text: #f5f3ee;
  --imems-sidebar-muted: #a39f96;
  --imems-sidebar-active: rgba(232, 194, 122, 0.18);
  --imems-shadow-sm: 0 4px 18px rgba(0, 0, 0, 0.36);
  --imems-shadow-md: 0 8px 26px rgba(0, 0, 0, 0.48);
  --imems-hero-shadow: 0 16px 34px rgba(0, 0, 0, 0.50);
}


/* Universal IMEMS Theme Manager Modal (Works on /, /imems/, /personnel-strength/, /duty/) */
.imems-tm-backdrop[hidden] { display: none !important; }
.imems-tm-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10020;
  background: rgba(15, 20, 28, 0.72);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  font-family: var(--imems-font-sans, 'Sarabun', sans-serif);
}
.imems-tm-dialog {
  width: min(760px, 100%);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  border-radius: 18px;
  overflow: hidden;
  background: var(--imems-bg, #f4f1ea);
  color: var(--imems-text, #1f1e1b);
  border: 1px solid var(--imems-border-strong, #d5cbb8);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.36);
}
.imems-tm-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 18px;
  background: var(--imems-topbar-bg, #1d1f23);
  color: var(--imems-topbar-text, #fcf9f2);
  border-bottom: 2px solid var(--imems-dot, #f0c97a);
}
.imems-tm-head strong { display: block; font-size: 16.5px; font-weight: 700; }
.imems-tm-head small { display: block; font-size: 12.5px; color: var(--imems-hero-sub, #d4cdc0); margin-top: 2px; }
.imems-tm-close {
  min-height: 38px;
  padding: 6px 14px !important;
  border-radius: 10px !important;
  border: 1px solid rgba(255, 255, 255, 0.25) !important;
  background: rgba(255, 255, 255, 0.10) !important;
  color: #fff !important;
  font-weight: 700;
  font-size: 13.5px;
  cursor: pointer;
  white-space: nowrap;
}
.imems-tm-body {
  padding: 16px 18px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.imems-tm-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  color: var(--imems-text, #1f1e1b);
}
.imems-tm-restore {
  padding: 5px 12px !important;
  border-radius: 8px !important;
  border: 1px solid var(--imems-border-strong, #d5cbb8) !important;
  background: var(--imems-surface, #fff) !important;
  color: var(--imems-primary, #1f6b69) !important;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}
.imems-tm-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.imems-tm-card {
  display: flex;
  align-items: stretch;
  gap: 6px;
  padding: 6px;
  border-radius: 12px;
  border: 1px solid var(--imems-border, #e4ddd0);
  background: var(--imems-surface, #fff);
}
.imems-tm-card.active {
  border-color: var(--imems-primary, #1f6b69);
  box-shadow: 0 0 0 2px var(--imems-primary-soft, #e4f3f2);
}
.imems-tm-pick {
  flex: 1;
  min-width: 0;
  display: flex !important;
  align-items: center !important;
  gap: 10px !important;
  padding: 6px 8px !important;
  border: 0 !important;
  background: transparent !important;
  color: var(--imems-text, #1f1e1b) !important;
  text-align: left !important;
  cursor: pointer;
}
.imems-tm-swatches { display: inline-flex; gap: 3px; flex-shrink: 0; }
.imems-tm-swatches i { width: 14px; height: 28px; border-radius: 5px; border: 1px solid rgba(0, 0, 0, 0.14); display: block; }
.imems-tm-meta { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.imems-tm-meta strong { font-size: 13.5px; font-weight: 700; }
.imems-tm-meta small { font-size: 11.5px; color: var(--imems-text-muted, #5e5a50); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.imems-tm-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--imems-surface-muted, #f3efe6);
  color: var(--imems-text-muted, #5e5a50);
  white-space: nowrap;
}
.imems-tm-del {
  padding: 4px 10px !important;
  border-radius: 8px !important;
  border: 1px solid var(--imems-danger-soft, #fdecea) !important;
  background: var(--imems-danger-soft, #fdecea) !important;
  color: var(--imems-danger, #b42318) !important;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.imems-tm-form {
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--imems-border, #e4ddd0);
  background: var(--imems-surface, #fff);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.imems-tm-form-row {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 10px;
}
.imems-tm-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--imems-text-muted, #5e5a50);
}
.imems-tm-form input[type="text"],
.imems-tm-form select {
  min-height: 38px;
  padding: 6px 10px;
  border-radius: 9px;
  border: 1px solid var(--imems-border-strong, #d5cbb8);
  background: var(--imems-bg, #f4f1ea);
  color: var(--imems-text, #1f1e1b);
  font-family: inherit;
  font-size: 13.5px;
}
.imems-tm-colors {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}
.imems-tm-colors input[type="color"] {
  width: 100%;
  height: 36px;
  padding: 2px;
  border-radius: 8px;
  border: 1px solid var(--imems-border-strong, #d5cbb8);
  background: var(--imems-surface, #fff);
  cursor: pointer;
}
.imems-tm-form-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
#imems-tm-msg { font-size: 12.5px; font-weight: 700; color: var(--imems-primary, #1f6b69); }
.imems-tm-submit {
  min-height: 40px;
  padding: 7px 16px !important;
  border-radius: 10px !important;
  border: 0 !important;
  background: var(--imems-hero-cta-bg, #f0c97a) !important;
  color: var(--imems-hero-cta-text, #1c1810) !important;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
}
@media (max-width: 640px) {
  .imems-tm-grid, .imems-tm-form-row { grid-template-columns: 1fr; }
  .imems-tm-colors { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
