:root {
  --bg: #0f1115;
  --bg-alt: #161a21;
  --card: #1d222b;
  --border: #2a3140;
  --text: #e9edf2;
  --muted: #9aa4b2;
  --accent: #c6ff3d;
  --accent-dark: #a3d92a;
  --done: #4ade80;
  --missed: #f87171;
  --unlogged: #fbbf24;
  --radius: 14px;
}

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

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.container { width: min(1200px, 94%); margin: 0 auto; }
main.container { padding: 1.5rem 0 3rem; }

h2 { font-size: 1.4rem; margin-bottom: 1rem; }
h3 { font-size: 1.05rem; margin-bottom: 0.7rem; }
.muted { color: var(--muted); font-size: 0.92rem; }
.row { display: flex; gap: 0.8rem; flex-wrap: wrap; }
.stack { display: grid; gap: 0.7rem; }
.spacer { flex: 1; }
[hidden] { display: none !important; }

/* Botones */
.btn {
  display: inline-block;
  background: var(--accent);
  color: #111;
  font: inherit;
  font-weight: 700;
  padding: 0.65rem 1.2rem;
  border-radius: 999px;
  border: 2px solid var(--accent);
  cursor: pointer;
  text-align: center;
  transition: background 0.15s, transform 0.15s;
}
.btn:hover { background: var(--accent-dark); }
.btn:active { transform: scale(0.97); }
.btn--ghost { background: transparent; color: var(--accent); }
.btn--ghost:hover { background: rgba(198, 255, 61, 0.1); }
.btn--danger { background: transparent; color: var(--missed); border-color: var(--missed); }
.btn--danger:hover { background: rgba(248, 113, 113, 0.12); }
.btn--small { padding: 0.35rem 0.9rem; font-size: 0.88rem; }
.file-btn { display: block; }

.icon-btn {
  background: var(--card); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  min-width: 2.2rem; height: 2.2rem; cursor: pointer; font-size: 1rem;
}
.icon-btn:hover { border-color: var(--accent); }
.icon-btn.on { border-color: var(--accent); background: rgba(198, 255, 61, 0.15); }

/* Barra superior */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: rgba(15, 17, 21, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid #222833;
}
.topbar__inner { display: flex; align-items: center; justify-content: space-between; height: 60px; gap: 1rem; }
.logo { font-weight: 800; font-size: 1.25rem; }
.logo span { color: var(--accent); text-decoration: line-through; }
.tabs { display: flex; gap: 0.3rem; }
.tab {
  background: none; border: none; color: var(--muted); font: inherit;
  padding: 0.5rem 0.9rem; border-radius: 999px; cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--card); color: var(--accent); font-weight: 600; }

.user-box { display: flex; align-items: center; gap: 0.7rem; color: var(--muted); font-size: 0.9rem; }

/* Login */
.auth { min-height: calc(100vh - 60px); display: grid; place-items: center; padding: 2rem 1rem; }
.auth__form { width: min(400px, 100%); }
.form__msg--error { color: var(--missed); }
.link { background: none; border: none; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; }

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

.panel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.2rem; }

/* Bienvenida */
.onboarding {
  background: linear-gradient(135deg, #1b2410, var(--card));
  border: 1px solid #3a4a1f; border-radius: var(--radius);
  padding: 1.5rem; margin-bottom: 1.5rem;
}
.onboarding p { color: var(--muted); margin-bottom: 1rem; }

/* Resumen */
.dashboard { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.kpi { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.2rem; }
.kpi__label { color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; }
.kpi__value { font-size: 1.6rem; font-weight: 800; margin: 0.2rem 0; }
.kpi__sub { color: var(--muted); font-size: 0.9rem; }
.kpi--accent .kpi__value { color: var(--accent); }

/* Calendario */
.cal-layout { display: grid; grid-template-columns: 1fr 320px; gap: 1.5rem; align-items: start; }
.cal-head { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 1rem; }
.cal-head h2 { margin: 0; flex: 1; text-align: center; text-transform: capitalize; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-weekdays { color: var(--muted); font-size: 0.8rem; text-align: center; margin-bottom: 4px; }

.day {
  background: var(--bg-alt); border: 1px solid transparent; border-radius: 10px;
  min-height: 92px; padding: 0.35rem; text-align: left;
  display: flex; flex-direction: column; gap: 3px;
  color: var(--text); font: inherit; cursor: pointer; overflow: hidden;
}
.day:hover { border-color: var(--border); }
.day--muted { opacity: 0.4; }
.day--today { border-color: var(--accent); }
.day--today .day__num { background: var(--accent); color: #111; }
.day__num { font-size: 0.8rem; font-weight: 700; width: 1.6rem; height: 1.6rem; display: grid; place-items: center; border-radius: 50%; }

.flag { font-size: 0.72rem; font-weight: 700; color: var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip {
  font-size: 0.74rem; padding: 2px 6px; border-radius: 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-left: 3px solid var(--muted); background: rgba(255,255,255,0.05);
}
.chip--done { border-color: var(--done); background: rgba(74, 222, 128, 0.15); }
.chip--missed { border-color: var(--missed); background: rgba(248, 113, 113, 0.15); }
.chip--unlogged { border-color: var(--unlogged); background: rgba(251, 191, 36, 0.12); }

.legend { display: flex; flex-wrap: wrap; gap: 1rem; margin-top: 1rem; color: var(--muted); font-size: 0.82rem; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 0.35rem; vertical-align: middle; }
.dot--pending { background: var(--muted); }
.dot--done { background: var(--done); }
.dot--missed { background: var(--missed); }
.dot--unlogged { background: var(--unlogged); }

/* Listas laterales */
.side { display: grid; gap: 1rem; }
.list { list-style: none; display: grid; gap: 0.5rem; }
.list .empty { color: var(--muted); font-size: 0.9rem; }
.item {
  display: flex; align-items: center; gap: 0.5rem;
  background: var(--bg-alt); border-radius: 10px; padding: 0.45rem 0.5rem;
  border-left: 3px solid var(--muted);
}
.item--done { border-color: var(--done); }
.item--missed { border-color: var(--missed); }
.item--unlogged { border-color: var(--unlogged); }
.item__main {
  flex: 1; display: flex; flex-direction: column; background: none; border: none;
  color: var(--text); font: inherit; text-align: left; cursor: pointer; min-width: 0;
}
.item__main span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item__date { color: var(--muted); font-size: 0.78rem; text-transform: capitalize; }
.item__actions { display: flex; gap: 0.3rem; }

/* Formularios */
.two-col { display: grid; grid-template-columns: 380px 1fr; gap: 1.5rem; align-items: start; }
.form { display: grid; gap: 0.9rem; }
.form label { display: grid; gap: 0.3rem; color: var(--muted); font-size: 0.9rem; }
.form__msg { color: var(--accent); min-height: 1.4em; font-size: 0.9rem; }
input, select, textarea {
  background: var(--bg-alt); color: var(--text);
  border: 1px solid #2f3747; border-radius: 10px;
  padding: 0.6rem 0.8rem; font: inherit; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type="date"] { color-scheme: dark; }
input[type="checkbox"], input[type="radio"] { width: auto; accent-color: var(--accent); }

.plan-days { display: grid; gap: 0.6rem; }
.plan-row { display: grid; grid-template-columns: 120px 1fr; gap: 0.5rem; align-items: center; background: var(--bg-alt); padding: 0.6rem; border-radius: 10px; }
.plan-row .check { display: flex; align-items: center; gap: 0.5rem; color: var(--text); font-weight: 600; cursor: pointer; }
.plan-row .plan-row__inputs { display: grid; gap: 0.4rem; }
.plan-row:not(.on) .plan-row__inputs { opacity: 0.35; }

/* Metas */
.goals { display: grid; gap: 1rem; }
.goal-group { display: grid; gap: 0.6rem; }
.goal { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.2rem; }
.goal--main { border-color: #3a4a1f; }
.goal--sub { margin-left: 1.5rem; position: relative; }
.goal--sub::before { content: ""; position: absolute; left: -1rem; top: -0.6rem; bottom: 50%; width: 0.8rem; border-left: 2px solid var(--border); border-bottom: 2px solid var(--border); border-bottom-left-radius: 8px; }
.goal--achieved { border-color: var(--done); }
.goal--failed { border-color: var(--missed); }
.goal__top { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; }
.goal__top h3 { margin-bottom: 0.2rem; }
.goal__notes { margin-top: 0.3rem; font-size: 0.92rem; }
.goal__actions { display: flex; gap: 0.4rem; align-items: center; }
.goal__actions select { width: auto; padding: 0.35rem 0.5rem; font-size: 0.85rem; }
.countdown { color: var(--accent); font-weight: 700; }
.bar { height: 8px; background: var(--bg-alt); border-radius: 999px; overflow: hidden; margin: 0.8rem 0 0.4rem; }
.bar__fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.3s; }
.goal__stats { color: var(--muted); font-size: 0.85rem; }

/* Admin */
.admin-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.admin-head h2 { margin: 0; }
.table-wrap { overflow-x: auto; }
.admin-table, .data-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.admin-table th, .data-table th { text-align: left; color: var(--muted); font-weight: 600; padding: 0.6rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.admin-table td, .data-table td { padding: 0.6rem; border-bottom: 1px solid #222833; vertical-align: middle; }
.admin-table .user-cell strong { display: block; }
.admin-table .user-cell span { color: var(--muted); font-size: 0.85rem; }
.admin-table .actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.badge { display: inline-block; padding: 0.15rem 0.6rem; border-radius: 999px; font-size: 0.78rem; font-weight: 700; background: var(--bg-alt); color: var(--muted); }
.badge--admin { background: rgba(198, 255, 61, 0.15); color: var(--accent); }

/* Tokens de API */
.token-new { display: flex; gap: 0.5rem; }
.token-new input { flex: 1; }
.token-created { background: rgba(198, 255, 61, 0.08); border: 1px solid #3a4a1f; border-radius: 10px; padding: 0.8rem; display: grid; gap: 0.5rem; }
.token-created code { font-family: ui-monospace, Consolas, monospace; font-size: 0.82rem; word-break: break-all; background: var(--bg-alt); padding: 0.5rem; border-radius: 8px; user-select: all; }
.token-item { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; background: var(--bg-alt); border-radius: 10px; padding: 0.55rem 0.7rem; }
.token-item div { min-width: 0; }
.token-item span { display: block; color: var(--muted); font-size: 0.8rem; }
a.link { text-decoration: underline; }

/* Listado */
.list-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.list-head h2 { margin: 0; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0.8rem; margin-bottom: 0.8rem; }
.filters label { display: grid; gap: 0.3rem; color: var(--muted); font-size: 0.85rem; }
.list-summary { margin-bottom: 0.6rem; }
.data-table tr.lrow { cursor: pointer; }
.data-table tr.lrow:hover td { background: rgba(255, 255, 255, 0.03); }
.data-table td:first-child { border-left: 3px solid transparent; }
.data-table .lrow--done td:first-child { border-left-color: var(--done); }
.data-table .lrow--missed td:first-child { border-left-color: var(--missed); }
.data-table .lrow--unlogged td:first-child { border-left-color: var(--unlogged); }
.data-table .lrow--pending td:first-child { border-left-color: var(--muted); }
.data-table .lrow--goal td { background: rgba(198, 255, 61, 0.06); }
.data-table .lrow--goal td:first-child { border-left-color: var(--accent); }
.data-table .sub { display: block; color: var(--muted); font-size: 0.85rem; }
.data-table .actions { display: flex; gap: 0.3rem; justify-content: flex-end; }
.nowrap { white-space: nowrap; }
.status { font-size: 0.85rem; }
.status--done { color: var(--done); }
.status--missed { color: var(--missed); }
.status--unlogged { color: var(--unlogged); }
.status--pending { color: var(--muted); }

/* Diálogo */
dialog {
  margin: auto; width: min(460px, 92vw);
  background: var(--card); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 1.4rem;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog h3 { font-size: 1.15rem; }
#dd-goals .flag { display: block; font-size: 0.9rem; margin-bottom: 0.3rem; }
#dd-fields { display: grid; gap: 0.9rem; }
.status-pick { border: none; display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.4rem; }
.status-pick legend { color: var(--muted); font-size: 0.9rem; margin-bottom: 0.3rem; }
.status-pick label { display: block; cursor: pointer; }
.status-pick input { position: absolute; opacity: 0; }
.status-pick span {
  display: block; text-align: center; padding: 0.55rem 0.3rem; border-radius: 10px;
  background: var(--bg-alt); border: 1px solid var(--border); color: var(--text); font-size: 0.88rem;
}
.status-pick input:checked + span { border-color: var(--accent); background: rgba(198, 255, 61, 0.12); }
.status-pick input:focus-visible + span { outline: 2px solid var(--accent); }
.dialog__actions { display: flex; gap: 0.5rem; align-items: center; margin-top: 0.4rem; }

/* Responsive */
@media (max-width: 950px) {
  .cal-layout, .two-col { grid-template-columns: 1fr; }
  /* Barra en dos filas: logo + Salir arriba, pestañas abajo a todo el ancho */
  .topbar__inner { flex-wrap: wrap; height: auto; padding: 0.5rem 0; row-gap: 0.4rem; }
  .tabs { order: 3; width: 100%; }
  .tab { flex: 1; padding: 0.45rem 0; text-align: center; }
}
@media (max-width: 640px) {
  .tab span, #user-name { display: none; }
  .logo { font-size: 1.05rem; }
  .day { min-height: 64px; padding: 0.2rem; }
  .chip { font-size: 0; padding: 0; height: 8px; border-left-width: 0; }
  .chip--pending { background: var(--muted); }
  .chip--done { background: var(--done); }
  .chip--missed { background: var(--missed); }
  .chip--unlogged { background: var(--unlogged); }
  .flag { font-size: 0.8rem; }
  .flag .flag__name { display: none; }
  .plan-row { grid-template-columns: 1fr; }
  .col-notes, .col-status { display: none; }
  .filters { grid-template-columns: 1fr 1fr; }
  .data-table td, .data-table th { padding: 0.5rem 0.35rem; }
  .goal--sub { margin-left: 1rem; }
}
