:root {
  --blue: #1a73e8;
  --blue-dark: #1967d2;
  --border: #dadce0;
  --text: #3c4043;
  --text-light: #70757a;
  --bg: #ffffff;
  --bg-panel: #f8f9fa;
  --hover: #f1f3f4;
  --today: #1a73e8;
  --radius: 8px;
}

* { box-sizing: border-box; }

/* O atributo [hidden] tem baixa prioridade no CSS: qualquer regra de
   "display" definida abaixo para o mesmo elemento (ex: .modal-overlay,
   .time-grid-view) o sobrescreveria e o elemento continuaria visível
   mesmo com hidden=true. Esta regra garante que hidden sempre funcione. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: 'Roboto', Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

button {
  font-family: inherit;
  cursor: pointer;
}

/* ===== Header ===== */
.app-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-title {
  font-size: 22px;
  color: var(--text-light);
  font-weight: 400;
}

.icon-btn {
  background: none;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-light);
}
.icon-btn.small { width: 28px; height: 28px; }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.small svg { width: 16px; height: 16px; }
.icon-btn:hover { background: var(--hover); }

.btn-outline {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 4px;
  padding: 8px 16px;
  font-size: 14px;
  color: var(--text);
}
.btn-outline:hover { background: var(--hover); }

.date-nav { display: flex; gap: 0; }

.current-period {
  font-size: 22px;
  font-weight: 400;
  margin: 0;
  flex: 1;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.show-completed-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-light);
  white-space: nowrap;
}

.view-select {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
}

/* ===== Body layout ===== */
.app-body {
  display: flex;
  flex: 1;
  min-height: 0;
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  padding: 16px 12px;
  overflow-y: auto;
  overflow-x: hidden;
  border-right: 1px solid transparent;
  transition: width .2s ease, padding .2s ease;
}
.sidebar.is-collapsed {
  width: 0;
  padding-left: 0;
  padding-right: 0;
}
.sidebar.is-collapsed > * {
  opacity: 0;
  pointer-events: none;
}

.btn-criar {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fff;
  border: none;
  box-shadow: 0 1px 3px rgba(60,64,67,.3), 0 4px 8px rgba(60,64,67,.15);
  border-radius: 24px;
  padding: 12px 24px 12px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 20px;
}
.btn-criar:hover { box-shadow: 0 1px 3px rgba(60,64,67,.3), 0 6px 10px rgba(60,64,67,.2); }
.btn-criar svg { color: var(--blue); }

/* Mini calendar */
.mini-calendar { margin-bottom: 24px; }
.mini-cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 500;
  font-size: 13px;
  padding: 0 4px 8px;
  text-transform: capitalize;
}
.mini-cal-nav { display: flex; }
.mini-cal-weekdays, .mini-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}
.mini-cal-weekdays span {
  text-align: center;
  font-size: 11px;
  color: var(--text-light);
  padding: 4px 0;
}
.mini-cal-grid button {
  border: none;
  background: none;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  font-size: 12px;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
}
.mini-cal-grid button:hover { background: var(--hover); }
.mini-cal-grid button.outside-month { color: #b0b3b8; }
.mini-cal-grid button.is-today { background: var(--blue); color: #fff; font-weight: 500; }
.mini-cal-grid button.is-selected:not(.is-today) { background: #e8f0fe; color: var(--blue); font-weight: 500; }

/* Calendars panel */
.calendars-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.calendars-panel-header h3 {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin: 0;
  padding: 0 4px;
}
.calendar-list { list-style: none; margin: 0; padding: 0; }
.calendar-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 4px;
  border-radius: 4px;
  font-size: 14px;
}
.calendar-list li:hover { background: var(--hover); }
.calendar-list li:hover .btn-del-calendar { visibility: visible; }
.calendar-list input[type="checkbox"] {
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 3px;
  border: none;
  flex-shrink: 0;
  cursor: pointer;
  position: relative;
}
.calendar-list input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 6px;
  top: 2px;
  width: 5px;
  height: 10px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.calendar-list .cal-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.btn-edit-calendar,
.btn-del-calendar {
  visibility: hidden;
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-light);
  line-height: 1;
  padding: 4px 6px;
  border-radius: 4px;
}
.btn-del-calendar { font-size: 16px; }
.btn-edit-calendar:hover,
.btn-del-calendar:hover { background: #e0e0e0; }
.calendar-list li:hover .btn-edit-calendar { visibility: visible; }

/* ===== Calendar main area ===== */
.calendar-view {
  flex: 1;
  overflow: auto;
  position: relative;
  min-width: 0;
}

/* ---- Time grid (day/week) ---- */
.time-grid-view {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.tg-header {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 3;
}
.tg-gutter { width: 56px; flex-shrink: 0; }
.tg-day-header {
  flex: 1;
  text-align: center;
  padding: 8px 4px 12px;
  border-left: 1px solid var(--border);
}
.tg-day-header .wd { font-size: 11px; color: var(--text-light); font-weight: 500; text-transform: uppercase; }
.tg-day-header .dn {
  font-size: 26px;
  font-weight: 400;
  color: var(--text);
  width: 40px;
  height: 40px;
  line-height: 40px;
  border-radius: 50%;
  margin: 2px auto 0;
}
.tg-day-header.is-today .dn { background: var(--blue); color: #fff; }
.tg-day-header.is-today .wd { color: var(--blue); }

.tg-allday-row {
  display: flex;
  border-bottom: 1px solid var(--border);
  min-height: 28px;
  flex-shrink: 0;
}
.tg-allday-row .tg-gutter { display: flex; align-items: center; justify-content: flex-end; font-size: 10px; color: var(--text-light); padding-right: 6px; }
.tg-allday-col {
  flex: 1;
  border-left: 1px solid var(--border);
  padding: 2px 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tg-body-scroll {
  flex: 1;
  overflow-y: auto;
  position: relative;
}
.tg-body {
  display: flex;
  position: relative;
}
.tg-hours-col {
  width: 56px;
  flex-shrink: 0;
}
.tg-hour-label {
  height: 48px;
  text-align: right;
  padding-right: 8px;
  font-size: 11px;
  color: var(--text-light);
  transform: translateY(-6px);
}
.tg-days {
  display: flex;
  flex: 1;
  position: relative;
}
.tg-day-col {
  flex: 1;
  border-left: 1px solid var(--border);
  position: relative;
}
.tg-hour-line {
  height: 48px;
  border-bottom: 1px solid #eee;
}
.tg-now-line {
  position: absolute;
  left: 0; right: 0;
  height: 2px;
  background: #ea4335;
  z-index: 2;
}
.tg-now-line::before {
  content: '';
  position: absolute;
  left: -5px; top: -4px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #ea4335;
}

.event-chip {
  position: absolute;
  left: 2px;
  right: 2px;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 12px;
  color: #fff;
  overflow: hidden;
  cursor: pointer;
  display: flex;
  align-items: flex-start;
  gap: 4px;
  line-height: 1.3;
  box-shadow: 0 1px 2px rgba(0,0,0,.15);
}
.event-chip .ev-check {
  flex-shrink: 0;
  width: 13px;
  height: 13px;
  margin-top: 1px;
  border-radius: 3px;
  border: 1.5px solid rgba(255,255,255,.85);
  background: rgba(255,255,255,.15);
  position: relative;
}
.event-chip .ev-check.checked { background: #fff; }
.event-chip .ev-check.checked::after {
  content: '';
  position: absolute;
  left: 3px; top: 0px;
  width: 3px; height: 7px;
  border: solid var(--blue);
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg);
}
.event-chip .ev-text { overflow: hidden; text-overflow: ellipsis; }
.event-chip .ev-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.event-chip .ev-time { font-size: 11px; opacity: .9; }
.event-chip.is-completed { opacity: .55; }
.event-chip.is-completed .ev-title { text-decoration: line-through; }

.allday-chip {
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 12px;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.allday-chip.is-completed { opacity: .55; text-decoration: line-through; }

/* ---- Month view ---- */
.month-view {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.mv-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.mv-weekdays span {
  text-align: center;
  padding: 8px 0;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-light);
  text-transform: uppercase;
}
.mv-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-auto-rows: 1fr;
  flex: 1;
}
.mv-cell {
  border-left: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 4px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 90px;
  cursor: pointer;
}
.mv-cell:hover { background: #f8f9fa; }
.mv-cell .dn {
  font-size: 12px;
  width: 24px;
  height: 24px;
  line-height: 24px;
  text-align: center;
  border-radius: 50%;
  margin-bottom: 2px;
  flex-shrink: 0;
}
.mv-cell.outside .dn { color: #b0b3b8; }
.mv-cell.is-today .dn { background: var(--blue); color: #fff; font-weight: 500; }
.mv-cell .mv-events { display: flex; flex-direction: column; gap: 1px; overflow: hidden; }
.mv-chip {
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 3px;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.mv-chip.is-completed { opacity: .55; text-decoration: line-through; }
.mv-more {
  font-size: 11px;
  color: var(--text-light);
  padding: 1px 5px;
}

/* ===== Modals ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal {
  background: #fff;
  border-radius: 8px;
  width: 460px;
  max-width: 92vw;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 8px 28px rgba(0,0,0,.28);
}
.modal-small { width: 340px; }
.modal-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 16px 8px;
}
.ev-title-input {
  flex: 1;
  border: none;
  border-bottom: 2px solid var(--border);
  font-size: 20px;
  padding: 6px 2px;
  outline: none;
}
.ev-title-input:focus { border-bottom-color: var(--blue); }
.modal-title { font-size: 16px; font-weight: 500; flex: 1; }
.modal-body { padding: 8px 16px; display: flex; flex-direction: column; gap: 14px; }
.form-row { display: flex; flex-direction: column; gap: 4px; }
.form-row.two-col { flex-direction: row; gap: 12px; }
.form-row.two-col > div { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.form-row label { font-size: 12px; color: var(--text-light); }
.form-row input[type="text"],
.form-row input[type="date"],
.form-row input[type="time"],
.form-row select,
.form-row textarea {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  width: 100%;
}
.form-row input[type="color"] { width: 60px; height: 36px; border: 1px solid var(--border); border-radius: 4px; padding: 2px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); }
.modal-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px 16px;
}
.spacer { flex: 1; }
.btn-text {
  background: none;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  color: var(--blue);
}
.btn-text:hover { background: #e8f0fe; }
.btn-text.btn-danger { color: #d93025; }
.btn-text.btn-danger:hover { background: #fce8e6; }
.btn-filled {
  background: var(--blue);
  color: #fff;
  border: none;
  padding: 9px 20px;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
}
.btn-filled:hover { background: var(--blue-dark); }

/* ===== Tela de login ===== */
.login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg-panel);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.login-box {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 40px 36px;
  width: 340px;
  max-width: 90vw;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  box-shadow: 0 1px 3px rgba(60,64,67,.15), 0 4px 12px rgba(60,64,67,.1);
}
.login-box h1 {
  font-size: 24px;
  font-weight: 400;
  color: var(--text);
  margin: 12px 0 4px;
}
.login-box p {
  font-size: 14px;
  color: var(--text-light);
  margin: 0 0 20px;
}
.login-box input[type="password"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
}
.login-box input[type="password"]:focus {
  outline: none;
  border-color: var(--blue);
}
.login-error {
  color: #d93025;
  font-size: 13px;
  margin-top: 10px;
  align-self: flex-start;
}
.login-submit { width: 100%; margin-top: 18px; padding: 10px 20px; }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .app-title, .header-right .show-completed-toggle { display: none; }
}
