:root {
  color-scheme: light dark;
  --bg: #f4f5f9;
  --surface: #ffffff;
  --surface-2: #f0f2f7;
  --border: rgba(20, 22, 34, 0.08);
  --border-strong: rgba(20, 22, 34, 0.14);
  --text: #171923;
  --muted: #6b7184;
  --accent: #5b6cff;
  --accent-hover: #4d5df2;
  --accent-soft: rgba(91, 108, 255, 0.12);
  --danger: #e5484d;
  --danger-soft: rgba(229, 72, 77, 0.12);
  --shadow: 0 1px 2px rgba(16, 18, 30, 0.05), 0 8px 24px -12px rgba(16, 18, 30, 0.18);
  --shadow-lg: 0 24px 60px -20px rgba(16, 18, 30, 0.35);
  --radius: 14px;
  --radius-sm: 9px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1015;
    --surface: #151821;
    --surface-2: #1c2030;
    --border: rgba(255, 255, 255, 0.07);
    --border-strong: rgba(255, 255, 255, 0.13);
    --text: #e9ebf2;
    --muted: #8c93a8;
    --accent: #6d7cff;
    --accent-hover: #7f8dff;
    --accent-soft: rgba(109, 124, 255, 0.16);
    --danger: #f0616d;
    --danger-soft: rgba(240, 97, 109, 0.16);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -12px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 24px 60px -20px rgba(0, 0, 0, 0.7);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  background-image: radial-gradient(1100px 380px at 50% -120px, var(--accent-soft), transparent);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* Top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 24px;
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.brand-mark {
  width: 24px;
  height: 24px;
  border-radius: 8px;
  background: linear-gradient(135deg, #6d7cff, #b565f2);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 2px 6px rgba(109, 124, 255, 0.35);
}

.brand-mark-lg {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: inline-block;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.topbar-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
}

.topbar-link:hover { color: var(--text); }

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #6d7cff, #b565f2);
  color: #fff;
  font-weight: 650;
  font-size: 0.85rem;
  user-select: none;
}

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}

.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }

.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.15);
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-danger {
  background: transparent;
  border-color: transparent;
  color: var(--danger);
}

.btn-danger:hover { background: var(--danger-soft); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }

.btn-sm { padding: 5px 10px; font-size: 0.8rem; border-radius: 8px; }
.btn-lg { padding: 12px 22px; font-size: 1rem; border-radius: 12px; }

.btn-plus { font-size: 1.1rem; line-height: 1; font-weight: 500; margin-top: -1px; }

/* Layout */

main {
  padding: 24px;
  max-width: 1180px;
  margin: 0 auto;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

/* Tag legend */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  min-height: 28px;
  align-items: center;
}

.legend-empty { color: var(--muted); font-size: 0.85rem; }

.chip {
  --chip: var(--accent);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 11px 4px 9px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text);
  background: color-mix(in srgb, var(--chip) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--chip) 32%, transparent);
}

.chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--chip);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--chip) 25%, transparent);
}

/* Login */

.login-wrap {
  min-height: calc(100vh - 140px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  width: 420px;
  max-width: 100%;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 44px 36px;
  box-shadow: var(--shadow);
}

.login-card h1 { font-size: 1.45rem; margin: 18px 0 8px; letter-spacing: -0.02em; }
.login-card p { color: var(--muted); margin: 0 0 26px; line-height: 1.5; }

/* Modal */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 10, 18, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fade-in 0.15s ease-out;
}

.modal-backdrop.hidden { display: none; }

.modal-box {
  width: 470px;
  max-width: 100%;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 22px 24px 24px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  animation: pop-in 0.18s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

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

.modal-header h2 {
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  margin: 0;
}

.icon-btn {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
}

.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.form-intro { margin: -8px 0 16px; font-size: 0.85rem; }

/* Fields */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  min-width: 0;
}

input[type="datetime-local"] { min-width: 0; }

.field label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

.hint { font-weight: 400; opacity: 0.75; }

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 480px) {
  .field-row { grid-template-columns: 1fr; }
}

input, textarea, select {
  width: 100%;
  padding: 9px 11px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.7; }
textarea { resize: vertical; min-height: 72px; }

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.modal-actions .spacer { flex: 1; }

.muted { color: var(--muted); font-size: 0.85rem; }

/* Link view */

.link-range { display: flex; flex-direction: column; gap: 8px; }

.link-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.link-row-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.link-row strong { font-weight: 600; }

.link-role {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

/* Toast */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  z-index: 1100;
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* FullCalendar */

.fc {
  --fc-border-color: var(--border);
  --fc-page-bg-color: transparent;
  --fc-neutral-bg-color: var(--surface-2);
  --fc-today-bg-color: color-mix(in srgb, var(--accent) 7%, transparent);
  --fc-event-text-color: var(--text);
  --fc-list-event-hover-bg-color: var(--surface-2);
  --fc-highlight-color: var(--accent-soft);
  --fc-now-indicator-color: var(--danger);
  font-size: 0.9rem;
}

.fc .fc-toolbar.fc-header-toolbar {
  margin-bottom: 18px;
  gap: 12px;
  flex-wrap: wrap;
}

.fc .fc-toolbar-title {
  font-size: 1.2rem;
  font-weight: 650;
  letter-spacing: -0.015em;
}

.fc .fc-button {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: none;
  box-shadow: none;
  transition: background 0.15s;
}

.fc .fc-button:hover { background: var(--surface-2); }
.fc .fc-button:focus, .fc .fc-button:focus-visible { box-shadow: 0 0 0 3px var(--accent-soft); }
.fc .fc-button:disabled { opacity: 0.45; }

.fc .fc-button-group {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 3px;
  gap: 2px;
}

.fc .fc-button-group > .fc-button {
  margin: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
}

.fc .fc-button-group > .fc-button-primary:not(:disabled).fc-button-active,
.fc .fc-button-group > .fc-button-primary:not(:disabled):active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.fc .fc-button-group > .fc-button:hover { background: color-mix(in srgb, var(--surface) 60%, transparent); }

.fc-theme-standard .fc-scrollgrid { border: none; }
.fc-theme-standard td, .fc-theme-standard th { border-color: var(--border); }

.fc .fc-col-header-cell-cushion {
  padding: 8px 4px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  text-decoration: none;
}

.fc .fc-daygrid-day-number {
  padding: 6px 8px;
  font-size: 0.8rem;
  color: var(--muted);
  text-decoration: none;
}

.fc .fc-day-today .fc-daygrid-day-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  margin: 4px;
  padding: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.fc .fc-day-other .fc-daygrid-day-number { opacity: 0.45; }
.fc .fc-daygrid-day-frame { min-height: 96px; }
.fc .fc-daygrid-day:hover { background: color-mix(in srgb, var(--surface-2) 55%, transparent); cursor: pointer; }

.fc .fc-event {
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
}

.fc .fc-daygrid-event { padding: 2px 6px; margin: 1px 4px; }
.fc .fc-daygrid-dot-event:hover { background: var(--surface-2); }
.fc .fc-daygrid-event-dot { border-width: 4px; margin: 0 6px 0 0; }
.fc .fc-event-time { font-weight: 600; opacity: 0.75; }

.ev-tinted {
  background: color-mix(in srgb, var(--ev) 20%, transparent) !important;
  border: 1px solid color-mix(in srgb, var(--ev) 35%, transparent) !important;
  border-left: 3px solid var(--ev) !important;
  color: var(--text) !important;
}

.fc .fc-timegrid-event .fc-event-main { padding: 3px 6px; }
.fc .fc-timegrid-slot-label-cushion, .fc .fc-timegrid-axis-cushion { font-size: 0.72rem; color: var(--muted); }

.fc .fc-daygrid-more-link { font-size: 0.75rem; font-weight: 600; color: var(--accent); }

.fc .fc-popover {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
}

.fc .fc-popover-header { background: var(--surface-2); }

.fc-theme-standard .fc-list { border-color: var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.fc .fc-list-day-cushion { background: var(--surface-2) !important; font-weight: 600; font-size: 0.85rem; }
.fc .fc-list-event td { padding: 10px 14px; }
.fc .fc-list-event-dot { border-width: 5px; }
.fc .fc-list-empty { background: transparent; color: var(--muted); }

@media (max-width: 640px) {
  main { padding: 14px; }
  .card { padding: 12px; }
  .topbar { padding: 10px 14px; }
  .topbar-link { display: none; }
  .fc .fc-toolbar.fc-header-toolbar { justify-content: center; }
  .fc .fc-toolbar-title { font-size: 1.05rem; }
  .fc .fc-daygrid-day-frame { min-height: 70px; }
}
