:root {
  --bg: #121318;
  --panel: #1b1d24;
  --panel-2: #22252f;
  --editor: #15171d;
  --border: #2f3342;
  --text: #e4e6ef;
  --muted: #9aa0b4;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --green: #16a34a;
  --green-hover: #15803d;
  --red: #dc2626;
  --amber: #d97706;
  --purple: #7c3aed;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 10px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 13px;
  overflow: hidden;
}

.cors-banner {
  background: #7f1d1d;
  color: #fecaca;
  border: 1px solid #ef4444;
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 8px;
  font-size: 12.5px;
  line-height: 1.45;
}

/* Toolbar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}

button, select, input[type="text"], input[type="number"] {
  height: 31px;
  padding: 0 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #262936;
  color: var(--text);
  font-size: 12.5px;
  outline: none;
}

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

button {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

button:hover { background: #323646; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); font-weight: 600; color: #fff; }
button.primary:hover { background: var(--accent-hover); }
button.save { background: var(--green); border-color: var(--green); font-weight: 600; color: #fff; }
button.save:hover { background: var(--green-hover); }
button.warn { background: #78350f; border-color: var(--amber); color: #fef3c7; }
button.warn:hover { background: #92400e; }
button.danger { background: #7f1d1d; border-color: var(--red); color: #fee2e2; }
button.danger:hover { background: #991b1b; }
button.purple { background: #5b21b6; border-color: var(--purple); color: #ede9fe; }
button.purple:hover { background: #6d28d9; }
button.sm { height: 26px; padding: 0 8px; font-size: 12px; }
button.lg { height: 38px; font-size: 13.5px; font-weight: 700; }
button.full { width: 100%; }

label.chk {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  font-size: 12px;
}

.status-bar {
  margin-left: auto;
  padding: 5px 10px;
  border-radius: 6px;
  font-weight: 500;
  font-size: 12px;
  background: #232631;
  border: 1px solid var(--border);
  max-width: 440px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status-bar.ok { color: #86efac; border-color: #166534; background: #052e16; }
.status-bar.err { color: #fca5a5; border-color: #991b1b; background: #450a0a; }
.status-bar.warn { color: #fde68a; border-color: #92400e; background: #451a03; }

/* Search Bar */
.search-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-top: 7px;
  padding: 6px 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.search-bar input[type="text"] { height: 26px; width: 200px; }
.match-info { color: var(--muted); font-size: 12px; min-width: 72px; }

/* Main Workspace */
.workspace {
  display: flex;
  gap: 8px;
  flex: 1;
  margin-top: 7px;
  min-height: 0;
}

/* Quick Edit Sidebar */
.sidebar {
  width: 365px;
  min-width: 320px;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.sidebar.collapsed { display: none; }

.tab-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 6px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  height: 28px;
  padding: 0 4px;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 5px;
  background: #1b1d24;
  color: var(--muted);
  border: 1px solid transparent;
}
.tab-btn:hover { color: var(--text); background: #292d3a; }
.tab-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: #60a5fa;
}
.tab-btn.span-full {
  grid-column: span 3;
  background: #231f3a;
  color: #ddd6fe;
  border-color: #4c1d95;
}
.tab-btn.span-full:hover { background: #312659; color: #fff; }
.tab-btn.span-full.active {
  background: var(--purple);
  color: #fff;
  border-color: #a78bfa;
}

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tab-panel { display: none; flex-direction: column; gap: 10px; }
.tab-panel.active { display: flex; }

.card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.card-title {
  font-size: 12px;
  font-weight: 700;
  color: #93c5fd;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.card-note {
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.4;
}

.alert-box {
  font-size: 11.5px;
  line-height: 1.45;
  padding: 7px 9px;
  border-radius: 6px;
  border: 1px solid #92400e;
  background: rgba(120, 53, 15, 0.3);
  color: #fde68a;
}
.alert-box.danger {
  border-color: #991b1b;
  background: rgba(127, 29, 29, 0.32);
  color: #fecaca;
}

.row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.row > input, .row > select { flex: 1; min-width: 0; }

.btn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.room-list, .lookup-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 195px;
  overflow-y: auto;
  padding: 6px;
  background: #171920;
  border: 1px solid var(--border);
  border-radius: 5px;
}

.room-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text);
  gap: 6px;
}
.room-item label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.room-item code { font-size: 10.5px; color: var(--muted); }

.lookup-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 4px 6px;
  border-radius: 4px;
  background: #1f222c;
  font-size: 11.5px;
  cursor: pointer;
}
.lookup-row:hover { background: #2a2e3d; }
.lookup-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.lookup-id {
  font-weight: 600;
  color: #93c5fd;
  font-family: 'Consolas', monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lookup-meta {
  font-size: 10.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tag-evo { color: #fde68a; }
.tag-skin { color: #86efac; }
.lookup-actions { display: flex; gap: 4px; flex-shrink: 0; }

.mini-textarea {
  width: 100%;
  height: 82px;
  background: #14161c;
  color: #a5d6ff;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 7px 8px;
  font-family: 'Cascadia Code', 'Consolas', monospace;
  font-size: 11.5px;
  line-height: 16px;
  resize: vertical;
  white-space: pre-wrap;
}

.mail-chk-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
  cursor: pointer;
}

/* Editor Panes */
.pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  min-width: 0;
}
.pane.right { flex: 0.55; }
.pane.right.collapsed { display: none; }

.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}
.pane-header strong { color: var(--text); }
.pane-actions { display: flex; gap: 5px; }

textarea {
  flex: 1;
  width: 100%;
  border: none;
  padding: 12px;
  background: var(--editor);
  color: #a5d6ff;
  font-family: 'Cascadia Code', 'Consolas', 'Courier New', monospace;
  font-size: 12.5px;
  line-height: 19px;
  resize: none;
  outline: none;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
}

#outputBox {
  color: #fdba74;
  background: #121318;
  white-space: pre-wrap;
  word-break: break-all;
}

.drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(59, 130, 246, 0.22);
  border: 3px dashed #60a5fa;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  z-index: 999;
  pointer-events: none;
  backdrop-filter: blur(2px);
}

.badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10.5px;
  font-weight: 600;
  background: #1e3a8a;
  color: #bfdbfe;
}
.badge.green { background: #14532d; color: #86efac; }
.badge.amber { background: #78350f; color: #fde68a; }
.badge.red { background: #7f1d1d; color: #fecaca; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
}
.modal-backdrop.open { display: flex; }
.modal {
  width: 520px;
  max-width: 94vw;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 15px;
  font-weight: 700;
  color: #93c5fd;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}
.modal-log {
  font-family: 'Consolas', monospace;
  font-size: 11.5px;
  background: #121318;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  color: #cbd5e1;
  max-height: 130px;
  overflow-y: auto;
  white-space: pre-wrap;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #16181f; }
::-webkit-scrollbar-thumb { background: #383d4f; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #4b526a; }

/* Responsive layout for Mobile & Tablet */
@media (max-width: 960px) {
  body {
    height: auto;
    min-height: 100vh;
    overflow-y: auto;
    padding: 8px;
  }
  .status-bar {
    margin-left: 0;
    width: 100%;
    max-width: none;
  }
  .search-bar input[type="text"] {
    flex: 1 1 140px;
    width: auto;
  }
  .workspace {
    flex-direction: column;
    overflow: visible;
  }
  .sidebar {
    width: 100%;
    min-width: 0;
    max-height: none;
  }
  .sidebar-body {
    max-height: 55vh;
  }
  .pane {
    min-height: 360px;
  }
  .pane.right {
    flex: 1;
    min-height: 260px;
  }
  button, select, input[type="text"], input[type="number"] {
    height: 34px;
  }
}
