/* =============================================================================
   dAImòn.WFM — Dark & Light Theme Variables + DATA_TABLE_SPEC v0.1 Styles
   ============================================================================= */

:root {
  --bg-app: #081229;
  --bg-surface: #0e1c3a;
  --bg-surface-2: #14264d;
  --bg-surface-hover: #1b3161;
  --bg-input: #0b1630;
  --bg-thead: #102042;
  --bg-thead-summary: #0c1936;
  --text-primary: #eef4ff;
  --text-secondary: #9bb0d3;
  --text-muted: #6e85ad;
  --border-color: #223868;
  --col-sep: #35528d;
  --accent-primary: #ff6b00;
  --accent-primary-hover: #ff8229;
  --accent-cyan: #00d4e6;
  --accent-success: #10b981;
  --accent-warning: #f59e0b;
  --accent-danger: #ef4444;
  --accent-purple: #8b5cf6;
  --shadow-lg: 0 18px 40px rgba(0, 0, 0, 0.45);
  --radius-sm: 5px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

:root[data-theme="light"] {
  --bg-app: #f1f5fb;
  --bg-surface: #ffffff;
  --bg-surface-2: #f4f7fc;
  --bg-surface-hover: #e9f0fb;
  --bg-input: #ffffff;
  --bg-thead: #e6eef9;
  --bg-thead-summary: #eef3fb;
  --text-primary: #0b1a3d;
  --text-secondary: #43577a;
  --text-muted: #6d7f9e;
  --border-color: #cfdbe9;
  --col-sep: #9fb3d1;
  --accent-primary: #f96302;
  --accent-primary-hover: #dc5600;
  --accent-cyan: #009fb3;
  --accent-success: #059669;
  --accent-warning: #d97706;
  --accent-danger: #dc2626;
  --accent-purple: #7c3aed;
  --shadow-lg: 0 14px 34px rgba(5, 21, 71, 0.14);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: "Segoe UI", Inter, system-ui, -apple-system, sans-serif;
  background: var(--bg-app);
  color: var(--text-primary);
  font-size: 13px;
  line-height: 1.4;
  height: 100%;
}

.hidden { display: none !important; }

/* Brand logos switch automatically with theme */
.brand-logo-light { display: none; }
.brand-logo-dark { display: block; }
:root[data-theme="light"] .brand-logo-light { display: block; }
:root[data-theme="light"] .brand-logo-dark { display: none; }

/* =============================================================================
   Buttons & Inputs
   ============================================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-surface-2);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--bg-surface-hover); border-color: var(--col-sep); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-sm { padding: 4px 8px; font-size: 11.5px; }
.btn-xs { padding: 2px 6px; font-size: 11px; }
.btn-block { width: 100%; justify-content: center; padding: 9px 14px; font-size: 13px; }

.btn-primary {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #ffffff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-primary-hover);
  border-color: var(--accent-primary-hover);
}
.btn-cyan {
  background: var(--accent-cyan);
  border-color: var(--accent-cyan);
  color: #041526;
}
.btn-danger {
  background: var(--accent-danger);
  border-color: var(--accent-danger);
  color: #ffffff;
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) {
  background: var(--bg-surface-2);
  border-color: var(--border-color);
}

input[type="text"], input[type="password"], input[type="date"], input[type="email"], input[type="number"], select, textarea {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  font-size: 12px;
  font-family: inherit;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 2px rgba(0, 212, 230, 0.18);
}

/* =============================================================================
   Login Screen
   ============================================================================= */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 20% 20%, rgba(0, 212, 230, 0.12), transparent 40%),
              radial-gradient(circle at 80% 80%, rgba(255, 107, 0, 0.14), transparent 45%),
              var(--bg-app);
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 26px 28px 30px;
  box-shadow: var(--shadow-lg);
}
.login-theme-row { display: flex; justify-content: flex-end; margin-bottom: 8px; }
.login-brand { text-align: center; margin-bottom: 20px; }
.login-brand img { max-height: 56px; margin: 0 auto 10px; }
.login-subtitle { color: var(--text-secondary); font-size: 12px; margin: 0; }
.login-form .form-group { margin-bottom: 14px; display: flex; flex-direction: column; gap: 5px; }
.login-form label { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.login-form input { padding: 9px 10px; font-size: 13px; }
.form-error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid var(--accent-danger);
  color: var(--accent-danger);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  margin-bottom: 12px;
}

/* =============================================================================
   Topbar & App Shell
   ============================================================================= */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 14px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.topbar-brand { cursor: pointer; display: flex; align-items: center; padding-right: 8px; border-right: 1px solid var(--border-color); }
.topbar-brand img { height: 34px; width: auto; }

.topnav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.nav-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.nav-btn:hover { background: var(--bg-surface-2); color: var(--text-primary); }
.nav-btn.active {
  background: rgba(255, 107, 0, 0.14);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  font-size: 11.5px;
}
.role-badge {
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(0, 212, 230, 0.16);
  color: var(--accent-cyan);
  font-weight: 700;
  font-size: 10.5px;
}

.main-content { flex: 1; padding: 10px 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.page-view { display: flex; flex-direction: column; gap: 8px; }

.page-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}
.page-toolbar-title { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.page-toolbar-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

/* =============================================================================
   Invalid Summary Bar (DATA_TABLE_SPEC 5.6)
   ============================================================================= */
.summary-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  padding: 6px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}
.summary-bar-label { font-size: 11.5px; color: var(--text-secondary); font-weight: 600; margin-right: 4px; }
.summary-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  border: 1px solid var(--border-color);
  background: var(--bg-surface-2);
  cursor: pointer;
  user-select: none;
}
.summary-badge:hover { filter: brightness(1.12); }
.summary-badge.danger  { border-color: var(--accent-danger);  color: var(--accent-danger);  background: rgba(239, 68, 68, 0.12); }
.summary-badge.warning { border-color: var(--accent-warning); color: var(--accent-warning); background: rgba(245, 158, 11, 0.12); }
.summary-badge.success { border-color: var(--accent-success); color: var(--accent-success); background: rgba(16, 185, 129, 0.12); }
.summary-badge.info    { border-color: var(--accent-cyan);    color: var(--accent-cyan);    background: rgba(0, 212, 230, 0.12); }
.summary-badge.muted   { border-color: var(--border-color);   color: var(--text-secondary); }

/* =============================================================================
   Collapsible Filter Panel & Bulk Panel (DATA_TABLE_SPEC 5 & 7.2)
   ============================================================================= */
.filter-panel, .bulk-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 7px 10px;
}
.filter-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
}
.filter-top-left, .filter-top-right { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.dblclick-op-badge {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(0, 212, 230, 0.12);
  color: var(--accent-cyan);
  border: 1px solid rgba(0, 212, 230, 0.3);
}
.filter-body { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border-color); display: flex; flex-direction: column; gap: 6px; }
.filter-group-box {
  background: var(--bg-surface-2);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.filter-rule-row { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.filter-breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 11.5px;
  color: var(--text-secondary);
  margin-top: 4px;
}
.filter-actions-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 2px; }

/* =============================================================================
   DATA_TABLE_SPEC v0.1 — Sticky 2-Row Header & Dense Grid
   ============================================================================= */
.grid-wrapper {
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.table-scroll {
  overflow: auto;
  max-height: calc(100vh - 280px);
  position: relative;
}
.table-scroll.expanded {
  max-height: calc(100vh - 200px);
}

table.wfm-grid {
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
  width: max-content;
  min-width: 100%;
  font-size: 12px;
}

table.wfm-grid thead {
  position: sticky;
  top: 0;
  z-index: 12;
  background: var(--bg-thead);
}

table.wfm-grid thead tr.grid-summary-row th {
  background: var(--bg-thead-summary);
  background-clip: padding-box;
  text-align: left;
  font-weight: 500;
  font-size: 11.5px;
  color: var(--text-secondary);
  padding: 4px 8px;
  border-bottom: 1px solid var(--border-color);
  white-space: normal;
}
.grid-summary-line { display: flex; gap: 6px; flex-wrap: wrap; line-height: 1.35; }
.grid-summary-line strong { color: var(--text-primary); }

table.wfm-grid thead tr.grid-col-row th {
  position: relative;
  background: var(--bg-thead);
  background-clip: padding-box;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-primary);
  text-align: left;
  padding: 5px 10px 5px 6px;
  border-right: 1px solid var(--col-sep);
  border-bottom: 2px solid var(--col-sep);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  user-select: none;
  min-width: 0 !important;
}
table.wfm-grid thead tr.grid-col-row th.sortable { cursor: pointer; }
table.wfm-grid thead tr.grid-col-row th.sortable:hover { background: var(--bg-surface-hover); }
table.wfm-grid thead tr.grid-col-row th.drag-over { box-shadow: inset 3px 0 0 var(--accent-primary); }

.sort-badge {
  display: inline-block;
  margin-left: 4px;
  padding: 0 4px;
  border-radius: 3px;
  font-size: 10px;
  background: var(--accent-primary);
  color: #ffffff;
}

.col-resizer {
  position: absolute;
  top: 0;
  right: 0;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 3;
}
.col-resizer:hover { background: var(--accent-cyan); opacity: 0.65; }

table.wfm-grid tbody td {
  padding: 3px 5px;
  border-right: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0 !important;
  font-size: 12px;
  vertical-align: middle;
}
table.wfm-grid tbody tr:nth-child(even) { background: rgba(255, 255, 255, 0.018); }
:root[data-theme="light"] table.wfm-grid tbody tr:nth-child(even) { background: #f8fafd; }
table.wfm-grid tbody tr:hover { background: var(--bg-surface-hover); }
table.wfm-grid tbody tr.row-uncovered { background: rgba(239, 68, 68, 0.08); }
table.wfm-grid tbody tr.row-conflict { background: rgba(245, 158, 11, 0.14); }

table.wfm-grid tbody td input,
table.wfm-grid tbody td select {
  width: 100%;
  min-width: 0 !important;
  max-width: 100%;
  padding: 2px 4px;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.grid-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 6px 10px;
  background: var(--bg-thead-summary);
  border-top: 1px solid var(--border-color);
  font-size: 12px;
}
.grid-pager { display: flex; align-items: center; gap: 5px; }

/* Status Pills */
.pill {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.pill-TO_COVER { background: rgba(239, 68, 68, 0.18); color: var(--accent-danger); }
.pill-COVERED { background: rgba(16, 185, 129, 0.18); color: var(--accent-success); }
.pill-NOT_REQUIRED { background: rgba(100, 116, 139, 0.22); color: var(--text-secondary); }
.pill-EXTERNAL { background: rgba(139, 92, 246, 0.2); color: var(--accent-purple); }
.pill-conflict { background: rgba(245, 158, 11, 0.22); color: var(--accent-warning); }

/* =============================================================================
   Dashboard & Calendar
   ============================================================================= */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 10px;
}
.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.kpi-card.clickable { cursor: pointer; }
.kpi-card.clickable:hover { border-color: var(--accent-primary); }
.kpi-label { font-size: 11.5px; color: var(--text-secondary); font-weight: 600; }
.kpi-value { font-size: 24px; font-weight: 800; line-height: 1.1; }
.kpi-sub { font-size: 11px; color: var(--text-muted); }

.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 10px;
}
.chart-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}
.chart-card h4 { margin: 0 0 8px; font-size: 13px; color: var(--text-primary); }
.chart-box { position: relative; height: 245px; }

/* Calendar View */
.calendar-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 12px;
}
.calendar-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
}
.cal-dow {
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  padding: 4px;
}
.cal-day {
  min-height: 76px;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 5px 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.cal-day:hover { border-color: var(--accent-cyan); }
.cal-day.other-month { opacity: 0.38; }
.cal-day.today { border-color: var(--accent-primary); box-shadow: inset 0 0 0 1px var(--accent-primary); }
.cal-day-num { font-size: 11.5px; font-weight: 700; display: flex; justify-content: space-between; }
.cal-badges { display: flex; flex-wrap: wrap; gap: 3px; }
.cal-mini { font-size: 10px; font-weight: 700; padding: 1px 5px; border-radius: 4px; }
.cal-mini.ok { background: rgba(16, 185, 129, 0.22); color: var(--accent-success); }
.cal-mini.err { background: rgba(239, 68, 68, 0.22); color: var(--accent-danger); }
.cal-mini.warn { background: rgba(245, 158, 11, 0.22); color: var(--accent-warning); }
.cal-mini.nr { background: rgba(100, 116, 139, 0.25); color: var(--text-secondary); }

/* =============================================================================
   Context Menu, Draggable Modal, Busy Overlay, Toast (DATA_TABLE_SPEC 8)
   ============================================================================= */
.context-menu {
  position: fixed;
  z-index: 1200;
  min-width: 210px;
  background: var(--bg-surface);
  border: 1px solid var(--col-sep);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 5px 0;
}
.context-menu-title {
  padding: 5px 10px;
  font-size: 11px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-color);
  font-weight: 600;
}
.context-menu-item {
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
}
.context-menu-item:hover { background: var(--bg-surface-hover); }

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(3, 9, 23, 0.68);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-dialog {
  background: var(--bg-surface);
  border: 1px solid var(--col-sep);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  position: relative;
}
.modal-dialog.modal-lg { max-width: 960px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 16px;
  background: var(--bg-thead);
  border-bottom: 1px solid var(--border-color);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  cursor: move;
  user-select: none;
}
.modal-header h3 { margin: 0; font-size: 14px; }
.modal-close {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}
.modal-close:hover { color: var(--text-primary); }
.modal-body { padding: 14px 16px; overflow-y: auto; flex: 1; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--border-color);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
}
.form-field { display: flex; flex-direction: column; gap: 4px; }
.form-field label { font-size: 11.5px; font-weight: 600; color: var(--text-secondary); }
.form-field.full { grid-column: 1 / -1; }

.busy-overlay {
  position: fixed;
  inset: 0;
  z-index: 1150;
  background: rgba(3, 9, 23, 0.6);
  cursor: wait;
  display: flex;
  align-items: center;
  justify-content: center;
}
.busy-card {
  background: var(--bg-surface);
  border: 1px solid var(--col-sep);
  border-radius: var(--radius-lg);
  padding: 20px 28px;
  min-width: 280px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.busy-spinner { font-size: 28px; animation: spin 1.4s linear infinite; display: inline-block; }
@keyframes spin { 0% { transform: rotate(0); } 100% { transform: rotate(360deg); } }
.busy-message { margin: 8px 0; font-weight: 600; font-size: 13px; }
.busy-progress { height: 5px; background: var(--bg-surface-2); border-radius: 999px; overflow: hidden; margin: 8px 0; }
.busy-progress-bar { width: 45%; height: 100%; background: var(--accent-primary); animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(260%); } }
.busy-timer { font-size: 11px; color: var(--text-muted); }

.toast-container {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 1300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--bg-surface);
  border: 1px solid var(--col-sep);
  border-left: 4px solid var(--accent-cyan);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 12.5px;
  max-width: 380px;
}
.toast.success { border-left-color: var(--accent-success); }
.toast.error   { border-left-color: var(--accent-danger); }
.toast.warning { border-left-color: var(--accent-warning); }
