:root {
  --bg-base: #0d0d0d;
  --bg-elevated: #181818;
  --bg-elevated-2: #222;
  --border: #333;
  --text: #e8e8e8;
  --text-muted: #888;
  --accent: #4caf50;
  --accent-hover: #5cbf60;
  --danger: #c62828;
  --danger-hover: #d32f2f;
  --warn: #f9a825;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { background: var(--bg-base); }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg-base);
  font-size: 14px;
  line-height: 1.5;
}

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

/* ========== LAYOUT ========== */
.admin-layout { display: flex; min-height: 100vh; }

/* ========== NAV ========== */
.admin-nav {
  width: 200px;
  min-width: 200px;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  padding: 1rem 0;
}
.admin-nav-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 1rem 1rem;
}
.admin-nav h1 { font-size: 1rem; margin: 0; color: var(--text); }
.nav-toggle { display: none; background: none; border: none; color: var(--text); font-size: 1.3rem; cursor: pointer; padding: 0; }
.admin-nav-links { display: flex; flex-direction: column; }
.admin-nav-links a {
  display: block;
  padding: 0.5rem 1rem;
  color: var(--text);
  text-decoration: none;
}
.admin-nav-links a:hover { background: var(--bg-elevated-2); }
.admin-nav-links a.active { color: var(--accent); border-left: 2px solid var(--accent); }

/* ========== CONTENT ========== */
.admin-content { flex: 1; padding: 1.5rem; max-width: 1100px; min-width: 0; }
.admin-content h2 { margin-top: 0; }

/* ========== CARD ========== */
.admin-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  margin-bottom: 1rem;
  overflow-x: auto;
}

/* ========== TABLE ========== */
.admin-table { width: 100%; border-collapse: collapse; min-width: 500px; }
.admin-table th, .admin-table td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.admin-table th { color: var(--text-muted); font-weight: 500; font-size: 0.85em; text-transform: uppercase; letter-spacing: 0.05em; }
.admin-table td { white-space: normal; word-break: break-word; }
.admin-table .token-mono { font-family: var(--mono); font-size: 0.85em; word-break: break-all; max-width: 250px; }

/* ========== FORM ========== */
.admin-form { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: end; }
.admin-form label { display: block; font-size: 0.85em; color: var(--text-muted); margin-bottom: 0.25rem; }
.admin-form input, .admin-form select {
  background: var(--bg-base);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  font-size: 14px;
}
.admin-form button {
  background: var(--accent);
  color: #000;
  border: none;
  padding: 0.4rem 0.8rem;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
}
.admin-form button:hover { background: var(--accent-hover); }
.admin-form button.danger { background: var(--danger); color: #fff; }
.admin-form button.danger:hover { background: var(--danger-hover); }

/* ========== COPY BUTTON ========== */
.btn-copy {
  background: none;
  border: 1px solid var(--border);
  color: var(--accent);
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.8em;
  font-family: inherit;
  margin-left: 0.4rem;
  transition: 0.15s;
}
.btn-copy:hover { background: var(--accent); color: #000; border-color: var(--accent); }
.btn-copy.copiado { background: var(--accent); color: #000; border-color: var(--accent); }

/* ========== LOGIN ========== */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2rem;
  width: 320px;
  max-width: 90vw;
}
.login-card h1 { margin: 0 0 1rem; font-size: 1.1rem; }
.login-error { color: var(--danger); margin-bottom: 1rem; font-size: 0.9em; }
.login-card input {
  width: 100%;
  background: var(--bg-base);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.7rem;
  border-radius: 4px;
  margin-bottom: 0.75rem;
}
.login-card button {
  width: 100%;
  background: var(--accent);
  color: #000;
  border: none;
  padding: 0.6rem;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
}

/* ========== BADGE ========== */
.badge { display: inline-block; padding: 0.1rem 0.4rem; border-radius: 3px; font-size: 0.75em; font-weight: 600; }
.badge-whitelist { background: rgba(76, 175, 80, 0.2); color: var(--accent); }
.badge-blacklist { background: rgba(198, 40, 40, 0.2); color: var(--danger); }

/* ========== FILE TREE ========== */
.file-tree { font-family: var(--mono); font-size: 0.85em; }
.file-tree ul { list-style: none; padding-left: 1.2rem; margin: 0.25rem 0; }
.file-tree details > summary { cursor: pointer; user-select: none; }
.file-tree details > summary::marker { color: var(--text-muted); }
.file-tree .tree-folder { color: var(--accent); font-weight: 500; }
.file-tree .tree-file { padding: 0.1rem 0; display: flex; gap: 0.75rem; align-items: center; }
.file-tree .tree-file:hover { background: var(--bg-elevated-2); border-radius: 3px; }
.file-tree .tree-file-mtime { color: var(--text-muted); font-size: 0.8em; min-width: 5rem; }
.file-tree .tree-file-name { color: var(--text); }

/* ========== RESPONSIVE (MOBILE) ========== */
@media (max-width: 768px) {
  .admin-layout { flex-direction: column; }
  .admin-nav { width: 100%; min-width: unset; padding: 0.5rem 0; }
  .nav-toggle { display: block; }
  .admin-nav-links { display: none; }
  .admin-nav-links.open { display: flex; }
  .admin-content { padding: 1rem; }
  .admin-table { min-width: 0; font-size: 0.85em; display: block; overflow-x: auto; }
  .admin-table td.token-mono { max-width: 120px; }
  .admin-form { flex-direction: column; align-items: stretch; }
  .admin-form div { width: 100%; }
  .admin-form input, .admin-form select { width: 100%; }
  .file-tree { font-size: 0.8em; }
  .file-tree ul { padding-left: 0.8rem; }
}
@media (max-width: 480px) {
  .admin-content { padding: 0.75rem; }
  .admin-card { padding: 0.75rem; }
  .admin-table { font-size: 0.8em; }
  .btn-copy { font-size: 0.75em; padding: 0.1rem 0.35rem; }
}
/* ========== UTIL ========== */
.text-muted { color: var(--text-muted); }
.text-accent { color: var(--accent); }

/* Keyboard accessibility */
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ========== FLASH ========== */
.flash {
  padding: 0.6rem 0.9rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
}
.flash-ok { border-color: var(--accent); color: var(--accent); }
.flash-err { border-color: var(--danger); color: var(--danger-hover); }

/* ========== DASHBOARD STATS ========== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}
.stat-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.stat-label { color: var(--text-muted); font-size: 0.8em; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 2rem; font-weight: 600; line-height: 1.1; }
.stat-link { font-size: 0.85em; color: var(--text-muted); }
a.stat-link:hover { color: var(--accent); }
.stat-warn { color: var(--warn); }

/* ========== LOGS: STATUS / METHOD ========== */
.status { font-family: var(--mono); font-weight: 600; }
.status-ok { color: var(--accent); }
.status-warn { color: var(--warn); }
.status-err { color: var(--danger-hover); }
.status-muted { color: var(--text-muted); }
.badge-method { background: var(--bg-elevated-2); color: var(--text-muted); font-family: var(--mono); }
.autorefresh { display: inline-flex; align-items: center; gap: 0.4rem; color: var(--text-muted); font-size: 0.9em; white-space: nowrap; }

/* ========== FILES ========== */
.files-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 0.75rem; flex-wrap: wrap; }
.files-head input[type="search"] { flex: 1; min-width: 180px; }
.file-tree .tree-file-size { color: var(--text-muted); font-size: 0.8em; min-width: 4rem; }
.btn-del {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  padding: 0 0.3rem; font-size: 0.9em; line-height: 1; opacity: 0; transition: 0.15s;
}
.file-tree .tree-file:hover .btn-del { opacity: 1; }
.btn-del:hover { color: var(--danger-hover); }

/* Search inputs match form inputs */
input[type="search"] {
  background: var(--bg-base);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  font-size: 14px;
}

/* ========== TOKEN REVEAL ========== */
[data-token] .token-value { letter-spacing: 0.05em; }

/* ========== PASSWORD FIELD + EYE ========== */
/* .pw-field .pw-eye is intentionally specific to beat .login-card button etc. */
.pw-field { position: relative; margin-bottom: 0.75rem; }
.pw-field input {
  width: 100%;
  padding-right: 2.6rem !important;
  margin-bottom: 0 !important;
  box-sizing: border-box;
}
.pw-field .pw-eye {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: 2.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin: 0;
  font-size: 1rem;
  line-height: 1;
  color: var(--text-muted);
  background: none !important;
  border: none !important;
  box-shadow: none;
  cursor: pointer;
}
.pw-field .pw-eye:hover { color: var(--text); background: none !important; }

/* ========== ACCOUNT FORM ========== */
.account-form { display: flex; flex-direction: column; }
.account-form label { font-size: 0.85em; color: var(--text-muted); margin: 0.5rem 0 0.25rem; }
.account-form input {
  background: var(--bg-base); border: 1px solid var(--border); color: var(--text);
  padding: 0.5rem 0.7rem; border-radius: 4px; width: 100%; font-size: 14px;
}
.account-form > button[type="submit"] {
  margin-top: 1.2rem; background: var(--accent); color: #000; border: none;
  padding: 0.55rem; border-radius: 4px; cursor: pointer; font-weight: 600;
}
.account-form > button[type="submit"]:hover { background: var(--accent-hover); }

/* ========== FILE VIEWER ========== */
.viewer-head { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.viewer-head .back-link { color: var(--text-muted); }
.viewer-head .back-link:hover { color: var(--accent); }
.viewer-name { font-weight: 600; word-break: break-all; }
.viewer-dl {
  margin-left: auto;
  font-size: 1.2rem;
  line-height: 1;
  color: var(--text-muted);
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
  text-decoration: none;
}
.viewer-dl:hover { color: var(--accent); background: var(--bg-elevated-2); text-decoration: none; }
.viewer-img { max-width: 100%; height: auto; display: block; border-radius: 4px; }
.viewer-pdf { width: 100%; height: 80vh; border: none; border-radius: 4px; }
.viewer-text { white-space: pre-wrap; word-break: break-word; font-family: var(--mono); font-size: 0.85em; margin: 0; }

/* Files: selection checkbox + compare button */
.file-select { margin-right: 0.2rem; cursor: pointer; flex: none; }
a.tree-file-name { color: var(--text); }
a.tree-file-name:hover { color: var(--accent); text-decoration: underline; }
#compareBtn {
  background: var(--accent); color: #000; border: none; padding: 0.4rem 0.8rem;
  border-radius: 4px; cursor: pointer; font-weight: 600;
}
#compareBtn:disabled { background: var(--bg-elevated-2); color: var(--text-muted); cursor: default; }

/* ========== MARKDOWN RENDER ========== */
.md-render { line-height: 1.65; }
.md-render h1, .md-render h2, .md-render h3 { border-bottom: 1px solid var(--border); padding-bottom: 0.2em; margin-top: 1.2em; }
.md-render h1 { font-size: 1.6em; } .md-render h2 { font-size: 1.35em; } .md-render h3 { font-size: 1.15em; }
.md-render a { color: var(--accent); }
.md-render code { background: var(--bg-elevated-2); padding: 0.1em 0.35em; border-radius: 3px; font-family: var(--mono); font-size: 0.9em; }
.md-render pre { background: var(--bg-base); border: 1px solid var(--border); border-radius: 6px; padding: 0.8rem; overflow-x: auto; }
.md-render pre code { background: none; padding: 0; }
.md-render blockquote { border-left: 3px solid var(--border); margin: 0.8em 0; padding: 0.2em 0 0.2em 1em; color: var(--text-muted); }
.md-render table { border-collapse: collapse; margin: 0.8em 0; }
.md-render th, .md-render td { border: 1px solid var(--border); padding: 0.4em 0.7em; }
.md-render img { max-width: 100%; height: auto; }
.md-render ul, .md-render ol { padding-left: 1.4em; }
.md-render hr { border: none; border-top: 1px solid var(--border); }

/* ========== DIFF / MERGE ========== */
.diff-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.diff-cols { display: flex; gap: 0.5rem; }
.diff-side { padding: 0.2rem 0.5rem; border-radius: 4px; font-weight: 600; font-size: 0.85em; }
.diff-actions { display: flex; align-items: center; gap: 0.6rem; }
.diff-actions select { background: var(--bg-base); border: 1px solid var(--border); color: var(--text); padding: 0.35rem 0.5rem; border-radius: 4px; }
.diff-actions button { background: var(--accent); color: #000; border: none; padding: 0.4rem 0.8rem; border-radius: 4px; cursor: pointer; font-weight: 600; }

.diff { width: 100%; border-collapse: collapse; table-layout: fixed; font-family: var(--mono); font-size: 0.82em; }
.diff td.d-cell {
  width: 50%; padding: 0.05rem 0.6rem; vertical-align: top;
  white-space: pre-wrap; word-break: break-word; border-left: 1px solid var(--border);
}
.diff tr.d-eq td { color: var(--text-muted); }
.diff td.d-del { background: rgba(198, 40, 40, 0.14); }
.diff td.d-ins { background: rgba(76, 175, 80, 0.14); }
.diff tr.d-choicerow td { background: var(--bg-elevated-2); padding: 0.4rem 0.6rem; }
.d-choice { display: flex; gap: 1rem; flex-wrap: wrap; align-items: center; font-family: -apple-system, "Segoe UI", Roboto, sans-serif; }
.d-choice label { display: inline-flex; align-items: center; gap: 0.3rem; cursor: pointer; }
span.diff-side.d-del { background: rgba(198, 40, 40, 0.2); color: #e88; }
span.diff-side.d-ins { background: rgba(76, 175, 80, 0.2); color: var(--accent); }
