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

:root {
  --bg:        #0f1117;
  --surface:   #1a1d24;
  --surface2:  #222635;
  --border:    #2d3141;
  --primary:   #4f8ef7;
  --primary-h: #3a7ce8;
  --text:      #e2e8f0;
  --muted:     #8892a4;
  --success:   #4ade80;
  --danger:    #f87171;
  --warning:   #fbbf24;
  --radius:    8px;
  --font:      'Segoe UI', system-ui, -apple-system, sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Navbar ─────────────────────────────────────────────────────────────────── */
.navbar {
  height: 56px;
  background: #001d3a;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 8px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar .logo {
  display: flex;
  align-items: center;
  text-decoration: none;
  margin-right: 16px;
  flex-shrink: 0;
}

.navbar-logo {
  height: 36px;
  width: auto;
  object-fit: contain;
}

.nav-links {
  display: flex;
  gap: 4px;
  flex: 1;
}

.nav-links a {
  color: rgba(255,255,255,.65);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: var(--radius);
  transition: background 0.15s, color 0.15s;
  font-size: 13px;
}

.nav-links a:hover,
.nav-links a.active {
  background: rgba(255,255,255,.1);
  color: #fff;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  flex-shrink: 0;
}

.user-info > span { color: rgba(255,255,255,.8); font-size: 13px; }

.navbar .btn-ghost {
  color: rgba(255,255,255,.65);
  border-color: rgba(255,255,255,.2);
}

.navbar .btn-ghost:hover {
  background: rgba(255,255,255,.1);
  color: #fff;
  border-color: rgba(255,255,255,.3);
}

/* ── Botones ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.btn-primary              { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover        { background: var(--primary-h); border-color: var(--primary-h); }
.btn-ghost                { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-ghost:hover          { background: var(--surface2); color: var(--text); }
.btn-danger               { background: rgba(248,113,113,.12); color: var(--danger); border-color: rgba(248,113,113,.3); }
.btn-danger:hover         { background: rgba(248,113,113,.22); }
.btn-sm                   { padding: 4px 10px; font-size: 12px; }
.btn-full                 { width: 100%; padding: 12px; font-size: 15px; }

/* ── Badges ─────────────────────────────────────────────────────────────────── */
.badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 99px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.badge-admin    { background: rgba(79,142,247,.2);  color: var(--primary); }
.badge-user     { background: rgba(74,222,128,.2);  color: var(--success); }
.badge-msal     { background: rgba(0,114,206,.2);   color: #4fa3e0; }
.badge-password { background: rgba(140,140,160,.15); color: var(--muted); }

/* ── Layout principal ────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  height: calc(100vh - 56px);
  overflow: hidden;
  position: relative;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────────── */
.sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: 16px;
  flex-shrink: 0;
  transition: width 0.25s ease, min-width 0.25s ease, padding 0.25s ease;
  display: flex;
  flex-direction: column;
}

.sidebar.collapsed {
  width: 0;
  min-width: 0;
  padding: 0;
  border-right: none;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 8px;
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
}

.btn-sidebar-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 15px;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.15s, background 0.15s;
}
.btn-sidebar-toggle:hover { color: var(--text); background: var(--surface2); }

.sidebar-expand-btn {
  display: none;
  position: absolute;
  top: 72px;
  left: 0;
  z-index: 10;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 var(--radius) var(--radius) 0;
  cursor: pointer;
  color: var(--muted);
  font-size: 15px;
  padding: 8px 6px;
  transition: color 0.15s, background 0.15s;
  align-items: center;
  justify-content: center;
}
.sidebar-expand-btn:hover { color: var(--text); background: var(--surface2); }

/* ── Árbol de archivos ───────────────────────────────────────────────────────── */
.tree { list-style: none; }
.tree li { position: relative; }

.tree-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 16px;
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  cursor: default;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.1s;
  border-radius: 0;
}

a.tree-item { cursor: pointer; }
a.tree-item:hover  { background: var(--surface2); }
a.tree-item.active { background: rgba(79,142,247,.15); color: var(--primary); }
.tree-item.muted   { color: var(--muted); }

.icon { flex-shrink: 0; font-style: normal; line-height: 1; }

.tree-children {
  padding-left: 16px;
  margin-left: 8px;
  border-left: 1px solid var(--border);
}

.tree-toggle { cursor: pointer; }
.tree-toggle::before {
  content: '▶';
  font-size: 8px;
  color: var(--muted);
  display: inline-block;
  transition: transform 0.2s;
  margin-right: 2px;
}
.tree-toggle.open::before { transform: rotate(90deg); }

/* ── Contenido principal ─────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

.file-frame {
  flex: 1;
  width: 100%;
  height: 100%;
  border: none;
  background: #fff;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 12px;
  color: var(--muted);
  text-align: center;
}

.big-icon { font-size: 52px; line-height: 1; }
.muted-text { color: var(--muted); font-size: 13px; }

/* ── Auth page (login) ───────────────────────────────────────────────────────── */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
}

.logo-text {
  font-size: 22px;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 4px;
}

.auth-logo { text-align: center; margin-bottom: 16px; }
.auth-logo-img { height: 52px; width: auto; object-fit: contain; }

.auth-subtitle {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 28px;
  text-align: center;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  color: var(--muted);
  font-size: 12px;
}
.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.btn-msal {
  background: #fff;
  color: #1a1a1a;
  border-color: var(--border);
  gap: 8px;
}
.btn-msal:hover { background: #f4f4f4; }

/* ── Formularios ─────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  margin-bottom: 6px;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
}

.form-group select option { background: var(--surface); }

/* ── Mensajes de error / info ────────────────────────────────────────────────── */
.error-msg {
  display: none;
  background: rgba(248,113,113,.1);
  border: 1px solid rgba(248,113,113,.3);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
}

.form-error {
  color: var(--danger);
  font-size: 12px;
  min-height: 18px;
  margin-bottom: 4px;
}

.error-text { color: var(--danger); }

/* ── Página de administración ────────────────────────────────────────────────── */
.page-body {
  padding: 32px;
  max-width: 960px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 20px;
  font-weight: 700;
}

/* ── Tabla ───────────────────────────────────────────────────────────────────── */
.table-wrapper {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  background: var(--surface);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}

tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: rgba(255,255,255,.025); }
td.muted { color: var(--muted); font-size: 13px; }

/* ── Modal ───────────────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 420px;
  animation: modalIn .2s ease;
}

@keyframes modalIn {
  from { transform: translateY(-12px); opacity: 0; }
  to   { transform: translateY(0);     opacity: 1; }
}

.modal h3 { font-size: 17px; font-weight: 700; margin-bottom: 24px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* ── Toast ───────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 300;
  display: none;
  animation: toastIn .25s ease;
}

.toast.show    { display: block; }
.toast.success { background: rgba(74,222,128,.15); border: 1px solid rgba(74,222,128,.3); color: var(--success); }
.toast.error   { background: rgba(248,113,113,.15); border: 1px solid rgba(248,113,113,.3); color: var(--danger); }

@keyframes toastIn {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* ── Página de error ─────────────────────────────────────────────────────────── */
.error-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  gap: 12px;
  text-align: center;
  padding: 32px;
}

.error-page h1 { font-size: 72px; font-weight: 800; color: var(--border); }
.error-page h2 { font-size: 20px; }
.error-page p  { color: var(--muted); margin-bottom: 16px; }

/* ── Utilidades ──────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

code {
  font-family: 'Consolas', 'Fira Mono', monospace;
  background: var(--surface2);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12px;
}

/* ── Scrollbar ───────────────────────────────────────────────────────────────── */
::-webkit-scrollbar              { width: 6px; height: 6px; }
::-webkit-scrollbar-track        { background: transparent; }
::-webkit-scrollbar-thumb        { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover  { background: var(--muted); }
