/* ==========================================================================
   MID-SEM MASTER VAULT — INTERACTIVE VISUALIZERS & CALCULATORS STYLESHEET
   Supports: CN (CIDR & Header Inspector), DAA (Master Theorem & 2D DP),
             DMDW (Apriori & Rules), HPC (5-Stage MIPS Pipeline & FSM)
   Matches Sepia, Dark, and Light vault themes
   ========================================================================== */

/* Visualizers Modal Container */
.viz-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.viz-modal-backdrop.open {
  display: flex;
  opacity: 1;
}

.viz-modal-container {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  width: 100%;
  max-width: 1280px;
  height: 92vh;
  max-height: 900px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  animation: vizModalSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes vizModalSlideIn {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Modal Header & Navigation */
.viz-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.25rem;
  background: var(--bg-page);
  border-bottom: 1px solid var(--border-card);
  gap: 1rem;
  flex-shrink: 0;
}

.viz-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.viz-brand-badge {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-pill);
  letter-spacing: 0.05em;
  background: var(--accent-glow);
  color: var(--accent-primary);
  border: 1px solid var(--accent-primary);
}

.viz-modal-title {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-title);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.viz-main-nav {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--bg-input);
  padding: 0.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-card);
  overflow-x: auto;
}

.viz-nav-btn {
  background: transparent;
  border: none;
  padding: 0.45rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.15s ease;
  white-space: nowrap;
  font-family: var(--font-main);
}

.viz-nav-btn:hover {
  color: var(--text-title);
  background: rgba(0, 0, 0, 0.04);
}

.viz-nav-btn.active {
  background: var(--bg-card);
  color: var(--accent-primary);
  box-shadow: var(--shadow-subtle);
  border: 1px solid var(--border-card);
}

.viz-nav-btn.active.nav-cn { color: var(--cn-color); }
.viz-nav-btn.active.nav-daa { color: var(--daa-color); }
.viz-nav-btn.active.nav-dmdw { color: var(--dmdw-color); }
.viz-nav-btn.active.nav-hpc { color: var(--hpc-color); }

.viz-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Modal Body & Content Area */
.viz-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  background: var(--bg-page);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.viz-tool-pane {
  display: none;
  flex-direction: column;
  gap: 1.25rem;
}

.viz-tool-pane.active {
  display: flex;
}

/* Sub-tab navigation inside tools */
.viz-sub-tabs {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border-card);
  padding-bottom: 0.5rem;
  margin-bottom: 0.5rem;
  overflow-x: auto;
}

.viz-sub-tab {
  background: transparent;
  border: none;
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.viz-sub-tab:hover {
  color: var(--text-title);
  background: var(--bg-card);
}

.viz-sub-tab.active {
  background: var(--bg-card);
  color: var(--text-title);
  font-weight: 700;
  border: 1px solid var(--border-card);
  box-shadow: var(--shadow-subtle);
}

/* Preset & Control Strip */
.viz-control-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--bg-card);
  padding: 0.85rem 1.15rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-card);
  box-shadow: var(--shadow-subtle);
}

.viz-presets-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.viz-preset-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.viz-preset-chip {
  background: var(--bg-input);
  border: 1px solid var(--border-card);
  color: var(--text-body);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.3rem 0.65rem;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: all 0.15s ease;
}

.viz-preset-chip:hover {
  background: var(--accent-glow);
  color: var(--accent-primary);
  border-color: var(--accent-primary);
}

/* Visualizer Cards & Grids */
.viz-grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

@media (max-width: 900px) {
  .viz-grid-2col {
    grid-template-columns: 1fr;
  }
}

.viz-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.viz-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-card);
  padding-bottom: 0.6rem;
}

.viz-card-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-title);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

/* Form Controls */
.viz-form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.viz-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.viz-input {
  background: var(--bg-input);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  font-family: var(--font-code);
  color: var(--text-title);
  transition: border-color 0.15s ease;
  width: 100%;
}

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

.viz-slider-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.viz-slider {
  flex: 1;
  accent-color: var(--accent-primary);
  cursor: pointer;
}

.viz-slider-val {
  font-family: var(--font-code);
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--accent-primary);
  min-width: 2.5rem;
  text-align: right;
}

/* Output Metric Badges */
.viz-metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
}

.viz-metric-box {
  background: var(--bg-input);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.viz-metric-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
}

.viz-metric-value {
  font-family: var(--font-code);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-title);
  word-break: break-all;
}

.viz-metric-sub {
  font-size: 0.72rem;
  color: var(--text-subtle);
}

/* ==========================================================================
   1. CN: CIDR & Bitwise Subnet Visualizer
   ========================================================================== */
.cn-binary-display {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: var(--bg-input);
  padding: 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-card);
  overflow-x: auto;
}

.cn-bit-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-code);
  font-size: 0.82rem;
}

.cn-bit-label {
  width: 110px;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
}

.cn-octets-wrap {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.cn-octet {
  display: flex;
  gap: 2px;
}

.cn-bit {
  width: 15px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 3px;
}

.cn-bit.net-bit {
  background: #38bdf8;
  color: #082f49;
}

.cn-bit.host-bit {
  background: #fb923c;
  color: #431407;
}

.cn-octet-dot {
  font-weight: 800;
  color: var(--text-subtle);
}

/* VLSM Table */
.cn-vlsm-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  font-family: var(--font-code);
}

.cn-vlsm-table th, .cn-vlsm-table td {
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border-card);
  text-align: left;
}

.cn-vlsm-table th {
  background: var(--bg-input);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

/* Packet Header Inspector Grid */
.cn-header-grid {
  display: grid;
  grid-template-columns: repeat(32, 1fr);
  gap: 2px;
  background: var(--border-card);
  padding: 2px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  min-width: 600px;
}

.cn-header-field {
  background: var(--bg-card);
  padding: 0.4rem 0.3rem;
  font-size: 0.72rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid transparent;
  min-height: 48px;
}

.cn-header-field:hover, .cn-header-field.selected {
  background: var(--accent-glow);
  border-color: var(--accent-primary);
  z-index: 2;
}

.cn-field-name {
  font-weight: 700;
  color: var(--text-title);
  font-size: 0.72rem;
  line-height: 1.1;
}

.cn-field-val {
  font-family: var(--font-code);
  font-size: 0.68rem;
  color: var(--accent-primary);
  margin-top: 2px;
}

.cn-flag-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.cn-flag-btn {
  background: var(--bg-input);
  border: 1px solid var(--border-card);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.cn-flag-btn.active {
  background: var(--cn-color);
  color: #ffffff;
  border-color: var(--cn-color);
}

/* ==========================================================================
   2. DAA: Master Theorem & 2D DP Table Visualizers
   ========================================================================== */
.daa-formula-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--daa-bg);
  color: var(--daa-color);
  border: 1px solid var(--daa-border);
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-code);
  font-size: 0.95rem;
  font-weight: 700;
}

.daa-tree-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  padding: 1.5rem;
  background: var(--bg-input);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-card);
  overflow-x: auto;
}

.daa-tree-level {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 1rem;
}

.daa-tree-nodes {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  flex: 1;
}

.daa-tree-node {
  background: var(--bg-card);
  border: 2px solid var(--daa-color);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.75rem;
  font-size: 0.78rem;
  font-family: var(--font-code);
  font-weight: 700;
  color: var(--text-title);
  box-shadow: var(--shadow-subtle);
  text-align: center;
}

.daa-tree-level-cost {
  font-family: var(--font-code);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--daa-color);
  background: var(--bg-card);
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-card);
  white-space: nowrap;
}

/* 2D DP Grid Table */
.daa-dp-table-wrap {
  overflow: auto;
  max-height: 400px;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-sm);
}

.daa-dp-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-code);
  font-size: 0.85rem;
  text-align: center;
}

.daa-dp-table th, .daa-dp-table td {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border-card);
  min-width: 44px;
}

.daa-dp-table th {
  background: var(--bg-input);
  font-weight: 700;
  color: var(--text-muted);
  position: sticky;
  top: 0;
  z-index: 1;
}

.daa-dp-table td.cell-active {
  background: #fef08a !important;
  color: #713f12 !important;
  font-weight: 800;
  transform: scale(1.05);
  box-shadow: 0 0 6px rgba(250, 204, 21, 0.6);
}

.daa-dp-table td.cell-backtrack {
  background: #86efac !important;
  color: #14532d !important;
  font-weight: 800;
}

.daa-dp-table td.cell-source {
  background: #bae6fd !important;
  color: #0369a1 !important;
}

.daa-step-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ==========================================================================
   3. DMDW: Apriori & Association Rule Frequency Simulator
   ========================================================================== */
.dmdw-iteration-box {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.dmdw-itemset-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--bg-input);
  border: 1px solid var(--border-card);
  padding: 0.25rem 0.55rem;
  border-radius: var(--radius-pill);
  font-family: var(--font-code);
  font-size: 0.78rem;
  font-weight: 600;
}

.dmdw-itemset-pill.frequent {
  background: var(--dmdw-bg);
  border-color: var(--dmdw-border);
  color: var(--dmdw-color);
  font-weight: 700;
}

.dmdw-itemset-pill.pruned {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.3);
  color: #ef4444;
  text-decoration: line-through;
}

.dmdw-rules-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.dmdw-rules-table th, .dmdw-rules-table td {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-card);
  text-align: left;
}

.dmdw-rules-table th {
  background: var(--bg-input);
  font-weight: 700;
  color: var(--text-muted);
}

.dmdw-lift-badge {
  font-family: var(--font-code);
  font-weight: 700;
  padding: 0.2rem 0.45rem;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
}

.dmdw-lift-badge.positive {
  background: #dcfce7;
  color: #15803d;
}

.dmdw-lift-badge.negative {
  background: #fee2e2;
  color: #b91c1c;
}

.dmdw-lift-badge.independent {
  background: #f1f5f9;
  color: #64748b;
}

/* ==========================================================================
   4. HPC: 5-Stage MIPS Pipeline & Forwarding Visualizer
   ========================================================================== */
.hpc-pipeline-diagram {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  background: var(--bg-input);
  padding: 1.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-card);
  overflow-x: auto;
  position: relative;
}

.hpc-stage-card {
  flex: 1;
  min-width: 100px;
  background: var(--bg-card);
  border: 2px solid var(--hpc-color);
  border-radius: var(--radius-sm);
  padding: 0.6rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  text-align: center;
  box-shadow: var(--shadow-subtle);
  position: relative;
}

.hpc-stage-title {
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--hpc-color);
}

.hpc-stage-desc {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.hpc-latch-card {
  background: var(--bg-page);
  border: 1px dashed var(--border-card);
  border-radius: var(--radius-xs);
  padding: 0.35rem 0.25rem;
  font-size: 0.65rem;
  font-family: var(--font-code);
  font-weight: 700;
  color: var(--text-subtle);
  text-align: center;
  writing-mode: vertical-lr;
}

.hpc-forwarding-wire {
  background: #f59e0b;
  color: #78350f;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-pill);
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

/* HPC Execution Trace Grid */
.hpc-trace-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-sm);
}

.hpc-trace-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-code);
  font-size: 0.8rem;
}

.hpc-trace-table th, .hpc-trace-table td {
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border-card);
  text-align: center;
  min-width: 42px;
}

.hpc-trace-table th {
  background: var(--bg-input);
  font-weight: 700;
  color: var(--text-muted);
}

.hpc-trace-table td.instr-name {
  text-align: left;
  font-weight: 700;
  color: var(--text-title);
  white-space: nowrap;
  background: var(--bg-card);
  position: sticky;
  left: 0;
  z-index: 1;
}

.hpc-stage-badge {
  display: inline-block;
  padding: 0.2rem 0.4rem;
  border-radius: 3px;
  font-weight: 700;
  font-size: 0.72rem;
}

.hpc-stage-badge.s-if { background: #dbeafe; color: #1e40af; }
.hpc-stage-badge.s-id { background: #ede9fe; color: #5b21b6; }
.hpc-stage-badge.s-ex { background: #fed7aa; color: #9a3412; }
.hpc-stage-badge.s-mem { background: #bbf7d0; color: #166534; }
.hpc-stage-badge.s-wb { background: #fbcfe8; color: #9d174d; }
.hpc-stage-badge.s-stall { background: #fee2e2; color: #991b1b; }
.hpc-stage-badge.s-fwd { box-shadow: 0 0 0 2px #f59e0b; }

/* 2-Bit FSM Diagram */
.hpc-fsm-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
}

@media (max-width: 768px) {
  .hpc-fsm-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.hpc-fsm-state-card {
  background: var(--bg-card);
  border: 2px solid var(--border-card);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  transition: all 0.2s ease;
}

.hpc-fsm-state-card.active {
  border-color: var(--hpc-color);
  background: var(--hpc-bg);
  box-shadow: 0 0 12px var(--hpc-border);
  transform: translateY(-2px);
}

.hpc-fsm-bits {
  font-family: var(--font-code);
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text-title);
}

.hpc-fsm-state-name {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
}

.hpc-fsm-predict {
  font-size: 0.75rem;
  font-weight: 800;
  padding: 0.15rem 0.4rem;
  border-radius: var(--radius-pill);
  display: inline-block;
  margin-top: 0.2rem;
}

.hpc-fsm-predict.taken { background: #dcfce7; color: #166534; }
.hpc-fsm-predict.not-taken { background: #fee2e2; color: #991b1b; }

/* Responsive adjustments */
@media (max-width: 768px) {
  .viz-modal-container {
    height: 96vh;
    max-height: none;
    border-radius: var(--radius-md);
  }
  .viz-modal-header {
    flex-direction: column;
    align-items: stretch;
  }
  .viz-main-nav {
    order: 2;
  }
  .cn-bit-label {
    width: 70px;
  }
}
