:root {
  --bg: #0b0d12;
  --bg-alt: #12151c;
  --panel: #151922;
  --panel-alt: #1b202b;
  --border: #262c39;
  --text: #e6e9f0;
  --text-dim: #8b93a7;
  --accent: #7c9eff;
  --accent-dim: #4a5f99;
  --accent-strong: #5b7fff;
  --danger: #ff6b6b;
  --success: #52d68f;
  --warn: #ffb454;
  --radius: 10px;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
}

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

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.5rem;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: 0.2px;
}

.brand-mark { color: var(--accent); }

/* Layout */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  overflow: hidden;
}

.panel {
  background: var(--bg);
  padding: 1.25rem 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.panel-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.panel-head.small h3 {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.hint {
  font-size: 0.78rem;
  color: var(--text-dim);
  line-height: 1.4;
}

/* Inputs */
textarea, input[type="text"], input[type="password"] {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 0.65rem 0.8rem;
  font-family: var(--mono);
  font-size: 0.85rem;
  resize: vertical;
  outline: none;
  transition: border-color 0.15s;
}

textarea:focus, input:focus {
  border-color: var(--accent-dim);
}

#urlInput {
  min-height: 160px;
}

#notesOutput {
  flex: 1;
  min-height: 400px;
  font-family: var(--mono);
  line-height: 1.5;
}

.output-panel { height: 100%; }

.row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.switch {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--text-dim);
}

.switch input { accent-color: var(--accent); width: 16px; height: 16px; }

/* Buttons */
.btn {
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  padding: 0.55rem 1rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}

.btn:hover { background: #232a38; border-color: #333d50; }
.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #0b0d12;
}
.btn-primary:hover { background: #6f8dff; }

.btn-secondary {
  background: var(--panel-alt);
  border-color: var(--accent-dim);
  color: var(--accent);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-dim);
}

.btn-tiny {
  padding: 0.25rem 0.55rem;
  font-size: 0.72rem;
  background: transparent;
  border-color: var(--border);
  color: var(--text-dim);
}

.btn-lg {
  padding: 0.8rem 1rem;
  font-size: 0.95rem;
}

.output-actions { display: flex; gap: 0.5rem; }

/* URL preview */
.url-preview {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 0.9rem;
  max-height: 180px;
  overflow-y: auto;
}

#urlPreviewList {
  margin: 0.5rem 0 0;
  padding: 0;
  list-style: none;
  font-family: var(--mono);
  font-size: 0.78rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

#urlPreviewList li {
  color: var(--text-dim);
  word-break: break-all;
  padding-bottom: 0.35rem;
  border-bottom: 1px dashed var(--border);
}

#urlPreviewList li .badge {
  display: inline-block;
  font-size: 0.65rem;
  padding: 0.1rem 0.4rem;
  border-radius: 20px;
  background: var(--accent-dim);
  color: #fff;
  margin-right: 0.4rem;
}

/* Log */
.log-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
  min-height: 0;
}

.log {
  flex: 1;
  min-height: 140px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 0.9rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  overflow-y: auto;
  color: var(--text-dim);
  white-space: pre-wrap;
}

.log .line { margin-bottom: 0.3rem; }
.log .ok { color: var(--success); }
.log .err { color: var(--danger); }
.log .warn { color: var(--warn); }
.log .info { color: var(--accent); }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 9, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: min(640px, 92vw);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-head h2 { margin: 0; font-size: 1.05rem; }

.modal-body {
  padding: 1.1rem 1.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.modal-foot {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

.settings-section h3 {
  margin: 0 0 0.35rem;
  font-size: 0.95rem;
}

.key-list, .model-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.key-row, .model-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.key-row input, .model-row input {
  flex: 1;
  font-size: 0.8rem;
}

.model-row .drag-handle {
  cursor: grab;
  color: var(--text-dim);
  font-size: 0.9rem;
  user-select: none;
}

.model-row.dragging { opacity: 0.4; }

.remove-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--danger);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  cursor: pointer;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.remove-btn:hover { background: rgba(255,107,107,0.1); }

.key-status {
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
  border-radius: 20px;
  flex-shrink: 0;
}

.key-status.unused { background: var(--panel); color: var(--text-dim); }
.key-status.ok { background: rgba(82,214,143,0.15); color: var(--success); }
.key-status.exhausted { background: rgba(255,107,107,0.15); color: var(--danger); }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-auto-rows: min-content; overflow-y: auto; }
  .panel { overflow-y: visible; }
  .output-panel { height: auto; }
  #notesOutput { min-height: 300px; }
}
