/* ═══════════════════════════════════════════════════════════
   IO Suite — Shared Theme
   Minimalist zinc/indigo design with light/dark mode
   ═══════════════════════════════════════════════════════════ */

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

/* ─── Theme Variables ─── */
:root {
  --bg-0: #f4f4f5;
  --bg-1: #ffffff;
  --bg-2: #f0f0f1;
  --bg-3: #e4e4e7;
  --text-0: #18181b;
  --text-1: #52525b;
  --text-2: #a1a1aa;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: rgba(79, 70, 229, 0.08);
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --border: #e4e4e7;
  --border-hover: #a1a1aa;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.06);
  --radius: 10px;
  --radius-sm: 6px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono: 'SF Mono', 'Fira Code', 'JetBrains Mono', ui-monospace, monospace;
  --ease: 180ms ease;
}

[data-theme="dark"] {
  --bg-0: #09090b;
  --bg-1: #18181b;
  --bg-2: #1f1f23;
  --bg-3: #27272a;
  --text-0: #fafafa;
  --text-1: #a1a1aa;
  --text-2: #52525b;
  --accent: #818cf8;
  --accent-hover: #6366f1;
  --accent-soft: rgba(129, 140, 248, 0.1);
  --border: #27272a;
  --border-hover: #3f3f46;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.4);
}

/* ─── Base ─── */
body {
  font-family: var(--font);
  background: var(--bg-0);
  color: var(--text-0);
  line-height: 1.5;
  min-height: 100vh;
  padding: 32px 20px;
  transition: background var(--ease), color var(--ease);
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ─── Layout ─── */
.container {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.container-narrow { max-width: 800px; }
.container-wide { max-width: 1400px; }

/* ─── Card ─── */
.card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: background var(--ease), border-color var(--ease);
}

.card-padded { padding: 24px; }

/* ─── Section headings ─── */
.section { display: flex; flex-direction: column; gap: 8px; }

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0 4px;
}

.eyebrow {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.section-subtitle {
  font-size: 0.8rem;
  color: var(--text-2);
}

/* ─── Typography ─── */
h1 {
  font-size: clamp(1.5rem, 3vw, 2.25rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

h2 {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

h3 {
  font-size: 1rem;
  font-weight: 600;
}

.subtitle {
  color: var(--text-1);
  font-size: 0.95rem;
  margin-top: 6px;
  max-width: 55ch;
}

.text-muted { color: var(--text-1); }
.text-dim { color: var(--text-2); }
.text-accent { color: var(--accent); }
.text-sm { font-size: 0.85rem; }
.text-xs { font-size: 0.75rem; }
.text-center { text-align: center; }

/* ─── Forms ─── */
select, textarea, input[type="text"], input[type="search"], input[type="url"], input[type="email"], input[type="number"] {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-0);
  font-size: 0.88rem;
  font-family: var(--font);
  transition: border-color var(--ease), background var(--ease);
  outline: none;
}

select:focus, textarea:focus, input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

textarea { resize: vertical; min-height: 90px; line-height: 1.5; }

label {
  display: block;
  margin-bottom: 4px;
  color: var(--text-1);
  font-size: 0.78rem;
  font-weight: 600;
}

.control-group { margin-bottom: 14px; }

.grid-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ─── Buttons ─── */
.btn {
  padding: 8px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--ease);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--font);
  background: var(--bg-1);
  color: var(--text-0);
}

.btn:hover:not(:disabled) {
  border-color: var(--border-hover);
  background: var(--bg-2);
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-primary:disabled, .btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-lg { padding: 10px 24px; font-size: 0.95rem; }

/* ─── Status indicators ─── */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-2);
  flex-shrink: 0;
  display: inline-block;
}

.status-dot.online { background: var(--green); }
.status-dot.offline { background: var(--red); }
.status-dot.warning { background: var(--yellow); }

.status-msg {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

.status-msg.success { background: rgba(34,197,94,0.1); color: var(--green); }
.status-msg.error { background: rgba(239,68,68,0.1); color: var(--red); }
.status-msg.info { background: var(--accent-soft); color: var(--accent); }

/* ─── Loading ─── */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-text {
  color: var(--text-2);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ─── IO Nav Header ─── */
.io-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px;
  margin-bottom: 8px;
}

.io-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.io-back {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-1);
  text-decoration: none;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all var(--ease);
}

.io-back:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.io-tool-name {
  font-size: 1.1rem;
  font-weight: 600;
}

/* ─── Nav Dropdown ─── */
.io-nav-wrapper {
  position: relative;
}

.io-nav-trigger {
  cursor: pointer;
  user-select: none;
}

.io-nav-trigger::after {
  content: '';
  display: inline-block;
  width: 0; height: 0;
  margin-left: 6px;
  vertical-align: middle;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 4px solid var(--text-2);
  transition: transform var(--ease);
}

.io-nav-wrapper.open .io-nav-trigger::after {
  transform: rotate(180deg);
}

.io-nav-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 200px;
  max-height: 70vh;
  overflow-y: auto;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  padding: 6px 0;
}

.io-nav-wrapper.open .io-nav-dropdown { display: block; }

.io-nav-section {
  padding: 8px 14px 4px;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.io-nav-item {
  display: block;
  padding: 6px 14px;
  font-size: 0.85rem;
  color: var(--text-0);
  text-decoration: none;
  transition: background var(--ease);
}

.io-nav-item:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.io-nav-item.active {
  color: var(--accent);
  font-weight: 600;
}

.io-nav-footer {
  display: block;
  padding: 8px 14px;
  margin-top: 4px;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-1);
  text-decoration: none;
}

.io-nav-footer:hover { color: var(--accent); }

.io-header-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

.theme-toggle {
  padding: 5px 12px;
  background: var(--bg-2);
  color: var(--text-0);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--font);
  transition: all var(--ease);
}

.theme-toggle:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ─── Footer ─── */
.io-footer {
  text-align: center;
  padding: 20px 0;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

.io-footer nav {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.io-footer a {
  display: inline-block;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-1);
  font-size: 0.75rem;
  font-weight: 500;
  transition: all var(--ease);
}

.io-footer a:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.io-footer .credit {
  font-size: 0.72rem;
  color: var(--text-2);
}

/* ─── Utilities ─── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.flex-row { display: flex; gap: 8px; align-items: center; }
.flex-col { display: flex; flex-direction: column; gap: 8px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-wrap { flex-wrap: wrap; }
.gap-sm { gap: 4px; }
.gap-md { gap: 12px; }
.gap-lg { gap: 24px; }
.p-sm { padding: 8px; }
.p-md { padding: 16px; }
.p-lg { padding: 24px; }
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mono { font-family: var(--mono); }
.w-full { width: 100%; }

/* ─── Tabs ─── */
.tab-bar {
  display: flex;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.tab-btn {
  padding: 10px 18px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-1);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--font);
  white-space: nowrap;
  transition: all var(--ease);
}

.tab-btn:hover { color: var(--text-0); background: var(--bg-2); }

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ─── Tables ─── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th {
  text-align: left;
  padding: 10px 12px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

tr:last-child td { border-bottom: none; }

tr:hover td { background: var(--accent-soft); }

/* ─── Code ─── */
code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--bg-2);
  padding: 2px 6px;
  border-radius: 4px;
}

pre {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  overflow-x: auto;
  font-size: 0.82rem;
}

pre code {
  background: none;
  padding: 0;
}

/* ─── Tool Page Layout ─── */
.tool-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}

.tool-layout-narrow {
  display: grid;
  grid-template-columns: minmax(280px, 420px) 1fr;
  gap: 24px;
  align-items: start;
}

.tool-panel {
  position: sticky;
  top: 20px;
}

/* ─── Form Groups ─── */
.form-group { margin-bottom: 14px; }
.form-group:last-child { margin-bottom: 0; }

.helper-text {
  font-size: 0.72rem;
  color: var(--text-2);
  margin-top: 3px;
  line-height: 1.4;
}

/* ─── Button Loading State ─── */
.btn.loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

.btn.loading::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 18px; height: 18px;
  margin: -9px 0 0 -9px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ─── Toast ─── */
.toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text-0);
  color: var(--bg-1);
  padding: 10px 20px;
  font-size: 0.85rem;
  border-radius: var(--radius);
  opacity: 0;
  transition: transform 0.3s, opacity 0.3s;
  z-index: 1000;
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ─── API Error Banner ─── */
.api-error {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  text-align: center;
}

.api-error p { margin-bottom: 12px; color: var(--text-1); }

/* ─── Error Message ─── */
.error-message {
  padding: 10px 14px;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-sm);
  color: var(--red);
  font-size: 0.85rem;
}

/* ─── Result Display ─── */
.result-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.result-header {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.result-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* ─── Drop Zone ─── */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: all var(--ease);
}

.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.drop-zone-text {
  color: var(--text-2);
  font-size: 0.85rem;
}

.drop-zone-text span {
  display: block;
  margin-top: 6px;
  font-size: 0.75rem;
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
  body { padding: 16px 12px; }
  .container { gap: 16px; }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .grid-controls { grid-template-columns: 1fr; }
  .tool-layout, .tool-layout-narrow { grid-template-columns: 1fr; }
  .tool-panel { position: static; }
  .io-header { flex-direction: column; gap: 8px; align-items: flex-start; }
  .tab-bar { gap: 0; }
  .tab-btn { padding: 8px 12px; font-size: 0.8rem; }
  .result-actions { flex-direction: column; }
}

@media (max-width: 480px) {
  body { padding: 12px 8px; }
  h1 { font-size: 1.4rem; }
  .card-padded { padding: 16px; }
  .btn { padding: 8px 14px; font-size: 0.82rem; }
}
