:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-soft: #f6f6f6;
  --line: #ececec;
  --line-strong: #d7d7d7;
  --text: #222222;
  --muted: #8f8f8f;
  --accent: #13b67b;
  --accent-dark: #0d8058;
  --danger: #d3363c;
  --shadow: 0 14px 36px rgba(0, 0, 0, 0.13);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  overflow-x: hidden;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Noto Sans JP", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 20px;
  line-height: 1.3;
  font-weight: 800;
}

h3 {
  margin-bottom: 7px;
  font-size: 14px;
  line-height: 1.35;
  font-weight: 700;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: 20px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px 14px;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(16px);
}

.month-nav,
.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.month-title {
  min-width: 0;
}

.month-title p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.month-title .app-name {
  margin: 0 0 4px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
}

.icon-btn,
.ghost-btn,
.primary-btn,
.secondary-btn,
.danger-btn {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
}

.icon-btn {
  width: 38px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  font-size: 24px;
}

.ghost-btn,
.secondary-btn,
.danger-btn {
  padding: 0 14px;
  border-color: var(--line);
}

.primary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 16px;
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  font-weight: 700;
}

.danger-btn {
  color: var(--danger);
  background: #fff5f5;
  border-color: #f1c4c4;
}

.full-width {
  width: 100%;
}

.panel-block > .full-width + .full-width {
  margin-top: 8px;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(19, 182, 123, 0.22);
  outline-offset: 2px;
}

.main-layout {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 18px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
  gap: 20px;
  overflow-x: hidden;
}

.calendar-panel,
.detail-panel {
  min-width: 0;
}

.calendar-panel {
  background: var(--surface);
  overflow-x: hidden;
}

.detail-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel-block,
.detail-block {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.detail-block {
  border-left: 6px solid var(--label-color, var(--accent));
}

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

.label-strip {
  display: flex;
  gap: 10px;
  padding: 10px 0 18px;
  overflow-x: auto;
  scrollbar-width: none;
}

.label-strip::-webkit-scrollbar {
  display: none;
}

.label-filter {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #ffffff;
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.label-filter input {
  position: absolute;
  width: 1px;
  min-height: 1px;
  opacity: 0;
  pointer-events: none;
}

.label-filter.is-off {
  opacity: 0.42;
}

.label-swatch {
  width: 6px;
  height: 24px;
  border-radius: 999px;
  background: var(--label-color, var(--accent));
}

.label-name {
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.all-filter {
  font-weight: 700;
}

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

.weekday-row {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.weekday-row span {
  padding: 11px 0;
}

.month-grid {
  border-bottom: 1px solid var(--line);
}

.day-cell {
  min-width: 0;
  min-height: 132px;
  padding: 6px 5px;
  border-top: 1px solid var(--line);
  background: #ffffff;
}

.day-cell:nth-child(7n + 6),
.weekday-row span:nth-child(6) {
  background: #fbfdff;
}

.day-cell:nth-child(7n),
.weekday-row span:nth-child(7) {
  background: #fffafb;
}

.day-cell.is-muted {
  background: #fafafa;
  color: #b9b9b9;
}

.day-cell.is-today {
  background: #f2f2f2;
}

.day-number {
  display: grid;
  width: 28px;
  height: 28px;
  margin: 0 auto 7px;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font-size: 15px;
  font-weight: 500;
}

.is-today .day-number {
  color: #0a65d8;
  font-weight: 800;
}

.day-cell:nth-child(7n + 6) .day-number {
  color: #0a65d8;
}

.day-cell:nth-child(7n) .day-number {
  color: #e33d48;
}

.day-events {
  display: grid;
  gap: 4px;
}

.event-pill,
.event-more {
  width: 100%;
  min-width: 0;
  min-height: 20px;
  padding: 1px 4px 2px;
  border: 0;
  border-radius: 4px;
  background: var(--label-bg, #eeeeee);
  color: var(--label-color, var(--text));
  font-size: 12px;
  line-height: 1.35;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.event-pill.is-high {
  box-shadow: inset 0 0 0 2px var(--label-color, var(--accent));
}

.event-more {
  color: var(--muted);
  background: var(--surface-soft);
}

.reminder-list,
.comment-list,
.attachment-list {
  display: grid;
  gap: 9px;
}

.reminder-item,
.comment-item {
  padding: 10px;
  border-radius: var(--radius);
  background: var(--label-bg, var(--surface-soft));
}

.reminder-item h3 {
  overflow-wrap: anywhere;
}

.event-meta,
.detail-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 13px;
}

.detail-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.detail-title-row h2 {
  overflow-wrap: anywhere;
}

.detail-note {
  margin: 14px 0 0;
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.label-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 1px 8px;
  border-radius: 5px;
  background: var(--label-bg);
  color: var(--label-color);
  font-size: 12px;
  font-weight: 700;
}

.label-editor-list {
  display: grid;
  gap: 10px;
}

.label-editor-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 72px;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.label-editor-row input[type="color"] {
  width: 44px;
  min-height: 40px;
  padding: 2px;
}

.label-editor-row input:disabled {
  color: var(--muted);
  background: var(--surface-soft);
}

.attachment-list {
  padding: 0;
  list-style: none;
}

.attachment-list li {
  padding: 8px 10px;
  border-radius: var(--radius);
  background: var(--surface-soft);
  overflow-wrap: anywhere;
}

.comment-form {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.comment-form input {
  flex: 1 1 auto;
}

.comment-form button {
  flex: 0 0 60px;
  white-space: nowrap;
}

.empty-state {
  margin: 0;
  padding: 12px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  color: var(--muted);
  background: var(--surface-soft);
}

.field-label {
  display: block;
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--text);
}

input,
select {
  min-height: 40px;
  padding: 0 10px;
}

textarea {
  resize: vertical;
  padding: 10px;
}

.event-dialog {
  width: min(760px, calc(100vw - 28px));
  max-height: calc(100dvh - 28px);
  padding: 0;
  border: 0;
  border-radius: 28px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.event-dialog::backdrop {
  background: rgba(0, 0, 0, 0.35);
}

.dialog-card {
  display: grid;
  gap: 14px;
  margin: 0;
  padding: 20px;
  max-height: calc(100dvh - 28px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
}

.dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.close-btn {
  color: var(--danger);
  font-size: 28px;
}

.save-top {
  min-width: 88px;
  background: #ffffff;
  color: var(--text);
  border-color: var(--line);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.dialog-actions {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
}

.floating-add {
  position: fixed;
  right: 26px;
  bottom: 26px;
  z-index: 20;
  width: 64px;
  height: 64px;
  border: 0;
  border-radius: 50%;
  background: #ffffff;
  color: #111111;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.18);
  font-size: 42px;
  line-height: 1;
  font-weight: 600;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 104px;
  z-index: 30;
  max-width: min(360px, calc(100vw - 36px));
  padding: 10px 12px;
  border-radius: var(--radius);
  background: #222222;
  color: #ffffff;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .main-layout {
    grid-template-columns: 1fr;
  }

  .detail-panel {
    padding-bottom: 80px;
  }
}

@media (max-width: 520px) {
  body {
    font-size: 14px;
  }

  .app-shell {
    padding-bottom: 0;
  }

  .topbar {
    padding: 18px 12px 10px;
    align-items: flex-start;
    flex-direction: column;
  }

  .month-nav {
    width: 100%;
    justify-content: space-between;
  }

  .top-actions {
    width: 100%;
    justify-content: space-between;
  }

  h1 {
    font-size: 28px;
  }

  .main-layout {
    padding: 0;
    gap: 14px;
  }

  .label-strip {
    padding: 8px 10px 14px;
    flex-wrap: wrap;
    overflow-x: visible;
  }

  .weekday-row {
    font-size: 12px;
  }

  .weekday-row span {
    padding: 9px 0;
  }

  .day-cell {
    min-height: 108px;
    padding: 5px 3px;
  }

  .day-number {
    width: 24px;
    height: 24px;
    margin-bottom: 5px;
    font-size: 14px;
  }

  .day-events {
    gap: 3px;
  }

  .event-pill,
  .event-more {
    min-height: 18px;
    padding: 1px 3px;
    font-size: 10px;
  }

  .detail-panel {
    padding: 0 10px 88px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .event-dialog {
    position: fixed;
    top: 208px;
    right: 8px;
    bottom: 112px;
    left: 8px;
    width: auto;
    height: calc(100dvh - 320px);
    max-width: none;
    max-height: calc(100dvh - 320px);
    margin: 0;
    border-radius: 24px;
  }

  .dialog-card {
    height: 100%;
    max-height: none;
    padding: 16px 14px calc(20px + env(safe-area-inset-bottom));
    overflow-y: auto;
  }

  .dialog-heading {
    position: sticky;
    top: -16px;
    z-index: 2;
    margin: -16px -14px 0;
    padding: 14px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
  }

  .dialog-actions {
    grid-template-columns: 1fr;
  }

  .dialog-actions span {
    display: none;
  }

  .label-editor-row {
    grid-template-columns: 42px minmax(0, 1fr) 64px;
    gap: 8px;
    padding: 8px;
  }

  .floating-add {
    right: 22px;
    bottom: 22px;
  }
}
