/* MyCalendar — elegant, professional calendar UI (desktop + mobile) */
:root {
  --brand: #2563eb;
  --brand-hover: #1d4ed8;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f8fafc;
  --surface: #ffffff;
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --radius: 12px;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #ca8a04;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #f1f5f9;
    --muted: #94a3b8;
    --line: #334155;
    --bg: #0f172a;
    --surface: #1e293b;
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.4);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.5);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
button { font: inherit; cursor: pointer; border: none; background: transparent; }

/* ---------- header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 800;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}
.brand span { color: var(--brand); }
.header-nav { display: flex; gap: 0.6rem; align-items: center; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  transition: transform 0.05s ease, box-shadow 0.15s, background 0.15s;
}
.btn:hover { background: #f1f5f9; border-color: #cbd5e1; }
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}
.btn-primary:hover { background: var(--brand-hover); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: #fef2f2; }

/* ---------- layout ---------- */
.app-main { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }
.flash {
  padding: 0.85rem 1rem; border-radius: 8px; margin-bottom: 1rem;
  font-size: 0.95rem; border: 1px solid transparent;
}
.flash-error { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.flash-success { background: #f0fdf4; color: #166534; border-color: #bbf7d0; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.card h3 { font-size: 1rem; margin-bottom: 0.5rem; color: var(--ink); font-weight: 700; letter-spacing: -0.01em; }
.card p { color: var(--muted); font-size: 0.95rem; margin-bottom: 0.75rem; }

.field {
  display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 0.9rem;
}
.field label { font-size: 0.85rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.field input, .field textarea, .field select {
  width: 100%; padding: 0.6rem 0.75rem; border: 1px solid var(--line);
  border-radius: 8px; background: var(--surface); color: var(--ink); font-size: 0.95rem;
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgb(37 99 235 / 0.15);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; }

/* ---------- calendar ---------- */
.calendar-page { display: flex; flex-direction: column; gap: 1rem; }
.calendar-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.75rem; flex-wrap: wrap;
}
.month-title { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.03em; white-space: nowrap; }
.today-btn { padding: 0.45rem 0.9rem; font-size: 0.9rem; }

.calendar-grid-wrap { overflow-x: hidden; }
.calendar-grid { width: 100%; }
.grid-weekdays {
  display: grid; grid-template-columns: repeat(7, 1fr);
  font-size: 0.8rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.08em;
  padding: 0.55rem 0.25rem; border-bottom: 2px solid var(--line);
}
.grid-days {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 1px; background: var(--line);
}
.day-cell {
  background: var(--surface);
  padding: 0.5rem;
  display: flex; flex-direction: column; gap: 0.3rem;
  position: relative; cursor: pointer;
  border-bottom: 1px solid var(--line);
  height: 140px; min-height: 140px;
}
.day-cell:hover { background: #f1f5f9; }
.day-cell.today { background: #dbeafe; position: relative; }
.day-cell.today::after { content: ""; position: absolute; top: 6px; right: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--brand); }
.day-number { font-size: 1.05rem; font-weight: 600; color: var(--ink); }
.day-cell .day-number.today { color: var(--brand); }
.day-cell.other-month { color: #cbd5e1; opacity: 0.5; cursor: default; }
.day-cell.other-month:hover { background: transparent; }

.day-events { display: flex; flex-direction: column; gap: 3px; margin-top: auto; }
.event-pill {
  font-size: 0.72rem; font-weight: 700; padding: 2px 7px; border-radius: 10px;
  color: #fff; white-space: normal; line-height: 1.2;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.15);
  max-width: 100%; word-break: break-word;
}
.event-pill.user   { background: var(--brand); }
.event-pill.claude { background: #7c3aed; }
.event-pill.gemini { background: var(--success); }
.event-pill.google { background: var(--warning); }
.event-pill.agent { opacity: 0.9; }

/* mobile list */
.calendar-list { display: flex; flex-direction: column; gap: 0.5rem; }
.list-day { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.75rem 1rem; }
.list-day h4 { font-size: 1rem; margin-bottom: 0.4rem; color: var(--ink); }
.list-event {
  display: flex; align-items: center; gap: 0.7rem; padding: 0.5rem;
  border-radius: 8px; background: #f8fafc; border: 1px solid var(--line);
}
.list-event .time { font-size: 0.85rem; color: var(--muted); min-width: 85px; font-weight: 600; }
.list-event .title { font-weight: 600; flex: 1; }
.list-event .source { font-size: 0.75rem; font-weight: 800; padding: 1px 6px; border-radius: 6px; background: var(--line); color: var(--muted); }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal-backdrop { position: absolute; inset: 0; background: rgb(0 0 0 / 0.45); backdrop-filter: blur(2px); }
.modal-panel {
  position: relative; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-md);
  width: 100%; max-width: 620px; max-height: 95vh; overflow-y: auto;
  animation: slideUp 0.2s ease;
}
@keyframes slideUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); }
.modal-head h3 { font-size: 1.15rem; font-weight: 800; letter-spacing: -0.02em; }
.modal-panel form { padding: 1rem 1.25rem 1.25rem; display: flex; flex-direction: column; gap: 1rem; }
.modal-actions { display: flex; gap: 0.6rem; justify-content: flex-end; margin-top: 0.25rem; }
.source-pill { font-size: 0.8rem; color: var(--muted); }

/* ---------- agents ---------- */
.page-head { margin-bottom: 1rem; }
.page-head h2 { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; }
.subtitle { color: var(--muted); font-size: 0.95rem; }
.agent-list { display: flex; flex-direction: column; gap: 0.5rem; }
.agent-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface);
}
.agent-info { display: flex; align-items: center; gap: 0.6rem; flex: 1; }
.agent-badge { font-size: 0.7rem; font-weight: 900; padding: 1px 7px; border-radius: 6px; color: #fff; }
.agent-badge.claude { background: #7c3aed; }
.agent-badge.gemini { background: var(--success); }
.agent-name { font-weight: 700; }
.agent-id { font-size: 0.8rem; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.agent-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }
.empty { color: var(--muted); font-size: 0.95rem; text-align: center; padding: 1.5rem; }

.token-box { margin-top: 1rem; padding: 1rem; border: 1px dashed var(--line); border-radius: 10px; background: var(--surface); }
.token-value { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; word-break: break-all; color: var(--ink); margin: 0.5rem 0; display: inline-block; padding: 0.4rem 0.7rem; background: rgba(255,255,255,0.06); border: 1px solid var(--line); border-radius: 6px; }

.hint-card h3 { margin-top: 0; }
pre { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 0.85rem; font-size: 0.85rem; overflow: auto; color: var(--ink); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; }

/* ---------- auth ---------- */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 60vh; }
.auth-card { width: 100%; max-width: 380px; padding: 2rem; }
.auth-card .brand { font-size: 1.5rem; margin-bottom: 1rem; }
.auth-card h2 { font-size: 1.25rem; margin-bottom: 0.5rem; }

/* ---------- responsive ---------- */
@media (max-width: 640px) {
  .app-main { padding: 1rem; }
  .calendar-grid-wrap { display: none; }
  .calendar-list-wrap { display: block; }
  .month-title { font-size: 1.25rem; }
  .field-row { grid-template-columns: 1fr; }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions button { width: 100%; }
  .header-inner { gap: 0.5rem; }
}

@media (min-width: 641px) {
  .calendar-list-wrap { display: none; }
}
