/* ===== CSS Variables & Theme ===== */
:root {
  --bg: #f5f5f7;
  --sidebar-bg: #1e1e2e;
  --sidebar-text: #cdd6f4;
  --sidebar-active: #89b4fa;
  --panel-bg: #ffffff;
  --text: #1e1e2e;
  --text-secondary: #6c6c80;
  --border: #e0e0e6;
  --input-bg: #f9f9fb;
  --input-focus: #89b4fa;
  --btn-primary: #1e1e2e;
  --btn-primary-text: #ffffff;
  --btn-secondary: #e0e0e6;
  --btn-secondary-text: #1e1e2e;
  --btn-copy: #a6e3a1;
  --result-bg: #f9f9fb;
  --error: #f38ba8;
  --success: #a6e3a1;
  --highlight: #f9e2af;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

[data-theme="dark"] {
  --bg: #181825;
  --sidebar-bg: #11111b;
  --sidebar-text: #a6adc8;
  --sidebar-active: #89b4fa;
  --panel-bg: #1e1e2e;
  --text: #cdd6f4;
  --text-secondary: #a6adc8;
  --border: #313244;
  --input-bg: #313244;
  --input-focus: #89b4fa;
  --btn-primary: #89b4fa;
  --btn-primary-text: #1e1e2e;
  --btn-secondary: #45475a;
  --btn-secondary-text: #cdd6f4;
  --btn-copy: #a6e3a1;
  --result-bg: #11111b;
  --error: #f38ba8;
  --success: #a6e3a1;
  --highlight: #f9e2af;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  transition: background 0.3s, color 0.3s;
}

/* ===== Sidebar ===== */
.sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 24px 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform 0.3s;
}

.sidebar-header {
  padding: 0 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  margin-bottom: 12px;
}

.sidebar-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.5px;
}

.sidebar-header span {
  font-size: 0.75rem;
  color: var(--sidebar-text);
  opacity: 0.7;
}

.sidebar nav { flex: 1; overflow-y: auto; padding: 0 8px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--sidebar-text);
  transition: all 0.15s;
  user-select: none;
  margin-bottom: 2px;
}

.nav-item:hover { background: rgba(255,255,255,0.08); }

.nav-item.active {
  background: rgba(137,180,250,0.15);
  color: var(--sidebar-active);
  font-weight: 600;
}

.nav-item .icon { font-size: 1.1rem; width: 24px; text-align: center; }

.sidebar-footer {
  padding: 16px 20px 0;
  border-top: 1px solid rgba(255,255,255,0.1);
  margin-top: 12px;
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.08);
  border: none;
  color: var(--sidebar-text);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  width: 100%;
  transition: background 0.15s;
}

.theme-toggle:hover { background: rgba(255,255,255,0.15); }

.icp-number {
  display: block;
  text-align: center;
  margin-top: 10px;
  font-size: 0.7rem;
  color: var(--sidebar-text);
  opacity: 0.5;
  text-decoration: none;
  transition: opacity 0.15s;
}

.icp-number:hover { opacity: 0.8; }

/* ===== Main Content ===== */
.main {
  margin-left: 240px;
  flex: 1;
  padding: 32px 40px;
  max-width: calc(100% - 240px);
  transition: margin 0.3s;
}

.tool-panel { display: none; animation: fadeIn 0.2s; }

.tool-panel.active { display: block; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.tool-header {
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.tool-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.tool-header p {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* ===== Form Elements ===== */
.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-secondary);
}

textarea, input[type="text"], input[type="number"], select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
  background: var(--input-bg);
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
  resize: vertical;
}

textarea:focus, input:focus, select:focus {
  outline: none;
  border-color: var(--input-focus);
  box-shadow: 0 0 0 3px rgba(137,180,250,0.2);
}

textarea { min-height: 200px; }

select {
  font-family: inherit;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236c6c80' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  white-space: nowrap;
}

.btn-primary {
  background: var(--btn-primary);
  color: var(--btn-primary-text);
}
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }

.btn-secondary {
  background: var(--btn-secondary);
  color: var(--btn-secondary-text);
}
.btn-secondary:hover { opacity: 0.8; }

.btn-copy {
  background: var(--success);
  color: #1e1e2e;
  font-size: 0.8rem;
  padding: 6px 12px;
}
.btn-copy:hover { opacity: 0.85; }

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }

/* ===== Result Area ===== */
.result-area {
  background: var(--result-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  font-family: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
  font-size: 0.85rem;
  line-height: 1.6;
  min-height: 80px;
  max-height: 400px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  position: relative;
}

.result-area:empty::after {
  content: "输出结果将显示在这里...";
  color: var(--text-secondary);
  opacity: 0.5;
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.result-header span {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* ===== Error & Success ===== */
.error-msg {
  color: var(--error);
  font-size: 0.85rem;
  margin-top: 8px;
  display: none;
}

.error-msg.show { display: block; }

.success-msg {
  color: var(--success);
  font-size: 0.8rem;
}

/* ===== Regex Highlight ===== */
.regex-highlight { background: var(--highlight); border-radius: 2px; padding: 0 1px; }

.match-count {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 8px;
}

.match-list {
  margin-top: 8px;
  max-height: 200px;
  overflow-y: auto;
}

.match-item {
  font-size: 0.8rem;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  font-family: "SF Mono", monospace;
}

.match-item span { color: var(--text-secondary); margin-right: 8px; }

/* ===== UUID List ===== */
.uuid-list {
  font-family: "SF Mono", monospace;
  font-size: 0.85rem;
  line-height: 2;
}

/* ===== Two-column layout ===== */
.col-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.col-2 .form-group { display: flex; flex-direction: column; }

.col-2 textarea { flex: 1; }

/* ===== Inline select & input groups ===== */
.inline-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

.inline-group input { flex: 1; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--btn-primary);
  color: var(--btn-primary-text);
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  z-index: 1000;
  animation: slideUp 0.3s;
  box-shadow: var(--shadow);
}

@keyframes slideUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* ===== Mobile Toggle ===== */
.mobile-nav-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  background: var(--sidebar-bg);
  color: #fff;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: var(--shadow);
}

/* ===== Overlay ===== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open { transform: translateX(0); }

  .sidebar-overlay.show { display: block; }

  .mobile-nav-toggle { display: flex; align-items: center; justify-content: center; }

  .main {
    margin-left: 0;
    padding: 20px 16px;
    max-width: 100%;
    padding-top: 60px;
  }

  .col-2 { grid-template-columns: 1fr; }

  .btn-row { flex-direction: column; }

  .btn { justify-content: center; }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }

::-webkit-scrollbar-track { background: transparent; }

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }
