/* =========================================================================
   Almo v2 — Base reset + app shell layout
   ========================================================================= */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text);
  background-color: var(--bg);
  background-image: var(--bg-tint);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  min-height: 100dvh;
}

h1, h2, h3, h4, h5, h6, p, figure {
  margin: 0;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

a {
  color: var(--primary);
  text-decoration: none;
}

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

:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

::selection {
  background: color-mix(in srgb, var(--primary) 26%, transparent);
}

/* Scrollbars */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

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

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

#app { min-height: 100dvh; }

/* ===== App shell ======================================================= */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100dvh;
}

/* ---- Sidebar (desktop) ---- */
.sidebar {
  position: sticky;
  top: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-5) var(--sp-4);
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-2) var(--sp-5);
}
.sidebar__logo {
  width: 38px; height: 38px;
  border-radius: var(--radius-md);
  display: grid; place-items: center;
  overflow: hidden;
  background: linear-gradient(135deg, var(--indigo-500), var(--teal-500));
  color: #fff;
  font-weight: var(--fw-bold);
  font-size: var(--text-lg);
  box-shadow: var(--shadow-primary);
  flex-shrink: 0;
}
.sidebar__logo img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; display: block; }
.sidebar__wordmark { font-size: var(--text-xl); font-weight: var(--fw-bold); letter-spacing: -0.02em; }
.sidebar__wordmark span { color: var(--primary); }

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  flex: 1;
  margin: 0 calc(-1 * var(--sp-1));
  padding: 0 var(--sp-1);
}
.nav__group-label {
  font-size: var(--text-2xs);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-subtle);
  font-weight: var(--fw-semibold);
  padding: var(--sp-4) var(--sp-3) var(--sp-2);
}
.nav__item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-weight: var(--fw-medium);
  font-size: var(--text-base);
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
@media (hover: hover) { .nav__item:hover { background: var(--surface-2); color: var(--text); } }
.nav__item .icon { width: 20px; height: 20px; flex-shrink: 0; }
.nav__item.is-active {
  background: var(--primary-soft);
  color: var(--primary-soft-text);
  font-weight: var(--fw-semibold);
}
.nav__item.is-active::before {
  content: "";
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 20px;
  border-radius: 999px;
  background: var(--primary);
}
.nav__label { flex: 1; }
.nav__badge {
  min-width: 20px; height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: var(--text-2xs);
  font-weight: var(--fw-bold);
  display: grid; place-items: center;
}

.sidebar__footer { display: flex; flex-direction: column; gap: var(--sp-2); padding-top: var(--sp-2); }
.sidebar__user {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-2);
  border-radius: var(--radius-md);
}
.sidebar__user-meta { min-width: 0; }
.sidebar__user-name { font-weight: var(--fw-semibold); font-size: var(--text-base); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar__user-sub { font-size: var(--text-xs); color: var(--text-subtle); }

/* ---- Main area ---- */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100dvh;
}
.topbar {
  display: none;
  align-items: center;
  gap: var(--sp-3);
  height: var(--topbar-h);
  padding: 0 var(--sp-4);
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
  z-index: var(--z-nav);
}
.topbar__brand { display: flex; align-items: center; gap: var(--sp-2); font-weight: var(--fw-bold); font-size: var(--text-lg); }
.topbar__brand .sidebar__logo { width: 32px; height: 32px; font-size: var(--text-base); }
.topbar__spacer { flex: 1; }

.content {
  flex: 1;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--sp-8) var(--sp-8) var(--sp-16);
}

/* Chat screen: pin the whole page to the viewport so the composer stays at the
   bottom and only the message stream scrolls (the stream is the scroll box). */
.main:has(.chat) { height: 100dvh; }
.content:has(.chat) { min-height: 0; overflow: hidden; padding-bottom: var(--sp-6); }

/* ---- Page header ---- */
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-6);
  flex-wrap: wrap;
}
.page-head__title { font-size: var(--text-2xl); font-weight: var(--fw-bold); letter-spacing: -0.02em; }
.page-head__subtitle { color: var(--text-muted); font-size: var(--text-base); margin-top: 2px; }
.page-head__actions { display: flex; gap: var(--sp-2); align-items: center; }

/* ---- Bottom nav (mobile) ---- */
.bottomnav { display: none; }

/* ===== Responsive ====================================================== */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar { display: flex; }
  .bottomnav {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    position: sticky;
    bottom: 0;
    z-index: var(--z-nav);
    height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: saturate(1.4) blur(12px);
    border-top: 1px solid var(--border);
  }
  .bottomnav__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border: none;
    background: transparent;
    color: var(--text-subtle);
    font-size: var(--text-2xs);
    font-weight: var(--fw-medium);
    position: relative;
  }
  .bottomnav__item .icon { width: 22px; height: 22px; }
  .bottomnav__item.is-active { color: var(--primary); }
  .bottomnav__badge {
    position: absolute;
    top: 6px;
    left: calc(50% + 8px);
    min-width: 16px; height: 16px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--danger);
    color: #fff;
    font-size: 9px;
    font-weight: var(--fw-bold);
    display: grid; place-items: center;
  }
  .content { padding: var(--sp-5) var(--sp-4) calc(var(--bottomnav-h) + var(--sp-8)); }
  /* Chat fills the space between the top bar and bottom nav; no extra bottom pad. */
  .content:has(.chat) { padding-bottom: var(--sp-3); }
  .page-head__title { font-size: var(--text-xl); }
}

@media (max-width: 560px) {
  .content { padding-left: var(--sp-4); padding-right: var(--sp-4); }
}

/* ===== Auth / login ==================================================== */
.auth {
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  min-height: 100dvh;
}
.auth__aside {
  position: relative;
  overflow: hidden;
  color: #fff;
  background: linear-gradient(145deg, var(--indigo-700), var(--indigo-500) 55%, var(--teal-600));
  display: flex;
  align-items: center;
  padding: var(--sp-12);
}
.auth__aside::after {
  content: "";
  position: absolute; inset: 0;
  background: radial-gradient(600px 400px at 85% 15%, rgba(255,255,255,0.18), transparent 60%),
    radial-gradient(500px 500px at 10% 90%, rgba(255,255,255,0.12), transparent 60%);
}
.auth__aside-inner { position: relative; max-width: 440px; }
.auth__logo {
  width: 56px; height: 56px;
  border-radius: var(--radius-lg);
  display: grid; place-items: center;
  background: rgba(255,255,255,0.16);
  backdrop-filter: blur(6px);
  font-size: var(--text-2xl); font-weight: var(--fw-bold);
  margin-bottom: var(--sp-6);
}
.auth__headline { font-size: var(--text-3xl); font-weight: var(--fw-bold); letter-spacing: -0.03em; line-height: 1.1; }
.auth__tagline { margin-top: var(--sp-3); font-size: var(--text-lg); opacity: 0.9; }
.auth__points { list-style: none; padding: 0; margin: var(--sp-8) 0 0; display: flex; flex-direction: column; gap: var(--sp-3); }
.auth__points li { display: flex; align-items: center; gap: var(--sp-3); font-weight: var(--fw-medium); opacity: 0.95; }

.auth__main { position: relative; display: flex; flex-direction: column; background: var(--bg); background-image: var(--bg-tint); }
.auth__topbar { display: flex; justify-content: flex-end; gap: var(--sp-2); padding: var(--sp-5); }
.auth__card-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: var(--sp-6) var(--sp-6) var(--sp-12); }
.auth__card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: var(--sp-8);
}
.auth__brand-sm { display: none; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-2); }
.auth__brand-sm .sidebar__wordmark { font-size: var(--text-xl); font-weight: var(--fw-bold); }
.auth__title { font-size: var(--text-xl); font-weight: var(--fw-bold); letter-spacing: -0.02em; }
.auth__invite {
  display: flex; align-items: flex-start; gap: var(--sp-2);
  font-size: var(--text-sm); color: var(--text-muted);
  background: var(--surface-2); border: 1px solid var(--border);
  padding: var(--sp-3); border-radius: var(--radius-md);
}
.auth__invite .icon { color: var(--accent); margin-top: 1px; }
.auth__footer { margin-top: var(--sp-5); color: var(--text-subtle); font-size: var(--text-sm); }

.auth__back {
  display: inline-flex; align-items: center; gap: 6px;
  border: none; background: transparent; color: var(--text-muted);
  font-weight: var(--fw-medium); font-size: var(--text-sm);
  padding: 0; align-self: flex-start;
}
@media (hover: hover) { .auth__back:hover { color: var(--text); } }
.auth__people { display: flex; flex-direction: column; gap: var(--sp-2); }
.auth__person {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface); text-align: left;
  transition: border-color var(--dur-fast), background var(--dur-fast), transform var(--dur-fast);
}
@media (hover: hover) { .auth__person:hover { border-color: var(--primary); background: var(--surface-2); } }
.auth__person:active { transform: scale(0.99); }
.auth__person-name { flex: 1; font-weight: var(--fw-semibold); }
.auth__person .icon:last-child { color: var(--text-subtle); }

@media (max-width: 860px) {
  .auth { grid-template-columns: 1fr; }
  .auth__aside { display: none; }
  .auth__brand-sm { display: flex; }
}

/* ---- Touch screens: no tap flash, no accidental text selection on controls ----
   (:hover rules are all wrapped in @media (hover: hover), so a tap never leaves a
   "stuck" hover colour behind.) Text fields and message/notes text stay selectable. */
html { -webkit-tap-highlight-color: transparent; }
@media (pointer: coarse) {
  button, a, label, summary, [role="button"], [role="tab"], .nav, .nav__item, .chip, .iconbtn,
  .ev, .drow, .week-col__head, .month-cell, .task-row {
    -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  }
  input, textarea, select, [contenteditable], .msg__bubble, .msg__bubble * { -webkit-user-select: text; user-select: text; }
}
