/* ─── Base / reset ─────────────────────────────────────────────────────── */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  color: #1e293b;
  background: #f1f5f9;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Vars ─────────────────────────────────────────────────────────────── */
:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --muted: #64748b;
  --text: #1e293b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --nav-bg: #0f172a;
  --nav-text: #cbd5e1;
  --nav-active: #ffffff;
}

/* ─── Auth screen ──────────────────────────────────────────────────────── */
.auth {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  background: var(--surface);
  padding: 32px 28px;
  border-radius: 16px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
  width: 100%;
  max-width: 420px;
}
.auth-card h1 {
  margin: 0 0 4px;
  font-size: 24px;
}
.auth-card .sub {
  color: var(--muted);
  margin: 0 0 24px;
  font-size: 14px;
}
.auth-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  padding: 4px;
  border-radius: 10px;
  margin-bottom: 20px;
}
.auth-tabs button {
  flex: 1;
  padding: 8px 12px;
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 500;
}
.auth-tabs button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

/* ─── Layout (post-login) ──────────────────────────────────────────────── */
.shell { display: flex; min-height: 100vh; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--nav-bg);
  color: white;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar .brand { font-weight: 600; font-size: 16px; }
.topbar .user-bits { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.topbar .user-bits .role-pill {
  background: rgba(255, 255, 255, 0.15);
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  text-transform: capitalize;
}
.topbar button.icon-btn {
  background: transparent;
  border: 0;
  color: white;
  font-size: 22px;
  cursor: pointer;
  padding: 4px 8px;
}
.topbar .menu-toggle { display: inline-flex; }

.body { display: flex; flex: 1; min-height: 0; }

nav.sidebar {
  background: var(--nav-bg);
  color: var(--nav-text);
  width: 100%;
  padding: 8px 0;
  display: none;
}
nav.sidebar.open { display: block; }
nav.sidebar a {
  display: block;
  padding: 12px 20px;
  color: var(--nav-text);
  text-decoration: none;
  border-left: 3px solid transparent;
  font-size: 15px;
}
nav.sidebar a.active {
  color: var(--nav-active);
  border-left-color: var(--primary);
  background: rgba(255, 255, 255, 0.04);
}
nav.sidebar a:hover { color: white; text-decoration: none; }

main.content {
  flex: 1;
  padding: 16px;
  min-width: 0;
  overflow-x: hidden;
}

/* ─── Desktop layout ───────────────────────────────────────────────────── */
@media (min-width: 768px) {
  .topbar .menu-toggle { display: none; }
  .body { flex-direction: row; }
  nav.sidebar {
    display: block !important;
    width: 220px;
    flex-shrink: 0;
    position: sticky;
    top: 48px;
    align-self: flex-start;
    height: calc(100vh - 48px);
    overflow-y: auto;
  }
  main.content { padding: 24px 32px; }
}

/* ─── Common UI ────────────────────────────────────────────────────────── */
h1, h2, h3 { margin-top: 0; }
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}
.page-header h1 { font-size: 22px; margin: 0; }

.card {
  background: var(--surface);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  margin-bottom: 20px;
}
.card-grid {
  display: grid;
  gap: 20px;
  grid-template-columns: 1fr;
  margin-bottom: 20px;
}
.card-grid .card { margin-bottom: 0; }
@media (min-width: 640px) {
  .card-grid.cols-2 { grid-template-columns: 1fr 1fr; }
  .card-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.muted { color: var(--muted); font-size: 14px; }
.empty {
  color: var(--muted);
  font-style: italic;
  padding: 12px 0;
}

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 13px; color: var(--muted); font-weight: 500; }
.field input, .field select, .field textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  outline: none;
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .field-row { grid-template-columns: 1fr; } }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.15s;
}
.btn:hover { background: #f8fafc; }
.btn.primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: #fef2f2; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data {
  width: 100%;
  border-collapse: collapse;
  min-width: 480px;
}
table.data th, table.data td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
table.data th {
  font-weight: 600;
  color: var(--muted);
  background: #f8fafc;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
table.data tr:last-child td { border-bottom: 0; }

/* Pills */
.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: #e2e8f0;
  color: var(--text);
  text-transform: capitalize;
}
.pill.income { background: #dcfce7; color: #166534; }
.pill.expense { background: #fee2e2; color: #991b1b; }
.pill.draft { background: #e2e8f0; color: var(--muted); }
.pill.scheduled { background: #dbeafe; color: #1e40af; }
.pill.published { background: #dcfce7; color: #166534; }
.pill.cancelled { background: #fee2e2; color: #991b1b; }

/* Stats */
.stat {
  background: var(--surface);
  padding: 20px 22px;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  min-width: 0;
}
.stat .label {
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}
.stat .value {
  font-size: 28px;
  font-weight: 700;
  margin-top: 10px;
  line-height: 1.1;
}
.stat .value.income { color: var(--success); }
.stat .value.expense { color: var(--danger); }
.stat .sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
}

/* Messages */
.msg {
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 14px;
}
.msg.error { background: #fee2e2; color: #991b1b; }
.msg.success { background: #dcfce7; color: #166534; }

/* Leadership team */
.leader-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
}
.leader-label {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
  width: 100%;
  margin-bottom: -4px;
}
@media (min-width: 600px) {
  .leader-label { width: 100px; flex-shrink: 0; margin-bottom: 0; padding-top: 6px; }
}
.leader-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.leader-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
}
.leader-chip.leader { background: #fef3c7; color: #92400e; }
.leader-chip.co-leader { background: #dbeafe; color: #1e40af; }
.chip-x {
  background: transparent;
  border: 0;
  cursor: pointer;
  font-size: 16px;
  color: inherit;
  opacity: 0.6;
  padding: 0 2px;
  line-height: 1;
}
.chip-x:hover { opacity: 1; }

/* Inline pickers (member/role selects in the Assign row) */
.picker {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 14px;
  min-width: 160px;
  flex: 1;
  max-width: 320px;
}
@media (max-width: 600px) {
  .picker { width: 100%; max-width: none; flex: none; }
  .leader-chips { flex-direction: column; align-items: stretch; }
  .leader-chips .btn { width: 100%; }
}

/* Permission matrix */
.matrix-wrap { overflow-x: auto; }
.matrix {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}
.matrix th, .matrix td {
  border: 1px solid var(--border);
  padding: 8px;
  text-align: center;
  font-size: 13px;
}
.matrix th { background: #f8fafc; font-weight: 600; }
.matrix td.role-cell {
  text-align: left;
  font-weight: 600;
  text-transform: capitalize;
  background: #f8fafc;
}
.matrix select { padding: 4px 6px; border-radius: 6px; border: 1px solid var(--border); }

/* Permission matrix collapsed view (mobile) */
.matrix-mobile { display: none; }
@media (max-width: 640px) {
  .matrix-wrap { display: none; }
  .matrix-mobile { display: block; }
  .matrix-mobile .role-block {
    background: var(--surface);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  }
  .matrix-mobile .role-block h3 {
    margin: 0 0 12px;
    text-transform: capitalize;
    font-size: 16px;
  }
  .matrix-mobile .perm-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-top: 1px solid var(--border);
  }
  .matrix-mobile .perm-row:first-of-type { border-top: 0; }
}

/* Loading */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  color: var(--muted);
}

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 16px;
  overflow-y: auto;
}
.modal {
  background: var(--surface);
  border-radius: 16px;
  padding: 24px;
  max-width: 560px;
  width: 100%;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}
/* Allow inputs (esp. native date pickers) to shrink inside the modal grid
   instead of forcing the modal wider than the viewport. */
.modal .field input,
.modal .field select,
.modal .field textarea { min-width: 0; }

/* Checkbox row used by All day / Mandatory toggles */
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  cursor: pointer;
  font-size: 14px;
  user-select: none;
}
.checkbox-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--primary);
}

/* Assignee picker */
.assignee-list {
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  background: #f8fafc;
}
.assignee-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}
.assignee-item:hover { background: white; }
.assignee-item input[type="checkbox"] {
  accent-color: var(--primary);
  width: 16px; height: 16px;
  cursor: pointer;
}
.modal h2 { margin-top: 0; }
.modal-actions {
  display: flex; gap: 8px; justify-content: flex-end;
  margin-top: 16px;
}

/* Calendar header & view toggle */
.cal-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.view-toggle {
  display: inline-flex;
  background: var(--bg);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}
.view-toggle button {
  border: 0;
  background: transparent;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}
.view-toggle button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.btn.icon-only { padding: 6px 10px; font-size: 16px; line-height: 1; }

/* Month grid */
.month-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.month-label {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  flex: 1;
  text-align: left;
}
.month-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  gap: 1px;
}
.month-grid .dow {
  background: #f8fafc;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  padding: 8px 4px;
  letter-spacing: 0.05em;
}
.day-cell {
  background: var(--surface);
  min-height: 110px;
  padding: 6px 6px 4px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow: hidden;
}
.day-cell.out-of-month { background: #fafafa; color: #94a3b8; }
.day-cell.today .day-num {
  background: var(--primary);
  color: white;
  border-radius: 999px;
  width: 24px; height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
}
.day-num {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 2px;
}
.day-cell:not(.out-of-month) .day-num { color: var(--text); }
.day-event {
  background: #dbeafe;
  color: #1e3a8a;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  line-height: 1.3;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.day-event:hover { filter: brightness(0.95); }
.day-event.allday { background: #d1fae5; color: #065f46; }
.day-event.mandatory { background: #fef3c7; color: #92400e; }
.day-event .t { font-weight: 600; opacity: 0.85; }
.more-events {
  font-size: 11px;
  color: var(--muted);
  padding: 0 6px;
  font-weight: 500;
}

/* Mobile: cells get tighter, hide event titles in favor of dots */
@media (max-width: 640px) {
  .day-cell { min-height: 64px; padding: 4px 3px; }
  .day-num { font-size: 11px; margin-bottom: 1px; }
  .day-event {
    font-size: 0;
    height: 5px;
    padding: 0;
    border-radius: 999px;
    margin: 1px 0;
  }
  .day-event .t, .day-event .t-title { display: none; }
  .more-events { font-size: 10px; padding: 0 2px; }
  .month-grid .dow { font-size: 10px; padding: 4px 2px; }
}

/* Calendar */
.event-list .event {
  background: var(--surface);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.event .date-block {
  background: var(--bg);
  border-radius: 8px;
  padding: 8px 10px;
  text-align: center;
  min-width: 56px;
  flex-shrink: 0;
}
.event .date-block .month {
  font-size: 11px; color: var(--muted); text-transform: uppercase;
  font-weight: 600; letter-spacing: 0.05em;
}
.event .date-block .day { font-size: 22px; font-weight: 700; }
.event .info { flex: 1; min-width: 0; }
.event .info h3 { margin: 0 0 4px; font-size: 16px; }
.event .info .meta { color: var(--muted); font-size: 13px; }
.event .actions { display: flex; flex-direction: column; gap: 4px; }
@media (max-width: 480px) {
  .event { flex-wrap: wrap; }
  .event .actions { flex-direction: row; width: 100%; }
}

/* Files */
.file-folder { margin-bottom: 24px; }
.file-folder h2 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 8px;
}
.file-list { display: grid; gap: 8px; }
.file-item {
  background: var(--surface);
  border-radius: 10px;
  padding: 12px 16px;
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}
.file-item .file-info { flex: 1; min-width: 0; }
.file-item .file-info .title { font-weight: 500; }
.file-item .file-info .desc { color: var(--muted); font-size: 13px; }

/* Media gallery */
.media-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
.media-tile {
  background: var(--surface);
  border-radius: 10px;
  padding: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  display: flex; flex-direction: column; gap: 8px;
}
.media-tile .media-preview {
  background: var(--bg);
  border-radius: 8px;
  aspect-ratio: 1;
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.media-tile .media-preview img { width: 100%; height: 100%; object-fit: cover; }
.media-tile .media-preview .placeholder {
  color: var(--muted); font-size: 14px;
}
.media-tile .title { font-weight: 500; font-size: 14px; }

/* Marketing kanban */
.kanban {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr;
}
@media (min-width: 768px) {
  .kanban { grid-template-columns: repeat(4, 1fr); }
}
.kanban-col {
  background: var(--bg);
  border-radius: 12px;
  padding: 12px;
  min-height: 100px;
}
.kanban-col h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 12px;
  color: var(--muted);
}
.kanban-card {
  background: var(--surface);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  font-size: 14px;
}
.kanban-card .title { font-weight: 500; }
.kanban-card .meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
