*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --border: #d0d0d0;
  --text: #222222;
  --text-muted: #666666;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --sidebar-bg: #fafafa;
  --sidebar-active: #e8e8e8;
  --radius: 4px;
}

html {
  font-size: 14px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

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

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo {
  font-weight: 700;
  font-size: 1rem;
  color: var(--accent);
}

.logo-sub {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.save-badge {
  font-size: 0.75rem;
  background: #e6f7e6;
  color: #166534;
  padding: 2px 8px;
  border-radius: var(--radius);
}

.save-detail {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
}

/* Layout */
.main {
  display: flex;
  flex: 1;
}

/* Sidebar */
.sidebar {
  width: 160px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 8px 0;
  position: sticky;
  top: 0;
  height: calc(100vh - 48px);
  overflow-y: auto;
}

.nav-link {
  display: block;
  padding: 8px 16px;
  text-decoration: none;
  color: var(--text);
  font-size: 0.9rem;
  border-left: 3px solid transparent;
  transition: background 0.1s, border-color 0.1s;
}

.nav-link:hover {
  background: var(--sidebar-active);
}

.nav-link.active {
  background: var(--sidebar-active);
  border-left-color: var(--accent);
  font-weight: 600;
}

/* Content */
.content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  max-width: 960px;
}

.content-center {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 48px);
}

/* Upload */
.upload-card {
  background: var(--surface);
  border: 2px dashed var(--border);
  padding: 48px;
  text-align: center;
  border-radius: var(--radius);
  max-width: 480px;
  margin: 0 auto;
}

.upload-card h2 {
  font-size: 1.25rem;
  margin-bottom: 8px;
}

.upload-card p {
  color: var(--text-muted);
  margin-bottom: 24px;
}

.upload-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.file-input-wrapper {
  position: relative;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}

.file-label {
  display: inline-block;
  padding: 8px 24px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.1s;
}

.file-label:hover {
  background: var(--sidebar-active);
}

/* Section */
.section {
  display: none;
}

.section-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--accent);
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: #333;
}

.card-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

/* Flash */
.flash-list {
  margin-bottom: 16px;
}

.flash {
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  color: #1e40af;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  margin-bottom: 4px;
  transition: opacity 0.5s;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  padding: 6px 16px;
  font-size: 0.85rem;
  font-family: inherit;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.1s, border-color 0.1s;
  line-height: 1.4;
}

.btn:hover {
  background: var(--sidebar-active);
  border-color: #b0b0b0;
}

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

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

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

.btn-danger:hover {
  background: var(--danger-hover);
}

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

/* Forms */
.input {
  padding: 6px 10px;
  font-size: 0.85rem;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  outline: none;
  width: auto;
  min-width: 80px;
}

.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.input-sm {
  width: 100%;
  min-width: 0;
}

select.input {
  min-width: 100px;
}

.field-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.inline-form {
  display: inline-block;
}

.form-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.input-row-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.input-row-group .input {
  width: 80px;
}

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

/* Config */
.config-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid #eee;
  gap: 12px;
}

.config-row:last-child {
  border-bottom: none;
}

.config-row .field-label {
  margin-bottom: 0;
  flex: 1;
}

.config-row .input-sm {
  max-width: 200px;
}

/* Code display */
.code-badge {
  font-size: 0.75rem;
  background: #fef3c7;
  color: #92400e;
  padding: 2px 8px;
  border-radius: var(--radius);
  cursor: help;
}

.code-display {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: var(--radius);
  padding: 12px;
}

.code-row {
  display: flex;
  gap: 8px;
  padding: 4px 0;
  font-size: 0.9rem;
}

.code-label {
  color: var(--text-muted);
  font-weight: 600;
  min-width: 120px;
}

.code-value {
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  color: var(--text);
  user-select: all;
}

/* Language selector */
.lang-form {
  display: inline-block;
}

.input-lang {
  min-width: 60px !important;
  padding: 2px 6px !important;
  font-size: 0.8rem !important;
}

/* Utilities */
.mt-1 {
  margin-top: 12px;
}

/* Responsive */
@media (max-width: 640px) {
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    display: flex;
    flex-wrap: wrap;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 4px 0;
  }

  .nav-link {
    padding: 6px 12px;
    border-left: none;
    font-size: 0.8rem;
  }

  .nav-link.active {
    border-left: none;
    border-bottom: 2px solid var(--accent);
  }

  .main {
    flex-direction: column;
  }

  .content {
    padding: 12px;
  }

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

  .topbar {
    flex-wrap: wrap;
    height: auto;
    padding: 8px 12px;
    gap: 4px;
  }

  .topbar-right {
    flex-wrap: wrap;
    gap: 6px;
  }
}
