/* Modern Week Calendar */

.modern-week-calendar {
  --wc-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --wc-bg: #fff;
  --wc-surface: #f8fafc;
  --wc-border: #e2e8f0;
  --wc-border-subtle: #f1f5f9;
  --wc-text: #1e293b;
  --wc-text-muted: #64748b;
  --wc-primary: #3b82f6;
  --wc-primary-hover: #2563eb;
  --wc-primary-light: #eff6ff;
  --wc-non-business-hour: #f8fafc;
  --wc-current-time: #ef4444;
  --wc-time-col-width: 65px;
  --wc-event-bg: #3b82f6;
  --wc-event-color: #fff;
  --wc-event-border-radius: 6px;

  display: flex;
  flex-direction: column;
  height: 100%;
  font-family: var(--wc-font-family);
  color: var(--wc-text);
  background: var(--wc-bg);
  border: 1px solid var(--wc-border);
  border-radius: 8px;
  overflow: hidden;
  user-select: none;
}

.modern-week-calendar *,
.modern-week-calendar *::before,
.modern-week-calendar *::after { box-sizing: border-box; }

.modern-week-calendar [hidden] { display: none; }

/* --- Toolbar --- */
.mwc-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--wc-border);
}

.mwc-group { display: flex; gap: 6px; }
.mwc-title { font-size: 1.15rem; font-weight: 600; }

.mwc-btn {
  padding: 6px 14px;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--wc-text);
  background: var(--wc-bg);
  border: 1px solid var(--wc-border);
  border-radius: 6px;
  cursor: pointer;
}
.mwc-btn:hover { background: var(--wc-surface); }
.mwc-btn.active,
.mwc-btn-primary { background: var(--wc-primary); border-color: var(--wc-primary); color: #fff; }
.mwc-btn-primary:hover { background: var(--wc-primary-hover); }
.mwc-btn-danger { background: #ef4444; border-color: #ef4444; color: #fff; margin-right: auto; }
.mwc-btn-danger:hover { background: #dc2626; }

/* --- Grid: one scroller, sticky header row --- */
.mwc-grid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: var(--wc-time-col-width) repeat(var(--mwc-days), minmax(0, 1fr));
}

.mwc-corner,
.mwc-day-head {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--wc-surface);
  border-bottom: 1px solid var(--wc-border);
}

.mwc-day-head {
  padding: 10px 4px;
  text-align: center;
  border-left: 1px solid var(--wc-border);
}
.mwc-day-head.mwc-today { background: var(--wc-primary-light); }

.mwc-day-name {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--wc-text-muted);
}
.mwc-day-num {
  width: 32px;
  margin: 2px auto 0;
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 32px;
  border-radius: 50%;
}
.mwc-today .mwc-day-name { color: var(--wc-primary); }
.mwc-today .mwc-day-num { background: var(--wc-primary); color: #fff; }

/* Hour labels */
.mwc-gutter { background: var(--wc-surface); }
.mwc-gutter > div { position: relative; height: var(--mwc-hour-h); }
.mwc-gutter span {
  position: absolute;
  top: -0.5em;
  right: 8px;
  font-size: 0.725rem;
  font-weight: 500;
  color: var(--wc-text-muted);
}

/* Day columns: hour lines, slot lines and business hours are all background gradients */
.mwc-col {
  position: relative;
  height: calc(var(--mwc-hours) * var(--mwc-hour-h));
  border-left: 1px solid var(--wc-border);
  background:
    repeating-linear-gradient(var(--wc-border) 0 1px, transparent 1px var(--mwc-hour-h)),
    repeating-linear-gradient(var(--wc-border-subtle) 0 1px, transparent 1px var(--mwc-slot-h)),
    linear-gradient(var(--wc-non-business-hour) var(--mwc-biz-top), var(--wc-bg) 0 var(--mwc-biz-bottom), var(--wc-non-business-hour) 0);
}
.mwc-layer { position: absolute; inset: 0; }

.mwc-now {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--wc-current-time);
  z-index: 5;
  pointer-events: none;
}
.mwc-now::before {
  content: '';
  position: absolute;
  left: -5px;
  top: -4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: inherit;
}

.mwc-preview {
  position: absolute;
  left: 2px;
  right: 2px;
  background: rgb(59 130 246 / 0.25);
  border: 1px dashed var(--wc-primary);
  border-radius: 4px;
  pointer-events: none;
}

/* --- Events --- */
.mwc-event {
  position: absolute;
  z-index: 4;
  padding: 4px 8px;
  overflow: hidden;
  font-size: 0.8rem;
  color: var(--wc-event-color);
  background: var(--wc-event-bg);
  border-radius: var(--wc-event-border-radius);
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.12);
  cursor: pointer;
  touch-action: none;
}
.mwc-event:hover { z-index: 8; box-shadow: 0 4px 6px rgb(0 0 0 / 0.15); }
.mwc-event.is-dragging { z-index: 20; opacity: 0.8; cursor: grabbing; box-shadow: 0 10px 15px rgb(0 0 0 / 0.2); }

.mwc-event-time,
.mwc-event-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mwc-event-time { font-size: 0.7rem; opacity: 0.9; }
.mwc-event-title { font-weight: 600; margin-top: 2px; }

.mwc-handle {
  position: absolute;
  left: 0;
  right: 0;
  height: 6px;
  cursor: ns-resize;
}
.mwc-handle[data-edge="top"] { top: 0; }
.mwc-handle[data-edge="bottom"] { bottom: 0; }
.mwc-handle:hover { background: rgb(255 255 255 / 0.4); }

/* --- Dialog --- */
.mwc-dialog {
  width: min(90vw, 420px);
  padding: 0;
  border: none;
  border-radius: 12px;
  box-shadow: 0 20px 25px rgb(0 0 0 / 0.2);
  font-family: var(--wc-font-family);
  color: var(--wc-text);
}
.mwc-dialog::backdrop { background: rgb(15 23 42 / 0.45); }

.mwc-dialog form { display: flex; flex-direction: column; gap: 14px; }
.mwc-dialog header,
.mwc-dialog footer { display: flex; align-items: center; gap: 8px; padding: 14px 20px; }
.mwc-dialog header {
  justify-content: space-between;
  font-size: 1.1rem;
  font-weight: 600;
  border-bottom: 1px solid var(--wc-border);
}
.mwc-dialog header button {
  border: none;
  background: none;
  font-size: 1.25rem;
  color: var(--wc-text-muted);
  cursor: pointer;
}
.mwc-dialog footer {
  justify-content: flex-end;
  background: var(--wc-surface);
  border-top: 1px solid var(--wc-border);
}

.mwc-dialog label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0 20px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--wc-text-muted);
}
.mwc-dialog input {
  padding: 8px 12px;
  font: inherit;
  font-size: 0.9rem;
  color: var(--wc-text);
  border: 1px solid var(--wc-border);
  border-radius: 6px;
}
.mwc-dialog input:focus {
  outline: none;
  border-color: var(--wc-primary);
  box-shadow: 0 0 0 3px rgb(59 130 246 / 0.15);
}
