:root {
  --void: #0C0C0E;
  --slate: #1C1C20;
  --bone: #F0EDE8;
  --bone-dim: #C8C4BC;
  --violet: #5B5BD6;
  --amber: #E8A838;
  --muted: #6B6B78;
  --green: #22c55e;
  --green-dim: #16a34a;
  --blue: #3b82f6;
  --red: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
  --transition: 200ms ease;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--void);
  color: var(--bone);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--violet); text-decoration: none; }
a:hover { opacity: 0.85; }

input, select, textarea, button {
  font-family: inherit;
  font-size: inherit;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--muted); border-radius: 3px; }

/* ===== LOGIN ===== */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px;
}

.login-card {
  background: var(--slate);
  padding: 40px 32px;
  border-radius: var(--radius);
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  font-size: 1.5rem;
  text-align: center;
  margin-bottom: 4px;
}

.login-card p {
  color: var(--muted);
  text-align: center;
  font-size: 0.875rem;
  margin-bottom: 24px;
}

.login-card .logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 24px;
}

.login-card .logo span {
  font-size: 1.25rem;
  font-weight: 700;
}

.logo-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--violet);
}

/* ===== APP SHELL ===== */
#app { display: none; height: 100dvh; overflow: hidden; }

.app-layout {
  display: flex;
  height: 100%;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: 220px;
  min-width: 220px;
  background: var(--slate);
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255,255,255,0.05);
  overflow-y: auto;
}

.sidebar-header {
  padding: 20px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.sidebar-header h2 { font-size: 1rem; font-weight: 600; }

.sidebar-nav {
  flex: 1;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--bone-dim);
  cursor: pointer;
  transition: all var(--transition);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-size: 0.875rem;
}

.nav-item:hover { background: rgba(255,255,255,0.05); color: var(--bone); }
.nav-item.active {
  background: rgba(91,91,214,0.15);
  color: var(--violet);
}

.nav-item .icon { width: 20px; text-align: center; font-size: 1.1rem; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.05);
}

/* ===== BOTTOM NAV (mobile) ===== */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--slate);
  border-top: 1px solid rgba(255,255,255,0.08);
  z-index: 100;
  padding: 4px 0;
  padding-bottom: max(4px, env(safe-area-inset-bottom));
}

.bottom-nav-inner {
  display: flex;
  justify-content: space-around;
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 8px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.65rem;
  cursor: pointer;
  transition: color var(--transition);
  min-width: 0;
}

.bottom-nav-item .icon { font-size: 1.2rem; }
.bottom-nav-item.active { color: var(--violet); }

/* ===== MAIN CONTENT ===== */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  padding-bottom: 80px;
}

.view { display: none; }
.view.active { display: block; }

/* ===== HEADINGS ===== */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-header h2 { font-size: 1.25rem; font-weight: 600; }

/* ===== CARDS ===== */
.card {
  background: var(--slate);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.card-value {
  font-size: 1.5rem;
  font-weight: 700;
}

/* ===== STAT GRID ===== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--slate);
  color: var(--bone);
}

.btn:hover { filter: brightness(1.15); }
.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--violet); color: #fff; }
.btn-green { background: var(--green); color: #000; }
.btn-blue { background: var(--blue); color: #fff; }
.btn-red { background: var(--red); color: #fff; }
.btn-amber { background: var(--amber); color: #000; }
.btn-ghost { background: transparent; color: var(--bone-dim); }
.btn-ghost:hover { background: rgba(255,255,255,0.05); }

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-icon { padding: 8px; min-width: 36px; }

/* ===== FORMS ===== */
.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--bone-dim);
  margin-bottom: 4px;
  font-weight: 500;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-control {
  width: 100%;
  padding: 10px 12px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  color: var(--bone);
  font-size: 0.875rem;
  transition: border-color var(--transition);
}

.form-control:focus {
  outline: none;
  border-color: var(--violet);
}

.form-control::placeholder { color: var(--muted); }

select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%236B6B78' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }

textarea.form-control { resize: vertical; min-height: 60px; }

/* ===== TABLE ===== */
.table-wrap {
  overflow-x: auto;
  margin-bottom: 16px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th {
  text-align: left;
  padding: 10px 12px;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  vertical-align: middle;
}

tr:hover td { background: rgba(255,255,255,0.02); }

/* ===== DIALOG ===== */
dialog {
  background: var(--slate);
  color: var(--bone);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius);
  padding: 0;
  max-width: 500px;
  width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  animation: modalIn 200ms ease;
}

dialog::backdrop { background: rgba(0,0,0,0.6); }

@keyframes modalIn {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.dialog-header h3 { font-size: 1rem; font-weight: 600; }

.dialog-body { padding: 20px; max-height: 60vh; overflow-y: auto; }

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

/* ===== TABS ===== */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  padding-bottom: 0;
}

.tab {
  padding: 8px 16px;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
}

.tab:hover { color: var(--bone); }
.tab.active { color: var(--violet); border-bottom-color: var(--violet); }

/* ===== SPINNER ===== */
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: var(--violet);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin: 40px auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== TOAST ===== */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  animation: toastIn 300ms ease;
  max-width: 360px;
  box-shadow: var(--shadow);
}

.toast-success { background: var(--green); color: #000; }
.toast-error { background: var(--red); color: #fff; }
.toast-info { background: var(--violet); color: #fff; }

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

/* ===== BADGE ===== */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 0.7rem;
  font-weight: 600;
}

.badge-violet { background: rgba(91,91,214,0.2); color: var(--violet); }
.badge-green { background: rgba(34,197,94,0.2); color: var(--green); }
.badge-amber { background: rgba(232,168,56,0.2); color: var(--amber); }
.badge-red { background: rgba(239,68,68,0.2); color: var(--red); }
.badge-muted { background: rgba(107,107,120,0.2); color: var(--muted); }

/* ===== CANVAS ===== */
.chart-wrap {
  background: var(--slate);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

canvas { display: block; width: 100%; max-height: 250px; }

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}

.empty-state .icon { font-size: 2rem; margin-bottom: 8px; }
.empty-state p { font-size: 0.9rem; }

/* ===== PROGRESS BAR ===== */
.progress-bar {
  height: 8px;
  background: rgba(255,255,255,0.08);
  border-radius: 100px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 100px;
  transition: width var(--transition);
}

.progress-fill.green { background: var(--green); }
.progress-fill.violet { background: var(--violet); }
.progress-fill.amber { background: var(--amber); }

/* ===== STREAK ===== */
.streak-display {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
}

.streak-display .fire { font-size: 1.3rem; }

/* ===== CALENDAR ===== */
.cal-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.cal-nav h3 { font-size: 1rem; font-weight: 600; }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.cal-header {
  text-align: center;
  padding: 8px;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
}

.cal-day {
  min-height: 94px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  cursor: pointer;
  transition: background var(--transition);
  gap: 3px;
  position: relative;
  padding: 4px;
  background: rgba(255,255,255,0.02);
  overflow: hidden;
}

.cal-day:hover { background: rgba(255,255,255,0.06); }
.cal-day.today { border: 1px solid var(--violet); padding: 3px; }
.cal-day.other-month { opacity: 0.35; }
.cal-day.selected { background: rgba(91,91,214,0.2); }
.cal-day.rest-day { background: rgba(107,107,120,0.09); }

.cal-day .day-num { font-size: 0.72rem; color: var(--muted); align-self: flex-end; line-height: 1; }
.cal-day.today .day-num { color: var(--violet); font-weight: 700; }

.cal-day .dot { width: 5px; height: 5px; border-radius: 50%; }
.cal-day .dot.workout { background: var(--green); }
.cal-day .dot.workout-planned { background: var(--blue); }
.cal-day .dot.nutrition { background: var(--amber); }
.cal-day .dot.missed { background: var(--red); }

.cal-event {
  display: block;
  font-size: 0.66rem;
  line-height: 1.3;
  padding: 2px 5px;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-left: 3px solid var(--muted);
  background: rgba(255,255,255,0.05);
  text-align: left;
}
.cal-event.gym { border-left-color: var(--violet); background: rgba(91,91,214,0.16); }
.cal-event.run { border-left-color: var(--amber); background: rgba(232,168,56,0.16); }
.cal-event.race { border-left-color: var(--green); background: rgba(34,197,94,0.2); font-weight: 600; }
.cal-event.done { border-left-color: var(--green); background: rgba(34,197,94,0.16); }
.cal-event.office { border-left-color: var(--muted); background: rgba(107,107,120,0.2); color: var(--muted); }
.cal-event.nutrition { border-left-color: var(--amber); background: rgba(232,168,56,0.1); color: var(--muted); }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .bottom-nav { display: block; }
  .main-content { padding: 16px; padding-bottom: 72px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
}

@media (min-width: 769px) {
  .bottom-nav { display: none; }
}

/* ===== MISC ===== */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.text-center { text-align: center; }
.text-muted { color: var(--muted); }
.text-sm { font-size: 0.8rem; }
.text-xs { font-size: 0.7rem; }
.font-bold { font-weight: 700; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

@media (max-width: 768px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

.toggle-wrap {
  display: flex;
  gap: 4px;
  background: rgba(255,255,255,0.05);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.toggle-opt {
  padding: 6px 14px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition);
}

.toggle-opt.active { background: var(--violet); color: #fff; }

/* ===== CALENDAR DRAG & DROP ===== */
.cal-event {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: grab;
  user-select: none;
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.cal-event:active { cursor: grabbing; }
.cal-event.gym { background: rgba(91,91,214,0.2); color: var(--violet); }
.cal-event.run { background: rgba(232,168,56,0.2); color: var(--amber); }
.cal-event.race { background: rgba(34,197,94,0.2); color: var(--green); }
.cal-event.done { background: rgba(34,197,94,0.25); color: var(--green); }
.cal-event.nutrition { background: rgba(59,130,246,0.2); color: var(--blue); }
.cal-event-highlight { border: 1px solid var(--violet); }
.cal-event.office { background: rgba(107,107,120,0.25); color: var(--bone-dim); }
.cal-event.marker-futbol { background: rgba(255,255,255,0.08); color: var(--bone); }

.cal-day.drag-over {
  background: rgba(91,91,214,0.15) !important;
  border: 1px dashed var(--violet);
}

.marker-palette {
  display: flex;
  gap: 8px;
  padding: 12px;
  background: var(--slate);
  border-radius: var(--radius);
  margin-top: 16px;
  flex-wrap: wrap;
}

.marker-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  cursor: grab;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  transition: all var(--transition);
}

.marker-chip:hover { background: rgba(255,255,255,0.1); }
.marker-chip:active { cursor: grabbing; }
.marker-chip.oficina { background: rgba(107,107,120,0.25); }
.marker-chip.descanso { background: rgba(59,130,246,0.2); color: var(--blue); }
.marker-chip.futbol { background: rgba(255,255,255,0.08); }

.day-selector {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.day-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.1);
  background: none;
  color: var(--bone);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all var(--transition);
}

.day-btn.active { background: var(--violet); border-color: var(--violet); color: #fff; }
.day-btn:hover { border-color: var(--violet); }

.separator {
  border: none;
  border-top: 1px solid rgba(255,255,255,0.06);
  margin: 16px 0;
}

.weekly-table th, .weekly-table td {
  text-align: center;
  vertical-align: top;
  min-width: 100px;
}

.weekly-table td { height: 60px; font-size: 0.75rem; }

.search-wrap {
  position: relative;
}

.search-wrap input {
  padding-left: 32px;
}

.search-wrap::before {
  content: '\1F50D';
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.85rem;
  opacity: 0.5;
}

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 0.7rem;
  background: rgba(255,255,255,0.06);
  color: var(--bone-dim);
}
