:root {
  --primary: #6d4aff;
  --primary-strong: #5b38f5;
  --bg: #f5f5f7;
  --card: #ffffff;
  --border: #e7e7ee;
  --text: #1f2430;
  --text-muted: #646a7a;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(31, 36, 48, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(180deg, #f8f7ff 0%, var(--bg) 100%);
  color: var(--text);
  padding: calc(12px + env(safe-area-inset-top)) 12px calc(24px + env(safe-area-inset-bottom));
  min-height: 100svh;
  overscroll-behavior-y: contain;
}

.app-shell {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 14px 14px;
  background: rgba(255,255,255,0.96);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
  border: 1px solid rgba(231,231,238,0.8);
  border-radius: 18px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.logo { width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0; }
header h1 { font-size: 0.98rem; font-weight: 700; line-height: 1.2; }
.header-actions {
  position: relative;
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  min-height: 44px;
  transition: transform .12s ease, opacity .15s ease, box-shadow .15s ease;
  touch-action: manipulation;
  box-shadow: 0 2px 8px rgba(31,36,48,0.06);
}
.btn:hover { opacity: .92; }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: #eef0f6; color: var(--text); }
.btn-icon { background: transparent; box-shadow: none; min-height: auto; padding: 6px 8px; font-size: 1.2rem; }
.btn-sm { padding: 8px 12px; min-height: 40px; font-size: 0.85rem; }
.header-menu-toggle {
  min-width: 44px;
  min-height: 44px;
  border-radius: 12px;
  background: #eef0f6;
  box-shadow: 0 2px 8px rgba(31,36,48,0.06);
}
.header-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 180px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  background: rgba(255,255,255,0.98);
  border: 1px solid rgba(231,231,238,0.95);
  border-radius: 16px;
  box-shadow: 0 16px 32px rgba(31,36,48,0.14);
  z-index: 150;
}
.header-menu.hidden { display: none; }
.header-menu-item {
  width: 100%;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-align: left;
  padding: 12px 14px;
  cursor: pointer;
}
.header-menu-item:hover,
.header-menu-item:focus-visible {
  background: #f3f4fa;
  outline: none;
}
.header-menu-item.active {
  background: #eef0f6;
  color: var(--primary-strong);
}

main { display: flex; flex-direction: column; gap: 12px; }
.month-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  max-width: 100%;
  margin: 0 auto;
  width: 100%;
  background: rgba(255,255,255,0.96);
  border-radius: 18px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(231,231,238,0.8);
}
.month-nav h2 { flex: 1; text-align: center; font-size: 1.02rem; font-weight: 700; }

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 7px;
  width: 100%;
  padding: 10px;
  background: rgba(255,255,255,0.96);
  border-radius: 20px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(231,231,238,0.8);
}
.weekdays > div {
  text-align: center;
  font-weight: 700;
  font-size: 0.78rem;
  color: var(--text-muted);
  padding: 4px 2px 8px;
  user-select: none;
  -webkit-user-select: none;
}
.day-cell {
  background: #fbfbfd;
  border-radius: 14px;
  min-height: 78px;
  padding: 7px 6px;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
  border: 1px solid transparent;
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: flex-start;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.day-cell:hover { transform: translateY(-1px); }
.day-cell.empty { background: transparent; border-color: transparent; cursor: default; }
.day-cell.today {
  outline: 2px solid rgba(109,74,255,0.14);
  border-color: rgba(109,74,255,0.16);
  background: linear-gradient(180deg, #f8f4ff 0%, #fcfbff 100%);
}
.day-number { font-weight: 700; font-size: 0.9rem; color: var(--text); }
.shift-badge {
  display: block;
  width: 100%;
  font-size: 0.72rem;
  padding: 5px 7px;
  border-radius: 999px;
  color: #fff;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.note-indicator {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.active-preset-banner {
  position: relative;
  max-width: min(48vw, 420px);
  padding: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}
.header-preset-group {
  position: relative;
  flex: 1;
  min-width: 0;
}
.active-preset-pill {
  flex: 1;
  padding: 10px 12px;
  border-radius: 999px;
  color: #fff;
  font-weight: 600;
  font-size: 0.86rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-preset-actions {
  display: flex;
  align-items: center;
}
.active-preset-banner .btn-icon {
  min-height: 32px;
  padding: 4px 6px;
  font-size: 0.9rem;
}
.active-preset-banner.hidden { display: none; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
  padding: 12px;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--card);
  border-radius: 20px 20px 12px 12px;
  width: 100%;
  max-width: 460px;
  max-height: min(88vh, 760px);
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(15,23,42,0.25);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-body { padding: 18px; }
.section { margin-bottom: 18px; }
.label { display: block; font-weight: 600; font-size: 0.85rem; margin-bottom: 6px; color: var(--text-muted); }
.preset-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.preset-btn {
  border: none;
  border-radius: 12px;
  padding: 8px 10px;
  color: #fff;
  cursor: pointer;
  font-size: 0.74rem;
  font-weight: 700;
  transition: opacity .15s, transform .05s;
}
.preset-btn:hover { opacity: .9; }
.preset-btn:active { transform: scale(.97); }
.shift-list { display: flex; flex-direction: column; gap: 8px; }
.shift-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: #f5f6fa;
  border-radius: 12px;
}
.shift-item .color-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.shift-item .shift-text { font-size: 0.9rem; flex: 1; }
.shift-item .del-btn { background: transparent; border: none; cursor: pointer; color: #dc2626; font-size: 1.1rem; padding: 2px 6px; }
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.95rem;
  resize: vertical;
  font-family: inherit;
  min-height: 88px;
}
textarea:focus { outline: none; border-color: var(--primary); }
.preset-list { display: flex; flex-direction: column; gap: 8px; }
.preset-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: #f5f6fa;
  border-radius: 12px;
}
.preset-row input[type="text"],
.preset-row input[type="time"] {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 0.85rem;
}
.preset-row input[type="color"] { width: 36px; height: 28px; border: none; border-radius: 8px; cursor: pointer; }
.preset-row .preset-del { margin-left: auto; }
.preset-form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.preset-form input[type="text"],
.preset-form input[type="time"] {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.9rem;
  flex: 1;
  min-width: 100px;
}
.preset-form input[type="color"] { width: 40px; height: 40px; border: none; border-radius: 10px; cursor: pointer; }

.preset-picker {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 220px;
  max-width: min(80vw, 320px);
  padding: 8px;
  background: rgba(255,255,255,0.98);
  border: 1px solid rgba(231,231,238,0.95);
  border-radius: 16px;
  box-shadow: 0 16px 32px rgba(31,36,48,0.14);
  z-index: 160;
}
.preset-picker .preset-select {
  width: 100%;
  border: none;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  color: #fff;
  font-weight: 700;
  min-height: 36px;
  font-size: 0.72rem;
  text-align: left;
}
.preset-picker .btn {
  width: 100%;
}
.preset-picker.hidden { display:none; }

.note-banner { position: fixed; left: 12px; right: 12px; top: 92px; z-index: 300; display:flex; justify-content:center; }
.note-banner.hidden { display:none; }
.note-banner-inner { width:100%; max-width:720px; background:var(--card); padding:12px; border-radius:16px; box-shadow:var(--shadow); }
.note-banner-inner #noteBannerTitle { font-weight:700; margin-bottom:8px; }
.note-actions { display:flex; justify-content:space-between; align-items:center; gap:12px; margin-top:8px; flex-wrap:wrap; }

@media (max-width: 800px) {
  body { padding: calc(10px + env(safe-area-inset-top)) 10px calc(20px + env(safe-area-inset-bottom)); }
  header { padding: 12px 12px; }
  .header-left { flex: 1; }
  .header-actions { gap: 6px; }
  .active-preset-banner { max-width: min(46vw, 250px); }
  .header-menu { min-width: 160px; }
  .month-nav { gap: 8px; padding: 10px 12px; }
  .month-nav h2 { font-size: 0.95rem; }
  .calendar-grid { gap: 6px; padding: 8px; }
  .day-cell { min-height: 74px; padding: 6px 5px; }
  .shift-badge { font-size: 0.7rem; padding: 4px 6px; }
  .active-preset-banner { padding: 8px; flex-wrap: wrap; }
  .preset-picker { width: 100%; }
  .modal { border-radius: 18px 18px 10px 10px; }
  .modal-body { padding: 16px; }
  .preset-row { flex-wrap: wrap; }
  .preset-form { flex-direction: column; align-items: stretch; }
  .preset-form input[type="text"], .preset-form input[type="time"], .preset-form input[type="color"] { width: 100%; }
  .preset-form input[type="color"] { max-width: 48px; }
  .note-banner { top: 84px; left:8px; right:8px; }
  .header-menu-toggle { min-height: 40px; min-width: 40px; }
  .preset-btn { padding: 6px 8px; font-size: 0.66rem; border-radius: 10px; }
  .preset-picker .preset-select { padding: 5px 6px; font-size: 0.6rem; }
}

@media (max-width: 480px) {
  .header-actions { max-width: 58%; }
  .active-preset-banner { max-width: calc(100% - 42px); }
  .active-preset-pill { min-height: 36px; padding: 8px 10px; font-size: 0.72rem; }
  .header-menu { min-width: 150px; }
  .header-menu-toggle { min-width: 36px; min-height: 36px; font-size: 1rem; }
  .preset-picker { right: 0; min-width: 180px; max-width: 78vw; }
  .calendar-grid { gap: 3px; padding: 4px; }
  .day-cell { min-height: 50px; padding: 3px 2px; gap: 2px; }
  .day-number { font-size: 0.64rem; }
  .shift-badge { font-size: 0.46rem; padding: 2px 3px; }
  .note-indicator { font-size: 0.46rem; }
  .btn { font-size: 0.8rem; min-height: 36px; }
  header h1 { font-size: 0.72rem; }
  .month-nav { padding: 8px 10px; }
  .month-nav h2 { font-size: 0.78rem; }
  .preset-picker .preset-select { font-size: 0.58rem; }
}
