/*
 * iptables Visualization - Custom Styles
 * Catppuccin Mocha Theme with Mermaid Live Editor-inspired Layout
 */

/* Font Import - Fira Code for monospace */
@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500;600&display=swap');

/* Global Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* CodeMirror 6 Customization */
#editor {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.cm-editor {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  height: 100% !important;
  font-family: 'Fira Code', 'Consolas', 'Monaco', 'Courier New', monospace !important;
  font-size: 14px !important;
  line-height: 1.6 !important;
}

.cm-scroller {
  overflow: auto !important;
  max-height: 100% !important;
  font-family: 'Fira Code', 'Consolas', 'Monaco', 'Courier New', monospace !important;
}

.cm-content {
  font-family: 'Fira Code', 'Consolas', 'Monaco', 'Courier New', monospace !important;
  padding: 16px 8px;
}

.cm-gutters {
  background-color: #181825 !important;
  border-right: 1px solid #313244 !important;
  color: #6c7086 !important;
}

.cm-activeLineGutter {
  background-color: #313244 !important;
}

.cm-lineNumbers {
  font-family: 'Fira Code', 'Consolas', 'Monaco', 'Courier New', monospace !important;
}

/* Smooth Transitions */
button {
  transition: all 0.2s ease;
}

button:active {
  transform: scale(0.98);
}

/* Resizable Panels */
#input-panel,
#output-panel {
  transition: flex 0.3s ease, min-width 0.3s ease, max-width 0.3s ease;
}

#input-header {
  transition: all 0.3s ease;
}

#input-title {
  transition: all 0.3s ease;
}

#input-editor-area,
#input-generate-area,
#input-buttons {
  transition: opacity 0.2s ease;
}

.save-text,
.load-text {
  transition: opacity 0.2s ease;
}

#divider {
  transition: background-color 0.2s ease;
  user-select: none;
}

#divider:hover {
  width: 4px;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

::-webkit-scrollbar-track {
  background: #1e1e2e;
}

::-webkit-scrollbar-thumb {
  background: #45475a;
  border-radius: 6px;
}

::-webkit-scrollbar-thumb:hover {
  background: #585b70;
}

/* Modal Backdrop Blur */
#save-modal, #load-modal {
  backdrop-filter: blur(4px);
}

/* Toast Animation */
#toast {
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* SVG Container - Zoom Smooth Transition */
#svg-container {
  transition: transform 0.1s ease-out;
  will-change: transform;
  display: inline-block;
  min-width: 100%;
  min-height: 100%;
}

#svg-container svg {
  display: block;
  max-width: none;
  height: auto;
}

/* Zoom level indicator */
#zoom-level {
  user-select: none;
  pointer-events: none;
  font-variant-numeric: tabular-nums;  /* Consistent width for numbers */
}

#zoom-percentage {
  min-width: 3.5rem;  /* Prevent layout shift (25% ~ 500%) */
  text-align: center;
}

/* Loading Spinner Animation */
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.animate-spin {
  animation: spin 1s linear infinite;
}

/* Responsive Design - Mobile & Tablet */
@media (max-width: 1023px) {
  /* Stack panels vertically on mobile/tablet */
  main {
    flex-direction: column !important;
  }

  /* Adjust panel heights on mobile */
  main > div:first-child {
    height: 50vh;
    border-right: none;
    border-bottom: 1px solid #313244;
  }

  main > div:last-child {
    height: 50vh;
  }

  /* Reduce header padding on mobile */
  header {
    padding: 12px 16px;
  }

  header h1 {
    font-size: 18px;
  }

  /* Smaller buttons on mobile */
  button {
    font-size: 13px;
    padding: 6px 12px;
  }

  /* Adjust editor font size */
  .cm-editor {
    font-size: 12px !important;
  }

  /* Modal adjustments */
  #save-modal > div,
  #load-modal > div {
    max-width: 90%;
    margin: 16px;
  }
}

@media (max-width: 640px) {
  /* Extra small screens */
  #output-actions {
    flex-wrap: wrap;
  }

  #output-actions button {
    flex: 1;
    min-width: 80px;
  }

  /* Toast position on mobile */
  #toast {
    top: auto;
    bottom: 16px;
    right: 16px;
    left: 16px;
    max-width: none;
  }
}

/* Print Styles */
@media print {
  header, footer, #output-actions, #save-modal, #load-modal, #toast {
    display: none !important;
  }

  main {
    flex-direction: row !important;
  }

  #output-container {
    flex: 1;
  }
}

/* ========================================
   Interactive Graph Styles
   ======================================== */

/* Tooltip */
#graph-tooltip {
  max-width: 400px;
  transition: opacity 0.2s ease;
}

#graph-tooltip.show {
  opacity: 1 !important;
}

/* Node Highlighting */
.node-highlighted polygon {
  stroke: #f9e2af !important;
  stroke-width: 2px !important;
  filter: brightness(1.2);
}

.node-highlighted text {
  font-weight: 600;
}

/* Edge Highlighting */
.edge-highlighted path {
  stroke: #f9e2af !important;
  stroke-width: 2px !important;
}

.edge-highlighted polygon {
  fill: #f9e2af !important;
  stroke: #f9e2af !important;
}

/* Search Matching */
.search-matched polygon {
  stroke: #a6e3a1 !important;
  stroke-width: 3px !important;
  animation: pulse-glow 1.5s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.3);
  }
}

/* Rule Modal */
#rule-modal {
  backdrop-filter: blur(4px);
}

#rule-modal > div {
  max-height: 80vh;
  overflow-y: auto;
}

/* Search Panel */
#search-panel {
  transition: all 0.3s ease;
}

#search-input {
  font-family: 'Fira Code', 'Consolas', 'Monaco', 'Courier New', monospace;
}

/* View Mode Toggle Buttons */
#static-view-btn,
#interactive-view-btn {
  min-width: 80px;
}

/* Mobile Responsiveness */
@media (max-width: 640px) {
  /* Hide tooltip on mobile */
  #graph-tooltip {
    display: none !important;
  }

  /* Adjust modal on mobile */
  #rule-modal > div {
    max-height: 70vh;
    max-width: 95%;
  }

  /* Stack view mode buttons */
  #output-actions {
    flex-wrap: wrap;
  }

  #static-view-btn,
  #interactive-view-btn {
    min-width: 60px;
    font-size: 12px;
    padding: 6px 12px;
  }

  /* Search panel adjustments */
  #search-panel {
    padding: 12px 16px;
  }

  #search-input {
    font-size: 14px;
  }
}

/* Disable pointer events on non-interactive mode */
body:not([data-interactive-mode]) .node {
  pointer-events: none;
}

/* Smooth transitions for mode switching */
.node {
  transition: all 0.2s ease;
}

/* Fixed node indicator */
.node-fixed polygon {
  stroke: #89b4fa !important;
  stroke-width: 3px !important;
  stroke-dasharray: 5,5;
  animation: dash-animation 0.5s linear infinite;
}

@keyframes dash-animation {
  to {
    stroke-dashoffset: -10;
  }
}

/* Dragging cursor */
.node:active {
  cursor: grabbing !important;
}

/* Interactive Tools Group */
#interactive-tools {
  transition: all 0.2s ease;
}

/* Active state when interactive mode is enabled */
[data-interactive-mode] #interactive-tools {
  background: rgba(137, 180, 250, 0.1);
  border-color: rgba(137, 180, 250, 0.3);
}

/* Disabled state styling */
#interactive-tools button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Enabled state styling */
#interactive-tools button:not(:disabled) {
  opacity: 1;
  cursor: pointer;
}

/* Hover effect for enabled buttons */
#interactive-tools button:not(:disabled):hover {
  background: rgba(180, 190, 254, 0.2);
}

/* Output actions responsive sizing */
#output-actions {
  transition: gap 0.2s ease;
}

/* Overflow Menu Styles */
#overflow-menu-container {
  position: relative;
}

#overflow-dropdown {
  animation: slideDown 0.15s ease-out;
  max-height: 300px;
  overflow-y: auto;
}

#overflow-dropdown:not(.hidden) {
  display: block;
}

#overflow-dropdown button {
  white-space: nowrap;
}

#overflow-dropdown button:first-child {
  border-radius: 0.375rem 0.375rem 0 0;
}

#overflow-dropdown button:last-child {
  border-radius: 0 0 0.375rem 0.375rem;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ========================================
   Packet Flow Simulation Styles
   ======================================== */

/* Node being visited (current) - only border effect, NO text changes */
.packet-path-visiting > polygon,
.packet-path-visiting > ellipse,
.packet-path-visiting > path:not([fill="none"]) {
  stroke: #89b4fa !important;
  stroke-width: 4 !important;
  filter: drop-shadow(0 0 12px #89b4fa);
  animation: packet-visit 0.6s ease-in-out;
}

/* Node already visited - only border effect, NO text changes */
.packet-path-visited > polygon,
.packet-path-visited > ellipse,
.packet-path-visited > path:not([fill="none"]) {
  stroke: #94e2d5 !important;
  stroke-width: 3 !important;
  filter: drop-shadow(0 0 6px #94e2d5);
}

/* Alternative path highlighting (yellow dashed) - only border, NO text changes */
.packet-path-alternative > polygon,
.packet-path-alternative > ellipse,
.packet-path-alternative > path:not([fill="none"]) {
  stroke: #f9e2af !important;
  stroke-width: 2 !important;
  stroke-dasharray: 5,5 !important;
  opacity: 0.6;
}

/* Edge being animated */
.packet-edge-animating {
  stroke: #89b4fa !important;
  stroke-width: 3 !important;
  filter: drop-shadow(0 0 6px #89b4fa);
  animation: flow 1s linear infinite;
}

.packet-edge-label-primary {
  fill: #89b4fa !important;
  font-weight: 600;
}

/* Alternative path edges */
.packet-edge-alternative {
  stroke: #f9e2af !important;
  stroke-width: 1.5 !important;
  stroke-dasharray: 5,5 !important;
  opacity: 0.3;
}

.packet-edge-label-alternative {
  fill: #f9e2af !important;
  opacity: 0.5;
}

/* Packet dot */
.packet-dot {
  transition: cx 0.6s ease-in-out, cy 0.6s ease-in-out;
  animation: packet-dot-pulse 1s ease-in-out infinite;
}

/* Visit animation for nodes */
@keyframes packet-visit {
  0% {
    stroke-width: 3;
    filter: drop-shadow(0 0 8px #89b4fa);
  }
  50% {
    stroke-width: 5;
    filter: drop-shadow(0 0 20px #89b4fa) drop-shadow(0 0 20px #89b4fa);
  }
  100% {
    stroke-width: 3;
    filter: drop-shadow(0 0 6px #94e2d5);
  }
}

/* Packet dot pulse */
@keyframes packet-dot-pulse {
  0%, 100% {
    r: 8;
    opacity: 1;
  }
  50% {
    r: 10;
    opacity: 0.8;
  }
}

/* Flow animation for edges */
@keyframes flow {
  0% {
    stroke-dasharray: 10,5;
    stroke-dashoffset: 0;
  }
  100% {
    stroke-dashoffset: 15;
  }
}

/* Verdict icons */
.verdict-icon {
  transform-origin: center;
}

.verdict-bg-accept {
  fill: #a6e3a1;
  filter: drop-shadow(0 0 8px #a6e3a1);
}

.verdict-bg-drop {
  fill: #f38ba8;
  filter: drop-shadow(0 0 8px #f38ba8);
}

.verdict-bg-unknown {
  fill: #f9e2af;
  filter: drop-shadow(0 0 8px #f9e2af);
}

.verdict-bg-return {
  fill: #89b4fa;
  filter: drop-shadow(0 0 8px #89b4fa);
}

.verdict-text {
  pointer-events: none;
}

/* Simulation panel */
#simulation-panel {
  animation: slideDown 0.3s ease-out;
}

/* Simulation result badges */
.simulation-result-accept {
  background-color: #a6e3a1;
  color: #1e1e2e;
}

.simulation-result-drop {
  background-color: #f38ba8;
  color: #1e1e2e;
}

.simulation-result-unknown {
  background-color: #f9e2af;
  color: #1e1e2e;
}

.simulation-result-return {
  background-color: #89b4fa;
  color: #1e1e2e;
}

/* Simulation form inputs */
#simulation-panel input:focus,
#simulation-panel select:focus {
  box-shadow: 0 0 0 2px rgba(137, 180, 250, 0.3);
}

/* Simulation results container */
#simulation-results {
  animation: slideDown 0.2s ease-out;
}

/* Error display */
#simulation-error {
  animation: slideDown 0.2s ease-out;
}

/* Path display styling */
#sim-path-display {
  max-height: 150px;
  overflow-y: auto;
  background-color: #181825;
  padding: 0.5rem;
  border-radius: 0.25rem;
  border: 1px solid #313244;
}

#sim-path-display::-webkit-scrollbar {
  width: 6px;
}

#sim-path-display::-webkit-scrollbar-track {
  background: #181825;
}

#sim-path-display::-webkit-scrollbar-thumb {
  background: #313244;
  border-radius: 3px;
}

#sim-path-display::-webkit-scrollbar-thumb:hover {
  background: #45475a;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  #simulation-panel .grid {
    grid-template-columns: 1fr;
  }
}