:root {
  --bg-app: #121212;
  --bg-sidebar: #1e1e1e;
  --bg-editor: #121212;
  --bg-card: #252526;
  --bg-input: #3c3c3c;
  --border: #333333;
  --text-main: #e0e0e0;
  --text-muted: #858585;
  --primary: #007acc;
  --primary-hover: #0062a3;
  --danger: #d94430;
  --success: #4caf50;
  --focus-ring: #007acc;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-app);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
}

/* Layout */
.app-layout {
  display: flex;
  height: 100vh;
}

/* Sidebar */
.sidebar {
  flex: 1;
  min-width: 350px;
  background: var(--bg-sidebar);
  border-right: 2px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 24px 20px;
  background: linear-gradient(135deg, var(--bg-sidebar), #2a2d2e);
  border-bottom: 3px solid var(--primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.sidebar-header h2 {
  font-size: 26px;
  margin: 0;
  font-weight: 800;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 2px;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.sidebar-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.action-btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 10px;
  border-radius: 8px;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.action-btn:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  transform: translateY(-3px);
  box-shadow: 0 4px 12px rgba(0, 122, 204, 0.4);
}

.sidebar-filter {
  padding: 8px;
}

.sidebar-theme {
  padding: 0 8px 12px 8px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-theme label {
  font-size: 13px;
  color: var(--text-muted);
}

.sidebar-theme input {
  flex: 1;
  padding: 4px 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-main);
  border-radius: 4px;
}

#filterInput {
  width: 100%;
  padding: 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-main);
}

/* Summary Panel */
.summary-panel {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, rgba(0, 122, 204, 0.08), rgba(0, 122, 204, 0.02));
}

.summary-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.summary-stats {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stat-total {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-right: 12px;
  border-right: 1px solid var(--border);
}

.stat-total .stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1;
}

.stat-total .stat-label {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.stat-difficulties {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

.stat-diff {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}

.stat-diff .stat-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.stat-easy .stat-dot {
  background: #4caf50;
}

.stat-medium .stat-dot {
  background: #ff9800;
}

.stat-hard .stat-dot {
  background: #f44336;
}

.stat-diff .stat-label {
  color: var(--text-muted);
  flex: 1;
}

.stat-diff .stat-value {
  font-weight: 600;
  color: var(--text-main);
  min-width: 18px;
  text-align: right;
}

.questions-list {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  list-style: none;
}

.question-item {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.question-item:hover {
  background: #2a2d2e;
}

.question-item.selected {
  background: #37373d;
  border-left: 3px solid var(--primary);
}

.q-header {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
}

.q-preview {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.global-warning {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background-color: var(--bg-card);
  color: var(--danger);
  border: 1px solid var(--danger);
  padding: 12px 16px;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  font-weight: 600;
  z-index: 1000;
  pointer-events: none;
}

.global-warning.hidden {
  display: none;
}

.warning-icon {
  font-size: 14px;
  margin-left: 4px;
  cursor: help;
}

.warning-icon.hidden {
  display: none;
}

/* Editor Area */
.editor-area {
  flex: 2;
  background: var(--bg-editor);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 20px;
}

.btn-new-question {
  background: var(--primary);
  color: white;
  border: none;
  padding: 10px 24px;
  border-radius: 6px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.3px;
  transition: background 0.15s, transform 0.1s;
}

.btn-new-question:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-new-question:active {
  transform: translateY(0);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: var(--text-muted);
}

.editor-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
  gap: 16px;
}

.editor-container.hidden {
  display: none;
}

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

.editor-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: bold;
}

.id-badge {
  color: var(--primary);
}

.editor-form {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group label {
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
}

input[type="text"],
textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 8px;
  border-radius: 4px;
  font-family: inherit;
}

input:focus,
textarea:focus {
  outline: 1px solid var(--focus-ring);
  border-color: var(--focus-ring);
}

/* Difficulty Selector */
.difficulty-selector {
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  width: fit-content;
}

.difficulty-selector button {
  background: var(--bg-card);
  border: none;
  color: var(--text-muted);
  padding: 6px 16px;
  cursor: pointer;
  border-right: 1px solid var(--border);
}

.difficulty-selector button:last-child {
  border-right: none;
}

.difficulty-selector button.active {
  background: var(--primary);
  color: white;
}

/* Answers */
.answers-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

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

.answers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 10px;
}

.answer-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.answer-main {
  flex: 1;
  display: flex;
  gap: 4px;
}

.answer-card input[type="text"] {
  flex: 1;
  font-size: 13px;
}

.answer-correct-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

/* Buttons */
button {
  cursor: pointer;
  font-family: inherit;
}

.primary-sm {
  background: var(--primary);
  color: white;
  border: none;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
}

.primary-sm:hover {
  background: var(--primary-hover);
}

.secondary {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 8px 16px;
  border-radius: 4px;
}

.secondary-sm {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
}

.secondary-sm:hover {
  background: var(--bg-input);
}

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-main);
  padding: 4px;
  border-radius: 4px;
  font-size: 16px;
}

.icon-btn:hover {
  background: var(--bg-input);
}

.icon-btn-sm {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 0 4px;
}

.icon-btn-sm:hover {
  color: var(--danger);
}

.danger-icon {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--danger);
  padding: 6px;
  border-radius: 4px;
  font-size: 14px;
}

.danger-icon:hover {
  background: rgba(217, 68, 48, 0.1);
}

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

::-webkit-scrollbar-track {
  background: var(--bg-sidebar);
}

::-webkit-scrollbar-thumb {
  background: #424242;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #4f4f4f;
}

.json-preview-details {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

details summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--text-muted);
  outline: none;
}

pre {
  background: var(--bg-input);
  padding: 8px;
  border-radius: 4px;
  font-size: 11px;
  overflow-x: auto;
  color: #dcdcaa;
}

/* Responsive */
@media (max-width: 1200px) {
  .editor-container {
    max-width: 100%;
  }

  .answers-grid {
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  }
}

@media (max-width: 900px) {
  body {
    height: auto;
    overflow: auto;
  }

  .app-layout {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
  }

  .sidebar {
    min-width: 0;
    border-right: none;
    border-bottom: 2px solid var(--border);
  }

  .sidebar-header {
    padding: 16px;
  }

  .sidebar-header h2 {
    font-size: 22px;
  }

  .sidebar-actions {
    gap: 8px;
  }

  .action-btn {
    padding: 8px;
    font-size: 18px;
  }

  .questions-list {
    max-height: 40vh;
  }

  .editor-area {
    padding: 16px;
  }
}

@media (max-width: 600px) {
  .sidebar-header {
    gap: 10px;
  }

  .sidebar-actions {
    justify-content: flex-start;
  }

  .summary-stats {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .stat-total {
    flex-direction: row;
    gap: 8px;
    padding-right: 0;
    border-right: none;
  }

  .editor-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .editor-actions {
    width: 100%;
    display: flex;
    gap: 8px;
  }

  .editor-actions .divider-vertical {
    display: none;
  }

  .btn-new-question {
    width: 100%;
  }

  .difficulty-selector button {
    padding: 6px 12px;
  }

  .answers-grid {
    grid-template-columns: 1fr;
  }

  .answer-card {
    flex-direction: column;
    align-items: stretch;
  }

  .answer-main {
    width: 100%;
  }

  .global-warning {
    left: 12px;
    right: 12px;
    bottom: 12px;
  }
}