:root {
  --bg:        #0e1116;
  --surface:   #161b22;
  --surface-2: #1c2230;
  --border:    #2a3140;
  --text:      #e6edf3;
  --text-dim:  #8b96a5;
  --accent:    #4f8cff;
  --accent-dim:#2d5bb5;
  --ok:        #3fb950;
  --warn:      #d29922;
  --err:       #f85149;
  --radius:    10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg:        #f6f8fa;
    --surface:   #ffffff;
    --surface-2: #f0f3f6;
    --border:    #d8dee4;
    --text:      #1f2328;
    --text-dim:  #656d76;
    --accent:    #0969da;
    --accent-dim:#0a5cc4;
    --ok:        #1a7f37;
    --warn:      #9a6700;
    --err:       #cf222e;
  }
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted  { color: var(--text-dim); }
.small  { font-size: 12px; }
.mono   { font-family: var(--mono); font-size: 12px; }
.error  { color: var(--err); }
.right  { text-align: right; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-card h1 { font-size: 20px; }

/* ---------- Estructura ---------- */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  gap: 20px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 600; padding: 0 8px;
}
.brand-mark {
  width: 26px; height: 26px; display: grid; place-items: center;
  background: var(--accent); color: #fff; border-radius: 7px; font-size: 15px;
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  background: none; border: none; color: var(--text-dim);
  text-align: left; padding: 9px 10px; border-radius: 7px;
  cursor: pointer; font-size: 13.5px; font-family: inherit;
}
.nav-item:hover  { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent); color: #fff; font-weight: 500; }
.sidebar-foot {
  display: flex; flex-direction: column; gap: 8px;
  padding: 12px 8px 0; border-top: 1px solid var(--border);
}

.content { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky; top: 0; z-index: 10;
}
.topbar h2 { font-size: 17px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.view { padding: 24px; display: flex; flex-direction: column; gap: 20px; }

/* ---------- Componentes ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.card-head h3 { font-size: 14px; font-weight: 600; }
.card-body { padding: 16px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.stat-label { color: var(--text-dim); font-size: 12px; margin-bottom: 5px; }
.stat-value { font-size: 24px; font-weight: 600; letter-spacing: -0.5px; }
.stat-value.ok   { color: var(--ok); }
.stat-value.err  { color: var(--err); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; padding: 9px 16px; color: var(--text-dim);
  font-weight: 500; font-size: 11.5px; text-transform: uppercase;
  letter-spacing: 0.4px; border-bottom: 1px solid var(--border);
  background: var(--surface-2); white-space: nowrap;
}
td { padding: 10px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }

.btn {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 7px;
  padding: 7px 13px; cursor: pointer; font-size: 13px;
  font-family: inherit; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-dim); }
.btn.danger  { color: var(--err); }
.btn.danger:hover:not(:disabled) { background: var(--err); color: #fff; border-color: var(--err); }
.btn.ghost   { background: none; border-color: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn.small   { padding: 4px 9px; font-size: 12px; }
.btn.icon    { padding: 4px 8px; }
.btn.full    { width: 100%; justify-content: center; }
.btn-row     { display: flex; gap: 6px; flex-wrap: wrap; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: 11.5px; font-weight: 500;
  background: var(--surface-2); border: 1px solid var(--border);
}
.badge.ok      { color: var(--ok);   border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.badge.err     { color: var(--err);  border-color: color-mix(in srgb, var(--err) 40%, transparent); }
.badge.warn    { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.badge.running { color: var(--accent); border-color: var(--accent); }

label {
  display: flex; flex-direction: column; gap: 5px;
  font-size: 13px; color: var(--text-dim);
}
input, select, textarea {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 7px;
  padding: 8px 10px; font-size: 13.5px; font-family: inherit; width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
}
textarea { resize: vertical; min-height: 110px; font-family: var(--mono); font-size: 12px; }
.form { display: flex; flex-direction: column; gap: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.checkbox { flex-direction: row; align-items: center; gap: 8px; cursor: pointer; }
.checkbox input { width: auto; }
.hint { font-size: 12px; color: var(--text-dim); margin-top: -2px; }
.form-actions {
  display: flex; gap: 8px; justify-content: flex-end;
  padding-top: 6px; border-top: 1px solid var(--border); margin-top: 4px;
}
fieldset {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; display: flex; flex-direction: column; gap: 12px;
}
legend { padding: 0 6px; font-size: 12px; color: var(--text-dim); }

.empty { padding: 40px 20px; text-align: center; color: var(--text-dim); }
.empty p { margin-bottom: 12px; }

/* ---------- Gráfico de volumen ---------- */
.chart { display: flex; align-items: flex-end; gap: 4px; height: 110px; padding-top: 8px; }
.chart-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; min-width: 0; }
.chart-bar { background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; }
.chart-bar.err { background: var(--err); }
.chart-label { font-size: 9.5px; color: var(--text-dim); text-align: center; overflow: hidden; white-space: nowrap; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); }
.modal-card {
  position: relative; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  width: 100%; max-width: 580px; max-height: 88vh;
  display: flex; flex-direction: column;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 15px; }
.modal-body { padding: 18px; overflow-y: auto; }

/* ---------- Avisos ---------- */
.toasts {
  position: fixed; bottom: 18px; right: 18px; z-index: 200;
  display: flex; flex-direction: column; gap: 8px; max-width: 400px;
}
.toast {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 7px; padding: 11px 15px; font-size: 13px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}
.toast.ok  { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--err); }

.inline-note {
  background: var(--surface-2); border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 7px; padding: 11px 14px; font-size: 12.5px; color: var(--text-dim);
}
.inline-note.ok  { border-left-color: var(--ok); }
.inline-note.err { border-left-color: var(--err); color: var(--err); }

.spin { display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Móvil ---------- */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .sidebar nav { flex-direction: row; overflow-x: auto; }
  .nav-item { white-space: nowrap; }
  .view, .topbar { padding-left: 16px; padding-right: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: stretch; }
}

/* ---------- Bloque plegable de opciones avanzadas ---------- */
.advanced {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.advanced > summary {
  padding: 11px 14px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-dim);
  user-select: none;
  list-style: none;
}
.advanced > summary::-webkit-details-marker { display: none; }
.advanced > summary::before {
  content: '▸';
  display: inline-block;
  margin-right: 8px;
  transition: transform 0.15s;
}
.advanced[open] > summary::before { transform: rotate(90deg); }
.advanced > summary:hover { color: var(--text); }
.advanced[open] > summary { border-bottom: 1px solid var(--border); }
.advanced-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---------- Selector de columnas ordenable ---------- */
.col-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0 0 12px;
  padding: 0;
}
.col-item {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  cursor: grab;
  font-size: 13px;
}
.col-item:active { cursor: grabbing; }
.col-item.dragging { opacity: 0.4; }
.col-item.drag-over {
  border-color: var(--accent);
  box-shadow: inset 0 2px 0 var(--accent);
}
.col-grip {
  color: var(--text-dim);
  font-size: 15px;
  line-height: 1;
  cursor: grab;
}
.col-pos {
  color: var(--text-dim);
  font-size: 11px;
  min-width: 16px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.col-name { color: var(--text); }
.col-name .badge { font-size: 10px; padding: 1px 6px; margin-left: 5px; }
.col-actions { display: flex; gap: 1px; }
.col-actions .btn { padding: 2px 7px; font-size: 12px; line-height: 1.3; }

.col-add { display: flex; gap: 8px; align-items: center; }
.col-add .col-select { flex: 1; }

@media (max-width: 820px) {
  .col-add { flex-direction: column; align-items: stretch; }
}
