* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #f8f9fa;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 750px;
  margin: 0 auto;
  background: #f8f9fa;
}

.app.hidden { opacity: 0; }
.app { transition: opacity 0.3s; }

.header {
  background: linear-gradient(135deg, #6aa84f 0%, #93c47d 100%);
  color: white;
  padding: 16px 12px;
  margin: 0 12px;
  border-radius: 0 0 16px 16px;
  text-align: center;
  flex-shrink: 0;
}
.header h1 { font-size: 18px; font-weight: 600; }
.header p { font-size: 12px; opacity: 0.9; margin-top: 4px; }

.tabs {
  display: flex;
  background: white;
  padding: 4px;
  margin: 12px 12px 0 12px;
  gap: 4px;
  border-radius: 16px;
  flex-shrink: 0;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}

.tab {
  flex: 1;
  padding: 10px 6px;
  text-align: center;
  cursor: pointer;
  border: none;
  background: transparent;
  font-size: 12px;
  color: #666;
  border-radius: 8px;
  transition: all 0.2s;
  font-weight: 500;
}
.tab:hover { background: #f0f0f0; }
.tab.active {
  background: linear-gradient(135deg, #6aa84f 0%, #93c47d 100%);
  color: white;
}

.content {
  flex: 1;
  overflow: hidden;
  padding: 12px;
  display: flex;
  flex-direction: column;
}

.tab-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tab-content > .card {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  min-height: 0;
}

.card {
  background: white;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}

.card-title { font-size: 15px; font-weight: 600; color: #333; }

.header-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.btn-group { display: flex; gap: 6px; }

.btn-primary {
  background: linear-gradient(135deg, #6aa84f 0%, #93c47d 100%);
  color: white;
  border: none;
  padding: 8px 14px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
}

.btn-secondary {
  background: #f0f0f0;
  color: #666;
  border: none;
  padding: 8px 14px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
}

.scroll-area {
  flex: 1;
  overflow: auto;
  min-height: 0;
  max-height: calc(100vh - 280px);
}

/* 스피너 */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: #888;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #eee;
  border-top-color: #6aa84f;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* 테이블 */
.customer-table, .product-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
}

.customer-table th, .customer-table td,
.product-table th, .product-table td {
  padding: 10px 8px;
  text-align: center;
  border: 1px solid #e0e0e0;
  white-space: nowrap;
}

.customer-table th, .product-table th {
  background: #fff;
  font-weight: 600;
  color: #555;
  position: sticky;
  top: 0;
  z-index: 10;
}

.customer-table thead, .product-table thead {
  position: sticky;
  top: 0;
  z-index: 10;
}

.customer-table thead::after, .product-table thead::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: #e0e0e0;
}

.btn-cell {
  white-space: nowrap;
}

.product-table th:nth-child(1), .product-table td:nth-child(1) { width: 60px; }
.product-table th:nth-child(2), .product-table td:nth-child(2) { width: auto; }
.product-table th:nth-child(3), .product-table td:nth-child(3) { width: 80px; }
.product-table th:nth-child(4), .product-table td:nth-child(4) { width: 80px; }
.product-table th:nth-child(5), .product-table td:nth-child(5) { width: 60px; }
.product-table th:nth-child(6), .product-table td:nth-child(6) { width: 100px; }

.customer-table tr:hover, .product-table tr:hover { background: #fafafa; }

.btn-edit, .btn-delete, .btn-subscribe {
  padding: 5px 10px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 11px;
  border: none;
  font-weight: 500;
}

.btn-edit { background: #e3f2fd; color: #1976d2; }
.btn-subscribe { background: #e8f5e9; color: #2e7d32; }
.btn-delete { background: #ffebee; color: #d32f2f; margin-left: 4px; }

.empty-state {
  text-align: center;
  padding: 30px;
  color: #999;
}

.empty-state .icon { font-size: 40px; margin-bottom: 10px; }

.schedule-item {
  background: #f8f9fa;
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 8px;
  border-left: 4px solid #6aa84f;
}

.schedule-item.delivery { border-left-color: #ff6b6b; }
.schedule-item .time { font-size: 16px; font-weight: 600; color: #333; }
.schedule-item .type {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  margin-left: 6px;
  font-weight: 500;
}
.schedule-item .type.pickup { background: #e8f5e9; color: #2e7d32; }
.schedule-item .type.delivery { background: #ffebee; color: #c62828; }
.schedule-item .customer { font-size: 14px; margin-top: 6px; color: #333; font-weight: 500; }
.schedule-item .menu { font-size: 12px; color: #888; margin-top: 2px; }

.day-header {
  font-size: 13px;
  font-weight: 600;
  color: #555;
  padding: 8px 0;
  margin-top: 12px;
  border-bottom: 2px solid #6aa84f;
  margin-bottom: 8px;
}
.day-header.today { color: #6aa84f; }
.day-header:first-child { margin-top: 0; }

.sub-tabs { display: flex; gap: 8px; margin-bottom: 12px; }

.sub-tab {
  padding: 6px 14px;
  border: none;
  background: #f0f0f0;
  border-radius: 16px;
  cursor: pointer;
  font-size: 12px;
  color: #666;
  font-weight: 500;
}
.sub-tab.active { background: #6aa84f; color: white; }

.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  display: inline-block;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #ccc;
  border-radius: 24px;
  transition: 0.3s;
}
.toggle-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.3s;
}
.toggle-switch input:checked + .toggle-slider { background: #6aa84f; }
.toggle-switch input:checked + .toggle-slider:before { transform: translateX(20px); }

/* 모달 */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}
.modal-overlay.active { display: flex; }

#editSubscriptionModal.active {
  z-index: 1100;
}

.modal-box {
  background: white;
  border-radius: 20px;
  width: 90%;
  max-width: 360px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.modal-wide {
  max-width: 700px;
  width: 95%;
}

.modal-header {
  padding: 16px;
  border-bottom: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h2 { font-size: 16px; color: #333; }
.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #999;
}

.modal-body { padding: 16px; }

.modal-body-row {
  display: flex;
  gap: 16px;
  padding: 16px;
  align-items: stretch;
}

.modal-body-left {
  flex: 1;
  min-width: 240px;
}

.modal-body-right {
  flex: 1;
  min-width: 280px;
  display: flex;
  flex-direction: column;
}

@media (max-width: 600px) {
  .modal-body-row { flex-direction: column; }
}

.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  color: #555;
  font-size: 13px;
}
.form-group input, .form-group select {
  width: 100%;
  padding: 12px;
  border: 2px solid #eee;
  border-radius: 12px;
  font-size: 14px;
  text-align: center;
}
.form-group input:focus, .form-group select:focus { outline: none; border-color: #6aa84f; }

.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid #eee;
  display: flex;
  gap: 8px;
}
.modal-footer .btn {
  flex: 1;
  padding: 12px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
}
.modal-footer .btn-submit { background: linear-gradient(135deg, #6aa84f 0%, #93c47d 100%); color: white; }
.modal-footer .btn-cancel { background: #f0f0f0; color: #666; }

.search-box {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.search-input {
  flex: 1;
  padding: 10px 14px;
  border: 2px solid #eee;
  border-radius: 20px;
  font-size: 13px;
  outline: none;
}
.search-input:focus { border-color: #6aa84f; }
.search-input::placeholder { color: #aaa; }

.time-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.time-slot-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: #f8f9fa;
  border-radius: 8px;
}
.time-slot-item span { font-weight: 500; }
.time-slot-item .btn-delete { margin-left: 0; }

.init-loading {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: linear-gradient(135deg, #6aa84f 0%, #93c47d 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.init-loading .spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255,255,255,0.3);
  border-top-color: white;
  margin-bottom: 16px;
}
.init-loading span { color: white; font-size: 14px; font-weight: 500; }

.day-checkboxes {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.day-check {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.day-check input { display: none; }
.day-check span {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #f0f0f0;
  font-size: 13px;
  font-weight: 500;
  color: #666;
  transition: all 0.2s;
}
.day-check input:checked + span { background: #6aa84f; color: white; }
.day-check:hover span { background: #e0e0e0; }
.day-check input:checked:hover + span { background: #5a9740; }

.calendar-preview {
  display: flex;
  flex-direction: column;
  padding: 4px;
  height: 400px;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  scroll-behavior: smooth;
}

.calendar-month {
  background: #f8f9fa;
  border-radius: 12px;
  padding: 12px;
  min-width: 180px;
  scroll-snap-align: start;
  flex-shrink: 0;
  height: 200px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin-bottom: 8px;
}

.calendar-month-title {
  font-weight: 600;
  font-size: 13px;
  color: #333;
  margin-bottom: 8px;
  text-align: center;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  font-size: 11px;
}

.calendar-day-header {
  text-align: center;
  font-weight: 600;
  color: #888;
  padding: 4px 0;
}

.calendar-day {
  text-align: center;
  padding: 4px 2px;
  border-radius: 4px;
  color: #999;
}
.calendar-day.active { background: #6aa84f; color: white; font-weight: 600; }
.calendar-day.skipped { background: #ffebee; color: #d32f2f; text-decoration: line-through; }
.calendar-day.today { border: 2px solid #6aa84f; }

.calendar-empty { padding: 20px; text-align: center; color: #999; font-size: 12px; }

.subscription-card {
  background: #f8f9fa;
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
  border-left: 4px solid #6aa84f;
  cursor: pointer;
}

.sub-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.sub-customer { font-size: 15px; font-weight: 600; color: #333; }

.sub-status {
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
}
.sub-status.active { background: #e8f5e9; color: #2e7d32; }
.sub-status.inactive { background: #ffebee; color: #d32f2f; }

.sub-card-summary { font-size: 12px; color: #666; }

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid #eee;
}
.detail-row:last-child { border-bottom: none; }
.detail-label { color: #888; font-size: 13px; }
.detail-value { font-weight: 500; font-size: 14px; color: #333; }
.detail-status.active { color: #2e7d32; }
.detail-status.inactive { color: #d32f2f; }

.app-info { padding: 8px 0; color: #888; font-size: 13px; }
.app-info p { margin: 4px 0; }

/* 횟수 입력칸 */
.sessions-input {
  width: 45px;
  padding: 8px 4px;
  border: 2px solid #eee;
  border-radius: 8px;
  font-size: 14px;
  text-align: center;
  -moz-appearance: textfield;
}
.sessions-input::-webkit-outer-spin-button,
.sessions-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.sessions-input:focus {
  outline: none;
  border-color: #6aa84f;
}

/* 일간 네비게이션 */
.day-nav {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 8px 0 12px;
  border-bottom: 1px solid #eee;
  margin-bottom: 12px;
  position: relative;
}

.day-label-wrap {
  text-align: center;
  cursor: pointer;
}

/* 주간 달력 */
.week-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.week-nav {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 8px 0 12px;
  border-bottom: 1px solid #eee;
  margin-bottom: 12px;
}

.week-nav-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: #f0f0f0;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  color: #666;
  transition: all 0.2s;
}

.week-nav-btn:hover {
  background: #6aa84f;
  color: white;
}

.week-label-wrap {
  text-align: center;
  position: relative;
}

.week-label {
  font-size: 15px;
  font-weight: 600;
  color: #333;
  display: block;
}

.week-range {
  font-size: 11px;
  color: #888;
}

.calendar-icon {
  font-size: 14px;
  margin-left: 4px;
  vertical-align: middle;
}

/* 날짜 선택 팝업 */
.date-picker {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  padding: 12px;
  z-index: 100;
  width: 280px;
}

.date-picker-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  padding: 0 4px;
}

.date-picker-header button {
  background: #f0f0f0;
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
}

.date-picker-header button:hover {
  background: #6aa84f;
  color: white;
}

.date-picker-header span {
  font-weight: 600;
  font-size: 14px;
}

.date-picker-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 11px;
  color: #888;
  margin-bottom: 6px;
}

.date-picker-days span:first-child { color: #d32f2f; }
.date-picker-days span:last-child { color: #1976d2; }

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

.date-picker-grid span {
  text-align: center;
  padding: 8px 4px;
  font-size: 12px;
  cursor: pointer;
  border-radius: 0;
  transition: background 0.1s;
}

.date-picker-grid span:first-child,
.date-picker-grid span:nth-child(7n+1) {
  border-radius: 6px 0 0 6px;
}

.date-picker-grid span:nth-child(7n) {
  border-radius: 0 6px 6px 0;
}

.date-picker-grid span.other-month {
  color: #ccc;
}

.date-picker-grid span.today {
  background: #6aa84f;
  color: white;
  font-weight: 600;
}

.date-picker-grid span.selected-week {
  background: #d4edda;
}

.date-picker-grid span.selected-week.today {
  background: #6aa84f;
}

.date-picker-grid span.hover-week {
  background: #fff3cd;
}

.date-picker-grid span.hover-week.today {
  background: #6aa84f;
}

.date-picker-grid span.hover-week.selected-week {
  background: #c3e6cb;
}

.date-picker-grid span.selected-day {
  background: #6aa84f;
  color: white;
  font-weight: 600;
  border-radius: 6px;
}

/* 고객 달력 버튼 */
.btn-calendar {
  padding: 5px 8px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 11px;
  border: none;
  background: #fff3cd;
  margin-left: 4px;
}

/* 전체 달력 */
.calendar-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

.calendar-nav {
  display: flex;
  align-items: center;
  gap: 12px;
}

.calendar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.calendar-sub-select {
  padding: 8px 12px;
  border: 2px solid #eee;
  border-radius: 8px;
  font-size: 12px;
  max-width: 180px;
}

.calendar-sub-select:focus {
  outline: none;
  border-color: #6aa84f;
}

.calendar-nav button {
  background: #f0f0f0;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
}

.calendar-nav button:hover {
  background: #6aa84f;
  color: white;
}

.calendar-nav span {
  font-weight: 600;
  font-size: 16px;
}

.full-calendar {
  border: 1px solid #eee;
  border-radius: 12px;
  overflow: hidden;
}

.full-calendar-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  background: #f8f9fa;
  text-align: center;
  font-weight: 600;
  font-size: 12px;
  padding: 10px 0;
}

.full-calendar-header .sunday { color: #d32f2f; }
.full-calendar-header .saturday { color: #1976d2; }

.full-calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}

.calendar-cell {
  min-height: 70px;
  border: 1px solid #eee;
  padding: 4px;
  font-size: 11px;
}

.calendar-cell.other-month {
  background: #fafafa;
  color: #ccc;
}

.calendar-cell.today {
  background: #e8f5e9;
}

.calendar-cell-date {
  font-weight: 600;
  margin-bottom: 4px;
}

.calendar-cell.sunday .calendar-cell-date { color: #d32f2f; }
.calendar-cell.saturday .calendar-cell-date { color: #1976d2; }
.calendar-cell.other-month .calendar-cell-date { color: #ccc; }

.calendar-event {
  background: #6aa84f;
  color: white;
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 10px;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.calendar-event.delivery {
  background: #ff6b6b;
}

.calendar-legend {
  margin-top: 12px;
  display: flex;
  gap: 16px;
  justify-content: center;
  font-size: 12px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 4px;
}

.legend-dot.pickup { background: #6aa84f; }
.legend-dot.delivery { background: #ff6b6b; }

.date-picker-grid span.sunday { color: #d32f2f; }
.date-picker-grid span.saturday { color: #1976d2; }
.date-picker-grid span.today.sunday,
.date-picker-grid span.today.saturday { color: white; }
.date-picker-grid span.other-month.sunday { color: #f5a0a0; }
.date-picker-grid span.other-month.saturday { color: #90caf9; }

.date-picker-today {
  width: 100%;
  margin-top: 10px;
  padding: 8px;
  background: #f0f0f0;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
}

.date-picker-today:hover {
  background: #6aa84f;
  color: white;
}

.week-calendar {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.week-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 8px;
}

.week-header-cell {
  text-align: center;
  padding: 8px 4px;
  background: #f8f9fa;
  border-radius: 8px;
}

.week-header-cell.today {
  background: #6aa84f;
  color: white;
}

.week-header-cell.sunday { color: #d32f2f; }
.week-header-cell.saturday { color: #1976d2; }
.week-header-cell.today.sunday,
.week-header-cell.today.saturday { color: white; }

.week-day-name {
  font-size: 12px;
  font-weight: 600;
}

.week-day-date {
  font-size: 10px;
  margin-top: 2px;
  opacity: 0.8;
}

.week-body {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  overflow-y: auto;
  align-items: start;
}

.week-day-col {
  background: #fafafa;
  border-radius: 8px;
  padding: 6px;
  min-height: 80px;
  max-height: 100%;
  overflow-y: auto;
}

.week-day-col.today {
  background: #e8f5e9;
}

.week-event {
  background: white;
  border-radius: 6px;
  padding: 6px;
  margin-bottom: 4px;
  border-left: 3px solid #6aa84f;
  font-size: 11px;
  overflow: hidden;
}

.week-event.delivery {
  border-left-color: #ff6b6b;
}

.week-event-time {
  font-weight: 600;
  color: #333;
  white-space: nowrap;
}

.week-event-name {
  color: #555;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.week-event-menu {
  color: #888;
  font-size: 10px;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.week-empty {
  color: #bbb;
  font-size: 10px;
  text-align: center;
  padding: 10px 0;
}
