@font-face {
  font-family: "Archivo";
  src: url("/fonts/archivo-latin-wght-normal.woff2") format("woff2-variations");
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
}

:root {
  color-scheme: light;
  --paper: #f2f3f0;
  --sheet: #fbfcf9;
  --ink: #17212b;
  --muted: #63706e;
  --line: #cbd0cc;
  --line-soft: #e3e6e2;
  --blue: #2457d6;
  --blue-dark: #173d9c;
  --blue-pale: #e8edfc;
  --orange: #f0642b;
  --orange-pale: #fff0e8;
  --green: #16845b;
  --green-pale: #e2f3eb;
  --red: #c33d35;
  --red-pale: #fde9e7;
  --shadow: 0 18px 48px rgba(23, 33, 43, .12);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
}

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

html { min-width: 320px; background: var(--ink); }

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: "Archivo", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.noise { display: none; }

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(36, 87, 214, .36);
  outline-offset: 3px;
}

.button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 10px 17px;
  border: 0;
  border-radius: 12px;
  font-weight: 720;
  text-decoration: none;
  cursor: pointer;
  transition: background-color .18s ease, color .18s ease, transform .18s var(--ease-out), box-shadow .18s ease;
}

.button:hover { transform: translateY(-1px); }
.button:active { transform: translateY(0); }
.button:disabled { cursor: wait; opacity: .58; transform: none; }
.button-primary { background: var(--blue); color: white; box-shadow: 0 8px 18px rgba(36, 87, 214, .2); }
.button-primary:hover { background: var(--blue-dark); box-shadow: 0 10px 22px rgba(36, 87, 214, .26); }
.button-secondary { background: var(--paper); color: var(--ink); border: 1px solid var(--line); }
.button-secondary:hover { background: var(--line-soft); }
.button-danger { background: var(--red); color: white; }

.icon-button {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
  transition: background .18s ease, color .18s ease;
}
.icon-button:hover { background: var(--line-soft); color: var(--blue); }

/* SSO gate */
.login-screen {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(460px, .9fr);
  grid-template-rows: auto 1fr;
  column-gap: clamp(40px, 8vw, 140px);
  padding: clamp(28px, 4vw, 64px);
  background: var(--paper);
  position: relative;
  overflow: hidden;
}

.login-screen::after {
  content: "";
  position: absolute;
  right: -10vw;
  bottom: -28vh;
  width: 54vw;
  height: 54vw;
  border: clamp(70px, 8vw, 130px) solid var(--blue);
  border-radius: 50%;
  opacity: .08;
}

.login-brand { display: flex; align-items: center; gap: 12px; font-size: 23px; font-weight: 820; letter-spacing: -.03em; }
.login-brand img, .wordmark img { border-radius: 10px; object-fit: cover; }

.login-copy { align-self: center; max-width: 690px; padding-bottom: 6vh; position: relative; z-index: 1; }
.login-date { color: var(--blue); font-size: 13px; font-weight: 730; text-transform: uppercase; letter-spacing: .09em; }
.login-copy h1 { margin: 16px 0 25px; font-size: clamp(3.5rem, 7vw, 7rem); line-height: .88; letter-spacing: -.04em; font-weight: 860; }
.login-copy h1 span { color: var(--blue); }
.login-copy > p:not(.login-date, .login-security) { max-width: 570px; margin: 0 0 34px; color: #4c5958; font-size: clamp(1.05rem, 1.6vw, 1.3rem); line-height: 1.55; }
.login-button { width: fit-content; padding-inline: 22px; }
.login-security { display: flex; align-items: center; gap: 8px; margin: 18px 0 0; color: var(--muted); font-size: 13px; }
.login-security span { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px var(--green-pale); }
.auth-error { width: fit-content; max-width: 540px; margin-top: 24px; padding: 12px 14px; color: #872923; background: var(--red-pale); border-radius: 10px; }

.login-ledger {
  grid-column: 2;
  grid-row: 1 / 3;
  align-self: center;
  min-height: 500px;
  padding: 32px 30px;
  position: relative;
  z-index: 1;
  background: var(--sheet);
  border-radius: 16px;
  box-shadow: var(--shadow);
  transform: rotate(1.4deg);
}
.login-ledger::before { content: ""; position: absolute; top: 0; bottom: 0; left: 93px; width: 1px; background: #efb5ae; }
.ledger-head { display: flex; justify-content: space-between; padding: 0 4px 23px; border-bottom: 2px solid var(--ink); font-weight: 800; font-size: 19px; }
.ledger-head span:last-child { color: var(--muted); font-weight: 600; font-size: 13px; }
.ledger-line { min-height: 100px; display: grid; grid-template-columns: 60px 18px 1fr auto; align-items: center; gap: 18px; border-bottom: 1px solid var(--line-soft); }
.ledger-line time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }
.ledger-line span { font-size: 18px; font-weight: 710; }
.ledger-line b { padding: 6px 9px; border-radius: 999px; background: var(--paper); font-size: 12px; }
.marker { width: 12px; height: 12px; display: block; border-radius: 50%; }
.marker.blue { background: var(--blue); }.marker.orange { background: var(--orange); }.marker.green { background: var(--green); }
.ledger-stamp { position: absolute; right: 30px; bottom: 34px; padding: 7px 12px; color: var(--green); border: 2px solid var(--green); border-radius: 5px; font-size: 12px; font-weight: 820; text-transform: uppercase; letter-spacing: .1em; transform: rotate(-4deg); }

/* Application */
.app-shell { height: 100vh; background: var(--paper); }
.topbar { height: 72px; display: grid; grid-template-columns: 260px 1fr auto; align-items: center; padding: 0 20px 0 24px; background: var(--sheet); border-bottom: 1px solid var(--line); }
.wordmark { display: flex; align-items: center; gap: 10px; text-decoration: none; font-size: 20px; font-weight: 820; letter-spacing: -.03em; }
.today-label { justify-self: center; display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 13px; font-weight: 650; }
.live-dot { width: 8px; height: 8px; display: inline-block; flex: 0 0 auto; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px var(--green-pale); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.profile { display: flex; align-items: center; gap: 10px; padding: 5px 8px; }
.avatar { width: 34px; height: 34px; display: grid; place-items: center; flex: 0 0 auto; overflow: hidden; border-radius: 50%; background: var(--blue-pale); color: var(--blue-dark); font-size: 12px; font-weight: 820; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.profile-copy { display: flex; flex-direction: column; line-height: 1.25; }
.profile-copy b { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.profile-copy small { color: var(--muted); font-size: 11px; }

.workspace { height: calc(100vh - 72px); display: grid; grid-template-columns: 240px minmax(480px, 1fr) 340px; }
.presence-panel, .chat-panel { min-width: 0; background: var(--sheet); }
.presence-panel { display: flex; flex-direction: column; padding: 28px 18px 20px; border-right: 1px solid var(--line); }
.chat-panel { display: flex; flex-direction: column; border-left: 1px solid var(--line); }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; padding: 0 8px 22px; }
.panel-heading h2 { margin: 0 0 2px; font-size: 18px; letter-spacing: -.02em; }
.panel-heading p { margin: 0; color: var(--muted); font-size: 12px; }
.presence-list { flex: 1; margin: 0; padding: 0; list-style: none; overflow: auto; }
.presence-item { display: flex; align-items: center; gap: 11px; padding: 10px 8px; border-radius: 12px; }
.presence-item:hover { background: var(--paper); }
.presence-item .avatar { width: 36px; height: 36px; }
.presence-person { min-width: 0; display: flex; flex-direction: column; }
.presence-person b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.presence-person span { color: var(--green); font-size: 11px; }
.presence-foot { display: flex; align-items: center; gap: 9px; padding: 18px 8px 0; border-top: 1px solid var(--line-soft); color: var(--muted); font-size: 11px; }

.planning { min-width: 0; overflow: auto; padding: 38px clamp(26px, 4vw, 64px) 64px; }
.planning-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 28px; margin-bottom: 30px; }
.planning-head h1 { margin: 0 0 6px; font-size: clamp(2rem, 3vw, 3.4rem); line-height: 1; letter-spacing: -.04em; }
.planning-head p { margin: 0; color: var(--muted); }
.filter-bar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 30px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.segmented { display: flex; gap: 4px; padding: 4px; background: #e4e7e3; border-radius: 12px; }
.segmented button { min-height: 34px; padding: 6px 12px; border: 0; border-radius: 9px; background: transparent; color: #55615f; font-size: 12px; font-weight: 690; cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--sheet); color: var(--ink); box-shadow: 0 3px 10px rgba(23, 33, 43, .08); }
.search-field { width: min(250px, 35%); display: flex; align-items: center; gap: 8px; padding: 0 11px; background: var(--sheet); border: 1px solid var(--line); border-radius: 12px; color: var(--muted); }
.search-field svg { width: 17px; }
.search-field input { min-width: 0; width: 100%; height: 40px; border: 0; outline: 0; background: transparent; color: var(--ink); }
.search-field:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(36, 87, 214, .12); }

.timeline { max-width: 900px; margin: 0 auto; position: relative; }
.day-group { display: grid; grid-template-columns: 90px 1fr; position: relative; animation: unfold .55s var(--ease-out) both; }
.day-group + .day-group { margin-top: 8px; }
.day-label { padding: 18px 18px 0 0; text-align: right; position: relative; }
.day-label strong { display: block; font-size: 13px; text-transform: capitalize; }
.day-label span { color: var(--muted); font-size: 11px; }
.day-items { min-width: 0; padding: 10px 0 22px 26px; border-left: 1px solid var(--line); }
.availability-row { min-height: 76px; display: grid; grid-template-columns: 42px minmax(0, 1fr) auto; align-items: center; gap: 13px; padding: 13px 12px; position: relative; border-bottom: 1px solid var(--line-soft); }
.availability-row::before { content: ""; width: 9px; height: 9px; position: absolute; left: -31px; top: 33px; border: 3px solid var(--paper); border-radius: 50%; background: var(--blue); box-shadow: 0 0 0 1px var(--blue); }
.availability-row.mine::before { background: var(--orange); box-shadow: 0 0 0 1px var(--orange); }
.availability-copy { min-width: 0; }
.availability-copy b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.availability-copy p { margin: 2px 0 0; overflow-wrap: anywhere; color: var(--muted); font-size: 13px; }
.availability-copy p:empty::before { content: "Disponible"; color: #7e8987; font-style: italic; }
.row-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .16s ease; }
.availability-row:hover .row-actions, .availability-row:focus-within .row-actions { opacity: 1; }
.row-actions .icon-button { width: 36px; height: 36px; }

.empty-state, .loading-state, .error-state { min-height: 280px; display: grid; place-items: center; align-content: center; text-align: center; color: var(--muted); }
.empty-state svg, .error-state svg { width: 42px; height: 42px; margin-bottom: 14px; color: var(--blue); }
.empty-state h2, .error-state h2 { margin: 0 0 6px; color: var(--ink); font-size: 18px; }
.empty-state p, .error-state p { max-width: 390px; margin: 0 0 16px; }
.loading-rule { width: min(380px, 60vw); height: 3px; overflow: hidden; background: var(--line-soft); }
.loading-rule::after { content: ""; display: block; width: 40%; height: 100%; background: var(--blue); animation: load 1.1s ease-in-out infinite; }

.chat-heading { padding: 28px 24px 22px; border-bottom: 1px solid var(--line-soft); }
.message-list { flex: 1; min-height: 0; overflow: auto; padding: 20px 20px 10px; scroll-behavior: smooth; }
.message { display: grid; grid-template-columns: 32px 1fr; gap: 10px; margin-bottom: 20px; }
.message .avatar { width: 32px; height: 32px; }
.message-head { display: flex; justify-content: space-between; gap: 8px; margin: 0 0 4px; }
.message-head b { font-size: 12px; }
.message-head time { color: #7d8785; font-size: 10px; font-variant-numeric: tabular-nums; }
.message p { margin: 0; overflow-wrap: anywhere; color: #394542; font-size: 13px; line-height: 1.55; }
.message-form { display: grid; grid-template-columns: 1fr 42px; align-items: end; gap: 8px; margin: 12px 16px 18px; padding: 8px 8px 8px 13px; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; }
.message-form:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(36, 87, 214, .1); }
.message-form textarea { width: 100%; max-height: 110px; resize: none; padding: 9px 0; border: 0; outline: 0; background: transparent; color: var(--ink); line-height: 1.35; }
.message-form textarea::placeholder, .search-field input::placeholder, .field textarea::placeholder { color: #7b8583; opacity: 1; }
.send-button { width: 42px; height: 42px; display: grid; place-items: center; border: 0; border-radius: 11px; background: var(--blue); color: white; cursor: pointer; }
.send-button:hover { background: var(--blue-dark); }

dialog { color: var(--ink); }
dialog::backdrop { background: rgba(23, 33, 43, .52); backdrop-filter: blur(3px); }
.editor-dialog, .confirm-dialog { width: min(520px, calc(100vw - 28px)); padding: 0; border: 0; border-radius: 16px; background: var(--sheet); box-shadow: var(--shadow); }
.editor-dialog[open], .confirm-dialog[open] { animation: dialog-in .24s var(--ease-out) both; }
.editor-dialog form, .confirm-dialog form { padding: 26px; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.dialog-head h2, .confirm-dialog h2 { margin: 0 0 5px; font-size: 23px; letter-spacing: -.03em; }
.dialog-head p, .confirm-dialog p { margin: 0; color: var(--muted); }
.field { display: block; margin-top: 18px; position: relative; }
.field > span { display: flex; justify-content: space-between; margin-bottom: 7px; font-size: 13px; font-weight: 720; }
.field small { color: var(--muted); font-weight: 500; }
.field input, .field textarea { width: 100%; padding: 12px 13px; border: 1px solid var(--line); border-radius: 11px; outline: 0; background: white; color: var(--ink); }
.field input:focus, .field textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(36, 87, 214, .1); }
.field em { display: block; margin-top: 5px; color: var(--muted); font-size: 10px; font-style: normal; text-align: right; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 27px; }
.confirm-dialog p { max-width: 42ch; }

.toast-region { position: fixed; right: 22px; bottom: 22px; z-index: 100; display: grid; gap: 8px; }
.toast { width: min(380px, calc(100vw - 28px)); display: flex; align-items: flex-start; gap: 10px; padding: 13px 15px; color: white; background: var(--ink); border-radius: 12px; box-shadow: var(--shadow); animation: toast-in .3s var(--ease-out) both; }
.toast.error { background: #842c27; }
.toast.success { background: #116849; }

.mobile-only { display: none; }
.count-badge { min-width: 17px; height: 17px; display: grid; place-items: center; position: absolute; top: 2px; right: 1px; padding: 0 4px; border-radius: 99px; background: var(--orange); color: white; font-size: 9px; font-weight: 800; }

@keyframes unfold { from { opacity: .25; clip-path: inset(0 0 100% 0); transform: translateY(-6px); } to { opacity: 1; clip-path: inset(0); transform: none; } }
@keyframes load { from { transform: translateX(-100%); } to { transform: translateX(350%); } }
@keyframes dialog-in { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

@media (max-width: 1180px) {
  .workspace { grid-template-columns: 220px minmax(440px, 1fr) 310px; }
  .planning { padding-inline: 28px; }
}

@media (max-width: 980px) {
  .topbar { grid-template-columns: 200px 1fr auto; }
  .workspace { grid-template-columns: minmax(440px, 1fr) 320px; }
  .presence-panel { width: 290px; height: calc(100vh - 72px); display: none; position: fixed; top: 72px; right: 0; z-index: 30; border: 0; border-left: 1px solid var(--line); box-shadow: var(--shadow); }
  .presence-panel.open { display: flex; animation: panel-right .3s var(--ease-out) both; }
  .mobile-only#presenceToggle, .panel-close { display: inline-grid; position: relative; }
  .login-screen { grid-template-columns: 1fr 390px; column-gap: 40px; }
  .login-ledger { min-height: 450px; }
  .ledger-line { grid-template-columns: 52px 14px 1fr; }
  .ledger-line b { display: none; }
}

@media (max-width: 760px) {
  body { overflow: auto; }
  .noise { display: none; }
  .login-screen { min-height: 100svh; display: flex; flex-direction: column; padding: 24px 22px 40px; }
  .login-brand { font-size: 20px; }
  .login-brand img { width: 44px; height: 44px; }
  .login-copy { margin: auto 0; padding: 52px 0 40px; }
  .login-copy h1 { margin-top: 13px; font-size: clamp(3.3rem, 16vw, 5.4rem); }
  .login-copy > p:not(.login-date, .login-security) { font-size: 1.05rem; }
  .login-button { width: 100%; }
  .login-ledger { display: none; }

  .app-shell { min-height: 100svh; height: auto; padding-bottom: 68px; }
  .topbar { height: 64px; grid-template-columns: 1fr auto; padding: 0 12px 0 16px; position: sticky; top: 0; z-index: 25; }
  .today-label, .profile-copy { display: none; }
  .wordmark { font-size: 18px; }
  .wordmark img { width: 32px; height: 32px; }
  .profile { padding: 0; }
  .profile .avatar { width: 34px; height: 34px; }
  .topbar-actions { gap: 1px; }
  .workspace { height: auto; display: block; }
  .planning { min-height: calc(100svh - 132px); padding: 26px 16px 50px; overflow: visible; }
  .planning-head { display: block; margin-bottom: 22px; }
  .planning-head h1 { font-size: 2.5rem; }
  .planning-head .button { width: 100%; margin-top: 22px; }
  .filter-bar { align-items: stretch; flex-direction: column; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; }
  .search-field { width: 100%; }
  .day-group { grid-template-columns: 62px 1fr; }
  .day-label { padding-right: 12px; }
  .day-items { padding-left: 18px; }
  .availability-row { grid-template-columns: 38px minmax(0, 1fr) auto; padding-inline: 7px 0; }
  .availability-row::before { left: -23px; }
  .row-actions { opacity: 1; }

  .presence-panel, .chat-panel { width: 100%; height: calc(100svh - 64px - 68px); display: none; position: fixed; inset: 64px 0 68px; z-index: 20; border: 0; background: var(--sheet); box-shadow: none; }
  .presence-panel { padding: 24px 18px; }
  .presence-panel.open, .chat-panel.open { display: flex; animation: panel-up .3s var(--ease-out) both; }
  .chat-heading { padding: 24px 20px 18px; }
  .message-list { padding-inline: 18px; }
  .mobile-nav { height: 68px; display: grid; grid-template-columns: repeat(3, 1fr); position: fixed; right: 0; bottom: 0; left: 0; z-index: 35; padding-bottom: env(safe-area-inset-bottom); background: var(--sheet); border-top: 1px solid var(--line); }
  .mobile-nav button { display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 2px; border: 0; background: transparent; color: var(--muted); font-size: 10px; font-weight: 650; }
  .mobile-nav button.active { color: var(--blue); }
  .mobile-nav svg { width: 21px; height: 21px; }
  .panel-close { display: inline-grid; }
  .toast-region { right: 14px; bottom: 82px; left: 14px; }
  .toast { width: 100%; }
}

@keyframes panel-right { from { transform: translateX(100%); } to { transform: none; } }
@keyframes panel-up { from { transform: translateY(18px); opacity: .5; } to { transform: none; opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
