:root {
  --bg: #F3F0FA;
  --surface: #FFFFFF;
  --ink: #2B2545;
  --muted: #6B6486;
  --primary: #5B4BD0;
  --primary-soft: #EDE9FF;
  --accent: #F07C5A;
  --success: #24855C;
  --success-soft: #E4F5EC;
  --danger: #C43A55;
  --danger-soft: #FCE9ED;
  --warning: #A66A00;
  --line: #E7E2F3;
  --radius: 24px;
  --light: rgba(255, 255, 255, .95);
  --dark: rgba(43, 37, 69, .14);
  --clay: -6px -6px 16px var(--light), 8px 8px 22px var(--dark);
  --clay-sm: -3px -3px 8px var(--light), 4px 4px 12px var(--dark);
  --clay-in: inset 3px 3px 8px rgba(43, 37, 69, .10), inset -3px -3px 8px rgba(255, 255, 255, .95);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Nunito", "Trebuchet MS", system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background:
    radial-gradient(900px 620px at 8% -8%, rgba(126, 105, 232, .18), transparent 70%),
    radial-gradient(760px 560px at 104% 104%, rgba(240, 124, 90, .14), transparent 70%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { line-height: 1.18; margin: 0; letter-spacing: -.01em; }
h1 { font-size: 32px; font-weight: 800; }
h2 { font-size: 24px; font-weight: 800; }
h3 { font-size: 20px; font-weight: 700; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.tiny { font-size: 12px; }
.hidden { display: none !important; }
.stack { display: grid; gap: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.spacer { flex: 1; }

.clay {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--clay);
}
.clay-sm {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--clay-sm);
}
.inset { box-shadow: var(--clay-in); }

/* Buttons */
.btn {
  appearance: none;
  border: 1px solid transparent;
  min-height: 48px;
  padding: 0 24px;
  border-radius: var(--radius);
  font: 700 16px/1 "Nunito", "Trebuchet MS", system-ui, sans-serif;
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--clay-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px); box-shadow: var(--clay-in); }
.btn:focus-visible, .icon-btn:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible, a:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; box-shadow: var(--clay-sm); }
.btn.loading { opacity: .7; cursor: progress; }
.btn.primary { background: var(--primary); color: #fff; box-shadow: var(--clay-sm); }
.btn.primary:hover { background: #4d3dc0; }
.btn.ghost { background: transparent; box-shadow: none; color: var(--muted); }
.btn.ghost:hover { background: rgba(91, 75, 208, .08); color: var(--primary); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 40px; padding: 0 18px; font-size: 14px; }
.btn.icon-only { width: 44px; padding: 0; min-height: 44px; }
.icon-btn {
  width: 44px; height: 44px; min-width: 44px;
  border: 0; border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--clay-sm);
  color: var(--ink); font-size: 22px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}

/* Forms */
.field { display: grid; gap: 7px; }
.field > span { font-size: 14px; font-weight: 700; color: var(--muted); }
input, select, textarea {
  width: 100%;
  font: 400 16px/1.5 "Nunito", "Trebuchet MS", system-ui, sans-serif;
  color: var(--ink);
  border: 1px solid transparent;
  background: #FBFAFE;
  border-radius: var(--radius);
  box-shadow: var(--clay-in);
  padding: 12px 18px;
  min-height: 48px;
}
textarea { min-height: 120px; resize: vertical; }
input::placeholder, textarea::placeholder { color: #8A83A1; }
input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; accent-color: var(--primary); box-shadow: none; }
input[type="file"] { padding: 10px; }
.form-actions { display: flex; gap: 12px; justify-content: flex-end; flex-wrap: wrap; }

/* Auth */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(440px, 100%); padding: 40px 36px; text-align: left; }
.brand-mark { width: 64px; height: 64px; border-radius: var(--radius); box-shadow: var(--clay-sm); display: grid; place-items: center; color: var(--primary); margin-bottom: 22px; }
.auth-card h1 { margin-bottom: 6px; }
.auth-card > .muted { margin-bottom: 26px; }
.callout { padding: 14px 18px; border-radius: var(--radius); background: var(--primary-soft); color: var(--primary); font-size: 14px; }

/* Shell */
.app-shell { display: grid; grid-template-columns: 264px minmax(0, 1fr); min-height: 100vh; }
.sidebar { margin: 20px; padding: 22px 18px; display: flex; flex-direction: column; gap: 22px; position: sticky; top: 20px; height: calc(100vh - 40px); }
.sidebar-brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 22px; padding: 0 10px; }
.brand-glyph { color: var(--primary); }
.nav-list { display: grid; gap: 4px; overflow-y: auto; padding-right: 2px; }
.nav-item {
  min-height: 44px; border: 0; background: transparent; color: var(--muted);
  border-radius: var(--radius); padding: 10px 16px; text-align: left;
  font: 700 15px/1.3 "Nunito", sans-serif; cursor: pointer; display: flex; gap: 10px; align-items: center;
}
.nav-item:hover { background: rgba(91, 75, 208, .07); color: var(--primary); }
.nav-item.active { background: var(--primary); color: #fff; box-shadow: var(--clay-in); }
.nav-item .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; opacity: .65; }
.sidebar-foot { margin-top: auto; display: grid; gap: 10px; }
.user-chip { padding: 12px 14px; border-radius: var(--radius); box-shadow: var(--clay-in); font-size: 14px; word-break: break-word; }
.main-column { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 18px; padding: 26px 34px 16px; }
.topbar-title { min-width: 0; }
.topbar-title h1 { font-size: 32px; }
.topbar-title p { font-size: 14px; margin: 2px 0 0; }
.top-tabs { margin-left: auto; display: flex; gap: 6px; padding: 6px; border-radius: var(--radius); box-shadow: var(--clay-sm); background: var(--surface); }
.top-tabs .nav-item { min-height: 42px; padding: 8px 16px; }
#menu-btn { display: none; }
#view-root { padding: 16px 34px 54px; outline: none; display: grid; gap: 22px; }

/* Cards and content */
.card { padding: 24px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.card-head h2, .card-head h3 { margin: 0; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; }
.stat-card { padding: 20px; display: grid; gap: 4px; }
.stat-value { font-size: 32px; font-weight: 800; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: 14px; font-weight: 700; }
.stat-link { justify-self: start; margin-top: 6px; border: 0; background: transparent; color: var(--primary); font-weight: 700; font-size: 14px; cursor: pointer; padding: 0; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: var(--radius); font-size: 12px; font-weight: 800; background: var(--primary-soft); color: var(--primary); white-space: nowrap; }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.muted { background: #F0EDF7; color: var(--muted); }
.badge.warning { background: #FFF1D9; color: var(--warning); }

.list { display: grid; gap: 10px; }
.list-row { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: var(--radius); box-shadow: var(--clay-sm); background: #fff; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row strong { display: block; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.empty { text-align: center; padding: 38px 24px; border-radius: var(--radius); box-shadow: var(--clay-in); color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-size: 18px; margin-bottom: 4px; }

/* Media */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 18px; }
.media-card { padding: 12px; display: grid; gap: 10px; }
.media-thumb { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 18px; background: #EFECF8; box-shadow: var(--clay-in); }
.media-meta { padding: 0 6px; }
.media-actions { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 4px 4px; }
.media-actions .btn { flex: 1; }

.dropzone { padding: 48px 24px; text-align: center; border-radius: var(--radius); box-shadow: var(--clay-in); background: #FBFAFE; cursor: pointer; }
.dropzone.dragover { background: var(--primary-soft); }
.dropzone strong { display: block; font-size: 20px; }
.progress { height: 8px; border-radius: 99px; background: #EDEAF6; overflow: hidden; box-shadow: var(--clay-in); }
.progress > span { display: block; height: 100%; background: var(--primary); width: 0; transition: width .2s ease; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 640px; }
th, td { text-align: left; padding: 13px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-size: 13px; font-weight: 800; }
tbody tr:last-child td { border-bottom: 0; }
td .btn { min-height: 36px; padding: 0 12px; font-size: 13px; }

/* Calendar */
.cal-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.segmented { display: inline-flex; padding: 4px; border-radius: var(--radius); box-shadow: var(--clay-sm); background: #fff; }
.segmented button { border: 0; background: transparent; padding: 8px 16px; min-height: 40px; border-radius: var(--radius); font: 700 14px "Nunito", sans-serif; color: var(--muted); cursor: pointer; }
.segmented button.active { background: var(--primary); color: #fff; box-shadow: var(--clay-in); }
.calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.calendar-day { min-height: 118px; padding: 10px; border-radius: var(--radius); box-shadow: var(--clay-sm); background: #fff; }
.calendar-day.muted { opacity: .55; }
.calendar-date { font-weight: 800; font-size: 14px; margin-bottom: 6px; }
.calendar-pill { display: block; width: 100%; text-align: left; border: 0; border-radius: 12px; padding: 6px 8px; margin-bottom: 5px; font-size: 12px; font-weight: 700; cursor: pointer; box-shadow: var(--clay-sm); background: var(--primary-soft); color: var(--primary); }
.calendar-pill.facebook { background: #E8F0FF; color: #2457B8; }
.day-list { display: grid; gap: 12px; }

/* Filters */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.filters input, .filters select { width: auto; min-width: 160px; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(43, 37, 69, .38); display: grid; place-items: center; padding: 18px; }
.modal { width: min(620px, 100%); max-height: calc(100vh - 40px); overflow-y: auto; padding: 26px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }

/* Drawer */
.drawer-backdrop { position: fixed; inset: 0; z-index: 48; background: rgba(43, 37, 69, .34); }
.drawer { position: fixed; z-index: 50; top: 0; right: 0; bottom: 0; width: min(320px, 86vw); border-radius: var(--radius) 0 0 var(--radius); padding: 22px; display: flex; flex-direction: column; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }

/* Toasts */
#toast-stack { position: fixed; z-index: 90; right: 22px; bottom: 22px; display: grid; gap: 10px; width: min(380px, calc(100vw - 32px)); }
.toast { padding: 14px 18px; border-radius: var(--radius); box-shadow: var(--clay); font-weight: 700; font-size: 14px; }
.toast.success { border-left: 5px solid var(--success); }
.toast.error { border-left: 5px solid var(--danger); }

.avatar { width: 52px; height: 52px; border-radius: 50%; box-shadow: var(--clay-in); object-fit: cover; background: var(--primary-soft); display: grid; place-items: center; color: var(--primary); font-weight: 800; }

@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .top-tabs { display: none; }
  #menu-btn { display: inline-flex; }
}

@media (max-width: 860px) {
  .app-shell { display: block; }
  .sidebar { display: none; }
  .topbar { padding: 16px 18px 10px; }
  .topbar-title h1 { font-size: 26px; }
  #view-root { padding: 12px 18px 44px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .calendar-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .auth-card { padding: 30px 22px; }
  .stats-grid { grid-template-columns: 1fr; }
  .calendar-grid { grid-template-columns: 1fr; }
  .btn { width: 100%; }
  .btn.icon-only, .icon-btn, .top-tabs .btn { width: auto; }
  .form-actions .btn, .row .btn { width: auto; }
  .modal { padding: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
