:root {
  --color-primary: #0891b2;
  --color-secondary: #22d3ee;
  --color-cta: #22c55e;
  --color-background: #ecfeff;
  --color-surface: #ffffff;
  --color-text: #164e63;
  --color-muted: #5b8a99;
  --color-border: #a5f3fc;
  --color-danger: #dc2626;
  --color-morning: #0891b2;
  --color-afternoon: #0e7490;
  --color-fullday: #155e75;
  --font-heading: 'Poppins', system-ui, sans-serif;
  --font-body: 'Open Sans', system-ui, sans-serif;
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --radius: 10px;
  --transition: 180ms ease;
  --max: 720px;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-body);
  color: var(--color-text);
  background:
    radial-gradient(1200px 500px at 10% -10%, #cffafe 0%, transparent 55%),
    radial-gradient(900px 400px at 100% 0%, #a5f3fc 0%, transparent 50%),
    var(--color-background);
}

h1,
h2,
h3 {
  font-family: var(--font-heading);
  font-weight: 600;
  margin: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 1.15em;
  height: 1.15em;
  display: inline-block;
  vertical-align: -0.2em;
}

.muted {
  color: var(--color-muted);
}

.error {
  color: var(--color-danger);
  margin: var(--space-sm) 0 0;
  font-size: 0.9rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  border: none;
  border-radius: 8px;
  padding: 12px 20px;
  font-weight: 600;
  transition: background var(--transition), opacity var(--transition), transform var(--transition);
}

.btn:hover {
  opacity: 0.92;
}

.btn:active {
  transform: scale(0.98);
}

.btn:focus-visible,
.icon-btn:focus-visible,
.tab:focus-visible,
.auth-tab:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--color-cta);
  color: #fff;
}

.btn-secondary {
  background: var(--color-primary);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  color: var(--color-primary);
  border: 1px solid var(--color-border);
}

.btn-danger {
  background: var(--color-danger);
  color: #fff;
}

.btn-sm {
  padding: 8px 12px;
  font-size: 0.875rem;
}

.btn-block {
  width: 100%;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--color-text);
  transition: background var(--transition);
}

.icon-btn:hover {
  background: rgba(8, 145, 178, 0.12);
}

label {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  font-size: 0.875rem;
  font-weight: 600;
}

input,
select,
textarea {
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: #fff;
  font-weight: 400;
}

/* Boot / Auth */
.boot-screen,
.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--space-lg);
}

.boot-card,
.auth-shell {
  width: min(100%, 420px);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-xl);
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--color-primary);
  color: #fff;
  display: grid;
  place-items: center;
  margin-bottom: var(--space-md);
}

.auth-brand h1 {
  font-size: 1.75rem;
  letter-spacing: -0.02em;
}

.auth-brand .muted {
  margin: var(--space-sm) 0 var(--space-lg);
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-sm);
  margin-bottom: var(--space-lg);
}

.auth-tab {
  border: 1px solid var(--color-border);
  background: transparent;
  border-radius: 8px;
  padding: 10px;
  font-weight: 600;
  color: var(--color-muted);
  transition: background var(--transition), color var(--transition);
}

.auth-tab.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

/* App shell */
#app {
  max-width: var(--max);
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: var(--space-xl);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md);
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(236, 254, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--color-border);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.05rem;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.topbar-name {
  font-size: 0.85rem;
  color: var(--color-muted);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-menu-wrap {
  position: relative;
}

.account-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  min-width: 180px;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: var(--space-xs);
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 10px 12px;
  border-radius: 6px;
  font-weight: 500;
  color: var(--color-text);
  cursor: pointer;
  transition: background var(--transition);
}

.menu-item:hover {
  background: rgba(8, 145, 178, 0.1);
}

.tabs {
  display: flex;
  gap: var(--space-sm);
  padding: var(--space-md);
  overflow-x: auto;
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 10px 14px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--color-muted);
  font-weight: 600;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition);
}

.tab.active {
  background: #fff;
  border-color: var(--color-border);
  color: var(--color-primary);
}

.main {
  padding: 0 var(--space-md) var(--space-lg);
}

.week-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
}

.week-nav h2 {
  font-size: 1rem;
}

.week-grid {
  display: grid;
  gap: var(--space-sm);
  margin-bottom: var(--space-lg);
}

.day-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-md);
}

.day-card.is-today {
  border-color: var(--color-primary);
}

.day-card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: var(--space-sm);
  font-weight: 600;
}

.day-card-head .date {
  font-size: 0.8rem;
  color: var(--color-muted);
  font-weight: 500;
}

.slot-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
}

.chip.morning {
  background: var(--color-morning);
}
.chip.afternoon {
  background: var(--color-afternoon);
}
.chip.fullday {
  background: var(--color-fullday);
}

.chip.ghost {
  background: #e0f2fe;
  color: var(--color-muted);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  margin: var(--space-lg) 0 var(--space-md);
  flex-wrap: wrap;
}

.section-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.section-head h3 {
  font-size: 1rem;
}

.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.item {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-md);
  display: flex;
  gap: var(--space-md);
  align-items: flex-start;
  justify-content: space-between;
}

.item-body {
  flex: 1;
  min-width: 0;
}

.item-title {
  font-weight: 600;
  margin-bottom: 2px;
}

.item-meta {
  font-size: 0.85rem;
  color: var(--color-muted);
}

.item-actions {
  display: flex;
  gap: var(--space-xs);
}

.empty {
  padding: var(--space-lg);
  text-align: center;
  color: var(--color-muted);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.5);
}

.filters {
  margin-bottom: var(--space-md);
}

.filters label {
  max-width: 280px;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: end center;
}

@media (min-width: 640px) {
  .modal {
    place-items: center;
  }
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(22, 78, 99, 0.35);
}

.modal-card {
  position: relative;
  width: min(100%, 480px);
  max-height: 90vh;
  overflow: auto;
  background: #fff;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: var(--space-lg);
  z-index: 1;
}

@media (min-width: 640px) {
  .modal-card {
    border-radius: var(--radius);
  }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.weekday-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--space-sm);
}

.weekday-grid label {
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 4px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
}

.weekday-grid input {
  width: auto;
  margin: 0;
}

.slot-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.slot-row label {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  cursor: pointer;
}

.form-actions {
  display: flex;
  gap: var(--space-sm);
  justify-content: flex-end;
  margin-top: var(--space-sm);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--color-text);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 60;
  max-width: min(90vw, 360px);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
  }
}
