/* =====================
   GLOBAL STYLES
===================== */
body {
  margin: 0;
  padding: 20px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial;
  display: flex;
  align-items: flex-start;
  background: transparent;
  color: #0f172a;
  transition: background 0.25s ease, color 0.25s ease;
}

.main-content {
  flex: 1;
  margin-left: 300px;
  width: calc(100% - 320px);
  transition: margin-left 0.25s ease, width 0.25s ease;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 280px;
  height: 100vh;
  overflow-y: auto;
  padding: 16px;
  background: linear-gradient(180deg, #eff6ff, #dbeafe);
  border-right: 1px solid rgba(0, 122, 204, 0.3);
  box-shadow: 6px 0 18px rgba(0, 0, 0, 0.08);
  z-index: 30;
  transition: transform 0.25s ease, background 0.25s ease;
}

.sidebar-title {
  margin: 0;
  font-size: 1.2rem;
  color: #1d4ed8;
}

.sidebar-section {
  margin-top: 16px;
  padding: 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(0, 122, 204, 0.2);
}

.sidebar-section h3 {
  margin: 0 0 10px;
}

.sidebar-actions {
  display: grid;
  gap: 8px;
}

.history-list {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  display: grid;
  gap: 8px;
}

.history-item {
  padding: 10px;
  border-radius: 10px;
  border: 1px solid rgba(0, 122, 204, 0.25);
  background: #f8fbff;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.history-item:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(37, 99, 235, 0.15);
}

.history-item.active {
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.history-item-head {
  display: flex;
  gap: 6px;
  align-items: center;
}

.history-item-head input {
  flex: 1;
  min-width: 0;
}

.history-item-controls {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.history-item-controls button {
  flex: 1;
  padding: 6px 8px;
}

.history-empty {
  margin-top: 8px;
  color: #64748b;
}

.help-guide {
  margin-top: 18px;
  width: 100%;
  max-width: 980px;
}

.help-accordion {
  border-radius: 14px;
  border: 1px solid rgba(0, 122, 204, 0.25);
  background: linear-gradient(145deg, #f8fbff, #eef6ff);
  overflow: hidden;
}

.help-accordion summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 16px;
  font-weight: 700;
  color: #1e3a8a;
}

.help-accordion summary::-webkit-details-marker {
  display: none;
}

.help-content {
  padding: 0 16px 14px;
}

.help-content h2,
.help-content h3 {
  margin: 14px 0 8px;
}

.help-content p,
.help-content li {
  line-height: 1.55;
}

.help-content ul,
.help-content ol {
  margin: 8px 0 0 20px;
}

.theme-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-toggle {
  display: none;
  position: fixed;
  left: 12px;
  top: 12px;
  z-index: 60;
}

label {
  font-size: 0.95rem;
  font-weight: 600;
  color: #0f172a;
}

fieldset {
  border: 1px solid rgba(0, 122, 204, 0.3);
  border-radius: 12px;
  padding: 12px 16px;
  background: linear-gradient(145deg, #f5f5f5, #e6f0ff);
  margin-bottom: 12px;
}

legend {
  font-size: 0.95rem;
  font-weight: 700;
  color: #2563eb;
}

/* =====================
   CONTROLS / INPUTS / BUTTONS
===================== */
#controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 16px;
  background: linear-gradient(135deg, #dbeafe, #f0f8ff);
  padding: 20px;
  border-radius: 12px;
  border: 1px solid rgba(0, 122, 204, 0.3);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.05);
}

input, select, button {
  padding: 8px 12px;
  border-radius: 12px;
  font-weight: 600;
  border: 1px solid rgba(0, 122, 204, 0.3);
  transition: all 0.25s ease;
}

input, select {
  background: #f5f5f5;
  color: #007acc;
}

input::placeholder, select::placeholder {
  color: #64748b;
}

input:focus, select:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 8px rgba(37, 99, 235, 0.3);
  background: #f5f5f5;
}

button {
  cursor: pointer;
  background: linear-gradient(135deg, #2563eb, #60a5fa);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 6px 12px rgba(37, 99, 235, 0.2);
}

button:hover {
  background: linear-gradient(135deg, #3b82f6, #60a5fa);
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.35), 0 0 24px rgba(96, 165, 250, 0.2);
  transform: translateY(-2px);
}

button:disabled {
  opacity: 0.6;
  cursor: default;
  background: #a5b4fc;
  box-shadow: none;
}

/* =====================
   CANVAS
===================== */
canvas {
  display: block;
  margin: 20px auto;
  border-radius: 16px;
  background: #f5f5f5;
  box-shadow: 0 12px 24px rgba(0, 122, 204, 0.25), 0 0 32px rgba(37, 99, 235, 0.15);
}

canvas:hover {
  box-shadow: 0 16px 32px rgba(0, 122, 204, 0.35), 0 0 40px rgba(37, 99, 235, 0.2);
}

/* =====================
   STATUS / TEXT
===================== */
#status {
  margin-top: 12px;
  font-size: 1rem;
  font-weight: 600;
  color: #2563eb;
  text-align: center;
  min-height: 22px;
}


/* =====================
   DARK MODE – GLOBAL VARIABLES
===================== */
body.dark {
  --bg: #0f172a;
  --box: #020617;
  --text: #e5e7eb;
  --accent: #a5b4fc;
  --muted: #94a3b8;
  --border: #334155;
  --shadow: rgba(0,0,0,0.6);
  --gradient-btn: linear-gradient(135deg,#6366f1,#22c55e);
  background: var(--bg);
  color: var(--text);
}

/* =====================
   BODY & LAYOUT
===================== */
body.dark {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial;
  margin: 0;
  padding: 20px;
  display: flex;
  align-items: flex-start;
}

body.dark .sidebar {
  background: linear-gradient(180deg, #0b1220, #111827);
  border-right-color: #334155;
  box-shadow: 6px 0 20px rgba(0, 0, 0, 0.4);
}

body.dark .sidebar-title {
  color: #c7d2fe;
}

body.dark .sidebar-section {
  background: rgba(2, 6, 23, 0.75);
  border-color: #334155;
}

body.dark .history-item {
  background: #0b1220;
  border-color: #334155;
}

body.dark .history-empty {
  color: #94a3b8;
}

body.dark .help-accordion {
  border-color: #334155;
  background: linear-gradient(145deg, #0b1220, #111827);
}

body.dark .help-accordion summary {
  color: #c7d2fe;
}

/* =====================
   HEADINGS & TEXT
===================== */
body.dark h1, body.dark h2, body.dark h3,
body.dark strong, body.dark .tool-title {
  color: #f9fafb;
}

body.dark .subtitle,
body.dark .small,
body.dark .field-info,
body.dark .tooltip,
body.dark .level,
body.dark .timeline-legend,
body.dark #vizNote {
  color: var(--muted);
}

body.dark label {
  color: #cbd5f5;
  font-size: 0.95rem;
  font-weight: 600;
}

/* =====================
   CARDS / PANELS / CONTAINERS
===================== */
body.dark .tool-container,
body.dark .panel,
body.dark .container,
body.dark .results,
body.dark .result-box,
body.dark .export-area,
body.dark .preview-box,
body.dark .preview-container,
body.dark .preview,
body.dark .card,
body.dark .buttons-box,
body.dark .tools-box,
body.dark .controls,
body.dark .palette,
body.dark .image-area,
body.dark fieldset,
body.dark table {
  background: var(--box);
  color: var(--text);
  border: 1px solid #1e293b;
  border-radius: 12px;
}

/* =====================
   INPUTS / TEXTAREA / SELECT
===================== */
body.dark input,
body.dark select,
body.dark textarea,
body.dark .tool-container input,
body.dark .tool-container select,
body.dark .tool-container textarea,
body.dark .tools-box input,
body.dark .tools-box select,
body.dark .tools-box textarea,
body.dark .controls input,
body.dark .controls select,
body.dark .controls textarea {
  background: #020617;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 12px;
  font-weight: 600;
  transition: all 0.25s ease;
}

body.dark input::placeholder,
body.dark textarea::placeholder,
body.dark .tool-container input::placeholder,
body.dark .tool-container textarea::placeholder,
body.dark .tools-box input::placeholder,
body.dark .controls input::placeholder {
  color: #64748b;
}

body.dark input:focus,
body.dark select:focus,
body.dark textarea:focus,
body.dark .controls input:focus,
body.dark .controls select:focus {
  outline: none;
  border-color: #60a5fa;
  box-shadow: 0 0 10px rgba(96,165,250,0.4);
  background: #020617;
}

/* Range sliders */
body.dark input[type="range"] {
  accent-color: #6366f1;
}

/* =====================
   BUTTONS
===================== */
body.dark button,
body.dark .btn,
body.dark .tool-container button,
body.dark .tools-box .btn,
body.dark .controls .btn {
  background: var(--gradient-btn);
  color: #ffffff;
  font-weight: 700;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(0,0,0,0.35);
  transition: all 0.25s ease;
}

body.dark button.secondary,
body.dark .btn.secondary,
body.dark .tool-container button.secondary {
  background: #020617;
  border: 1px solid var(--border);
  color: var(--text);
}

body.dark button:hover,
body.dark .btn:hover,
body.dark .tool-container button:hover,
body.dark .controls .btn:hover {
  filter: brightness(1.1);
  transform: translateY(-2px);
}

body.dark button:disabled,
body.dark .btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  background: #1e293b;
  box-shadow: none;
}

/* =====================
   TABLES
===================== */
body.dark table {
  background: #1e1e1e;
  border-collapse: collapse;
  border: 1px solid #333;
}

body.dark th, body.dark td {
  border: 1px solid #333;
  padding: 8px;
  color: #e0e0e0;
}

body.dark th {
  background-color: #2a2a2a;
  color: #ffffff;
}

body.dark tr:nth-child(even) { background-color: #242424; }
body.dark tr:nth-child(odd) { background-color: #1e1e1e; }

/* =====================
   CANVAS / GRAPH / PREVIEW
===================== */
body.dark canvas,
body.dark .graph-wrap {
  background: #020617;
  border-radius: 10px;
}

body.dark .preview {
  background: #0f172a;
  border: 1px dashed var(--border);
}

body.dark pre,
body.dark #cssCode {
  background: #020617;
  color: var(--text);
  border: 1px solid #1e293b;
}

/* =====================
   SCROLLBARS (Webkit)
===================== */
body.dark textarea::-webkit-scrollbar-track { background: #020617; }
body.dark textarea::-webkit-scrollbar-thumb { background: #475569; }
body.dark textarea::-webkit-scrollbar-thumb:hover { background: #64748b; }

/* =====================
   DRAGGABLE COLORS / PATTERNS / IMAGE
===================== */
body.dark .draggable-color,
body.dark .draggable-pattern {
  border: 1px solid var(--border);
  color: var(--text);
}

body.dark .image-area {
  background: #0f172a;
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.02);
}

body.dark .image-area img {
  background: transparent;
}

body.dark .image-area::after {
  color: #94a3b8;
}

/* =====================
   FIELDSET / LEGEND
===================== */
body.dark fieldset {
  border: 1px solid rgba(59,130,246,0.35);
  border-radius: 12px;
  padding: 12px 16px;
  background: linear-gradient(145deg, #0f172a, #1e293b);
  margin-bottom: 12px;
}

body.dark legend {
  font-size: 0.95rem;
  color: #93c5fd;
  font-weight: 700;
}

/* =====================
   CONTROLS PANEL
===================== */
body.dark #controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 16px;
  background: linear-gradient(135deg, #0f172a, #1e293b);
  padding: 20px;
  border-radius: 12px;
  border: 1px solid rgba(59,130,246,0.35);
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.6);
}

body.dark #controls input,
body.dark #controls select {
  padding: 8px 12px;
  border-radius: 12px;
  font-weight: 600;
  background: #020617;
  color: #93c5fd;
  border: 1px solid rgba(59,130,246,0.35);
  transition: all 0.25s ease;
}

body.dark #controls input:focus,
body.dark #controls select:focus {
  outline: none;
  border-color: #60a5fa;
  box-shadow: 0 0 10px rgba(96,165,250,0.4);
}

/* Button inside controls */
body.dark #controls button {
  padding: 10px 16px;
  border-radius: 12px;
  cursor: pointer;
  background: linear-gradient(135deg, #2563eb, #3b82f6);
  color: #ffffff;
  font-weight: 700;
  border: none;
  box-shadow: 0 6px 14px rgba(37,99,235,0.35);
}

body.dark #controls button:hover {
  background: linear-gradient(135deg, #3b82f6, #60a5fa);
  box-shadow:
    0 6px 18px rgba(59,130,246,0.55),
    0 0 26px rgba(96,165,250,0.35);
  transform: translateY(-2px);
}

body.dark #controls button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  background: #1e293b;
  box-shadow: none;
}

@media (max-width: 960px) {
  .main-content {
    margin-left: 0;
    width: 100%;
  }

  .sidebar {
    transform: translateX(-102%);
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-toggle {
    display: inline-block;
  }
}
