:root {
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-2: #f1f3f4;
  --text: #3c4043;
  --muted: #5f6368;
  --accent: rgba(19, 93, 190, 0.7);
  --accent-hover: rgba(16, 81, 166, 0.7);
  --accent-pressed: rgba(13, 72, 144, 0.7);
  --accent-soft: #e8f0fe;
  --danger: #d93025;
  --border: #dadce0;
  --today: rgba(19, 93, 190, 0.7);
}

* { box-sizing: border-box; }

.hidden { display: none !important; }

body {
  margin: 0;
  font-family: "Google Sans", Roboto, system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  font-weight: 500;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* ===== Top app bar ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.gcal-brand { display: flex; align-items: center; gap: 10px; }

.title-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
}

.gcal-brand h1 {
  margin: 0;
  font-size: 21px;
  font-weight: 400;
  color: var(--muted);
}

.gcal-nav { display: flex; align-items: center; gap: 6px; }

.gcal-nav #monthLabel {
  min-width: 160px;
  text-align: center;
  font-size: 18px;
  color: var(--text);
}

.gcal-spacer { flex: 1; }

/* ===== Buttons ===== */
.btn {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 16px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  background: var(--panel);
  color: var(--text);
  transition: background .1s, box-shadow .1s;
}
.btn:hover { background: #f8f9fa; }
.btn:active { background: var(--panel-2); }

.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }

.btn.icon { padding: 8px 12px; font-size: 18px; line-height: 1; color: var(--muted); }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .15);
}
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.primary:active { background: var(--accent-pressed); }

.btn.danger {
  background: var(--panel);
  border-color: var(--danger);
  color: var(--danger);
}
.btn.danger:hover { background: #fce8e6; }

/* ===== View switcher (pills) ===== */
.views {
  display: flex;
  gap: 0;
  background: var(--panel-2);
  border-radius: 4px;
  padding: 2px;
}
.views .btn {
  border: none;
  background: transparent;
  border-radius: 4px;
  padding: 8px 18px;
  color: var(--text);
}
.views .btn:hover { background: rgba(0, 0, 0, .04); }
.views .btn.active {
  background: var(--panel);
  color: var(--accent);
  font-weight: 500;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .2);
}

/* ===== Layout ===== */
.layout {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 16px;
  padding: 16px 2cm 16px 24px;
  margin: 0;
}

.calendar {
  background: var(--panel);
  border-radius: 8px;
  padding: 16px;
}

.weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0;
}

.week-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0;
}

.week-row { position: relative; }

.strip {
  position: absolute;
  top: 36px;
  height: 20px;
  line-height: 20px;
  background: var(--accent);
  color: #fff;
  font-size: 12.5px;
  padding: 0 6px;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  box-sizing: border-box;
}
.strip.done { text-decoration: line-through; opacity: .55; }

.weekdays span {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 6px 0;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .3px;
}

.day {
  height: 104px;
  border: 1px solid var(--border);
  border-radius: 0;
  margin: -1px 0 0 -1px;
  padding: 4px 6px 6px 6px;
  background: var(--panel);
  cursor: pointer;
  overflow: hidden;
  transition: background .1s;
}
.day:hover { background: #f8f9fa; }
.day.empty { background: transparent; border-color: transparent; cursor: default; }
.day.other .num { color: var(--muted); }
.day.other .chip { opacity: .4; }
.day.selected { background: var(--accent-soft); }

.day .month-tag {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
  margin: -2px 0 2px;
}

.day .num {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin: 0 auto 4px;
}
.day.today .num { background: var(--accent); color: #fff; font-weight: 600; }

.day .chip {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  background: transparent;
  color: var(--text);
  padding: 1px 0;
  margin: 0 0 2px;
  overflow: hidden;
}
.day .chip::before {
  content: "";
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}
.day .chip-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.day .chip.done { text-decoration: line-through; opacity: .55; }

.chip-spacer { height: 20px; }

/* ===== Side panel ===== */
.mini-cal {
  background: var(--panel);
  border-radius: 8px;
  padding: 12px;
  align-self: start;
}

.mini-month { margin-bottom: 14px; }
.mini-month:last-child { margin-bottom: 0; }

.mini-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 6px;
  cursor: pointer;
  text-align: center;
}
.mini-title:hover { color: var(--accent); }

.mini-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
}

.mini-wd {
  text-align: center;
  font-size: 10px;
  color: var(--muted);
  padding: 2px 0;
}

.mini-day {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  margin: 0 auto;
  font-size: 11px;
  border-radius: 50%;
  cursor: pointer;
  color: var(--text);
}
.mini-day:hover { background: var(--panel-2); }
.mini-day.today { background: var(--accent); color: #fff; font-weight: 600; }
.mini-day.selected { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.side {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  align-self: start;
}

.side h2 {
  font-size: 16px;
  margin: 0 0 12px;
  color: var(--text);
  font-weight: 500;
}

.event-list { list-style: none; margin: 0; padding: 0; }

.event-list li {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 12px;
  margin-bottom: 6px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.event-list li:hover { background: #f8f9fa; }
.event-list .title { font-weight: 500; }
.event-list .title.done { text-decoration: line-through; color: var(--muted); }
.event-list .time { color: var(--muted); font-size: 12px; }
.event-list .empty { color: var(--muted); font-size: 13px; cursor: default; }

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal.hidden { display: none; }

.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
}
.modal-card h3 { margin: 0 0 4px; font-size: 18px; font-weight: 400; }
.modal-card label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.modal-card .row { display: flex; gap: 12px; }
.modal-card .row label { flex: 1; }
.modal-card input, .modal-card textarea, .modal-card select {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
.modal-card input:focus, .modal-card textarea:focus, .modal-card select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.modal-actions { display: flex; gap: 8px; margin-top: 4px; }
.modal-actions .danger { margin-left: auto; }

.google-status { font-size: 13px; min-height: 20px; }
.google-ok { color: #188038; font-weight: 500; margin-bottom: 4px; }
.google-meta { color: var(--muted); font-size: 12px; }

/* ===== Year view ===== */
.days.year {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}
.year-month {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px;
  cursor: pointer;
}
.year-month:hover { background: #f8f9fa; }
.year-month-title {
  text-align: center;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 6px;
  font-size: 13px;
}
.year-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
}
.year-day {
  text-align: center;
  font-size: 11px;
  padding: 3px 0;
  border-radius: 3px;
}
.year-day.today { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

@media (max-width: 760px) {
  .app-header {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 12px;
  }

  .gcal-brand { gap: 0; }
  .gcal-brand h1 { display: none; }
  .title-icon { width: 32px; height: 32px; font-size: 15px; }

  .views { margin-left: auto; }
  .views .btn { padding: 7px 14px; font-size: 13px; }

  #addEvent { padding: 7px 12px; font-size: 13px; }
  #googleBtn { display: none; }

  .gcal-spacer { display: none; }

  .gcal-nav {
    order: 5;
    width: 100%;
    justify-content: center;
    gap: 4px;
  }
  .gcal-nav #monthLabel { min-width: 0; flex: 1; font-size: 15px; }
  .gcal-nav .btn { padding: 8px 12px; }

  .mini-cal { display: none; }

  .layout {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 8px 8px 16px;
  }

  .calendar { padding: 6px; border-radius: 6px; }

  .weekdays span { font-size: 10px; padding: 4px 0; }

  .day {
    height: 60px;
    padding: 3px;
  }
  .day .num {
    width: 22px;
    height: 22px;
    font-size: 11px;
    margin: 0 auto 2px;
  }
  .day .chip {
    font-size: 10px;
    gap: 3px;
    margin: 1px 0;
  }
  .day .chip::before { width: 6px; height: 6px; }
  .day .month-tag { font-size: 8px; margin: -1px 0 1px; }

  .strip {
    top: 24px;
    height: 14px;
    line-height: 14px;
    font-size: 10px;
    padding: 0 4px;
  }

  .chip-spacer { height: 12px; }

  .days.year { grid-template-columns: repeat(2, 1fr); gap: 10px; }
}
