:root {
  --background: #f4f7f8;
  --surface: #ffffff;
  --text: #1f2a30;
  --muted: #6d7b82;
  --line: #dce4e7;
  --accent: #347e91;
  --accent-soft: #dfeff2;
  --parent: #5d8fc7;
  --lesson: #54a678;
  --homework: #d5a72c;
  --event: #d66b6b;
  --school: #8d73b8;
  --other: #849097;
  --summer: #fff9db;
  --shadow: 0 8px 28px rgba(44, 70, 80, .09);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--text);
  background: var(--background);
  min-height: 100vh;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

#app {
  width: min(100%, 1120px);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom));
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.eyebrow, .section-label {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .14em;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: clamp(23px, 5vw, 34px); }
h2 { margin-bottom: 0; font-size: 20px; }
.period { margin-bottom: 0; color: var(--muted); font-size: 13px; }

.icon-button, .month-button, .close-button {
  border: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.icon-button {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  font-size: 19px;
}

.today-panel {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 18px;
  align-items: center;
  padding: 15px 17px;
  margin-bottom: 14px;
  border-radius: 18px;
  color: white;
  background: linear-gradient(135deg, #397f91, #58a0aa);
  box-shadow: var(--shadow);
}

.today-panel .section-label { color: rgba(255,255,255,.74); }
.today-panel strong { display: block; font-size: 15px; }
.today-events { min-width: 0; font-size: 13px; }
.today-events p { margin: 2px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  margin-bottom: 18px;
  padding: 5px;
  border-radius: 15px;
  background: #e5ecee;
}

.tab-button {
  min-height: 42px;
  border: 0;
  border-radius: 11px;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
}

.tab-button.active {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 3px 12px rgba(44,70,80,.08);
}

.view { display: none; }
.view.active { display: block; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-bottom: 12px;
}

.month-button {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  font-size: 26px;
  line-height: 1;
}

.member-filter {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 2px 0 10px;
  scrollbar-width: none;
}
.member-filter::-webkit-scrollbar { display: none; }

.filter-chip {
  flex: 0 0 auto;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.filter-chip.active {
  color: white;
  border-color: var(--accent);
  background: var(--accent);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 13px;
  margin-bottom: 11px;
  color: var(--muted);
  font-size: 11px;
}

.legend span { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot.parent { background: var(--parent); }
.dot.lesson { background: var(--lesson); }
.dot.homework { background: var(--homework); }
.dot.event { background: var(--event); }
.dot.school { background: var(--school); }

.calendar-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.weekday-row {
  border-bottom: 1px solid var(--line);
  background: #f8fafb;
}

.weekday-row span {
  padding: 10px 2px;
  text-align: center;
  font-size: 12px;
  font-weight: 800;
}

.saturday { color: #397fc3; }
.sunday { color: #c9525d; }

.day-cell {
  position: relative;
  min-height: 103px;
  padding: 7px 5px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  overflow: hidden;
}

.day-cell:nth-child(7n) { border-right: 0; }
.day-cell.other-month { background: #f5f7f7; color: #aab4b8; }
.day-cell.summer-day { background: var(--summer); }
.day-cell.today { box-shadow: inset 0 0 0 2px var(--accent); }

.day-number {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 800;
}

.day-number .holiday { font-size: 8px; color: #c9525d; }
.day-cell.sat .day-number { color: #397fc3; }
.day-cell.sun .day-number { color: #c9525d; }

.event-pill {
  display: block;
  width: 100%;
  margin: 3px 0;
  padding: 3px 4px;
  border: 0;
  border-left: 3px solid currentColor;
  border-radius: 5px;
  color: var(--text);
  background: rgba(255,255,255,.82);
  font-size: 9px;
  line-height: 1.25;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.event-pill.parent { color: var(--parent); }
.event-pill.lesson { color: var(--lesson); }
.event-pill.homework { color: var(--homework); }
.event-pill.event { color: var(--event); }
.event-pill.school { color: var(--school); }
.event-pill.other { color: var(--other); }

.more-events { color: var(--muted); font-size: 9px; }

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.primary-button, .secondary-button, .danger-button {
  min-height: 42px;
  padding: 0 16px;
  border-radius: 12px;
  font-weight: 800;
}

.primary-button { border: 0; color: white; background: var(--accent); }
.secondary-button { border: 1px solid var(--line); color: var(--text); background: var(--surface); }
.danger-button { border: 1px solid #efb7b7; color: #b14242; background: #fff3f3; }

.progress-card, .homework-item, .event-list-item {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.progress-card { padding: 16px; margin-bottom: 12px; }
.progress-head { display: flex; justify-content: space-between; margin-bottom: 10px; }
.progress-track { height: 9px; border-radius: 999px; background: #e6ecee; overflow: hidden; }
.progress-bar { height: 100%; width: 0; border-radius: inherit; background: var(--accent); transition: width .25s; }

.homework-list, .event-list { display: grid; gap: 10px; }

.homework-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
}

.homework-check {
  width: 26px;
  height: 26px;
  accent-color: var(--accent);
}

.item-title { margin: 0 0 5px; font-size: 15px; }
.item-meta { margin: 0; color: var(--muted); font-size: 12px; }
.mini-progress { height: 6px; margin-top: 8px; border-radius: 999px; background: #e7edef; overflow: hidden; }
.mini-progress span { display: block; height: 100%; background: var(--accent); }

.edit-link {
  padding: 8px;
  border: 0;
  color: var(--accent);
  background: transparent;
  font-weight: 800;
}

.event-list-item {
  display: grid;
  grid-template-columns: 60px 5px 1fr auto;
  gap: 12px;
  align-items: stretch;
  padding: 13px;
}

.event-date-box {
  align-self: center;
  text-align: center;
}
.event-date-box strong { display: block; font-size: 18px; }
.event-date-box span { color: var(--muted); font-size: 11px; }
.category-line { border-radius: 999px; background: var(--other); }
.category-line.parent { background: var(--parent); }
.category-line.lesson { background: var(--lesson); }
.category-line.homework { background: var(--homework); }
.category-line.event { background: var(--event); }
.category-line.school { background: var(--school); }

.floating-button {
  position: fixed;
  right: max(18px, calc((100vw - 1120px) / 2 + 18px));
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 19px;
  color: white;
  background: var(--accent);
  box-shadow: 0 12px 28px rgba(52,126,145,.34);
  font-size: 28px;
}

.app-dialog {
  width: min(calc(100% - 24px), 520px);
  max-height: min(88vh, 760px);
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(30,50,60,.28);
}

.app-dialog::backdrop { background: rgba(25,40,48,.48); backdrop-filter: blur(2px); }
.app-dialog form { padding: 20px; overflow-y: auto; }

.dialog-header {
  display: flex;
  justify-content: space-between;
  gap: 15px;
  margin-bottom: 18px;
}

.close-button {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  box-shadow: none;
  font-size: 24px;
}

label {
  display: block;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input, select, textarea {
  width: 100%;
  margin-top: 6px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--text);
  background: #fbfcfc;
}

textarea { resize: vertical; }
input[type="range"] { padding: 7px 0; accent-color: var(--accent); }
.form-grid.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dialog-actions { display: flex; align-items: center; gap: 8px; margin-top: 20px; }
.action-spacer { flex: 1; }
.form-note { color: var(--muted); font-size: 12px; line-height: 1.6; }

.switch-label {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
}
.switch-label input { width: auto; margin: 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(92px + env(safe-area-inset-bottom));
  z-index: 20;
  transform: translate(-50%, 12px);
  max-width: calc(100% - 32px);
  padding: 11px 16px;
  border-radius: 999px;
  color: white;
  background: rgba(31,42,48,.92);
  box-shadow: var(--shadow);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.empty-state {
  padding: 34px 18px;
  border: 1px dashed var(--line);
  border-radius: 16px;
  color: var(--muted);
  text-align: center;
  background: rgba(255,255,255,.55);
}

@media (max-width: 600px) {
  #app { padding-left: 10px; padding-right: 10px; }
  .today-panel { grid-template-columns: 92px 1fr; }
  .day-cell { min-height: 84px; padding: 5px 3px; }
  .event-pill { padding: 2px 3px; font-size: 8px; }
  .legend { gap: 5px 10px; }
  .form-grid.two { grid-template-columns: 1fr; gap: 0; }
  .event-list-item { grid-template-columns: 50px 4px 1fr auto; gap: 9px; }
}

@media print {
  body { background: white; }
  #app { width: 100%; padding: 0; }
  .app-header .icon-button, .today-panel, .main-tabs, .member-filter,
  .legend, .floating-button, .month-button { display: none !important; }
  .calendar-card { box-shadow: none; }
  .day-cell { min-height: 110px; }
}
