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

:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --bg-input: #0d1117;
  --border: #30363d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --success: #3fb950;
  --warning: #d29922;
  --danger: #f85149;
  --radius: 8px;
  --sidebar-width: 320px;
  --transition: 0.2s ease;
}

html {
  font-size: 15px;
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
}

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

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 100;
  transition: transform var(--transition);
}

.sidebar-header {
  padding: 20px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-header h1 .logo {
  font-size: 1.4rem;
}

.sidebar-header p {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Search */
.search-box {
  padding: 12px 16px;
}

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

.search-box input::placeholder { color: var(--text-muted); }
.search-box input:focus { border-color: var(--accent); }

/* Tool List */
.tool-list {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: none;
  padding: 4px 8px 16px;
}

.tool-list::-webkit-scrollbar { display: none; }

.tool-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-secondary);
  transition: all var(--transition);
  user-select: none;
}

.tool-item:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.tool-item.active {
  background: rgba(88, 166, 255, 0.1);
  color: var(--accent);
}

.tool-item .icon {
  font-size: 1.1rem;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}

.tool-item .label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tool-item.hidden { display: none; }

/* ===== Main Content ===== */
.main {
  flex: 1;
  min-width: 0;
  padding: 32px 40px;
  overflow-y: auto;
  height: 100vh;
  margin-left: var(--sidebar-width);
}

.tool-view { display: none; }
.tool-view.active { display: block; }

.tool-title {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.tool-desc {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 24px;
}

/* ===== Form Elements ===== */
textarea,
input[type="text"],
input[type="number"],
select {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
  font-size: 0.85rem;
  outline: none;
  transition: border-color var(--transition);
  resize: vertical;
}

textarea:focus,
input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
  border-color: var(--accent);
}

textarea { min-height: 120px; }

label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

.input-group { margin-bottom: 16px; }

.output-area {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-all;
  min-height: 60px;
  position: relative;
  line-height: 1.5;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
}

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

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

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

.btn-sm { padding: 5px 10px; font-size: 0.8rem; }

.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px 8px;
  font-size: 0.75rem;
}

/* Two-column layout */
.cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* Inline options */
.options-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 16px;
}

.options-row label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 0;
  cursor: pointer;
}

.options-row select,
.options-row input[type="number"] {
  width: auto;
  min-width: 80px;
}

input[type="checkbox"] {
  accent-color: var(--accent);
}

/* Regex matches highlight */
.match-highlight mark {
  background: rgba(88, 166, 255, 0.3);
  color: var(--accent);
  padding: 1px 2px;
  border-radius: 2px;
}

/* Diff styles */
.diff-line { padding: 1px 8px; font-family: monospace; font-size: 0.85rem; }
.diff-add { background: rgba(63, 185, 80, 0.15); color: var(--success); }
.diff-remove { background: rgba(248, 81, 73, 0.15); color: var(--danger); }
.diff-same { color: var(--text-muted); }

/* JWT sections */
.jwt-section { margin-bottom: 16px; }
.jwt-section h4 {
  font-size: 0.85rem;
  color: var(--accent);
  margin-bottom: 6px;
}

/* Markdown preview */
.md-preview {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  line-height: 1.7;
}

.md-preview h1, .md-preview h2, .md-preview h3 { margin: 16px 0 8px; color: var(--text-primary); }
.md-preview h1 { font-size: 1.6rem; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.md-preview h2 { font-size: 1.3rem; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.md-preview h3 { font-size: 1.1rem; }
.md-preview p { margin: 8px 0; }
.md-preview code { background: var(--bg-tertiary); padding: 2px 6px; border-radius: 4px; font-size: 0.9em; }
.md-preview pre { background: var(--bg-tertiary); padding: 12px; border-radius: var(--radius); overflow-x: auto; margin: 12px 0; }
.md-preview pre code { background: none; padding: 0; }
.md-preview ul, .md-preview ol { padding-left: 24px; margin: 8px 0; }
.md-preview blockquote { border-left: 3px solid var(--accent); padding-left: 12px; color: var(--text-secondary); margin: 8px 0; }
.md-preview a { color: var(--accent); }
.md-preview strong { color: var(--text-primary); }
.md-preview hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.md-preview img { max-width: 100%; }

/* Color swatch */
.color-swatch {
  width: 60px;
  height: 60px;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  display: inline-block;
  vertical-align: middle;
  margin-right: 12px;
}

/* QR code */
.qr-output { text-align: center; padding: 20px; }
.qr-output canvas, .qr-output img { border-radius: var(--radius); }

/* Welcome screen */
.welcome {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-secondary);
}

.welcome h2 {
  font-size: 2rem;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.welcome p { font-size: 1rem; max-width: 500px; margin: 0 auto; }

/* Mobile hamburger */
.hamburger {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  color: var(--text-primary);
  font-size: 1.2rem;
  cursor: pointer;
}

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 90;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .hamburger { display: block; }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
  }

  .sidebar.open { transform: translateX(0); }
  .overlay.show { display: block; }

  .main { padding: 60px 16px 32px; margin-left: 0; }

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

@media (max-width: 480px) {
  .main { padding: 56px 12px 24px; }
  .tool-title { font-size: 1.3rem; }
}

/* Toast notification */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  z-index: 9999;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s ease;
  pointer-events: none;
}

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