/* ═══════════════════════════════════════════════════════════
   SOIP – Sundyne Operations Intelligence Platform
   main.css  |  Design System + Layout
═══════════════════════════════════════════════════════════ */

/* ── Fonts & Custom Properties ─────────────────────────── */
:root {
  /* Brand */
  --brand-primary: #3B82F6;
  --brand-accent: #F97316;
  --brand-accent-2: #60A5FA;
  --brand-glow: rgba(249, 115, 22, 0.15);

  /* Surfaces */
  --bg-app: #F8FAFC;
  --bg-card: #FFFFFF;
  --bg-sidebar: #0F172A;
  --bg-sidebar-2: #1E293B;
  --bg-header: #FFFFFF;
  --bg-input: #F1F5F9;
  --bg-hover: #EFF6FF;
  --bg-row-even: #F8FAFC;

  /* Text */
  --text-primary: #1E293B;
  --text-secondary: #475569;
  --text-muted: #94A3B8;
  --text-sidebar: #CBD5E1;
  --text-sidebar-mut: #64748B;
  --text-link: #3B82F6;

  /* Borders */
  --border: #E2E8F0;
  --border-sidebar: rgba(255, 255, 255, 0.07);
  --border-focus: #3B82F6;

  /* Status */
  --success: #059669;
  --success-bg: #ECFDF5;
  --warn: #D97706;
  --warn-bg: #FFFBEB;
  --danger: #DC2626;
  --danger-bg: #FEF2F2;
  --info: #0EA5E9;
  --info-bg: #F0F9FF;

  /* Sidebar dimensions */
  --sidebar-w: 220px;

  /* Radii */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.10);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.14);
  --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);

  /* Transitions */
  --trans: 200ms ease-out;
  --trans-slow: 300ms ease-out;
}

/* ── Reset ─────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: 'Fira Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

a {
  color: var(--text-link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
}

/* ── Legacy Filter UI (Interdependent & Tree) ─────────────────── */
.filter-row {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 4px 3px 8px;
  margin-right: 6px;
}

.filter-row .s-select {
  background: transparent;
  border: none;
  padding: 2px 4px;
  font-size: 11px;
  color: var(--text);
  width: auto;
  max-width: 130px;
}

.ms-wrapper {
  position: relative;
  display: inline-block;
  width: auto;
}

.ms-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  background: transparent;
  border: none;
  padding: 2px 6px;
  border-radius: 12px;
  font-size: 10px;
  height: auto;
  min-width: 60px;
  max-width: 160px;
  color: var(--text-primary);
}

.ms-btn:hover {
  background: var(--surface3);
}

.ms-btn-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ms-caret {
  font-size: 10px;
  color: var(--text-dim);
  margin-left: 4px;
}

.ms-popup {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  width: max(100%, 280px);
  max-width: 320px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  flex-direction: column;
}

.ms-popup.open {
  display: flex;
}

.ms-search {
  padding: 8px;
  border-bottom: 1px solid var(--border);
}

.ms-search-input {
  width: 100%;
  padding: 6px 10px;
}

.ms-options {
  padding: 8px 8px 8px 12px;
  overflow-y: auto;
  position: relative;
  max-height: 250px;
}

.ms-options::before {
  content: '';
  position: absolute;
  top: 20px;
  bottom: 20px;
  left: 12px;
  border-left: 1px dotted var(--text-muted);
  z-index: 1;
}

.ms-list {
  display: flex;
  flex-direction: column;
}

.ms-options label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-bright);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  position: relative;
  margin-left: 16px;
  z-index: 2;
}

.ms-options label::before {
  content: '';
  position: absolute;
  top: 50%;
  left: -16px;
  width: 14px;
  border-top: 1px dotted var(--text-muted);
}

.ms-options label:hover {
  background: var(--surface3);
}

.ms-all-label {
  font-weight: 600;
  margin-bottom: 4px;
  padding-bottom: 4px;
}

.fr-remove {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface3);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  flex-shrink: 0;
  border: none;
  cursor: pointer;
}

.fr-remove:hover {
  background: var(--danger);
  color: white;
}

/* ── Date-filter tree ─────────────────────────────────────────── */
.dt-node {
  padding: 0;
}

.dt-node-m {
  padding-left: 14px;
}

.dt-row {
  display: flex;
  align-items: center;
}

.dt-lbl {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  cursor: pointer;
  font-size: 11px;
  border-radius: 3px;
  white-space: nowrap;
  user-select: none;
}

.dt-lbl:hover {
  background: var(--surface3);
}

.dt-year-lbl {
  font-weight: 600;
  color: var(--text-bright);
}

.dt-mo-lbl {
  color: var(--text);
}

.dt-day-lbl {
  padding-left: 28px;
  color: var(--text-muted);
}

.dt-tog {
  display: inline-block;
  width: 14px;
  font-size: 9px;
  cursor: pointer;
  color: var(--text-muted);
  flex-shrink: 0;
}

.dt-ch {
  display: none;
  padding-left: 8px;
  border-left: 1px solid var(--border);
  margin-left: 18px;
}

.dt-ch.dt-open {
  display: block;
}

.dt-empty {
  padding: 8px;
  color: var(--text-muted);
  font-size: 11px;
}

.filter-add-btn {
  padding: 5px 10px;
  font-size: 11px;
  border-radius: 20px;
  flex-shrink: 0;
}

.filter-clear-btn {
  padding: 5px 10px;
  font-size: 11px;
  border-radius: 20px;
  flex-shrink: 0;
  color: var(--danger);
  border-color: rgba(220, 38, 38, 0.3);
}

.filter-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  margin-left: auto;
}

/* ═══════════════════════════════════════════════════════════
   AUTH OVERLAY
═══════════════════════════════════════════════════════════ */
.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  background: linear-gradient(135deg, #0F1929 0%, #1D3461 50%, #0F1929 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity var(--trans-slow);
}

body:not(.auth-open) .auth-overlay {
  opacity: 0;
  pointer-events: none;
}

.auth-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(20px);
  border-radius: var(--radius-xl);
  padding: 48px 44px;
  width: 380px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
  text-align: center;
  animation: authIn 0.4s ease;
}

@keyframes authIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.auth-logo {
  display: inline-flex;
  margin-bottom: 20px;
  filter: drop-shadow(0 4px 16px rgba(74, 144, 217, 0.5));
}

.auth-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
  margin-bottom: 4px;
  letter-spacing: -0.02em;
}

.auth-subtitle {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.45);
  margin-bottom: 32px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.auth-form {
  text-align: left;
}

.auth-form .field-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.5);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
  margin-top: 16px;
}

.auth-form .auth-form .field-label:first-child {
  margin-top: 0;
}

.auth-input {
  width: 100%;
  background: rgba(255, 255, 255, 0.07) !important;
  border: 1px solid rgba(255, 255, 255, 0.12) !important;
  color: #fff !important;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.9rem;
  transition: border-color var(--trans);
}

.auth-input::placeholder {
  color: rgba(255, 255, 255, 0.3);
}

.auth-input:focus {
  outline: none;
  border-color: var(--brand-accent) !important;
  box-shadow: 0 0 0 3px var(--brand-glow);
}

.auth-message {
  min-height: 20px;
  font-size: 0.82rem;
  color: rgba(255, 255, 255, 0.5);
  margin: 12px 0 4px;
  text-align: center;
}

.auth-message.error {
  color: #FC8181;
}

.auth-submit-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 20px;
  background: var(--brand-accent);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 11px 0;
  font-size: 0.9rem;
  font-weight: 600;
  transition: background var(--trans), transform var(--trans);
}

.auth-submit-btn:hover {
  background: #1a5fc4;
  transform: translateY(-1px);
}

.auth-submit-btn:active {
  transform: translateY(0);
}

.auth-submit-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ═══════════════════════════════════════════════════════════
   LANDING PAGE
═══════════════════════════════════════════════════════════ */
.landing-view {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.landing-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.landing-header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.landing-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.landing-brand-icon {
  flex-shrink: 0;
}

.landing-brand-name {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--brand-primary);
  letter-spacing: -0.02em;
}

.landing-brand-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.landing-header-right {
  display: flex;
  align-items: center;
  gap: 20px;
}

.landing-stat-badge {
  text-align: center;
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 20px;
  min-width: 80px;
}

.lsb-num {
  display: block;
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--brand-accent);
  line-height: 1;
}

.lsb-label {
  display: block;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 2px;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-primary), var(--brand-accent));
  color: #fff;
  font-weight: 700;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.user-role {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: capitalize;
}

.logout-btn {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  transition: all var(--trans);
}

.logout-btn:hover {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: var(--danger);
}

/* Landing hero banner */
.landing-hero {
  background: linear-gradient(135deg, var(--brand-primary) 0%, #1E4A8A 100%);
  padding: 16px 32px;
}

.landing-hero-text {
  max-width: 1180px;
  margin: 0 auto;
}

.landing-hero-text h1 {
  font-family: 'Fira Code', monospace;
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.landing-hero-text p {
  font-size: 0.88rem;
  color: rgba(255, 255, 255, 0.65);
  line-height: 1.6;
}

/* Landing grid */
.landing-main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 36px 32px;
  flex: 1;
}

.landing-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 20px;
}

/* Module Card */
.module-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 24px 20px;
  cursor: pointer;
  transition: all var(--trans-slow);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
  overflow: hidden;
}

.module-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--card-accent, var(--brand-accent));
  opacity: 0;
  transition: opacity var(--trans);
}

.module-card:hover {
  border-color: var(--card-accent, var(--brand-accent));
  box-shadow: 0 8px 32px rgba(30, 111, 217, 0.12);
  transform: translateY(-2px);
}

.module-card:hover::before {
  opacity: 1;
}

.module-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.module-card-icon {
  width: 52px;
  height: 52px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--card-accent, var(--brand-accent));
  color: #fff;
  font-size: 1.3rem;
}

.module-card-badge {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 3px 10px;
  white-space: nowrap;
}

.module-card-body {
  flex: 1;
}

.module-card-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--brand-primary);
  margin-bottom: 6px;
  cursor: pointer;
}

.module-card-name:hover {
  color: var(--brand-accent);
  text-decoration: underline;
}

.module-card-desc {
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.55;
}

.module-card-footer {
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.module-card-launch {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--brand-accent);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: gap var(--trans);
}

.module-card:hover .module-card-launch {
  gap: 10px;
}

.module-card-launch svg {
  transition: transform var(--trans);
}

.module-card:hover .module-card-launch svg {
  transform: translateX(3px);
}

/* Disabled/coming soon card */
.module-card.disabled {
  opacity: 0.55;
  cursor: default;
}

.module-card.disabled:hover {
  transform: none;
  border-color: var(--border);
  box-shadow: var(--shadow-card);
}

.module-card.disabled::before {
  display: none;
}

/* ═══════════════════════════════════════════════════════════
   MODULE VIEW — no sidebar, top nav bar
═══════════════════════════════════════════════════════════ */
.module-view {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Top Nav Bar (replaces sidebar) ─────────────────────── */
.module-topnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 40px;
  padding: 0 12px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-sidebar);
  position: sticky;
  top: 0;
  z-index: 200;
  gap: 12px;
  flex-shrink: 0;
}

.topnav-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.topnav-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.topnav-divider {
  width: 1px;
  height: 22px;
  background: var(--border-sidebar);
  flex-shrink: 0;
}

.topnav-back {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-sidebar-mut);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  transition: all var(--trans);
  flex-shrink: 0;
}

.topnav-back:hover {
  background: rgba(255, 255, 255, 0.07);
  color: #fff;
}

.topnav-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-sidebar);
  letter-spacing: -0.01em;
  flex-shrink: 0;
}

/* ── topbar: nav tabs row (moved from dark header to main area) ── */
.topbar {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding-top: 4px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.nav-tabs {
  display: flex;
  flex-direction: row;
  gap: 4px;
  flex-shrink: 0;
}

.table-tab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  cursor: pointer;
  font-family: 'Fira Code', monospace;
  font-size: 11.5px;
  color: var(--text-secondary);
  border: 1px solid transparent;
  border-bottom: none;
  background: var(--bg-hover);
  text-align: left;
  white-space: nowrap;
  transition: none;
}

.table-tab:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.table-tab.active {
  background: var(--bg-card);
  color: var(--brand-accent);
  border-color: var(--border);
  border-bottom-color: var(--bg-card);
  font-weight: 600;
  position: relative;
  top: 1px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  padding-bottom: 2px;
}

/* Top nav icon buttons (white-on-dark) */
.module-topnav .icon-btn,
.module-topnav .audit-btn {
  background: transparent;
  border-color: var(--border-sidebar);
  color: var(--text-sidebar-mut);
}

.module-topnav .icon-btn:hover,
.module-topnav .audit-btn:hover {
  background: rgba(255, 255, 255, 0.07);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.2);
}

/* Export menu in topnav needs white bg */
.module-topnav .export-menu {
  background: var(--bg-card);
  border-color: var(--border);
}

.module-topnav .export-opt {
  color: var(--text-primary);
}

/* User info in top nav */
.topnav-user {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topnav-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-primary), var(--brand-accent));
  color: #fff;
  font-weight: 700;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.topnav-user-info {
  line-height: 1.2;
}

.topnav-user-name {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-sidebar);
}

.topnav-user-role {
  font-size: 0.65rem;
  color: var(--text-sidebar-mut);
  text-transform: capitalize;
}

.topnav-logout-btn {
  color: var(--text-sidebar-mut);
  padding: 5px 7px;
  border-radius: var(--radius-sm);
  transition: all var(--trans);
  display: flex;
  align-items: center;
}

.topnav-logout-btn:hover {
  background: rgba(255, 255, 255, 0.07);
  color: #FC8181;
}

/* Header Stats (Reference Register) */
#header-stats {
  max-width: 420px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  flex-shrink: 1;
}

#header-stats::-webkit-scrollbar {
  display: none;
}

.stat-pill {
  display: flex;
  align-items: baseline;
  gap: 5px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 2px 8px;
  border-radius: 100px;
  white-space: nowrap;
  flex-shrink: 0;
}

.stat-label {
  font-size: 0.58rem;
  font-weight: 700;
  color: var(--text-sidebar-mut);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-val {
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
}

/* ── Module Main Content ─────────────────────────────────── */
.module-main {
  flex: 1;
  overflow-x: hidden;
  padding: 0 16px 16px;
  min-width: 0;
  background: var(--bg-app);
}

.module-header-row {
  padding: 4px 0 2px;
}

.module-title {
  font-family: 'Fira Code', monospace;
  font-size: 1.12rem;
  font-weight: 700;
  color: var(--brand-primary);
  letter-spacing: -0.02em;
}

.module-subtitle {
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-top: 1px;
}

/* ── Filter Bar ─────────────────────────────────────────── */
.filterbar {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  margin-bottom: 4px;
  box-shadow: var(--shadow-sm);
}

.search-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
  margin-bottom: 4px;
}

.search-icon-svg {
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-input {
  flex: 1;
  background: transparent;
  border: none;
  font-size: 0.82rem;
  color: var(--text-primary);
  padding: 2px 0;
  outline: none;
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-kbd {
  font-size: 0.62rem;
  color: var(--text-muted);
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  flex-shrink: 0;
  font-family: 'IBM Plex Mono', monospace;
}

.filter-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--info-bg);
  border: 1px solid var(--info);
  border-radius: 100px;
  padding: 3px 10px;
  font-size: 0.75rem;
  color: var(--brand-primary);
}

.filter-chip-close {
  cursor: pointer;
  color: var(--brand-accent);
  font-size: 0.8rem;
  opacity: 0.6;
  transition: opacity var(--trans);
}

.filter-chip-close:hover {
  opacity: 1;
}

.filter-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

/* CRUD bar */
.crud-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

/* ── Buttons ─────────────────────────────────────────────── */
.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 11px;
  color: var(--text-secondary);
  transition: all var(--trans);
  cursor: pointer;
  white-space: nowrap;
}

.icon-btn:hover {
  background: var(--bg-hover);
  border-color: var(--brand-accent-2);
  color: var(--brand-primary);
}

.icon-btn svg {
  flex-shrink: 0;
}

.add-record-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
  background: var(--brand-accent);
  border: 1px solid var(--brand-accent);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  transition: all var(--trans);
}

.add-record-btn:hover {
  background: #1a5fc4;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--brand-accent);
  color: #fff;
  border: 1px solid var(--brand-accent);
  border-radius: var(--radius-sm);
  padding: 8px 18px;
  font-size: 0.85rem;
  font-weight: 600;
  transition: all var(--trans);
  cursor: pointer;
}

.btn-primary:hover {
  background: #1a5fc4;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 18px;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all var(--trans);
  cursor: pointer;
}

.btn-secondary:hover {
  background: var(--bg-app);
}

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--trans);
}

.btn-danger:hover {
  background: var(--danger);
  color: #fff;
}

.audit-btn {
  color: var(--text-muted);
}

.filter-add-btn,
.filter-clear-btn {
  font-size: 0.78rem;
}

.filter-clear-btn {
  color: var(--danger);
  border-color: transparent;
  background: transparent;
}

.filter-clear-btn:hover {
  background: var(--danger-bg);
  border-color: var(--danger);
}

/* Export dropdown */
.export-wrap {
  position: relative;
}

.export-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  min-width: 150px;
  z-index: 100;
  display: none;
}

.export-menu.open {
  display: block;
}

.export-opt {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 14px;
  font-size: 0.82rem;
  color: var(--text-primary);
  background: none;
  border: none;
  cursor: pointer;
  transition: background var(--trans);
}

.export-opt:hover {
  background: var(--bg-hover);
}

/* Saved queries dropdown */
.saved-queries-wrap {
  position: relative;
}

.saved-queries-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  min-width: 220px;
  z-index: 100;
  display: none;
}

.saved-queries-menu.open {
  display: block;
}

.saved-queries-header {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 10px 14px 6px;
  border-bottom: 1px solid var(--border);
}

.saved-query-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background var(--trans);
}

.saved-query-item:hover {
  background: var(--bg-hover);
}

.saved-query-del {
  color: var(--danger);
  opacity: 0;
  font-size: 0.75rem;
  cursor: pointer;
  transition: opacity var(--trans);
}

.saved-query-item:hover .saved-query-del {
  opacity: 1;
}

/* Rows select */
.rows-label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.rows-select {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: 0.75rem;
  color: var(--text-primary);
  cursor: pointer;
}

.save-query-btn {
  font-size: 0.78rem;
}

/* ── Loading bar ─────────────────────────────────────────── */
.loading-bar {
  height: 3px;
  background: var(--brand-accent);
  border-radius: 100px;
  margin-bottom: 8px;
  opacity: 0;
  transition: opacity var(--trans);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}

.loading-bar.active {
  opacity: 1;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }

  100% {
    background-position: -200% 0;
  }
}

.result-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 6px;
  min-height: 18px;
}

/* ── Sub-tabs bar (MOC Code/Type, By Category/Part No.) ─── */
.sub-tabs-bar {
  display: flex;
  gap: 6px;
  padding: 4px 16px 0;
  background: var(--bg-base);
  border-bottom: 1px solid var(--border);
}

.sub-tab-btn {
  padding: 4px 14px;
  border: 1.5px solid var(--border);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--trans), color var(--trans), border-color var(--trans);
  position: relative;
  bottom: -1px;
}

.sub-tab-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.sub-tab-btn.active {
  background: var(--bg-card);
  color: var(--brand-accent);
  border-color: var(--brand-accent);
  border-bottom: 2px solid var(--bg-card);
  z-index: 1;
}

/* ── Table ───────────────────────────────────────────────── */
.table-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.table-wrap {
  overflow-x: scroll;
  overflow-y: scroll;
  max-width: 100%;
  max-height: calc(100vh - 240px);
  scrollbar-color: #8fb7ee #dfe9f8;
  scrollbar-width: auto;
}

.table-wrap::-webkit-scrollbar {
  width: 14px;
  height: 14px;
}

.table-wrap::-webkit-scrollbar-track {
  background: #dfe9f8;
  border-radius: 999px;
}

.table-wrap::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #9cc0f2 0%, #79a9e7 100%);
  border-radius: 999px;
  border: 3px solid #dfe9f8;
}

.table-wrap::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #89b5ee 0%, #5f96df 100%);
}

.table-wrap::-webkit-scrollbar-corner {
  background: #dfe9f8;
}

table {
  width: 100%;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.6rem;
}

thead {
  background: #F9FAFB;
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

th {
  padding: 4px 8px;
  text-align: left;
  font-size: 0.52rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: color var(--trans);
}

th:hover {
  color: var(--text-primary);
}

th.sorted-asc::after {
  content: ' ↓';
  color: var(--brand-accent);
}

th.sorted-desc::after {
  content: ' ↑';
  color: var(--brand-accent);
}

th.col-check {
  width: 40px;
}

td {
  padding: 4px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  white-space: pre-wrap;
  word-break: normal;
  max-width: 350px;
  min-width: 85px;
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background: var(--bg-hover);
}

tr.row-selected td {
  background: #EFF6FF;
}

tr:nth-child(even) td {
  background: var(--bg-row-even);
}

tr:nth-child(even):hover td {
  background: var(--bg-hover);
}

tr:nth-child(even).row-selected td {
  background: #EFF6FF;
}

/* ── Spare Guide (master module) — spacious row layout ───── */
table.master-table {
  font-size: 0.82rem;
}

table.master-table th {
  padding: 10px 16px;
  font-size: 0.67rem;
}

table.master-table td {
  padding: 12px 16px;
  vertical-align: top;
  line-height: 1.6;
  border-bottom: 1px solid var(--border);
}

table.master-table tr:last-child td {
  border-bottom: none;
}

table.master-table tbody tr {
  transition: background var(--trans);
}

table.master-table tbody tr:hover td {
  background: var(--bg-hover);
}

table.master-table tbody tr:nth-child(even) td {
  background: #f8fafc;
}

table.master-table tbody tr:nth-child(even):hover td {
  background: var(--bg-hover);
}


/* Status badge */
.status-badge {
  display: inline-block;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 100px;
  padding: 2px 9px;
}

.status-badge.active {
  background: var(--success-bg);
  color: var(--success);
}

.status-badge.obsolete {
  background: var(--warn-bg);
  color: var(--warn);
}

.status-badge.other {
  background: var(--bg-app);
  color: var(--text-muted);
}

/* Row link (part number) */
.row-link {
  color: var(--brand-accent);
  font-weight: 600;
  cursor: pointer;
  font-family: 'Fira Code', monospace;
  font-size: 0.65rem;
  white-space: nowrap;
}

.row-link:hover {
  text-decoration: underline;
}

/* Strikethrough in cells */
.strike {
  text-decoration: line-through;
  opacity: 0.55;
}


/* Search match highlight */
.match-highlight {
  background: #fef08a;
  /* Soft yellow */
  color: #1a1a1a;
  border-radius: 2px;
  padding: 0 1px;
  box-shadow: 0 0 0 1px rgba(253, 224, 71, 0.4);
  font-weight: 600;
}

/* ── Advance Order row — entire row highlighted red ──────── */
tr.row-advance-order td {
  background: #FFF1F0 !important;
  color: #b91c1c !important;
  font-weight: 600;
}

tr.row-advance-order:hover td {
  background: #FFE4E4 !important;
}

/* ── Inline row action buttons (edit / delete) ───────────── */
.row-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  opacity: 0;
  transition: opacity var(--trans);
}

tr:hover .row-actions {
  opacity: 1;
}

.row-act-btn {
  width: 22px;
  height: 22px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--bg-card);
  cursor: pointer;
  transition: all var(--trans);
  flex-shrink: 0;
}

.row-act-btn.edit {
  color: var(--brand-accent);
}

.row-act-btn.del {
  color: var(--danger);
}

.row-act-btn.edit:hover {
  background: var(--info-bg);
  border-color: var(--brand-accent);
}

.row-act-btn.del:hover {
  background: var(--danger-bg);
  border-color: var(--danger);
}

th.col-actions {
  width: 72px;
  text-align: center;
  cursor: default;
}

td.col-actions {
  text-align: center;
  padding: 6px 8px;
}

/* ── Spare Guide eye-icon view button ────────────────────── */
th.col-view-action {
  width: 52px;
  text-align: center;
  cursor: default;
}

td.col-view-action {
  text-align: center;
  padding: 4px 6px;
}

.row-view-btn {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid #f87171;
  background: #fff1f0;
  color: #dc2626;
  cursor: pointer;
  transition: all var(--trans);
  flex-shrink: 0;
}

.row-view-btn:hover {
  background: #dc2626;
  border-color: #dc2626;
  color: #fff;
  transform: scale(1.1);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 2.4rem;
  margin-bottom: 12px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 0.9rem;
  margin-bottom: 16px;
}

.empty-state button {
  background: var(--brand-accent);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 8px 18px;
  font-size: 0.85rem;
  cursor: pointer;
}

/* Pagination */
.pagination {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  font-size: 0.65rem;
  color: var(--text-secondary);
}

.pagination-info {
  color: var(--text-muted);
}

.pagination-btns {
  display: flex;
  align-items: center;
  gap: 4px;
}

.pg-btn {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--trans);
}

.pg-btn:hover {
  background: var(--bg-hover);
  border-color: var(--brand-accent-2);
}

.pg-btn.active {
  background: var(--brand-primary);
  color: #fff;
  border-color: var(--brand-primary);
  font-weight: 700;
}

.pg-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ── Modals ──────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 800;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  display: none;
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: modalIn 0.2s ease;
  max-width: 560px;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(10px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-wide {
  max-width: 820px;
}

.modal-sm {
  max-width: 380px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--trans);
}

.modal-close:hover {
  background: var(--bg-app);
  color: var(--text-primary);
}

.modal-body {
  padding: 20px 22px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

/* ── Form elements ───────────────────────────────────────── */
.field-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 5px;
}

.s-input {
  font-size: 0.85rem;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  transition: border-color var(--trans), box-shadow var(--trans);
  width: 100%;
}

.s-input:focus {
  outline: none;
  border-color: var(--brand-accent);
  box-shadow: 0 0 0 3px var(--brand-glow);
}

.s-select {
  font-size: 0.82rem;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  cursor: pointer;
}

/* ── Toast ───────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-sidebar);
  color: var(--text-sidebar);
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  transform: translateY(20px);
  opacity: 0;
  transition: all var(--trans-slow);
  pointer-events: none;
  max-width: 340px;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.success {
  border-left: 3px solid var(--success);
}

.toast.error {
  border-left: 3px solid var(--danger);
}

.toast.info {
  border-left: 3px solid var(--brand-accent);
}

/* ── Audit log table ────────────────────────────────────── */
.audit-table-row {
  transition: background var(--trans);
}

.audit-table-row:hover {
  background: var(--bg-hover);
}

/* ── Bulk delete bar ────────────────────────────────────── */
.bulk-delete-btn {
  color: var(--danger);
  border-color: var(--danger);
}

.bulk-delete-btn:hover {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger);
}

/* ── Selection checkbox ─────────────────────────────────── */
input[type="checkbox"] {
  accent-color: var(--brand-accent);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

/* ── Filter toggle ──────────────────────────────────────── */
.filter-toggle-btn {}

/* Coming soon overlay on card */
.coming-soon-tag {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: var(--warn-bg);
  color: var(--warn);
  border: 1px solid var(--warn);
  border-radius: 100px;
  padding: 2px 8px;
}

/* ── Scrollbar styling ──────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.12);
  border-radius: 100px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.22);
}

/* Sidebar scrollbar */
.sidebar ::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
}

.sidebar ::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 900px) {
  .landing-grid {
    grid-template-columns: 1fr 1fr;
  }

  .landing-header-inner {
    padding: 14px 20px;
  }

  .landing-main {
    padding: 24px 20px;
  }
}

@media (max-width: 640px) {
  .landing-grid {
    grid-template-columns: 1fr;
  }

  .auth-card {
    padding: 36px 24px;
    width: 100%;
    max-width: 360px;
  }

  .sidebar {
    display: none;
  }

  .module-main {
    padding: 0 14px 20px;
  }

  .table-wrap {
    max-height: calc(100vh - 240px);
  }
}