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

:root {
  --bg:          #0f1117;
  --surface:     #1a1d27;
  --surface2:    #22263a;
  --border:      #2e3248;
  --accent:      #5c6ef8;
  --accent-h:    #7b8aff;
  --text:        #e2e4f0;
  --muted:       #8a8fa8;
  --success:     #3ecf8e;
  --warning:     #f0a500;
  --danger:      #f05252;
  --radius:      10px;
  --font:        'Segoe UI', system-ui, sans-serif;
  --sidebar-w:   220px;
}

body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; height: 100dvh; overflow: hidden; }

.hidden { display: none !important; }
.error  { color: var(--danger); font-size: 13px; }

/* ── Login ── */
.login-screen {
  display: flex; align-items: center; justify-content: center; height: 100dvh;
}
.login-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 2.5rem 2rem; width: 340px; display: flex; flex-direction: column; gap: 1rem; text-align: center;
}
.login-logo { font-size: 2rem; font-weight: 800; letter-spacing: -1px; color: var(--text); }
.login-logo span { color: var(--accent); }
.login-sub { color: var(--muted); font-size: 13px; }
.login-box input {
  padding: 0.65rem 0.9rem; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface2); color: var(--text); font-size: 15px; width: 100%;
}
.login-box input:focus { outline: none; border-color: var(--accent); }
.login-box button {
  background: var(--accent); color: #fff; border: none; border-radius: var(--radius);
  padding: 0.65rem; font-size: 15px; cursor: pointer; transition: background .15s;
}
.login-box button:hover { background: var(--accent-h); }

/* ── App layout ── */
#app { display: flex; height: 100dvh; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}
.sidebar-logo {
  font-size: 1.4rem; font-weight: 800; letter-spacing: -0.5px; padding: 1.4rem 1.2rem 1rem;
  color: var(--text); flex-shrink: 0;
}
.sidebar-logo span { color: var(--accent); }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 0.25rem 0.6rem; display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex; align-items: center; gap: 0.65rem; padding: 0.55rem 0.8rem;
  border-radius: 8px; color: var(--muted); text-decoration: none; font-size: 14px;
  cursor: pointer; transition: background .12s, color .12s;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--surface2); color: var(--accent); }

.sidebar-footer { padding: 1rem 0.6rem; border-top: 1px solid var(--border); flex-shrink: 0; }
.sidebar-footer button {
  width: 100%; background: transparent; border: 1px solid var(--border); border-radius: 8px;
  color: var(--muted); padding: 0.45rem; font-size: 13px; cursor: pointer; transition: all .12s;
}
.sidebar-footer button:hover { background: var(--surface2); color: var(--text); }

/* ── Main content ── */
.main-content { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
#view-container { flex: 1; overflow: auto; height: 100%; }

/* ── View shell ── */
.view { display: flex; flex-direction: column; height: 100%; }
.view-header {
  display: flex; align-items: center; justify-content: space-between; padding: 1.1rem 1.5rem;
  border-bottom: 1px solid var(--border); background: var(--surface); flex-shrink: 0;
}
.view-header h1 { font-size: 1.05rem; font-weight: 600; }
.view-header .actions { display: flex; gap: 0.5rem; }
.view-body { flex: 1; overflow-y: auto; padding: 1.5rem; }

/* ── Buttons ── */
.btn {
  border: none; border-radius: 8px; padding: 0.45rem 1rem; font-size: 13px;
  cursor: pointer; transition: background .12s; font-family: var(--font);
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); }
.btn-ghost { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--border); }
.btn-danger:hover { background: rgba(240,82,82,.1); border-color: var(--danger); }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Cards / grid ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.2rem; display: flex; flex-direction: column; gap: 0.4rem;
}
.stat-card .stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.stat-card .stat-value { font-size: 2rem; font-weight: 700; color: var(--text); }
.stat-card .stat-sub { font-size: 12px; color: var(--muted); }

/* ── Table ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th { text-align: left; padding: 0.6rem 0.8rem; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; border-bottom: 1px solid var(--border); }
tbody td { padding: 0.7rem 0.8rem; border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface2); }

/* ── Badges ── */
.badge { display: inline-block; font-size: 11px; padding: 0.2rem 0.55rem; border-radius: 5px; font-weight: 500; }
.badge-pendiente   { background: #2a2a40; color: var(--muted); }
.badge-en_progreso { background: #1e3a5f; color: #60a5fa; }
.badge-completada  { background: #0d2e1f; color: var(--success); }
.badge-cancelada   { background: #2e1a1a; color: var(--danger); }
.badge-ingreso     { background: #0d2e1f; color: var(--success); }
.badge-egreso      { background: #2e1a1a; color: var(--danger); }
.badge-entrada     { background: #0d2e1f; color: var(--success); }
.badge-salida      { background: #2e1a1a; color: var(--danger); }

/* ── Priority dots ── */
.pri { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.pri-baja    { background: var(--success); }
.pri-media   { background: var(--warning); }
.pri-alta    { background: #f97316; }
.pri-urgente { background: var(--danger); }

/* ── Chat ── */
.chat-view { display: flex; flex-direction: column; height: 100%; }
.chat-messages {
  flex: 1; overflow-y: auto; padding: 1.2rem 1.5rem;
  display: flex; flex-direction: column; gap: 0.75rem;
}
.message { max-width: 78%; padding: 0.65rem 0.9rem; border-radius: var(--radius); line-height: 1.5; white-space: pre-wrap; word-break: break-word; font-size: 14px; }
.message.user      { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 3px; }
.message.assistant { align-self: flex-start; background: var(--surface2); border: 1px solid var(--border); border-bottom-left-radius: 3px; }
.message.thinking  { align-self: flex-start; background: var(--surface2); border: 1px solid var(--border); color: var(--muted); font-style: italic; font-size: 13px; }
.chat-form {
  display: flex; gap: 0.6rem; padding: 0.9rem 1.5rem;
  border-top: 1px solid var(--border); background: var(--surface); flex-shrink: 0;
}
.chat-form textarea {
  flex: 1; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-family: var(--font); font-size: 14px; padding: 0.65rem 0.9rem; resize: none; line-height: 1.4;
}
.chat-form textarea:focus { outline: none; border-color: var(--accent); }
.chat-form button { height: 40px; align-self: flex-end; }

/* ── Notes grid ── */
.notes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.note-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; display: flex; flex-direction: column; gap: 0.5rem;
}
.note-card .note-body { font-size: 13.5px; color: var(--text); white-space: pre-wrap; word-break: break-word; flex: 1; }
.note-card .note-meta { font-size: 11px; color: var(--muted); }
.note-card .note-tags { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.tag { background: var(--surface2); border: 1px solid var(--border); border-radius: 4px; font-size: 11px; padding: 0.15rem 0.4rem; color: var(--muted); }

/* ── Empty state ── */
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty svg { width: 48px; height: 48px; opacity: .3; margin-bottom: 0.75rem; }
.empty p { font-size: 14px; }

/* ── Section title ── */
.section-title { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 0.75rem; margin-top: 1.5rem; }
.section-title:first-child { margin-top: 0; }

/* ── Upload zone ── */
.upload-zone {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 2rem; text-align: center;
  color: var(--muted); font-size: 14px; cursor: pointer; transition: border-color .15s;
  margin-bottom: 1.5rem;
}
.upload-zone:hover { border-color: var(--accent); color: var(--accent); }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
.modal-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.5rem; width: 460px; max-width: 95vw; display: flex; flex-direction: column; gap: 0.75rem;
  max-height: 90vh; overflow-y: auto;
}
.modal-box h3 { font-size: 1rem; font-weight: 600; margin-bottom: 0.25rem; }
.modal-box label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 0.25rem; }
.modal-box input, .modal-box textarea, .modal-box select {
  background: var(--surface2); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); font-family: var(--font); font-size: 14px; padding: 0.5rem 0.75rem; width: 100%;
}
.modal-box input:focus, .modal-box textarea:focus, .modal-box select:focus { outline: none; border-color: var(--accent); }
.modal-box textarea { resize: vertical; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.5rem; }

/* ── Toast ── */
#toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; display: flex; flex-direction: column; gap: 0.5rem; z-index: 300; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.7rem 1rem; font-size: 13px; min-width: 220px; animation: slideIn .2s ease;
}
.toast.success { border-color: var(--success); color: var(--success); }
.toast.error   { border-color: var(--danger); color: var(--danger); }
.toast.info    { border-color: var(--accent); color: var(--accent); }
@keyframes slideIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ── Reporting cards ── */
.report-links { display: flex; flex-direction: column; gap: 0.5rem; }
.report-link {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.9rem 1rem; font-size: 14px;
}
.report-link span { color: var(--muted); font-size: 13px; }

/* ── Responsive ── */
@media (max-width: 640px) {
  :root { --sidebar-w: 60px; }
  .nav-item span, .sidebar-logo, .sidebar-footer button { display: none; }
  .nav-item { justify-content: center; padding: 0.6rem; }
  .nav-item svg { width: 20px; height: 20px; }
}
