:root {
  --ink: #242424;
  --muted: #777b82;
  --line: rgba(34, 42, 53, .10);
  --soft: #f7f7f7;
  --surface: #ffffff;
  --green: #157f3b;
  --green-bg: #edf8f0;
  --amber: #9a5b00;
  --amber-bg: #fff5df;
  --red: #a63b32;
  --red-bg: #fff0ee;
  --blue: #335f9a;
  --blue-bg: #eef4fb;
  --shadow: 0 1px 5px -4px rgba(19, 19, 22, .7), 0 0 0 1px rgba(34, 42, 53, .08), 0 4px 14px rgba(34, 42, 53, .06);
}

* { box-sizing: border-box; }
html { background: #fff; color: var(--ink); font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif; }
body { margin: 0; min-height: 100vh; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 3px solid rgba(51, 95, 154, .25); outline-offset: 2px; }
[hidden] { display: none !important; }

.topbar {
  height: 64px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(16px, 3vw, 42px);
  position: sticky;
  top: 0;
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(14px);
  z-index: 50;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 700; letter-spacing: -.03em; }
.brand-mark { width: 21px; height: 21px; border: 6px solid var(--ink); border-radius: 50%; position: relative; flex: 0 0 auto; }
.brand-mark::after { content: ""; position: absolute; width: 7px; height: 2px; background: var(--ink); right: -8px; top: 4px; transform: rotate(-45deg); }
.topbar-actions { display: flex; align-items: center; gap: 9px; }
.automation-pill { font-size: 12px; font-weight: 600; background: var(--green-bg); color: var(--green); border-radius: 999px; padding: 7px 11px; display: flex; align-items: center; gap: 7px; }
.pulse { width: 7px; height: 7px; border-radius: 50%; background: #21a552; box-shadow: 0 0 0 4px rgba(33, 165, 82, .12); }
.icon-button, .user-button, .toolbar-button {
  border: 0;
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.icon-button { width: 36px; height: 36px; display: grid; place-items: center; }
.icon-button svg, .button svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-button.loading svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.user-button { min-height: 36px; padding: 0 11px; display: flex; align-items: center; gap: 9px; font-size: 12px; font-weight: 600; }

.shell { width: min(1500px, 100%); margin: 0 auto; padding: 36px clamp(14px, 2.5vw, 34px) 80px; }
.calendar-intro { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 40px; align-items: end; margin-bottom: 30px; }
.eyebrow { font: 500 10px/1.3 "Roboto Mono", monospace; letter-spacing: .14em; margin: 0 0 10px; color: var(--muted); }
h1, h2, h3, p { margin-top: 0; }
.calendar-intro h1 { margin-bottom: 8px; font-size: clamp(34px, 4vw, 52px); line-height: 1.02; letter-spacing: -.055em; }
.calendar-intro > div > p:last-child { max-width: 720px; margin: 0; color: var(--muted); font-size: 14px; line-height: 1.65; }
.metrics { display: grid; grid-template-columns: repeat(3, minmax(125px, 1fr)); background: #fff; border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
.metrics article { padding: 15px 18px; min-width: 130px; }
.metrics article + article { border-left: 1px solid var(--line); }
.metric-label { display: block; color: var(--muted); font: 500 9px/1.2 "Roboto Mono", monospace; letter-spacing: .10em; margin-bottom: 5px; }
.metrics strong { font-size: 24px; letter-spacing: -.04em; margin-right: 5px; }
.metrics small { color: var(--muted); font-size: 11px; }

.calendar-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin-bottom: 14px; }
.week-navigation, .calendar-options { display: flex; align-items: center; gap: 8px; }
.toolbar-button { min-width: 35px; height: 35px; padding: 0 11px; font-weight: 600; }
.today-button { font-size: 12px; }
.week-navigation h2 { margin: 0 0 0 9px; font-size: 18px; letter-spacing: -.03em; }
.toggle-label { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); cursor: pointer; }
.toggle-label input { accent-color: var(--ink); }
.timezone-pill { color: var(--muted); background: var(--soft); border-radius: 999px; padding: 7px 10px; font: 500 10px/1 "Roboto Mono", monospace; }
.status-message { margin: 0 0 12px; border-radius: 8px; background: var(--soft); color: var(--muted); padding: 10px 13px; font-size: 12px; }

.calendar-layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 18px; align-items: start; }
.calendar-card, .detail-panel { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); }
.calendar-card { min-width: 0; overflow: hidden; }
.calendar-scroll { overflow: auto; max-height: min(72vh, 780px); }
.weekly-calendar { min-width: 1000px; }
.calendar-header { display: grid; grid-template-columns: 64px repeat(7, minmax(128px, 1fr)); position: sticky; top: 0; background: rgba(255, 255, 255, .97); backdrop-filter: blur(10px); z-index: 25; border-bottom: 1px solid var(--line); }
.calendar-corner { display: flex; align-items: center; justify-content: center; color: var(--muted); font: 500 9px/1 "Roboto Mono", monospace; border-right: 1px solid var(--line); }
.day-heading { min-height: 60px; display: flex; align-items: center; justify-content: center; gap: 7px; border-right: 1px solid var(--line); color: var(--muted); }
.day-heading span { text-transform: uppercase; font: 500 9px/1 "Roboto Mono", monospace; letter-spacing: .08em; }
.day-heading strong { color: var(--ink); font-size: 17px; }
.day-heading.today strong { width: 31px; height: 31px; display: grid; place-items: center; border-radius: 50%; background: var(--ink); color: #fff; }
.calendar-body { position: relative; display: grid; grid-template-columns: 64px repeat(7, minmax(128px, 1fr)); grid-template-rows: var(--calendar-height); min-height: var(--calendar-height); }
.time-axis { grid-column: 1; grid-row: 1; position: relative; border-right: 1px solid var(--line); z-index: 2; background: #fff; }
.time-axis span { position: absolute; right: 9px; transform: translateY(-50%); color: #999da2; font: 500 9px/1 "Roboto Mono", monospace; }
.day-column { position: relative; min-width: 0; border-right: 1px solid var(--line); background-image: repeating-linear-gradient(to bottom, transparent 0, transparent 23px, rgba(34, 42, 53, .055) 23px, rgba(34, 42, 53, .055) 24px); background-size: 100% 24px; transition: background-color .15s; }
.day-column.today { background-color: rgba(51, 95, 154, .025); }
.day-column.drop-target { background-color: rgba(51, 95, 154, .10); box-shadow: inset 0 0 0 2px rgba(51, 95, 154, .25); }
.calendar-event {
  grid-row: 1;
  position: relative;
  align-self: start;
  z-index: 8;
  margin: 0 4px;
  width: calc(100% - 8px);
  overflow: hidden;
  text-align: left;
  padding: 6px 7px;
  border: 0;
  border-left: 3px solid var(--blue);
  border-radius: 6px;
  background: var(--blue-bg);
  color: #203958;
  cursor: grab;
  box-shadow: 0 0 0 1px rgba(51, 95, 154, .12), 0 2px 5px rgba(35, 55, 80, .07);
}
.calendar-event:active { cursor: grabbing; }
.calendar-event.selected { box-shadow: 0 0 0 2px #242424, 0 3px 9px rgba(20, 20, 20, .14); }
.calendar-event.overdue { background: var(--red-bg); border-left-color: var(--red); color: #71322d; }
.calendar-event.complete { background: var(--green-bg); border-left-color: var(--green); color: #225a33; cursor: pointer; opacity: .78; }
.calendar-event span, .calendar-event strong, .calendar-event small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.calendar-event span { font: 500 9px/1.2 "Roboto Mono", monospace; opacity: .72; }
.calendar-event strong { font-size: 11px; line-height: 1.25; margin-top: 3px; }
.calendar-event small { font-size: 9px; opacity: .72; margin-top: 3px; }
.calendar-legend { min-height: 46px; display: flex; align-items: center; gap: 15px; padding: 10px 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; }
.calendar-legend span { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.calendar-legend small { margin-left: auto; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--blue); }
.legend-dot.overdue { background: var(--red); }
.legend-dot.complete { background: var(--green); }

.detail-panel { position: sticky; top: 82px; min-height: 420px; overflow: hidden; }
.detail-empty { padding: 64px 32px; text-align: center; color: var(--muted); }
.detail-empty-icon { width: 42px; height: 42px; margin: 0 auto 18px; border-radius: 50%; background: var(--soft); display: grid; place-items: center; color: var(--ink); }
.detail-empty h2 { color: var(--ink); font-size: 18px; margin-bottom: 8px; }
.detail-empty p { font-size: 12px; line-height: 1.55; }
.detail-content { padding: 21px; }
.detail-heading, .detail-section-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.subject-badge, .detail-status { border-radius: 999px; padding: 5px 8px; font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; background: var(--soft); }
.detail-status.upcoming { color: var(--blue); background: var(--blue-bg); }
.detail-status.overdue { color: var(--red); background: var(--red-bg); }
.detail-status.complete { color: var(--green); background: var(--green-bg); }
.detail-content > h2 { font-size: 21px; letter-spacing: -.035em; margin: 14px 0 7px; }
.detail-time { color: var(--muted); font-size: 11px; line-height: 1.5; }
.detail-section { border-top: 1px solid var(--line); padding-top: 17px; margin-top: 18px; }
.detail-section h3 { font-size: 12px; margin: 0 0 10px; }
.detail-section-title span { color: var(--muted); font-size: 10px; }
.section-help { color: var(--muted); font-size: 10px; line-height: 1.5; margin: -4px 0 11px; }
.task-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 7px; }
.task-list label { display: grid; grid-template-columns: 17px minmax(0, 1fr); gap: 8px; align-items: start; cursor: pointer; font-size: 11px; line-height: 1.45; }
.task-list input { margin: 1px 0 0; width: 15px; height: 15px; accent-color: var(--ink); }
.task-list input:checked + span { color: var(--muted); text-decoration: line-through; }
.schedule-form { display: grid; grid-template-columns: 1fr; gap: 8px; }
.schedule-form label, .auth-form label { display: grid; gap: 5px; color: var(--muted); font-size: 10px; font-weight: 600; }
.schedule-form input, .auth-form input { min-width: 0; width: 100%; height: 38px; border: 1px solid rgba(34, 42, 53, .16); border-radius: 7px; padding: 0 9px; background: #fff; color: var(--ink); font-size: 11px; }
.schedule-form .button { grid-column: 1 / -1; }
.button { min-height: 39px; border: 0; border-radius: 7px; padding: 0 13px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; text-decoration: none; font-size: 11px; font-weight: 700; cursor: pointer; }
.button:disabled { opacity: .45; cursor: not-allowed; }
.button-dark { background: var(--ink); color: #fff; box-shadow: inset 0 2px 0 rgba(255, 255, 255, .12); }
.button-light { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.full-button { width: 100%; margin-top: 9px; }
.handout-pending { margin: 12px 0 0; text-align: center; color: var(--muted); font-size: 10px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--ink); color: #fff; border-radius: 8px; padding: 10px 14px; font-size: 11px; font-weight: 600; opacity: 0; pointer-events: none; transition: .2s ease; z-index: 100; box-shadow: 0 10px 30px rgba(0, 0, 0, .18); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast[data-kind="error"] { background: var(--red); }

.auth-page { background: #f7f7f7; display: grid; place-items: center; padding: 24px; }
.auth-shell { width: min(430px, 100%); }
.auth-card { background: #fff; border-radius: 14px; padding: clamp(28px, 7vw, 42px); box-shadow: var(--shadow); }
.auth-brand { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 700; margin-bottom: 54px; }
.auth-card h1 { font-size: clamp(31px, 8vw, 42px); line-height: 1.04; letter-spacing: -.055em; margin-bottom: 12px; }
.auth-copy { color: var(--muted); font-size: 13px; line-height: 1.6; margin-bottom: 26px; }
.auth-form { display: grid; gap: 14px; }
.auth-form input { height: 44px; font-size: 14px; }
.auth-form .button { min-height: 44px; margin-top: 2px; font-size: 13px; }
.form-error { color: var(--red); min-height: 18px; margin: -3px 0; font-size: 11px; }
.setup-complete { padding: 16px; border-radius: 8px; background: var(--green-bg); color: var(--green); font-size: 13px; line-height: 1.55; }
.setup-complete p { margin: 5px 0 0; color: #315c3d; }

@media (max-width: 1120px) {
  .calendar-intro { grid-template-columns: 1fr; gap: 22px; }
  .compact-metrics { width: min(520px, 100%); }
  .calendar-layout { grid-template-columns: minmax(0, 1fr) 300px; }
}

@media (max-width: 900px) {
  .automation-pill { display: none; }
  .calendar-layout { grid-template-columns: 1fr; }
  .detail-panel { position: static; min-height: 0; }
  .calendar-scroll { max-height: 68vh; }
  .calendar-legend small { display: none; }
}

@media (max-width: 640px) {
  .topbar { height: 58px; }
  .brand { font-size: 13px; }
  .user-button #currentUser { display: none; }
  .shell { padding-top: 25px; }
  .calendar-intro { margin-bottom: 24px; }
  .calendar-intro h1 { font-size: 36px; }
  .metrics { grid-template-columns: repeat(3, 1fr); }
  .metrics article { min-width: 0; padding: 12px 10px; }
  .metrics strong { display: block; font-size: 21px; }
  .calendar-toolbar { align-items: flex-start; flex-direction: column; }
  .calendar-options { width: 100%; justify-content: space-between; }
  .week-navigation { width: 100%; }
  .week-navigation h2 { font-size: 15px; margin-left: auto; }
  .calendar-scroll { max-height: 65vh; }
  .calendar-legend { gap: 9px; overflow-x: auto; }
  .schedule-form { grid-template-columns: 1fr; }
  .schedule-form .button { grid-column: 1; }
  .auth-page { padding: 14px; }
  .auth-card { padding: 28px 22px; }
}
