/* -------- Theme & base -------- */
:root{
  --bg: #0b1220;
  --panel: #0f1624;
  --panel-2: #0b1320;
  --border: #1c2a3a;
  --text: #e7eef7;
  --muted: #94a6be;
  --accent: #4da3ff;
  --danger: #ff6475;

  /* Fixed calendar cell size (desktop default) */
  --cell-w: 160px;
  --cell-h: 120px;
  --gap: 10px;

  /* Controls */
  --btn-radius: 12px;
  --btn-pad-y: 10px;
  --btn-pad-x: 12px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body{
  margin: 0;
  background: radial-gradient(1200px 800px at 20% -10%, #132039 0%, #0b1220 55%);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.container{
  max-width: 1200px;
  margin: 12px auto 56px;
  padding: 0 12px;
}

/* -------- Header (sticky on mobile) -------- */
.app-header{
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(180deg, rgba(11,18,32,.96), rgba(11,18,32,.92));
  backdrop-filter: saturate(140%) blur(6px);
  border-bottom: 1px solid rgba(255,255,255,.04);
  padding-bottom: 8px;
  margin-bottom: 10px;

  display:flex; align-items:center; justify-content:space-between; gap:12px; flex-wrap:wrap;
}
.app-header h1{ margin: 8px 0 4px; font-size: clamp(18px, 2.6vw, 28px); }

.nav{
  display:flex; gap:8px; flex-wrap:wrap;
  overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch;
}
.nav::-webkit-scrollbar{ height:8px; }
.nav::-webkit-scrollbar-thumb{ background:#22324a; border-radius:999px; }
.nav::-webkit-scrollbar-track{ background:transparent; }

button, input, textarea{
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--btn-radius);
  padding: var(--btn-pad-y) var(--btn-pad-x);
  font-size: 14px;
  min-height: 44px;          /* touch target */
  transition: transform .08s ease, box-shadow .2s ease, border-color .2s ease, background .2s ease;
}
button:hover{ transform: translateY(-1px); box-shadow: 0 6px 18px rgba(0,0,0,.22); border-color:#2f4158; }
button:active{ transform: translateY(0); box-shadow:none; }
button.danger{ border-color:#512b33; background:#201016; color:#ffccd2; }
button.danger:hover{ border-color:#7a3d48; }

/* -------- Calendar scaffold -------- */
.calendar-wrap{
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  overflow-x: auto;              /* IMPORTANT: horizontal scroll on small screens */
  -webkit-overflow-scrolling: touch;
}

/* Days-of-week header aligned to fixed cell width */
.dow{
  display: grid;
  grid-template-columns: repeat(7, var(--cell-w));
  gap: var(--gap);
  min-width: max-content;
  padding: 2px 2px 8px;
  color: var(--muted);
  font-size: 12px;
}
.dow > div{
  width: var(--cell-w);
  text-align: left;
  padding-left: 6px;
}

/* Fixed-size grid */
.grid{
  display: grid;
  grid-template-columns: repeat(7, var(--cell-w));
  grid-auto-rows: var(--cell-h);
  gap: var(--gap);
  min-width: max-content;        /* Allow wider than viewport */
}

.day{
  width: var(--cell-w);
  height: var(--cell-h);
  background: #0d1422;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  display:flex; flex-direction:column; gap:6px;
  cursor: pointer;
  transition: transform .06s ease, border-color .2s ease, background .2s ease;
}
.day:hover{ transform: translateY(-1px); border-color:#2f4158; background:#0e1728; }
.day .date{ font-weight:600; color:var(--muted); font-size:12px; }
.day.today{ outline:2px solid var(--accent); outline-offset:-2px; }
.events{ display:flex; flex-direction:column; gap:4px; overflow:hidden; }
.event-pill{
  font-size: 12px;
  padding: 4px 6px;
  border: 1px solid #243041;
  border-radius: 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: #0b1320;
}
.event-pill.google{ border-style: dashed; opacity:.95; }
.event-pill.ms{ border-style: dotted; opacity:.95; }

/* -------- Dialogs -------- */
dialog{
  border: none; padding: 0;
  background: var(--panel); color: var(--text);
  border-radius: 16px;
  box-shadow: 0 25px 60px rgba(0,0,0,.35);
  max-width: min(760px, 96vw);
  width: 100%;
  max-height: 92vh;
}
dialog::backdrop{ background: rgba(3,8,20,.55); backdrop-filter: blur(3px); }

.modal{ display:flex; flex-direction:column; max-height:92vh; }
.modal-header{
  position: sticky; top: 0; z-index: 2;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(15,22,36,0.98), rgba(15,22,36,0.92));
}
.modal-header h3{ margin: 0; font-size: 18px; }
.modal-body{
  overflow: auto; padding: 16px;
  display:flex; flex-direction:column; gap:12px;
}
.modal-actions{
  position: sticky; bottom: 0; z-index: 2;
  display:flex; gap:8px; flex-wrap:wrap; justify-content:flex-end;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: linear-gradient(0deg, rgba(15,22,36,0.98), rgba(15,22,36,0.92));
}
label{ display:flex; flex-direction:column; gap:6px; font-size:14px; color:var(--muted); }
input, textarea{ width:100%; }

/* Day view event rows */
.event-row{
  display:grid;
  grid-template-columns: 96px 1fr;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-2);
  margin-bottom: 10px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.02);
}
.event-row .time{ color: var(--muted); font-size: 13px; }
.event-row .title{ font-size: 14px; line-height: 1.35; }
.event-row .muted{ color: var(--muted); font-size: 12px; margin-top: 4px; }
.event-row .actions{ grid-column: 1 / -1; display:flex; flex-wrap:wrap; gap:8px; }

/* Smoothness & motion */
.smooth-enter { animation: fadeIn .18s ease-out; }
@keyframes fadeIn { from{ opacity:0; transform:translateY(4px); } to{ opacity:1; transform:none; } }

/* -------- Responsive tweaks -------- */
/* Tablets */
@media (max-width: 900px){
  :root{ --cell-w: 150px; --cell-h: 115px; }
}

/* Large phones / small tablets */
@media (max-width: 720px){
  :root{ --cell-w: 140px; --cell-h: 110px; }
  .app-header{ gap: 8px; }
  .event-row{ grid-template-columns: 1fr; } /* time stacks */
}

/* Phones */
@media (max-width: 560px){
  :root{
    --cell-w: 130px; --cell-h: 105px;
    --btn-radius: 14px;
  }
  .dow{ font-size: 11px; }
  .day .date{ font-size: 11px; }
}

/* Small phones */
@media (max-width: 420px){
  :root{ --cell-w: 120px; --cell-h: 100px; }
  .container{ margin-bottom: 70px; } /* room for iOS safe area */
  .modal-header h3{ font-size: 16px; }
}

@supports (padding: max(0px)){
  .modal-actions{ padding-bottom: max(12px, env(safe-area-inset-bottom)); }
}