:root {
  --bg: #f4f5fb;
  --surface: #ffffff;
  --surface-2: #f3f4fa;
  --border: #e6e8f0;
  --text: #1b2030;
  --text-dim: #71788c;
  --brand-1: #6366f1;
  --brand-2: #8b5cf6;
  --accent: #6366f1;
  --accent-soft: #eef0fe;
  --green: #15a34a;
  --green-soft: #e7f8ee;
  --amber: #d97706;
  --amber-soft: #fdf2dc;
  --red: #e11d48;
  --red-soft: #fdeaee;
  --shadow-sm: 0 1px 2px rgba(20, 25, 50, .06), 0 1px 3px rgba(20, 25, 50, .05);
  --shadow-md: 0 6px 20px rgba(30, 35, 70, .08);
  --shadow-lg: 0 18px 50px rgba(30, 35, 70, .14);
  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 22px;
  --tabbar-h: 64px;
}

* { box-sizing: border-box; }

/* El atributo hidden debe ganar siempre, aunque haya reglas de display */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }

/* ============ Branding ============ */
.brand { display: flex; flex-direction: column; align-items: center; gap: .35rem; margin-bottom: 1.75rem; }
.brand-logo {
  font-weight: 800;
  font-size: 2.4rem;
  letter-spacing: 4px;
  background: linear-gradient(120deg, var(--brand-1), var(--brand-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand-logo.sm { font-size: 1.35rem; letter-spacing: 2px; }
.brand-tag { color: var(--text-dim); font-size: .92rem; text-align: center; }

/* ============ Auth ============ */
.auth-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background:
    radial-gradient(1200px 600px at 100% -10%, #eae9ff 0%, transparent 55%),
    radial-gradient(1000px 500px at -10% 110%, #e7f1ff 0%, transparent 55%),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  padding: 2.25rem 2rem;
}

/* segmented control */
.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 1.5rem;
}
.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-dim);
  padding: .6rem .5rem;
  border-radius: 999px;
  font-size: .92rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s ease;
}
.seg-btn.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow-sm); }

.field { display: block; margin-bottom: 1.1rem; }
.field > span { display: block; font-size: .82rem; font-weight: 600; color: var(--text-dim); margin-bottom: .4rem; }
.field input {
  width: 100%;
  padding: .8rem .9rem;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: 1rem;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field input::placeholder { color: #aab0c0; }
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
#auth-code { letter-spacing: 10px; text-align: center; font-weight: 700; }

.btn-primary {
  width: 100%;
  padding: .85rem;
  background: linear-gradient(120deg, var(--brand-1), var(--brand-2));
  color: #fff;
  border: none;
  border-radius: var(--r-sm);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(99, 102, 241, .28);
  transition: transform .12s ease, box-shadow .12s ease;
}
.btn-primary:hover { transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }

.error {
  background: var(--red-soft);
  color: var(--red);
  font-size: .85rem;
  padding: .6rem .75rem;
  border-radius: var(--r-sm);
  margin: 0 0 1rem;
}

/* ============ App shell ============ */
.app { min-height: 100dvh; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .85rem 1.25rem;
  background: rgba(255, 255, 255, .85);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.user-box { display: flex; align-items: center; gap: .6rem; }
.me-name { font-weight: 600; font-size: .92rem; }
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: .85rem;
  background: linear-gradient(120deg, var(--brand-1), var(--brand-2));
}
.btn-ghost {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 36px; height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}
.btn-ghost:hover { color: var(--red); border-color: var(--red); }

main {
  max-width: 920px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem calc(var(--tabbar-h) + 2rem);
}

/* ============ Tabbar ============ */
.tabbar {
  position: fixed;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px;
  box-shadow: var(--shadow-md);
}
.tabbar-btn {
  border: none;
  background: transparent;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: .45rem;
  padding: .6rem 1rem;
  border-radius: 999px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.tabbar-btn .ico { font-size: 1.05rem; }
.tabbar-btn.active { background: var(--accent-soft); color: var(--accent); }

/* ============ Section header ============ */
.section-head { margin-bottom: 1.25rem; }
.section-title { font-size: 1.5rem; font-weight: 800; margin: 0; letter-spacing: -.01em; }
.section-sub { color: var(--text-dim); font-size: .92rem; margin: .35rem 0 0; }

/* ============ Calendar ============ */
.cal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  padding: 1.1rem;
  margin-top: 1rem;
}
.cal-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.cal-month { font-size: 1.1rem; font-weight: 700; text-transform: capitalize; }
.cal-nav { display: flex; gap: .4rem; align-items: center; }
.cal-nav button {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  height: 38px;
  min-width: 38px;
  padding: 0 .75rem;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
}
.cal-nav button:hover { border-color: var(--accent); color: var(--accent); }
.cal-nav .today-btn { font-size: .85rem; }

.weekdays, .cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 7px;
}
.weekdays { margin-bottom: 7px; }
.weekday {
  text-align: center;
  font-size: .72rem;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .03em;
}
.day {
  aspect-ratio: 1 / 1;
  background: var(--surface-2);
  border: 1.5px solid transparent;
  border-radius: var(--r-sm);
  padding: .45rem;
  display: flex;
  flex-direction: column;
  min-height: 52px;
  transition: transform .1s ease, box-shadow .1s ease, background .1s ease;
}
.day.empty { background: transparent; }
.day.clickable { cursor: pointer; touch-action: none; -webkit-user-select: none; user-select: none; }
.day.clickable:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.day .num { font-weight: 700; font-size: .9rem; color: var(--text); }
.day.past { opacity: .5; }
.day.today { box-shadow: inset 0 0 0 2px var(--accent); }
.day.today .num { color: var(--accent); }

/* estados — vista común */
.day.all-free { background: var(--green-soft); }
.day.all-free .num { color: var(--green); }
.day.some-busy { background: var(--amber-soft); }
.day.all-busy { background: var(--red-soft); }
/* mi calendario */
.day.busy-me { background: var(--red-soft); border-color: var(--red); }

.day .badge {
  margin-top: auto;
  font-size: .68rem;
  font-weight: 600;
  color: var(--text-dim);
  line-height: 1.15;
}
.day.all-free .badge { color: var(--green); }
.day.some-busy .badge { color: var(--amber); }
.day.all-busy .badge { color: var(--red); }
.day.busy-me .badge { color: var(--red); }

.legend {
  display: flex;
  gap: 1.1rem;
  flex-wrap: wrap;
  margin-top: 1.1rem;
  font-size: .82rem;
  color: var(--text-dim);
}
.legend span { display: inline-flex; align-items: center; gap: .45rem; }
.dot { width: 13px; height: 13px; border-radius: 4px; display: inline-block; }
.dot.green { background: var(--green); }
.dot.amber { background: var(--amber); }
.dot.red { background: var(--red); }

/* ============ Timeline (Gantt de equipo) ============ */
.tl-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; font-size: .85rem;
  flex: 0 0 auto;
}

.gantt-scroll {
  margin-top: 1rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.gantt {
  --name-w: 150px;
  --col-w: 30px;
  display: grid;
  grid-template-columns: var(--name-w) repeat(var(--days), minmax(var(--col-w), 1fr));
  min-width: max-content;
}

/* Esquina y números de día */
.g-corner, .g-head {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.g-corner {
  left: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  padding: 0 .9rem;
  font-weight: 700;
  font-size: .82rem;
  color: var(--text-dim);
  border-right: 1px solid var(--border);
}
.g-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: .35rem 0;
  gap: 1px;
  border-left: 1px solid var(--border);
}
.g-head .g-wd { font-size: .58rem; font-weight: 700; color: var(--text-dim); text-transform: uppercase; }
.g-head .g-dnum { font-size: .82rem; font-weight: 700; }
.g-head.weekend { background: #eef0f6; }
.g-head.today-col { background: var(--accent-soft); }
.g-head.today-col .g-dnum { color: var(--accent); }

/* Nombre de persona (columna fija) */
.g-name {
  position: sticky;
  left: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .55rem .9rem;
  background: var(--surface);
  border-right: 1px solid var(--border);
  border-top: 1px solid var(--border);
}
.g-label {
  font-weight: 600;
  font-size: .88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Celdas de día */
.g-cell {
  border-left: 1px solid var(--border);
  border-top: 1px solid var(--border);
  min-height: 46px;
  display: flex;
  align-items: center;
  background: var(--surface);
}
.g-cell.weekend { background: #fafbfe; }
.g-cell.today-col { box-shadow: inset 0 0 0 2px var(--accent-soft); }

/* Barra de "no disponible" */
.g-fill {
  height: 60%;
  width: 100%;
  background: var(--red);
}
.g-fill.start { margin-left: 5px; border-top-left-radius: 999px; border-bottom-left-radius: 999px; }
.g-fill.end { margin-right: 5px; border-top-right-radius: 999px; border-bottom-right-radius: 999px; }

.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 2.5rem 1rem;
}

/* ============ Responsive ============ */
@media (max-width: 600px) {
  .tabbar {
    left: 0;
    right: 0;
    bottom: 0;
    transform: none;
    width: 100%;
    border-radius: 18px 18px 0 0;
    border-bottom: none;
    padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
    justify-content: space-around;
  }
  .tabbar-btn {
    flex-direction: column;
    gap: 2px;
    padding: .35rem .5rem;
    flex: 1;
  }
  .tabbar-btn .ico { font-size: 1.25rem; }
  .tabbar-btn .lbl { font-size: .68rem; }
  main { padding: 1.1rem .9rem calc(var(--tabbar-h) + 2.5rem); }
  .section-title { font-size: 1.3rem; }
  .day { min-height: 46px; padding: .3rem; border-radius: 9px; }
  .day .num { font-size: .82rem; }
  .day .badge { font-size: .6rem; }
  .me-name { display: none; }
  .cal-card { padding: .8rem; }
  .weekdays, .cal-grid { gap: 5px; }
}
