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

:root {
  --purple:      #6c5ef6;
  --purple-dark: #5648d4;
  --purple-soft: #ede9fe;
  --bg:          #f0eeff;
  --card:        #ffffff;
  --rail-bg:     #ffffff;
  --sidebar-bg:  #ffffff;
  --text:        #1e1b3a;
  --muted:       #9491b0;
  --border:      #ece9f8;
  --soon:        #c4c2d6;
  --success:     #22c55e;
  --error-bg:    #fee2e2;
  --error-text:  #991b1b;
  --warn-bg:     #fef3c7;
  --warn-text:   #92400e;
  --ok-bg:       #dcfce7;
  --ok-text:     #166534;
  --radius:      14px;
  --radius-sm:   8px;
  --shadow:      0 1px 8px rgba(108,94,246,0.07);
  --shadow-md:   0 4px 20px rgba(108,94,246,0.10);
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow: hidden;
}

/* ─────────────────────────────────────────
   APP SHELL
───────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ─────────────────────────────────────────
   LOGO BOX
───────────────────────────────────────── */
.logo-box {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--purple), #a78bfa);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

/* ─────────────────────────────────────────
   TOOL SIDEBAR
───────────────────────────────────────── */
.tool-sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 20px 14px;
  gap: 16px;
}

.sidebar-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 4px;
}
.sidebar-brand {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}
.sidebar-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.sidebar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}
.sidebar-search svg { width: 14px; height: 14px; color: var(--muted); flex-shrink: 0; }
.sidebar-search input {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  width: 100%;
}
.sidebar-search input:focus { outline: none; }
.sidebar-search input::placeholder { color: var(--muted); }

.tool-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
  flex: 1;
  overflow-y: auto;
}
.tool-list::-webkit-scrollbar { width: 4px; }
.tool-list::-webkit-scrollbar-track { background: transparent; }
.tool-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.tool-group { display: flex; flex-direction: column; gap: 3px; }
.group-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
  padding: 0 8px;
  margin-bottom: 4px;
}

.tool-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background 0.15s;
  color: var(--text);
}
.tool-item:hover:not(:disabled) { background: var(--bg); }
.tool-item.active { background: var(--purple-soft); }
.tool-item.soon { opacity: 0.55; cursor: not-allowed; }

.tool-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.tool-item.active .tool-icon { background: var(--purple); }
.tool-icon svg { width: 14px; height: 14px; color: var(--muted); }
.tool-item.active .tool-icon svg { color: #fff; }

.tool-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tool-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tool-item.active .tool-name { color: var(--purple); font-weight: 600; }

.tool-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  width: fit-content;
}
.active-badge { background: var(--purple); color: #fff; }
.soon-badge { background: var(--border); color: var(--muted); }

/* Help Card */
.help-card {
  border-radius: var(--radius);
  background: linear-gradient(135deg, #6c5ef6 0%, #a78bfa 100%);
  padding: 16px;
  color: #fff;
  margin-top: auto;
}
.help-title { font-size: 14px; font-weight: 700; margin-bottom: 3px; }
.help-sub { font-size: 11px; opacity: 0.75; margin-bottom: 12px; }
.help-btn {
  width: 100%;
  padding: 8px;
  background: #fff;
  color: var(--purple);
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s;
}
.help-btn:hover { opacity: 0.9; }

/* ─────────────────────────────────────────
   MAIN CONTENT
───────────────────────────────────────── */
.main-content {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
}

/* Top bar */
.content-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-title { font-size: 17px; font-weight: 700; color: var(--text); }
.topbar-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  background: var(--purple-soft);
  color: var(--purple);
}
.topbar-right { display: flex; align-items: center; gap: 10px; }

.sort-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
}
.sort-wrap svg { width: 14px; height: 14px; color: var(--muted); }
.sort-wrap select {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
}
.sort-wrap select:focus { outline: none; }

.icon-btn {
  width: 36px;
  height: 36px;
  border: 1.5px solid var(--border);
  background: var(--card);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--muted);
  transition: border-color 0.15s, color 0.15s;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { border-color: var(--purple); color: var(--purple); }

/* Settings panel */
.settings-panel {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  flex-shrink: 0;
}
.settings-grid {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}
.setting-item { display: flex; flex-direction: column; gap: 5px; }
.setting-item label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
}
.setting-item input[type="number"] {
  padding: 7px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  width: 140px;
}
.setting-item input:focus { outline: none; border-color: var(--purple); }
.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px !important;
  font-weight: 500 !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
  color: var(--text) !important;
  margin-top: 14px;
}
.toggle-row input[type="checkbox"] { accent-color: var(--purple); width: 15px; height: 15px; }

/* Scroll area */
.content-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.content-scroll::-webkit-scrollbar { width: 5px; }
.content-scroll::-webkit-scrollbar-track { background: transparent; }
.content-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ─────────────────────────────────────────
   CARDS
───────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 10px;
}
.card-title { font-size: 14px; font-weight: 700; color: var(--text); }
.card-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.card-actions { display: flex; align-items: center; gap: 10px; margin-top: 12px; }

/* Textarea */
textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'Inter', monospace;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  resize: vertical;
  transition: border-color 0.2s;
  line-height: 1.7;
}
textarea:focus { outline: none; border-color: var(--purple); }

/* ─────────────────────────────────────────
   BUTTONS
───────────────────────────────────────── */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 20px;
  background: var(--purple);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn-primary svg { width: 15px; height: 15px; }
.btn-primary:hover { background: var(--purple-dark); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { background: #b8b2f5; cursor: not-allowed; }
.btn-primary.btn-sm { padding: 7px 14px; font-size: 12px; }

.btn-ghost {
  padding: 9px 18px;
  background: transparent;
  color: var(--muted);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.btn-ghost:hover { border-color: var(--purple); color: var(--purple); }

/* Chip */
.chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  background: var(--purple-soft);
  color: var(--purple);
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
}

/* ─────────────────────────────────────────
   PROGRESS
───────────────────────────────────────── */
.progress-track {
  background: var(--border);
  border-radius: 999px;
  height: 6px;
  overflow: hidden;
  margin: 10px 0 8px;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--purple), #a78bfa);
  border-radius: 999px;
  width: 0%;
  transition: width 0.4s ease;
}
.progress-text { font-size: 12px; color: var(--muted); }

/* ─────────────────────────────────────────
   TABLES
───────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead { background: var(--bg); }
th {
  padding: 10px 14px;
  text-align: left;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--muted);
  white-space: nowrap;
  border-bottom: 1.5px solid var(--border);
}
td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: top;
  max-width: 260px;
  word-break: break-word;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafafe; }

.badge-ok   { background: var(--ok-bg);   color: var(--ok-text);   padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.badge-err  { background: var(--error-bg); color: var(--error-text); padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.badge-warn { background: var(--warn-bg);  color: var(--warn-text);  padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; }

/* Debug */
#debugOutput {
  background: #1e1e2e;
  color: #cdd6f4;
  padding: 14px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  line-height: 1.7;
  overflow-x: auto;
  white-space: pre-wrap;
  max-height: 360px;
  overflow-y: auto;
  margin-top: 12px;
}
