/* MyCalendar — app shell */

:root {
  color-scheme: light;
  --bg: #ffffff;
  --bg-elev: #ffffff;
  --bg-sunk: #f6f7f9;
  --surface-2: #f1f3f4;
  --text: #1f2125;
  --text-dim: #5f6368;
  --line: #e0e3e7;
  --line-soft: #eceff1;
  --accent: #1a73e8;
  --accent-weak: #e8f0fe;
  --danger: #d93025;
  --sat: #1a73e8;
  --sun: #d93025;
  --today: #1a73e8;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(60, 64, 67, .18), 0 2px 10px rgba(60, 64, 67, .08);
  --topbar-h: 56px;
  --side-w: 264px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #17181b;
    --bg-elev: #202124;
    --bg-sunk: #131416;
    --surface-2: #2a2b2f;
    --text: #e8eaed;
    --text-dim: #9aa0a6;
    --line: #34363a;
    --line-soft: #292a2e;
    --accent: #8ab4f8;
    --accent-weak: #1f2a3d;
    --danger: #f28b82;
    --sat: #8ab4f8;
    --sun: #f28b82;
    --today: #8ab4f8;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 2px 12px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", Meiryo, system-ui, sans-serif;
  overflow: hidden;
}

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.g-logo { stroke: none; width: 18px; height: 18px; }

/* ---------- topbar ---------- */

.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-elev);
  position: relative;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 500;
  letter-spacing: .01em;
  white-space: nowrap;
}
.brand img { border-radius: 6px; }

.nav { display: flex; align-items: center; gap: 4px; margin-left: 8px; }

.period {
  font-size: 17px;
  font-weight: 500;
  margin: 0 0 0 6px;
  white-space: nowrap;
}

.spacer { flex: 1 1 auto; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  flex: none;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { transform: scale(.95); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #10233f; } }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.full { width: 100%; }
.btn.danger { color: var(--danger); border-color: transparent; }
.btn.google { height: 44px; padding: 0 20px; }

.link-btn {
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 6px;
}
.link-btn:hover { background: var(--accent-weak); }

.segmented { display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.seg {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  padding: 7px 14px;
  cursor: pointer;
}
.seg[aria-pressed="true"] { background: var(--accent-weak); color: var(--accent); font-weight: 500; }

.account { border: 0; background: none; padding: 0; cursor: pointer; border-radius: 999px; line-height: 0; flex: none; }
.account img { border-radius: 999px; background: var(--surface-2); }

.status-bar {
  padding: 7px 14px;
  background: var(--accent-weak);
  color: var(--text);
  font-size: 13px;
  border-bottom: 1px solid var(--line);
  text-align: center;
}
.status-bar.error { background: color-mix(in srgb, var(--danger) 14%, transparent); }

/* ---------- layout ---------- */

.layout {
  display: flex;
  height: calc(100% - var(--topbar-h));
  min-height: 0;
}

.sidebar {
  width: var(--side-w);
  flex: none;
  border-right: 1px solid var(--line);
  background: var(--bg-elev);
  padding: 14px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }

.account-card { display: flex; align-items: center; gap: 10px; padding: 4px 6px; }
.side-avatar { border-radius: 999px; background: var(--surface-2); }
.account-meta { min-width: 0; }
.account-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-email { color: var(--text-dim); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.side-section { flex: 1 1 auto; min-height: 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 0 6px 6px; gap: 6px; }
.side-head h2 { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--text-dim); margin: 0; }
.side-head-actions { display: flex; gap: 2px; font-size: 12px; }

.calendar-list { display: flex; flex-direction: column; gap: 1px; }

.cal-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
}
.cal-item:hover { background: var(--surface-2); }
.cal-item input { position: absolute; opacity: 0; pointer-events: none; }
.cal-box {
  width: 16px; height: 16px; flex: none;
  border-radius: 4px;
  border: 2px solid var(--c, var(--text-dim));
  display: inline-flex; align-items: center; justify-content: center;
}
.cal-item input:checked + .cal-box { background: var(--c, var(--accent)); }
.cal-box svg { width: 12px; height: 12px; stroke: #fff; stroke-width: 3; opacity: 0; }
.cal-item input:checked + .cal-box svg { opacity: 1; }
.cal-item input:focus-visible + .cal-box { outline: 2px solid var(--accent); outline-offset: 2px; }
.cal-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.side-footer { display: flex; flex-direction: column; gap: 6px; border-top: 1px solid var(--line-soft); padding-top: 10px; }

.muted { color: var(--text-dim); }
.small { font-size: 12px; }
.center { text-align: center; }
.error { color: var(--danger); font-size: 13px; }

/* ---------- gate ---------- */

.gate { flex: 1; display: grid; place-items: center; padding: 24px 16px; overflow-y: auto; }
.gate-card {
  max-width: 420px;
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 32px 24px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg-elev);
  box-shadow: var(--shadow);
}
.gate-card h2 { margin: 0; font-size: 20px; }
.gate-card p { margin: 0; }

/* ---------- month grid ---------- */

.month { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.dow-row, .grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }

.dow-row { border-bottom: 1px solid var(--line); }
.dow { text-align: center; padding: 6px 0; font-size: 11px; color: var(--text-dim); font-weight: 500; }
.dow.sun { color: var(--sun); }
.dow.sat { color: var(--sat); }

.grid {
  flex: 1 1 auto;
  min-height: 0;
  grid-auto-rows: minmax(0, 1fr);
}

/* 左右スワイプで前月・翌月へ（3面のトラックを指に追従させる） */
.month-viewport {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  touch-action: pan-y;
}
.month-track {
  display: flex;
  width: 300%;
  height: 100%;
  transform: translate3d(-33.3333%, 0, 0);
  will-change: transform;
}
.month-track > .grid {
  flex: 0 0 33.3333%;
  width: 33.3333%;
  height: 100%;
}
.month-track.dragging { cursor: grabbing; }
.month-track.dragging .cell { cursor: grabbing; }

.cell {
  border-right: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
  padding: 2px 3px 4px;
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: pointer;
  background: var(--bg);
}
.cell:nth-child(7n) { border-right: 0; }
.cell:hover { background: var(--bg-sunk); }
.cell.other { background: var(--bg-sunk); }
.cell.other .num { color: var(--text-dim); opacity: .7; }

/* 予定がある日は背景に色を敷く */
.cell.has { background: color-mix(in srgb, var(--accent) 9%, var(--bg)); }
.cell.has.other { background: color-mix(in srgb, var(--accent) 6%, var(--bg-sunk)); }
.cell.has:hover { background: color-mix(in srgb, var(--accent) 16%, var(--bg)); }
.cell.today.has { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--today) 45%, transparent); }

.cell-head { text-align: center; padding-top: 2px; }
.num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
}
.cell.sun .num { color: var(--sun); }
.cell.sat .num { color: var(--sat); }
.cell.today .num { background: var(--today); color: #fff; }
@media (prefers-color-scheme: dark) { .cell.today .num { color: #10233f; } }

.chips { display: flex; flex-direction: column; gap: 2px; overflow: hidden; }

.chip {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 11.5px;
  line-height: 1.45;
  text-align: left;
  padding: 1px 4px;
  border-radius: 5px;
  cursor: pointer;
  overflow: hidden;
  white-space: nowrap;
}
.chip:hover { background: var(--surface-2); }
.chip .dot { width: 8px; height: 8px; border-radius: 999px; background: var(--c); flex: none; }
.chip .time { color: var(--text-dim); flex: none; font-variant-numeric: tabular-nums; }
.chip .title { overflow: hidden; text-overflow: ellipsis; }
.chip.allday { background: var(--c); color: #fff; padding-left: 6px; }
.chip.allday .dot { display: none; }
.chip.allday:hover { filter: brightness(1.08); }

.more { border: 0; background: none; color: var(--text-dim); font: inherit; font-size: 11px; text-align: left; padding: 0 5px; cursor: pointer; }
.more:hover { text-decoration: underline; }

/* ---------- agenda ---------- */

.agenda { flex: 1; overflow-y: auto; padding: 8px 0 40px; }
.agenda-day { display: grid; grid-template-columns: 92px 1fr; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line-soft); }
.agenda-date { color: var(--text-dim); font-size: 13px; padding-top: 6px; }
.agenda-date.today { color: var(--today); font-weight: 600; }
.agenda-date .d { font-size: 20px; font-weight: 500; display: block; line-height: 1.2; color: var(--text); }
.agenda-date.today .d { color: var(--today); }
.agenda-list { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

.row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
  min-width: 0;
}
.row:hover { background: var(--surface-2); }
.row .dot { width: 10px; height: 10px; border-radius: 999px; background: var(--c); flex: none; align-self: center; }
.row .time { color: var(--text-dim); font-size: 12.5px; flex: none; min-width: 84px; font-variant-numeric: tabular-nums; }
.row .title { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .cal { color: var(--text-dim); font-size: 11.5px; flex: none; max-width: 30%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.empty { padding: 48px 16px; text-align: center; color: var(--text-dim); }

/* ---------- dialogs ---------- */

dialog.sheet {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0;
  width: min(480px, calc(100vw - 32px));
  max-height: min(78vh, 720px);
  background: var(--bg-elev);
  color: var(--text);
  box-shadow: var(--shadow);
  overflow: hidden;
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, .42); backdrop-filter: blur(2px); }

.sheet-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 10px 14px 18px;
  border-bottom: 1px solid var(--line-soft);
  position: sticky;
  top: 0;
  background: var(--bg-elev);
}
.sheet-head h3 { margin: 0; font-size: 16px; font-weight: 500; flex: 1; overflow: hidden; text-overflow: ellipsis; }
.sheet-body { padding: 14px 18px 18px; overflow-y: auto; max-height: calc(78vh - 60px); }

.sheet-actions { display: flex; align-items: center; gap: 8px; margin-top: 18px; }

.field { display: block; margin-bottom: 10px; }
.field-label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 5px; }
.field input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

code {
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: .92em;
  word-break: break-all;
}

.detail { display: grid; grid-template-columns: 22px 1fr; gap: 10px 10px; align-items: start; margin-bottom: 12px; }
.detail svg { color: var(--text-dim); margin-top: 2px; }
.detail .v { min-width: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.detail a { color: var(--accent); }
.badge { display: inline-flex; align-items: center; gap: 6px; }
.badge .dot { width: 10px; height: 10px; border-radius: 999px; background: var(--c); flex: none; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #202124;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 60;
  max-width: calc(100vw - 32px);
  text-align: center;
}
@media (prefers-color-scheme: dark) { .toast { background: #e8eaed; color: #202124; } }

.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 25; }

.only-narrow { display: none; }

/* ---------- responsive ---------- */

@media (max-width: 860px) {
  .only-narrow { display: inline-flex; }
  .brand span { display: none; }
  .period { font-size: 15px; }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 26;
    width: 280px;
    transform: translateX(-100%);
    transition: transform .18s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }

  .agenda-day { grid-template-columns: 72px 1fr; padding: 10px 12px; }
  .row .time { min-width: 68px; }
  .row .cal { display: none; }

  dialog.sheet {
    width: 100vw;
    max-width: 100vw;
    margin: auto 0 0;
    border-radius: 16px 16px 0 0;
    max-height: 84vh;
  }
  .sheet-body { padding-bottom: max(18px, env(safe-area-inset-bottom)); }
}

@media (max-width: 560px) {
  .nav .btn.ghost { padding: 0 10px; }
  .chip .time { display: none; }
  .seg { padding: 7px 10px; }
  .brand img { display: none; }
}
