/* ═══════════════════════════════════════════════════════════════════════════
   NAS melli1537 — Design System
   "Centro de control espacial doméstico"
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Variables ──────────────────────────────────────────────────────────────── */
:root {
  --bg:           #07070f;
  --surface:      #0f0f1a;
  --surface2:     #171726;
  --surface3:     #1f1f32;
  --border:       rgba(255, 255, 255, 0.07);
  --accent:       #7c6dfa;
  --accent-glow:  rgba(124, 109, 250, 0.25);
  --accent2:      #00d4aa;
  --text:         #ededf5;
  --text-muted:   #6e6e8a;
  --danger:       #ff4d6d;
  --success:      #00d4aa;

  --font-head: 'Outfit', system-ui, sans-serif;
  --font-body: 'DM Sans', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Courier New', monospace;
  --radius:    16px;
}

/* ── Reset ───────────────────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  transition:
    border-color     0.2s ease,
    box-shadow       0.2s ease,
    background-color 0.2s ease,
    opacity          0.2s ease,
    transform        0.2s ease;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Background: orbs + noise ───────────────────────────────────────────────── */
.orb {
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
}
.orb-1 {
  width: 600px;
  height: 600px;
  top: -200px;
  left: -200px;
  background: rgba(124, 109, 250, 0.08);
  filter: blur(120px);
}
.orb-2 {
  width: 600px;
  height: 600px;
  bottom: -200px;
  right: -200px;
  background: rgba(0, 212, 170, 0.06);
  filter: blur(120px);
}

.noise-layer {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n' x='0' y='0'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 300px 300px;
}

/* ── View system ─────────────────────────────────────────────────────────────── */
.view {
  display: none;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}
.view.active {
  display: flex;
  flex-direction: column;
}

/* ── Logo wordmark ───────────────────────────────────────────────────────────── */
.logo-wordmark {
  font-family: var(--font-head);
  font-weight: 800;
  font-size: 22px;
  color: var(--text);
  letter-spacing: -0.5px;
  user-select: none;
  line-height: 1;
}
.logo-dot { color: var(--accent2); }
.logo-nas { color: var(--accent);  }

/* ── Typography ──────────────────────────────────────────────────────────────── */
.label-hint {
  font-weight: 400;
  color: var(--text-muted);
}
.label-spacer {
  visibility: hidden;
}

/* ── Forms ───────────────────────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 14px;
}
.form-group label {
  display: block;
  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 7px;
  letter-spacing: 0.02em;
}
.form-group input[type="text"],
.form-group input[type="password"] {
  width: 100%;
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  outline: none;
}
.form-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-group input::placeholder { color: var(--text-muted); }

/* ── Alerts ──────────────────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: 10px;
  font-family: var(--font-body);
  font-size: 14px;
  margin-bottom: 16px;
  display: none;
  line-height: 1.5;
}
.alert.show { display: block; }

.alert-error {
  background: rgba(255, 77, 109, 0.12);
  border: 1px solid rgba(255, 77, 109, 0.3);
  color: #ff8fa3;
  animation: shake 0.4s ease-out;
}
.alert-success {
  background: rgba(0, 212, 170, 0.1);
  border: 1px solid rgba(0, 212, 170, 0.3);
  color: var(--success);
}

@keyframes shake {
  0%, 100% { transform: translateX(0);  }
  25%, 75%  { transform: translateX(-8px); }
  50%       { transform: translateX( 8px); }
}

/* ── Spinner ─────────────────────────────────────────────────────────────────── */
.spinner {
  width: 17px;
  height: 17px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  display: none;
  flex-shrink: 0;
}
.spinner.show { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  border-radius: 10px;
  padding: 10px 18px;
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none !important;
  filter: none !important;
}

/* Primary */
.btn-primary {
  background: linear-gradient(135deg, #7c6dfa, #6358e8);
  color: #fff;
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.3px;
  box-shadow: 0 8px 24px rgba(124, 109, 250, 0.35);
  border: none;
}
.btn-primary:hover:not(:disabled) {
  filter: brightness(1.1);
  transform: translateY(-1px);
}
.btn-primary:active:not(:disabled) {
  transform: scale(0.98);
  filter: brightness(0.97);
}

/* Ghost */
.btn-ghost {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 13px;
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface3);
  color: var(--text);
}

/* Danger */
.btn-danger {
  background: transparent;
  border: 1px solid rgba(255, 77, 109, 0.35);
  color: var(--danger);
  font-size: 13px;
}
.btn-danger:hover:not(:disabled) {
  background: rgba(255, 77, 109, 0.1);
  border-color: rgba(255, 77, 109, 0.6);
}

/* Size modifiers */
.btn-sm   { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn-full { width: 100%; padding: 13px; font-size: 15px; }

/* Icon-only button */
.btn-icon {
  background: transparent;
  border: none;
  padding: 6px;
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}
.btn-icon:hover {
  color: var(--danger);
  background: rgba(255, 77, 109, 0.08);
}

/* Admin pill */
.btn-admin-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 14px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
}
.btn-admin-pill:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ══════════════════════════════════════════════════════════════════════════════
   LOGIN
   ══════════════════════════════════════════════════════════════════════════════ */
#view-login {
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 48px 40px;
  background: rgba(15, 15, 26, 0.85);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow:
    0 32px 80px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.04);
  animation: card-enter 0.4s ease-out both;
}

@keyframes card-enter {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0);    }
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}
.login-logo .logo-wordmark {
  display: block;
  font-size: 28px;
  margin-bottom: 7px;
}
.logo-sub {
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--text-muted);
}

/* ══════════════════════════════════════════════════════════════════════════════
   HEADER (shared, fixed)
   ══════════════════════════════════════════════════════════════════════════════ */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: 64px;
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(7, 7, 15, 0.80);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; }

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

/* Hidden data-source span (app.js writes here, MutationObserver reads it) */
#dash-username {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

.header-username {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-muted);
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #a855f7);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
  user-select: none;
}

/* ══════════════════════════════════════════════════════════════════════════════
   DASHBOARD
   ══════════════════════════════════════════════════════════════════════════════ */
.dashboard-body {
  flex: 1;
  padding: 96px 32px 56px;
  max-width: 1040px;
  margin: 0 auto;
  width: 100%;
}

.dashboard-welcome { margin-bottom: 40px; }

.greeting {
  font-family: var(--font-head);
  font-weight: 800;
  font-size: 32px;
  color: var(--text);
  line-height: 1.2;
  margin-bottom: 6px;
}
.greeting-name { color: var(--accent); }

.greeting-sub {
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--text-muted);
}

/* ── App Grid ────────────────────────────────────────────────────────────────── */
.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

/* ── App Card ────────────────────────────────────────────────────────────────── */
.app-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px 52px;
  cursor: pointer;
  overflow: hidden;
  /* explicit transition so hover is snappy */
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

/* Radial glow overlay — fades in on hover */
.app-card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  opacity: 0;
  background: radial-gradient(circle at 50% 0%,
    rgba(124, 109, 250, 0.13), transparent 70%);
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.app-card:hover {
  transform: translateY(-4px);
  border-color: rgba(124, 109, 250, 0.4);
  box-shadow:
    0 20px 40px rgba(0, 0, 0, 0.3),
    0 0 0 1px rgba(124, 109, 250, 0.2);
}
.app-card:hover::before { opacity: 1; }
.app-card:active { transform: scale(0.97); }

/* ── Full-card invisible link (generated by app.js) ── */
/* Covers the entire card so clicking anywhere opens the app */
.app-card > a.btn {
  position: absolute !important;
  inset: 0 !important;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  color: transparent !important;
  font-size: 0 !important;
  letter-spacing: 0 !important;
  border-radius: var(--radius) !important;
  padding: 0 !important;
  margin: 0 !important;
  z-index: 5;
}

/* Card content stays above the transparent link */
.app-icon,
.app-name {
  position: relative;
  z-index: 1;
  pointer-events: none;
}

.app-icon {
  width: 72px;
  height: 72px;
  background: rgba(124, 109, 250, 0.1);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  line-height: 1;
  margin-bottom: 20px;
}

.app-name {
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 17px;
  color: var(--text);
}

/* Online badge (bottom-right) */
.app-card::after {
  content: '●\00a0Online';
  position: absolute;
  bottom: 16px;
  right: 16px;
  font-family: var(--font-body);
  font-size: 11px;
  color: var(--success);
  z-index: 1;
  pointer-events: none;
  animation: pulse-badge 2.5s ease-in-out infinite;
}
@keyframes pulse-badge {
  0%, 100% { opacity: 1;    }
  50%       { opacity: 0.4; }
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-muted);
}
.empty-state .empty-icon {
  font-size: 3rem;
  display: block;
  margin-bottom: 16px;
}
.empty-state p { font-size: 15px; line-height: 1.7; }

/* ══════════════════════════════════════════════════════════════════════════════
   ADMIN PANEL
   ══════════════════════════════════════════════════════════════════════════════ */
.admin-body {
  flex: 1;
  padding: 96px 32px 56px;
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
}

.admin-page-header { margin-bottom: 28px; }

.admin-title {
  font-family: var(--font-head);
  font-weight: 800;
  font-size: 28px;
  color: var(--text);
}

/* ── Section card ─────────────────────────────────────────────────────────── */
.admin-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 20px;
  overflow: hidden;
}

.admin-section-header {
  background: var(--surface2);
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.admin-section-header h2 {
  font-family: var(--font-head);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.badge-pill {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface3);
  border: 1px solid var(--border);
  padding: 3px 10px;
  border-radius: 99px;
}

/* ── Table ────────────────────────────────────────────────────────────────── */
.table-scroll { overflow-x: auto; }

.users-table {
  width: 100%;
  border-collapse: collapse;
}
.users-table thead tr {
  background: var(--surface2);
}
.users-table th {
  padding: 10px 20px;
  text-align: left;
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.users-table td {
  padding: 14px 20px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.users-table tbody tr:last-child td { border-bottom: none; }
.users-table tbody tr:nth-child(even) td {
  background: rgba(23, 23, 38, 0.4);
}
.users-table tbody tr:hover td {
  background: rgba(124, 109, 250, 0.05);
}

.username {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text);
}

.role-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 99px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.role-admin {
  background: rgba(124, 109, 250, 0.15);
  color: #a5b4fc;
  border: 1px solid rgba(124, 109, 250, 0.3);
}
.role-user {
  background: rgba(110, 110, 138, 0.12);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* ── App checkboxes ────────────────────────────────────────────────────────── */
.app-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.app-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  user-select: none;
}
.app-check:has(input:checked) { color: var(--text); }

.app-check input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  background: var(--surface3);
  border: 1.5px solid rgba(255, 255, 255, 0.12);
  border-radius: 5px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.app-check input[type="checkbox"]:hover {
  border-color: var(--accent);
}
.app-check input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' d='M2 6l3 3 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 11px;
}

/* ── Row actions ───────────────────────────────────────────────────────────── */
.row-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* ── Add user form ──────────────────────────────────────────────────────────── */
.add-user-form {
  padding: 20px 24px;
  display: grid;
  gap: 14px;
}
@media (min-width: 640px) {
  .add-user-form {
    grid-template-columns: 1fr 1fr 1fr auto;
    align-items: end;
  }
}
.add-user-form .form-group { margin-bottom: 0; }
.form-submit-cell { display: flex; flex-direction: column; }

/* ══════════════════════════════════════════════════════════════════════════════
   MODALS
   ══════════════════════════════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal-overlay.open {
  display: flex;
  animation: overlay-in 0.2s ease-out both;
}
@keyframes overlay-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal {
  background: rgba(15, 15, 26, 0.96);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px;
  width: 100%;
  max-width: 400px;
  box-shadow:
    0 32px 80px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.04);
  animation: modal-in 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
@keyframes modal-in {
  from { opacity: 0; transform: scale(0.92); }
  to   { opacity: 1; transform: scale(1);    }
}

.modal-header {
  margin-bottom: 20px;
}
.modal-header h3 {
  font-family: var(--font-head);
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.modal-header p {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
}
.modal-header strong {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text);
}
.modal-header-danger h3 { color: var(--danger); }

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

/* ══════════════════════════════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════════════════════════════ */
@media (max-width: 639px) {
  .app-header {
    padding: 0 16px;
  }
  .logo-wordmark {
    font-size: 18px;
  }
  .header-username {
    display: none; /* avatar is enough on mobile */
  }
  .dashboard-body,
  .admin-body {
    padding: 80px 16px 48px;
  }
  .app-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  }
  .greeting {
    font-size: 24px;
  }
  .login-card {
    padding: 36px 24px;
  }
  .users-table td:nth-child(3) {
    min-width: 220px; /* app checkboxes need space */
  }
  .modal {
    padding: 24px 20px;
  }
}

@media (min-width: 640px) and (max-width: 1023px) {
  .app-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  }
}
