:root {
  --bg: #0f1720;
  --panel: #1b2430;
  --fg: #e6edf3;
  --muted: #9aa7b2;
  --accent: #4c8bf5;
  --accent-hov: #3b78e0;
  --ok: #1f7a4a;
  --ok-fg: #4ade80;
  --warn: #7a5a1f;
  --warn-fg: #fbbf24;
  --err: #8a2b2b;
  --border: #2a3643;
  --panel-w: 440px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
}

/* ── Topbar ─────────────────────────────────────────────────────────────────── */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 24px; background: #0b1219; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.brand { font-weight: 700; letter-spacing: .5px; font-size: 1.05rem; }
.user {
  display: flex; gap: 10px; align-items: center;
  font-size: .88rem; color: var(--muted);
}

/* Generic user icon in topbar */
.user-icon-wrap {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 6px;
  border: 1px solid var(--border); color: var(--muted);
}

/* Gear button */
.btn-gear {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  border-radius: 6px; width: 32px; height: 32px; cursor: pointer; font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  transition: color .15s, border-color .15s;
}
.btn-gear:hover { color: var(--fg); border-color: var(--accent); }

/* ── Gear dropdown ──────────────────────────────────────────────────────────── */
.gear-menu-wrap { position: relative; }
.gear-dropdown {
  position: absolute; right: 0; top: calc(100% + 6px);
  background: #131c27; border: 1px solid var(--border);
  border-radius: 8px; min-width: 215px; z-index: 600;
  padding: 6px 0; box-shadow: 0 8px 28px rgba(0,0,0,.5);
}
.gear-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%; text-align: left;
  background: none; border: none; color: var(--fg);
  padding: 9px 16px; cursor: pointer;
  font: inherit; font-size: .88rem;
  transition: background .15s;
}
.gear-item:hover { background: rgba(76,139,245,.12); }
.gear-icon { font-size: 1rem; width: 18px; text-align: center; flex-shrink: 0; }
.gear-sep { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

/* ── Container ──────────────────────────────────────────────────────────────── */
.container { max-width: 1100px; margin: 24px auto; padding: 0 20px; }

/* ── Flash messages ─────────────────────────────────────────────────────────── */
.flashes { margin-bottom: 16px; }
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 8px; font-size: .9rem; }
.flash-success { background: var(--ok); color: #fff; }
.flash-error   { background: var(--err); color: #fff; }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: none; border-radius: 6px; padding: 8px 14px;
  cursor: pointer; font-weight: 600; text-decoration: none;
  font: inherit; font-size: .88rem; transition: background .15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hov); }
.btn-ghost {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) { color: var(--fg); border-color: var(--muted); }
.btn-sm { padding: 5px 10px; font-size: .82rem; }
.btn:disabled, .btn[disabled] { opacity: .45; cursor: not-allowed; }

/* ── Section cards ──────────────────────────────────────────────────────────── */
.section-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; margin-bottom: 16px; overflow: hidden;
}
.section-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  flex-wrap: wrap; gap: 10px;
}
.section-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.section-actions { display: flex; align-items: center; gap: 8px; }

/* ── Badges ─────────────────────────────────────────────────────────────────── */
.code-badge {
  background: #1e3a5f; color: #93c5fd;
  border-radius: 5px; padding: 3px 9px; font-weight: 700;
  font-size: .9rem; letter-spacing: .5px;
}
.code-badge.sm { font-size: .8rem; padding: 2px 7px; }

.int-name-badge {
  color: var(--muted); font-size: .88rem; font-weight: 400;
}

.status-badge {
  border-radius: 4px; padding: 2px 8px; font-size: .8rem; font-weight: 600;
}
.status-badge.ok   { background: rgba(31,122,74,.25); color: var(--ok-fg); }
.status-badge.warn { background: rgba(122,90,31,.25); color: var(--warn-fg); }
.status-badge.sm   { padding: 2px 6px; font-size: .75rem; }

/* ── Upload trigger label ───────────────────────────────────────────────────── */
.upload-trigger { cursor: pointer; }
.upload-trigger:hover { color: var(--fg); border-color: var(--muted); }

/* ── Tooltip on disabled button ─────────────────────────────────────────────── */
.tooltip-btn { position: relative; }
.tooltip-btn::after {
  content: attr(data-tooltip);
  position: absolute; bottom: calc(100% + 6px); left: 50%;
  transform: translateX(-50%);
  background: #0b1219; color: var(--fg); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 10px; font-size: .8rem; font-weight: 400;
  white-space: nowrap; max-width: 280px; white-space: normal;
  text-align: center; pointer-events: none; opacity: 0;
  transition: opacity .2s; z-index: 200; width: max-content;
}
.tooltip-btn:hover::after { opacity: 1; }

/* ── Files table ────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.files-table {
  width: 100%; border-collapse: collapse; font-size: .875rem;
}
.files-table th {
  padding: 8px 12px; text-align: left; font-size: .78rem;
  color: var(--muted); font-weight: 600; letter-spacing: .3px;
  border-bottom: 1px solid var(--border); background: #161f2a;
}
.files-table td {
  padding: 9px 12px; border-bottom: 1px solid rgba(42,54,67,.5);
  vertical-align: middle;
}
.files-table tr:last-child td { border-bottom: none; }
.files-table tr:hover td { background: rgba(76,139,245,.04); }

.th-actions { width: 72px; }
.fn-cell { max-width: 300px; }

/* fn-wrap: icon + filename + download arrow pegados al texto */
.fn-wrap {
  display: flex; align-items: center; gap: 5px;
  width: fit-content; max-width: 100%;
}
.fn-text {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: .84rem; flex-shrink: 1; min-width: 0;
}
.fn-text.out { color: var(--ok-fg); }
.fn-user {
  font-size: .72rem; color: var(--muted); margin-top: 2px;
  padding-left: 33px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.dt-cell { white-space: nowrap; color: var(--muted); font-size: .82rem; width: 120px; }
.act-cell { white-space: nowrap; text-align: right; width: 72px; }

/* ── File type icons (CSV / XL) ─────────────────────────────────────────────── */
.fti {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 18px; border-radius: 3px;
  font-size: .62rem; font-weight: 800; letter-spacing: .3px; flex-shrink: 0;
}
.fti-csv { background: #1a2e4a; color: #93c5fd; border: 1px solid #244166; }
.fti-xl  { background: #162b18; color: #4ade80; border: 1px solid #1f5226; }

/* ── Download arrow (inline with filename) ──────────────────────────────────── */
.btn-dl {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 4px; flex-shrink: 0;
  background: transparent; border: 1px solid var(--border);
  color: var(--muted); cursor: pointer; font-size: .8rem;
  text-decoration: none; transition: color .15s, border-color .15s;
}
.btn-dl:hover { color: var(--accent); border-color: var(--accent); }
.btn-dl.btn-dl-ok:hover { color: var(--ok-fg); border-color: var(--ok-fg); }

/* ── Icon buttons (process) ─────────────────────────────────────────────────── */
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 5px;
  background: transparent; border: 1px solid var(--border);
  color: var(--muted); cursor: pointer; font-size: .85rem;
  text-decoration: none; transition: color .15s, border-color .15s;
  margin-left: 3px;
}
.btn-icon:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); }
.btn-icon-proc:hover:not(:disabled) { color: #fbbf24; border-color: #fbbf24; }
.btn-icon-del:hover:not(:disabled)  { color: #f87171; border-color: #f87171; }
.btn-icon:disabled { opacity: .35; cursor: not-allowed; }

.empty-rows { padding: 14px 18px; margin: 0; font-size: .88rem; }

/* ── Logs card ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 16px 20px; margin-bottom: 16px;
}
.logs-card details summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
.logs-card pre {
  background: #0b1219; border: 1px solid var(--border); border-radius: 6px;
  padding: 12px; max-height: 280px; overflow: auto; font-size: .8rem;
  margin-top: 10px;
}

/* ── Empty state ────────────────────────────────────────────────────────────── */
.empty-state {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 48px 32px; text-align: center; margin-top: 32px;
}
.empty-icon { font-size: 2.5rem; margin-bottom: 12px; }
.empty-state p { color: var(--muted); margin: 6px 0; }

/* ── Toast ──────────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed; bottom: 24px; right: 24px; z-index: 1000;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  background: #1e2d3d; border: 1px solid var(--border); border-radius: 8px;
  padding: 11px 18px; font-size: .88rem; color: var(--fg);
  max-width: 340px; opacity: 0; transform: translateY(8px);
  transition: opacity .3s, transform .3s;
  pointer-events: auto;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { border-color: var(--ok-fg); color: var(--ok-fg); }
.toast-warn    { border-color: var(--warn-fg); color: var(--warn-fg); }
.toast-info    { border-color: var(--accent); }

/* ── Config side panel ──────────────────────────────────────────────────────── */
.panel-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,.45);
  opacity: 0; pointer-events: none;
  transition: opacity .25s;
}
.panel-overlay.open {
  opacity: 1; pointer-events: auto;
}
.config-panel {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: var(--panel-w); max-width: 100%;
  background: #131c27; border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform .28s cubic-bezier(.4,0,.2,1);
}
.panel-overlay.open .config-panel {
  transform: translateX(0);
}

.panel-header {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.panel-title {
  flex: 1; font-weight: 700; font-size: .98rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.btn-close {
  background: transparent; border: none; color: var(--muted);
  cursor: pointer; font-size: 1rem; padding: 4px 6px; border-radius: 4px;
  line-height: 1; transition: color .15s;
}
.btn-close:hover { color: var(--fg); }

.panel-body {
  flex: 1; overflow-y: auto; padding: 16px 18px;
}

/* ── Panel dir list ─────────────────────────────────────────────────────────── */
.panel-section { margin-bottom: 16px; }

.dir-list { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; }
.dir-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 7px;
  cursor: pointer; transition: background .15s, border-color .15s;
}
.dir-item:hover { background: rgba(76,139,245,.08); border-color: var(--accent); }
.dir-left { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dir-arrow { color: var(--muted); font-size: 1.1rem; }
.dt-small { font-size: .8rem; }

/* ── Panel file list ────────────────────────────────────────────────────────── */
.file-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.file-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 7px;
}
.file-info { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.file-name {
  flex: 1; font-size: .84rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ── Ext badges ─────────────────────────────────────────────────────────────── */
.ext-badge {
  display: inline-block; border-radius: 4px; padding: 1px 6px;
  font-size: .72rem; font-weight: 700; letter-spacing: .3px; flex-shrink: 0;
}
.ext-xlsx { background: #1a3a1f; color: #4ade80; }
.ext-json { background: #2e2a14; color: #fbbf24; }
.ext-zip  { background: #1e2d3d; color: #93c5fd; }

/* ── Upload section in panel ────────────────────────────────────────────────── */
.upload-section { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 16px; }
.upload-section-title { margin: 0 0 12px; font-size: .9rem; font-weight: 600; color: var(--muted); }
.upload-row { display: flex; gap: 10px; flex-wrap: wrap; }
.upload-label {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border: 1px solid var(--border); border-radius: 7px;
  cursor: pointer; font-size: .85rem; transition: border-color .15s, background .15s;
  flex: 1; min-width: 130px; justify-content: center;
}
.upload-label:hover { border-color: var(--accent); background: rgba(76,139,245,.07); }
.upload-label-inner { display: flex; align-items: center; gap: 7px; }
.upload-status { margin-top: 8px; font-size: .82rem; color: var(--accent); min-height: 1.2em; }
.upload-status.err { color: #f87171; }

/* ── Create dir form ────────────────────────────────────────────────────────── */
.create-form { margin-top: 12px; }
.input-row {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.input-row input[type=text] {
  padding: 6px 10px; background: #0f1720; color: var(--fg);
  border: 1px solid var(--border); border-radius: 6px; font: inherit; font-size: .88rem;
}
.input-row input[type=text]:focus { outline: none; border-color: var(--accent); }
.inline-err { font-size: .8rem; color: #f87171; margin-top: 6px; min-height: 1em; }

.hidden { display: none !important; }

/* ── Login card ─────────────────────────────────────────────────────────────── */
.login-card {
  max-width: 420px; margin: 80px auto; padding: 32px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  text-align: center;
}
.login-card h1 { margin-top: 0; }
.muted { color: var(--muted); }
