:root {
  --bg: #0c0e14;
  --bg-elevated: #13161f;
  --bg-hover: #1a1e2a;
  --border: #252a38;
  --border-light: #323848;
  --text: #e8eaef;
  --text-muted: #8b92a5;
  --text-dim: #5c6378;
  --accent: #7c5cff;
  --accent-hover: #9178ff;
  --accent-muted: rgba(124, 92, 255, 0.15);
  --cyan: #22d3ee;
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --sidebar-width: 240px;
  --font: "DM Sans", system-ui, sans-serif;

  --status-enquiry: #fbbf24;
  --status-tentative: #fb923c;
  --status-confirmed: #34d399;
  --status-completed: #60a5fa;
  --status-cancelled: #6b7280;

  --pay-unpaid: #f87171;
  --pay-partial: #fbbf24;
  --pay-paid: #34d399;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.app {
  display: flex;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 10;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.85rem;
  margin-bottom: 2rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.brand-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.brand-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.brand-mark {
  width: 52px;
  height: 52px;
  min-width: 52px;
  min-height: 52px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #000;
}

.brand-logo {
  display: block;
  width: 52px;
  height: 52px;
  max-width: 52px;
  max-height: 52px;
  object-fit: cover;
  border-radius: var(--radius-sm);
}

.brand-name {
  font-weight: 700;
  font-size: 1.15rem;
  line-height: 1.15;
}

.brand-tag {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

.sidebar-bottom {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.sidebar-footer .btn {
  width: 100%;
  text-align: center;
}

.mobile-menu-btn {
  display: none;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.mobile-menu-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.sidebar-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.nav { display: flex; flex-direction: column; gap: 0.25rem; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 0.85rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--accent-muted); color: var(--accent-hover); }

.nav-icon { font-size: 1rem; width: 1.25rem; text-align: center; }

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.import-label { cursor: pointer; text-align: center; }

.sidebar-version {
  margin-top: auto;
  padding-top: 0.75rem;
  text-align: center;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  user-select: none;
}

/* Login */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: var(--bg);
}

.login-card {
  width: min(100%, 400px);
  padding: 1.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.login-logo {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: #000;
}

.login-brand-name {
  font-weight: 700;
  font-size: 1.15rem;
  line-height: 1.15;
}

.login-brand-tag {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

.login-intro {
  margin: 0 0 1.25rem;
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.login-submit {
  width: 100%;
  margin-top: 0.25rem;
}

.login-forgot {
  width: 100%;
  margin-top: 0.65rem;
}

.login-error {
  margin: 0;
  color: var(--danger);
  font-size: 0.85rem;
  line-height: 1.4;
}

.login-status {
  margin: 0 0 1rem;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.login-denied-title {
  margin: 0 0 0.65rem;
  font-size: 1.15rem;
}

.login-denied-text {
  margin: 0 0 1.25rem;
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

body.login-open {
  overflow: hidden;
}

body.login-open .app {
  visibility: hidden;
}

/* Main */
.main {
  flex: 1 1 auto;
  margin-left: var(--sidebar-width);
  padding: clamp(1rem, 1.5vw, 1.75rem) clamp(1rem, 2.5vw, 2.5rem);
  min-width: 0;
  max-width: none;
  box-sizing: border-box;
}

.main > .topbar,
.main > .view {
  width: 100%;
  max-width: none;
  margin-left: 0;
  margin-right: 0;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.75rem;
  gap: 1rem;
}

.topbar h1 { font-size: 1.6rem; font-weight: 700; }
.subtitle { color: var(--text-muted); font-size: 0.9rem; margin-top: 0.15rem; }

.view { display: none; }
.view.active { display: block; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); border-color: var(--border-light); }

.btn-danger {
  background: rgba(248, 113, 113, 0.12);
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.25);
}
.btn-danger:hover { background: rgba(248, 113, 113, 0.22); }

.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.8rem; }
.btn-icon { width: 36px; height: 36px; padding: 0; font-size: 1.25rem; }

/* Form controls */
.input, .select, .textarea {
  width: 100%;
  padding: 0.55rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.875rem;
  transition: border-color 0.15s;
}

.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.date-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.input-date {
  padding-right: 2.5rem;
  flex: 1;
  min-width: 0;
}

.input-date::-webkit-calendar-picker-indicator {
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.date-input-btn {
  position: absolute;
  right: 0.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.date-input-btn:hover {
  background: var(--bg-hover);
  color: var(--accent-hover);
}

.date-input-wrap:focus-within .date-input-btn {
  color: var(--accent-hover);
}

.select[multiple] { min-height: 100px; }
.textarea { resize: vertical; min-height: 60px; }

.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field label { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); }
.hint { font-size: 0.72rem; color: var(--text-dim); }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  cursor: pointer;
}

.checkbox-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
}

.crew-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.crew-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.5rem 0.25rem 0.65rem;
  background: var(--accent-muted);
  color: var(--accent-hover);
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 500;
}

.crew-tag-remove {
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 0.15rem;
  opacity: 0.7;
}

.crew-tag-remove:hover { opacity: 1; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.span-2 { grid-column: span 2; }

.form-section-title {
  grid-column: 1 / -1;
  margin: 0.15rem 0 0;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.form-section-title:not(:first-child) {
  margin-top: 0.55rem;
}

/* Calendar */
.calendar-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.calendar-nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.calendar-nav h2 {
  font-size: 1.15rem;
  font-weight: 600;
  min-width: 180px;
  text-align: center;
}

.calendar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.legend-item { display: flex; align-items: center; gap: 0.4rem; }
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.status-enquiry { background: var(--status-enquiry); }
.status-tentative { background: var(--status-tentative); }
.status-confirmed { background: var(--status-confirmed); }
.status-completed { background: var(--status-completed); }
.status-cancelled { background: var(--status-cancelled); }

.calendar-grid {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.calendar-weekdays {
  display: grid;
  width: 100%;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  background: var(--bg-hover);
  border-bottom: 1px solid var(--border);
}

.calendar-weekdays span {
  padding: 0.6rem;
  text-align: center;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.calendar-days {
  display: grid;
  width: 100%;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-auto-rows: minmax(100px, auto);
}

.calendar-day {
  min-height: 100px;
  min-width: 0;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 0.35rem;
  cursor: pointer;
  transition: background 0.12s, box-shadow 0.12s;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  user-select: none;
  overflow: hidden;
}

.calendar-day:nth-child(7n) { border-right: none; }
.calendar-days .calendar-day:nth-last-child(-n+7) { border-bottom: none; }

.calendar-day:hover { background: var(--bg-hover); }
.calendar-day.other-month { opacity: 0.35; }
.calendar-day.today .day-number {
  background: var(--accent);
  color: #fff;
}

.calendar-day.selected {
  background: var(--accent-muted);
  box-shadow: inset 0 0 0 2px var(--accent);
}

.calendar-day.selected.today .day-number {
  background: var(--accent);
  color: #fff;
}

.day-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.day-shows {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  max-width: 100%;
  min-height: 0;
  overflow: hidden;
  pointer-events: none;
}

.show-pill {
  display: block;
  font-size: 0.68rem;
  padding: 2px 6px;
  border-radius: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
  border-left: 2px solid;
  pointer-events: none;
}

.show-pill.status-enquiry { background: rgba(251, 191, 36, 0.15); border-color: var(--status-enquiry); color: #fde68a; }
.show-pill.status-tentative { background: rgba(251, 146, 60, 0.15); border-color: var(--status-tentative); color: #fdba74; }
.show-pill.status-confirmed { background: rgba(52, 211, 153, 0.15); border-color: var(--status-confirmed); color: #6ee7b7; }
.show-pill.status-completed { background: rgba(96, 165, 250, 0.15); border-color: var(--status-completed); color: #93c5fd; }
.show-pill.status-cancelled { background: rgba(107, 114, 128, 0.15); border-color: var(--status-cancelled); color: #9ca3af; text-decoration: line-through; }

.show-more {
  font-size: 0.65rem;
  color: var(--text-dim);
  padding: 0 4px;
}

.calendar-day-detail {
  margin-top: 1.25rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
}

.calendar-day-detail-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.85rem;
}

.calendar-day-detail-body {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.calendar-day-detail-empty {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.day-detail-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.75rem 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  font-family: inherit;
  color: inherit;
}

.day-detail-item:hover {
  border-color: var(--border-light);
  background: var(--bg-hover);
}

.day-detail-item-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.25rem;
}

.day-detail-client {
  font-weight: 600;
  font-size: 0.9rem;
}

.day-detail-location {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.day-detail-meta {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.day-detail-crew {
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* Table */
.filters-bar, .view-header-row {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.filters-bar .input { flex: 1; min-width: 200px; }
.filters-bar .select { width: auto; min-width: 160px; }
.view-header-row .input { flex: 1; min-width: 200px; }

.table-wrap {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  overflow-y: hidden;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table th {
  text-align: left;
  padding: 0.75rem 1rem;
  background: var(--bg-hover);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }

/* Keep non-calendar rows neutral on hover */
#view-shows .data-table tr:hover td,
#view-payments .data-table tr:hover td,
#view-reports .data-table tr:hover td {
  background: transparent;
}

#showsTable tr.shows-month-header td {
  background: var(--bg-hover);
  border-bottom: 1px solid var(--border);
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 0.55rem 0.75rem;
}

#showsTable tr.shows-month-header:first-child td {
  border-top: none;
}

#view-shows .data-table tr.shows-month-header:hover td {
  background: var(--bg-hover);
}

.status-badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: capitalize;
}

.status-badge.status-enquiry { background: rgba(251, 191, 36, 0.15); color: var(--status-enquiry); }
.status-badge.status-tentative { background: rgba(251, 146, 60, 0.15); color: var(--status-tentative); }
.status-badge.status-confirmed { background: rgba(52, 211, 153, 0.15); color: var(--status-confirmed); }
.status-badge.status-completed { background: rgba(96, 165, 250, 0.15); color: var(--status-completed); }
.status-badge.status-cancelled { background: rgba(107, 114, 128, 0.15); color: var(--status-cancelled); }

.status-select {
  appearance: none;
  -webkit-appearance: none;
  display: inline-block;
  padding: 0.2rem 1.5rem 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  font-family: inherit;
  text-transform: capitalize;
  border: 1px solid transparent;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.4rem center;
  transition: border-color 0.15s, opacity 0.15s;
}

.status-select:hover { opacity: 0.9; }
.status-select:focus { outline: none; border-color: var(--border-light); }

.status-select.status-enquiry { background-color: rgba(251, 191, 36, 0.15); color: var(--status-enquiry); border-color: rgba(251, 191, 36, 0.35); }
.status-select.status-tentative { background-color: rgba(251, 146, 60, 0.15); color: var(--status-tentative); border-color: rgba(251, 146, 60, 0.35); }
.status-select.status-confirmed { background-color: rgba(52, 211, 153, 0.15); color: var(--status-confirmed); border-color: rgba(52, 211, 153, 0.35); }
.status-select.status-completed { background-color: rgba(96, 165, 250, 0.15); color: var(--status-completed); border-color: rgba(96, 165, 250, 0.35); }
.status-select.status-cancelled { background-color: rgba(107, 114, 128, 0.15); color: var(--status-cancelled); border-color: rgba(107, 114, 128, 0.35); }

.payment-state {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.25;
  border: 1px solid transparent;
  white-space: nowrap;
}

.payment-state.state-unpaid,
.payment-state.state-pending {
  background: rgba(248, 113, 113, 0.15);
  color: var(--pay-unpaid);
  border-color: rgba(248, 113, 113, 0.35);
}

.payment-state.state-partial {
  background: rgba(251, 191, 36, 0.15);
  color: var(--pay-partial);
  border-color: rgba(251, 191, 36, 0.35);
}

.payment-state.state-paid {
  background: rgba(52, 211, 153, 0.15);
  color: var(--pay-paid);
  border-color: rgba(52, 211, 153, 0.35);
}

.table-actions { display: flex; gap: 0.35rem; }

.shows-actions {
  display: flex;
  gap: 0.35rem;
  justify-content: flex-start;
}

.insight-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.insight-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
}

.insight-card h3 {
  font-size: 1rem;
  margin-bottom: 0.35rem;
}

.insight-card p {
  font-size: 0.86rem;
  color: var(--text-muted);
}

.stat-card .stat-value {
  color: var(--text);
  font-size: 1.3rem;
  font-weight: 700;
  margin-top: 0.2rem;
}

.reports-detail-grid {
  grid-template-columns: 1fr;
}

.compact-table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-top: 0.6rem;
}

.compact-table th,
.compact-table td {
  padding: 0.55rem 0.7rem;
}

#view-invoices .invoice-table-filters {
  display: grid;
  grid-template-columns: minmax(180px, 1.3fr) minmax(150px, 0.9fr) auto auto;
  gap: 0.7rem;
  align-items: center;
  margin-bottom: 0.85rem;
}

#view-invoices .table-wrap {
  overflow-x: auto;
  margin-top: 0.45rem;
}

#view-invoices .insight-grid {
  gap: 0.85rem;
  margin-bottom: 0.9rem;
}

#view-invoices .insight-card {
  padding: 1rem;
}

#invoiceShowsTable th:first-child,
#invoiceShowsTable td:first-child {
  text-align: center;
  width: 92px;
}

#invoiceShowsTable .invoice-mobile-vj-col {
  display: none;
}

.invoice-show-check {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.invoice-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.55rem;
  margin-top: 1.1rem;
  margin-bottom: 0.45rem;
}

.invoice-history-actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.invoice-paid-btn.is-paid {
  color: var(--success);
  border-color: rgba(52, 211, 153, 0.35);
}

.invoice-paid-btn.is-unpaid {
  color: var(--warning);
  border-color: rgba(251, 191, 36, 0.35);
}

.invoice-editor-totals {
  display: flex;
  gap: 1rem;
  justify-content: flex-end;
  margin-top: 0.65rem;
  font-size: 0.86rem;
}

#invoiceEditorItemsTable .input {
  width: 100%;
  min-width: 0;
}

#invoiceEditorItemsTable td[data-label="Date"] {
  color: var(--text);
  font-weight: 600;
}

/* Wider invoice editor so line item text is fully visible */
#invoiceEditorModal .modal-content {
  width: min(1040px, 96vw);
}

.invoice-billing-row {
  grid-column: 1 / -1;
  display: grid;
  gap: 1rem;
  align-items: stretch;
}

.invoice-billing-fields {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.invoice-billing-address-field {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.invoice-billing-address-field .textarea {
  flex: 1;
  min-height: 6.5rem;
  resize: vertical;
}

#invoiceEditorItemsTable th,
#invoiceEditorItemsTable td {
  white-space: normal;
  vertical-align: middle;
}

.invoice-preview-modal-content {
  width: min(1120px, 96vw);
}

.invoice-preview-body {
  padding: 0;
  min-height: 72vh;
}

#invoicePreviewFrame {
  width: 100%;
  height: 72vh;
  border: none;
  background: #fff;
}

.payment-input {
  width: 100%;
  min-width: 0;
  max-width: 120px;
  padding: 0.4rem 0.45rem;
  font-size: 0.78rem;
}

.tds-cell {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.tds-input {
  width: 100%;
  min-width: 0;
  max-width: 90px;
  padding: 0.35rem 0.4rem;
  font-size: 0.76rem;
}

.tds-amount {
  font-size: 0.75rem;
  color: var(--text-muted);
}

#view-payments .table-wrap {
  overflow-x: auto;
}

#paymentsTable {
  width: 100%;
  min-width: 0;
  table-layout: fixed;
}

#paymentsTable th,
#paymentsTable td {
  white-space: normal;
  padding: 0.5rem 0.35rem;
  vertical-align: middle;
  overflow-wrap: anywhere;
}

#paymentsTable th {
  font-size: 0.64rem;
  line-height: 1.25;
}

#paymentsTable td {
  font-size: 0.76rem;
}

#paymentsTable .payment-input,
#paymentsTable .tds-input {
  max-width: none;
  width: 100%;
  padding: 0.28rem 0.32rem;
  font-size: 0.72rem;
}

#paymentsTable td:nth-child(2) {
  word-break: break-word;
}

.vj-payment-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 68px;
  padding: 0.16rem 0.5rem;
  border-radius: 999px;
  border: 1px solid transparent;
  background: var(--bg-hover);
  font-family: inherit;
  font-size: 0.66rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s;
}

.vj-payment-btn:hover {
  opacity: 0.9;
}

.vj-payment-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.vj-payment-btn.state-unpaid,
.vj-payment-btn.state-pending {
  background: rgba(248, 113, 113, 0.18);
  color: var(--pay-unpaid);
  border-color: rgba(248, 113, 113, 0.38);
}

.vj-payment-btn.state-partial {
  background: rgba(251, 191, 36, 0.18);
  color: var(--pay-partial);
  border-color: rgba(251, 191, 36, 0.38);
}

.vj-payment-btn.state-paid {
  background: rgba(52, 211, 153, 0.18);
  color: var(--pay-paid);
  border-color: rgba(52, 211, 153, 0.38);
}

#paymentsTable .payment-actions {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

#paymentsTable .payment-actions .btn {
  width: 100%;
  font-size: 0.72rem;
  padding: 0.3rem 0.45rem;
}

/* Cards grid */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  transition: border-color 0.15s;
}

/* Keep non-calendar section cards neutral on hover */
.card:hover { border-color: var(--border); }

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.65rem;
}

.card-title { font-weight: 600; font-size: 1rem; }
.card-subtitle { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.1rem; }

.card-meta {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.card-meta span { display: flex; align-items: center; gap: 0.4rem; }

.card-actions {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.85rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border);
}

.role-tag {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  background: var(--accent-muted);
  color: var(--accent-hover);
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}

/* Modal — center all sub-windows to the viewport */
dialog.modal {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: 100vw;
  max-height: 100vh;
  max-height: 100dvh;
  margin: 0;
  border: none;
  padding: 1rem;
  background: transparent;
  overflow: auto;
}

dialog.modal[open] {
  display: grid;
  place-items: center;
  align-content: center;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
}

dialog.modal .modal-content {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: min(640px, 92vw);
  max-height: min(90vh, 90dvh);
  margin: 0;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.modal-content-sm { width: min(480px, 92vw); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 { font-size: 1.1rem; font-weight: 700; }

.modal-body {
  padding: 1.25rem;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
}

.modal-footer-right { display: flex; gap: 0.5rem; margin-left: auto; }

#profileForm.profile-form-locked .input,
#profileForm.profile-form-locked .textarea,
#profileForm.profile-form-locked .select {
  background: transparent;
  border-color: transparent;
  color: var(--text);
  cursor: default;
  resize: none;
  box-shadow: none;
}

#profileForm.profile-form-locked .input:focus,
#profileForm.profile-form-locked .textarea:focus,
#profileForm.profile-form-locked .select:focus {
  outline: none;
  border-color: transparent;
  box-shadow: none;
}

#profileForm.profile-form-locked label {
  color: var(--text-muted);
  font-size: 0.78rem;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
}

.empty-state p { margin-bottom: 1rem; }

#view-shows.shows-crew-view .status-select {
  display: none;
}

#view-shows.shows-crew-view #showStatusFilter {
  display: none;
}

#view-reports.reports-crew-view .filters-bar {
  margin-bottom: 1rem;
}

#reportsCrewPanel {
  margin-top: 0.5rem;
}

#reportsCrewPanel .insight-card h3 {
  margin-bottom: 0.85rem;
}

.hidden { display: none !important; }

/* Force classic desktop layout */
@media (min-width: 769px) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: clip;
  }

  .app {
    display: flex;
    width: 100%;
    max-width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .mobile-menu-btn {
    display: none !important;
  }

  .sidebar {
    width: var(--sidebar-width);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    overflow: visible;
    gap: 0;
    padding: 1.35rem 1.15rem;
  }

  :root {
    --sidebar-width: 288px;
  }

  .brand {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.95rem;
    margin-bottom: 2rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
  }

  .brand-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    width: 100%;
  }

  .brand-left {
    width: 100%;
    gap: 0.9rem;
    align-items: center;
  }

  .brand-left > div:last-child {
    flex: 1;
    min-width: 0;
  }

  .brand-mark,
  .brand-logo {
    width: 56px;
    height: 56px;
    min-width: 56px;
    min-height: 56px;
    max-width: 56px;
    max-height: 56px;
  }

  .brand-name {
    font-size: 1.22rem;
    line-height: 1.15;
  }

  .brand-tag {
    font-size: 0.9rem;
    margin-top: 0.15rem;
  }

  .sidebar-panel {
    display: flex !important;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    padding-top: 0;
    border-top: none;
  }

  .nav {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1;
  }

  .nav-item {
    width: 100%;
    min-width: 0;
    justify-content: flex-start;
    text-align: left;
    font-size: 1.02rem;
    padding: 0.82rem 1rem;
  }

  .sidebar-footer {
    width: 100%;
    margin-left: 0;
    justify-content: initial;
    gap: 0.35rem;
    border-top: 1px solid var(--border);
    padding-top: 1rem;
  }

  .sidebar-footer .btn {
    flex: 0 0 auto;
  }

  .sidebar-version {
    padding-top: 0.85rem;
  }

  .main {
    flex: 1 1 auto;
    margin-left: var(--sidebar-width);
    padding: clamp(1rem, 1.5vw, 1.75rem) clamp(1rem, 2.5vw, 2.5rem);
    min-width: 0;
    max-width: none;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
  }

  .topbar {
    flex-shrink: 0;
  }

  .main > .topbar,
  .main > .view,
  .filters-bar,
  .view-header-row,
  .table-wrap,
  .insight-grid,
  .insight-card,
  .cards-grid,
  .empty-state {
    width: 100%;
    max-width: none;
    box-sizing: border-box;
  }

  .main > .topbar,
  .main > .view {
    margin-left: 0;
    margin-right: 0;
  }

  .view.active {
    width: 100%;
    min-width: 0;
  }

  .topbar {
    align-items: center;
  }

  .filters-bar,
  .view-header-row {
    align-items: center;
  }

  #view-payments .filters-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr));
    gap: clamp(0.5rem, 1vw, 0.75rem);
  }

  #view-payments .filters-bar .select {
    flex: none;
    min-width: 0;
    max-width: none;
    width: 100%;
  }

  .filters-bar .input,
  .view-header-row .input {
    flex: 1 1 12rem;
    min-width: 0;
    max-width: none;
  }

  .filters-bar .select {
    flex: 1 1 10rem;
    min-width: 0;
    max-width: none;
  }

  .insight-grid,
  #view-payments #paymentsStats,
  #view-invoices #invoiceStats,
  #view-reports #reportsStats {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr));
    gap: clamp(0.65rem, 1.2vw, 1rem);
  }

  #view-reports .reports-detail-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: clamp(0.75rem, 1.5vw, 1rem);
  }

  #view-reports .reports-detail-grid > .insight-card:first-child {
    grid-column: 1 / -1;
  }

  #view-clients .cards-grid,
  #view-crew .cards-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 16rem), 1fr));
    gap: clamp(0.75rem, 1.2vw, 1rem);
  }

  #view-invoices .invoice-table-filters {
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto auto;
    gap: clamp(0.5rem, 1vw, 0.75rem);
  }

  #view-calendar.active {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    gap: clamp(0.75rem, 1.5vw, 1.5rem);
    align-items: stretch;
    padding-bottom: clamp(0.75rem, 1.2vw, 1.25rem);
  }

  #view-calendar .calendar-toolbar,
  #view-calendar .calendar-legend {
    grid-column: 1 / -1;
    margin-bottom: 0;
  }

  #view-calendar .calendar-grid {
    grid-column: 1;
    grid-row: 3;
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    min-width: 0;
  }

  #view-calendar .calendar-weekdays span {
    padding: 0.75rem 0.55rem;
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--text-muted);
  }

  #view-calendar .calendar-days {
    flex: 1 1 auto;
    min-height: clamp(18rem, calc(100dvh - 17rem), 56rem);
    grid-auto-rows: 1fr;
    align-content: stretch;
  }

  #view-calendar .calendar-day {
    aspect-ratio: auto;
    min-height: 0;
    height: 100%;
    padding: clamp(0.35rem, 0.6vw, 0.55rem);
  }

  #view-calendar .calendar-day-detail {
    grid-column: 1;
    grid-row: 4;
    margin-top: 0;
    min-width: 0;
  }

  #view-invoices .invoice-actions {
    justify-content: flex-end;
  }

  #view-invoices .insight-card,
  #view-invoices .invoice-actions {
    width: 100%;
  }

  .table-wrap {
    width: 100%;
    overflow: hidden;
  }

  #view-payments .table-wrap,
  #view-invoices .table-wrap,
  #view-reports .compact-table-wrap {
    overflow-x: auto;
  }

  /* Desktop: unified table header style (matches All Shows) */
  .main .data-table thead th {
    background: var(--bg-hover);
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 0.9rem 0.7rem;
    border-bottom: 2px solid var(--border-light);
    border-top: 1px solid var(--border);
  }

  /* Desktop: equal-width, aligned columns for Shows + Payments + Invoices */
  #showsTable,
  #paymentsTable,
  #invoiceShowsTable,
  #invoiceHistoryTable {
    width: 100%;
    table-layout: fixed;
  }

  #showsTable th:nth-child(1),
  #showsTable td:nth-child(1) { width: 8.5%; }

  #showsTable th:nth-child(2),
  #showsTable td:nth-child(2) { width: 11%; }

  #showsTable th:nth-child(3),
  #showsTable td:nth-child(3) { width: 18%; }

  #showsTable th:nth-child(4),
  #showsTable td:nth-child(4) { width: 12%; }

  #showsTable th:nth-child(5),
  #showsTable td:nth-child(5) { width: 10%; }

  #showsTable th:nth-child(6),
  #showsTable td:nth-child(6) { width: 10%; }

  #showsTable th:nth-child(7),
  #showsTable td:nth-child(7) { width: 8.5%; }

  #showsTable th:nth-child(8),
  #showsTable td:nth-child(8) { width: 8.5%; }

  #showsTable th:nth-child(9),
  #showsTable td:nth-child(9) { width: 13.5%; }

  #invoiceShowsTable th:nth-child(1),
  #invoiceShowsTable td:nth-child(1) { width: 7%; }

  #invoiceShowsTable th:nth-child(2),
  #invoiceShowsTable td:nth-child(2) { width: 9%; }

  #invoiceShowsTable th:nth-child(3),
  #invoiceShowsTable td:nth-child(3) { width: 12%; }

  #invoiceShowsTable th:nth-child(4),
  #invoiceShowsTable td:nth-child(4) { width: 20%; }

  #invoiceShowsTable th:nth-child(5),
  #invoiceShowsTable td:nth-child(5) { width: 12%; }

  #invoiceShowsTable th:nth-child(7),
  #invoiceShowsTable td:nth-child(7) { width: 9%; }

  #invoiceShowsTable th:nth-child(8),
  #invoiceShowsTable td:nth-child(8) { width: 8%; }

  #invoiceShowsTable th:nth-child(9),
  #invoiceShowsTable td:nth-child(9) { width: 9%; }

  #invoiceHistoryTable th:nth-child(1),
  #invoiceHistoryTable td:nth-child(1) { width: 14%; }

  #invoiceHistoryTable th:nth-child(2),
  #invoiceHistoryTable td:nth-child(2) { width: 12%; }

  #invoiceHistoryTable th:nth-child(3),
  #invoiceHistoryTable td:nth-child(3) { width: 24%; }

  #invoiceHistoryTable th:nth-child(4),
  #invoiceHistoryTable td:nth-child(4) { width: 10%; }

  #invoiceHistoryTable th:nth-child(5),
  #invoiceHistoryTable td:nth-child(5) { width: 14%; }

  #invoiceHistoryTable th:nth-child(6),
  #invoiceHistoryTable td:nth-child(6) { width: 26%; }

  #paymentsTable th:nth-child(1),
  #paymentsTable td:nth-child(1) { width: 7.5%; }

  #paymentsTable th:nth-child(2),
  #paymentsTable td:nth-child(2) { width: 12%; }

  #paymentsTable th:nth-child(3),
  #paymentsTable td:nth-child(3) { width: 7%; }

  #paymentsTable th:nth-child(4),
  #paymentsTable td:nth-child(4) { width: 5.5%; }

  #paymentsTable th:nth-child(5),
  #paymentsTable td:nth-child(5) { width: 8%; }

  #paymentsTable th:nth-child(6),
  #paymentsTable td:nth-child(6) { width: 8%; }

  #paymentsTable th:nth-child(7),
  #paymentsTable td:nth-child(7) { width: 8%; }

  #paymentsTable th:nth-child(8),
  #paymentsTable td:nth-child(8) { width: 8%; }

  #paymentsTable th:nth-child(9),
  #paymentsTable td:nth-child(9) { width: 7%; }

  #paymentsTable th:nth-child(10),
  #paymentsTable td:nth-child(10) { width: 7.5%; }

  #paymentsTable th:nth-child(11),
  #paymentsTable td:nth-child(11) { width: 8%; }

  #paymentsTable th:nth-child(12),
  #paymentsTable td:nth-child(12) { width: 9%; }

  #paymentsTable th:nth-child(13),
  #paymentsTable td:nth-child(13) { width: 12%; }

  #showsTable th,
  #showsTable td,
  #paymentsTable th,
  #paymentsTable td {
    text-align: center;
    vertical-align: middle;
    border-right: 1px solid var(--border);
  }

  #showsTable th:last-child,
  #showsTable td:last-child,
  #paymentsTable th:last-child,
  #paymentsTable td:last-child {
    border-right: none;
  }

  #showsTable .status-select,
  #paymentsTable .payment-input,
  #paymentsTable .tds-input,
  #paymentsTable .vj-payment-btn {
    margin-left: auto;
    margin-right: auto;
  }

  #paymentsTable .payment-actions {
    flex-direction: row;
    justify-content: center;
    gap: 0.35rem;
  }

#paymentsTable .payment-actions .btn {
  width: auto;
  min-width: 52px;
}

#view-payments .payment-client-invoice {
  display: none;
}

  /* Desktop: larger, more readable Payments table */
  #view-payments .data-table {
    font-size: 0.9375rem;
  }

  #paymentsTable th,
  #paymentsTable td {
    padding: 0.85rem 0.7rem;
  }

  #paymentsTable td {
    font-size: 0.925rem;
    line-height: 1.5;
  }

  #paymentsTable .payment-input,
  #paymentsTable .tds-input {
    max-width: none;
    padding: 0.5rem 0.55rem;
    font-size: 0.875rem;
  }

  #paymentsTable .tds-amount {
    font-size: 0.84rem;
  }

  #paymentsTable .tds-cell {
    gap: 0.4rem;
  }

  #paymentsTable .payment-state {
    font-size: 0.84rem;
    padding: 0.3rem 0.7rem;
  }

  #paymentsTable .vj-payment-btn {
    min-width: 84px;
    padding: 0.34rem 0.7rem;
    font-size: 0.82rem;
  }

  #paymentsTable .payment-actions .btn {
    min-width: 64px;
    padding: 0.45rem 0.7rem;
    font-size: 0.84rem;
  }

  /* Desktop: larger, more readable All Shows table */
  #view-shows .data-table {
    font-size: 0.9375rem;
  }

  #showsTable tbody td {
    font-size: 0.925rem;
    line-height: 1.5;
    padding: 0.85rem 0.7rem;
  }

  #showsTable tr.shows-month-header td {
    color: #fff;
    background: transparent;
    font-size: 0.98rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: none;
    padding: 0.8rem 0.85rem;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
  }

  #showsTable .status-select {
    font-size: 0.84rem;
    padding: 0.3rem 1.55rem 0.3rem 0.65rem;
  }

  #paymentsTable thead th {
    font-size: 0.9rem;
    letter-spacing: 0.07em;
  }

  dialog.modal .modal-header h2 {
    color: #fff;
  }

  dialog.modal .modal-body,
  dialog.modal .modal-body label,
  dialog.modal .form-section-title,
  dialog.modal .hint {
    color: #fff;
  }

  dialog.modal .modal-close {
    color: #fff;
  }

  #showModal .crew-tags {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.45rem;
  }

  #showModal .crew-tag {
    flex: 0 0 auto;
  }

  #showsTable .shows-actions .btn {
    font-size: 0.84rem;
    padding: 0.42rem 0.7rem;
  }

  /* Invoice editor: billing fields align to form-grid columns */
  #invoiceEditorModal .invoice-billing-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-columns: subgrid;
    grid-template-rows: auto auto;
  }

  #invoiceEditorModal .invoice-billing-fields {
    grid-column: 1;
    grid-row: 1 / 3;
    display: grid;
    grid-template-rows: subgrid;
  }

  #invoiceEditorModal .invoice-billing-address-field {
    grid-column: 2;
    grid-row: 1 / 3;
  }

  /* Desktop: larger, more readable Invoices tables (match Payments) */
  #view-invoices .data-table {
    font-size: 0.9375rem;
  }

  #invoiceShowsTable th,
  #invoiceHistoryTable th,
  #invoiceShowsTable td,
  #invoiceHistoryTable td {
    text-align: center;
    vertical-align: middle;
    border-right: 1px solid var(--border);
  }

  #invoiceShowsTable th:last-child,
  #invoiceShowsTable td:last-child,
  #invoiceHistoryTable th:last-child,
  #invoiceHistoryTable td:last-child {
    border-right: none;
  }

  #invoiceShowsTable td,
  #invoiceHistoryTable td {
    font-size: 0.925rem;
    line-height: 1.5;
    padding: 0.85rem 0.7rem;
  }

  #invoiceShowsTable .invoice-show-check {
    width: 18px;
    height: 18px;
  }

  #invoiceHistoryTable .invoice-history-actions .btn {
    font-size: 0.84rem;
    padding: 0.42rem 0.7rem;
  }

  /* Desktop: larger Reports tables (match Payments) */
  #view-reports .data-table {
    font-size: 0.9375rem;
  }

  #view-reports .compact-table th,
  #view-reports .compact-table td {
    text-align: center;
    vertical-align: middle;
    border-right: 1px solid var(--border);
  }

  #view-reports .compact-table th:last-child,
  #view-reports .compact-table td:last-child {
    border-right: none;
  }

  #view-reports .compact-table td {
    font-size: 0.925rem;
    line-height: 1.5;
    padding: 0.85rem 0.7rem;
  }

  #view-reports .insight-card h3 {
    font-size: 1.05rem;
    margin-bottom: 0.5rem;
  }
}

@media (min-width: 900px) {
  #view-calendar.active {
    grid-template-columns: minmax(0, 2fr) minmax(min(100%, 18rem), 1fr);
    grid-template-rows: auto auto minmax(0, 1fr);
  }

  #view-calendar .calendar-grid {
    grid-column: 1;
    grid-row: 3;
  }

  #view-calendar .calendar-day-detail {
    grid-column: 2;
    grid-row: 3;
    align-self: stretch;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
  }
}

@media (min-width: 1024px) {
  #view-calendar.active {
    grid-template-columns: minmax(0, 2.2fr) minmax(min(100%, 20rem), 1fr);
  }
}

@media (min-width: 1440px) {
  #view-calendar.active {
    grid-template-columns: minmax(0, 2.5fr) minmax(20rem, 1fr);
  }
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  color: var(--text);
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  box-shadow: var(--shadow);
  z-index: 1000;
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { transform: translateY(12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Responsive */
@media (max-width: 768px) {
  :root {
    --mobile-title: 0.96rem;
    --mobile-body: 0.82rem;
    --mobile-muted: 0.82rem;
    --mobile-label: 0.58rem;
    --mobile-row-pad-y: 0.22rem;
    --mobile-row-pad-x: 0.38rem;
    --mobile-table-divider: color-mix(in srgb, var(--border-light) 35%, transparent);
    --mobile-table-divider-width: 0.5px;
  }

  .app {
    flex-direction: column;
    min-height: auto;
  }

  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    flex-direction: column;
    flex-wrap: nowrap;
    padding: 0.75rem;
    gap: 0.45rem;
    align-items: stretch;
    overflow-x: visible;
  }

  .brand {
    margin-bottom: 0;
    padding-bottom: 0.65rem;
    border-bottom: 1px solid var(--border);
    flex: none;
    min-width: 0;
    gap: 0.6rem;
  }

  .brand-mark,
  .brand-logo {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    max-width: 44px;
    max-height: 44px;
  }

  .brand-name {
    font-size: 1.05rem;
  }

  .brand-tag {
    font-size: 0.78rem;
  }

  .mobile-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .sidebar-panel {
    display: none;
    flex: none;
    min-height: 0;
    gap: 0.6rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
  }

  .sidebar.open .sidebar-panel {
    display: flex;
  }

  .nav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    gap: 0.45rem;
    flex: none;
  }

  .nav-item {
    width: 100%;
    min-width: 0;
    justify-content: center;
    text-align: center;
  }

  .sidebar-footer {
    flex-direction: row;
    flex-wrap: wrap;
    width: 100%;
    margin-left: 0;
    border-top: 1px solid var(--border);
    padding-top: 0.75rem;
    justify-content: stretch;
    gap: 0.45rem;
  }

  .sidebar-footer #profileBtn {
    flex: 1 1 100%;
    width: 100%;
  }

  .sidebar-footer .btn {
    flex: 1 1 auto;
  }

  .sidebar-version {
    display: none;
    width: 100%;
    padding-top: 0.5rem;
    font-size: 0.68rem;
  }

  .sidebar.open .sidebar-version {
    display: block;
  }

  .main {
    margin-left: 0;
    padding: 0.9rem;
    max-width: 100%;
    width: 100%;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.7rem;
  }

  .topbar-actions {
    display: flex;
    justify-content: flex-start;
  }

  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }

  .invoice-billing-row {
    grid-template-columns: 1fr;
  }

  .invoice-billing-address-field .textarea {
    min-height: 5rem;
  }

  .calendar-weekdays span {
    padding: 0.4rem 0.2rem;
    font-size: 0.62rem;
  }

  .calendar-day {
    aspect-ratio: 1 / 1;
    min-height: 0;
    padding: 0.25rem;
  }

  .calendar-days {
    grid-auto-rows: auto;
  }

  .day-number {
    width: 22px;
    height: 22px;
    font-size: 0.72rem;
  }

  .show-pill {
    font-size: 0.6rem;
    padding: 1px 4px;
  }

  .table-wrap {
    overflow-x: visible;
    overflow-y: visible;
  }

  .data-table thead {
    display: none;
  }

  .data-table,
  .data-table tbody,
  .data-table tr,
  .data-table td {
    display: block;
    width: 100%;
  }

  .data-table tr {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 0.65rem;
    overflow: hidden;
  }

  .data-table tr:last-child {
    margin-bottom: 0;
  }

  .data-table td {
    border-bottom: var(--mobile-table-divider-width) solid var(--mobile-table-divider);
    padding: 0.42rem 0.55rem;
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    align-items: flex-start;
    text-align: right;
  }

  .data-table td:last-child {
    border-bottom: none;
  }

  .data-table td::before {
    content: attr(data-label);
    color: var(--text-dim);
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    text-align: left;
  }

  .data-table td strong {
    font-weight: 600;
  }

  .status-select,
  .payment-input,
  .tds-input {
    max-width: 145px;
    width: 100%;
    margin-left: auto;
  }

  #paymentsTable .payment-actions,
  .shows-actions {
    width: 100%;
    align-items: stretch;
  }

  /* Mobile modals — fit viewport; vertical scroll on body only */
  dialog.modal {
    padding: 0.5rem;
    padding-top: max(0.5rem, env(safe-area-inset-top, 0px));
    padding-right: max(0.5rem, env(safe-area-inset-right, 0px));
    padding-bottom: max(0.5rem, env(safe-area-inset-bottom, 0px));
    padding-left: max(0.5rem, env(safe-area-inset-left, 0px));
    overflow: hidden;
  }

  dialog.modal[open] {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    min-height: 100dvh;
    min-height: -webkit-fill-available;
  }

  dialog.modal .modal-content,
  dialog.modal form.modal-content,
  dialog.modal .invoice-preview-modal-content {
    width: 100%;
    max-width: 100%;
    max-height: calc(100dvh - 0.75rem - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin: 0 auto;
    touch-action: manipulation;
  }

  dialog.modal .modal-header {
    padding: 0.65rem 0.75rem;
    flex-shrink: 0;
  }

  dialog.modal .modal-header h2 {
    font-size: 0.92rem;
    line-height: 1.25;
    padding-right: 0.35rem;
    color: #fff;
  }

  dialog.modal .modal-body,
  dialog.modal .modal-body label,
  dialog.modal .form-section-title,
  dialog.modal .hint {
    color: #fff;
  }

  dialog.modal .modal-close {
    flex-shrink: 0;
    min-width: 2rem;
    min-height: 2rem;
    color: #fff;
  }

  dialog.modal .modal-body {
    padding: 0.65rem 0.75rem;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    flex: 1 1 auto;
    min-height: 0;
    max-height: calc(100dvh - 7.25rem - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  }

  dialog.modal .modal-footer {
    padding: 0.55rem 0.75rem calc(0.55rem + env(safe-area-inset-bottom, 0px));
    flex-shrink: 0;
  }

  dialog.modal .modal-footer .btn {
    min-height: 2.35rem;
  }

  dialog.modal .form-grid {
    gap: 0.65rem;
  }

  dialog.modal .form-section-title:not(:first-child) {
    margin-top: 0.35rem;
  }

  /* Mobile compact mode for non-calendar tabs */
  #view-shows .filters-bar,
  #view-payments .filters-bar,
  #view-reports .filters-bar,
  #view-invoices .filters-bar,
  #view-clients .view-header-row,
  #view-crew .view-header-row {
    gap: 0.45rem;
    margin-bottom: 0.75rem;
  }

  /* All Shows — compact header + filters (rows unchanged below) */
  body[data-active-view="shows"] .topbar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
    margin-bottom: 0.55rem;
  }

  body[data-active-view="shows"] .topbar-left {
    flex: 1;
    min-width: 0;
  }

  body[data-active-view="shows"] .topbar h1 {
    font-size: 1.05rem;
    line-height: 1.2;
  }

  body[data-active-view="shows"] .topbar .subtitle {
    display: none;
  }

  body[data-active-view="shows"] .topbar-actions {
    flex-shrink: 0;
    justify-content: flex-end;
    margin-left: 0.35rem;
  }

  body[data-active-view="shows"] #addShowBtn {
    padding: 0.28rem 0.48rem;
    font-size: 0.68rem;
    min-height: 1.65rem;
    border-radius: 6px;
    white-space: nowrap;
  }

  body[data-active-view="shows"] #view-shows .filters-bar {
    gap: 0.32rem;
    margin-bottom: 0.48rem;
  }

  body[data-active-view="shows"] #view-shows .filters-bar .input,
  body[data-active-view="shows"] #view-shows .filters-bar .select {
    padding: 0.32rem 0.4rem;
    font-size: 0.74rem;
    border-radius: 6px;
  }

  #view-shows .input,
  #view-shows .select,
  #view-payments .select,
  #view-reports .select,
  #view-invoices .input,
  #view-invoices .select,
  #view-clients .input,
  #view-crew .input {
    padding: 0.42rem 0.55rem;
    font-size: 0.8rem;
  }

  #view-shows .data-table tr,
  #view-payments .data-table tr,
  #view-reports .data-table tr,
  #view-invoices .data-table tr {
    margin-bottom: 0.32rem;
    border-radius: 6px;
  }

  #view-shows .data-table td,
  #view-payments .data-table td,
  #view-reports .data-table td,
  #view-invoices .data-table td {
    padding: 0.18rem 0.38rem;
    gap: 0.28rem;
  }

  #view-shows .data-table tr,
  #view-payments .data-table tr,
  #view-reports .data-table tr,
  #invoiceShowsTable tr,
  #invoiceHistoryTable tr {
    column-gap: 0;
  }

  #view-shows .data-table td,
  #view-payments .data-table td,
  #view-reports .data-table td,
  #view-invoices .data-table td {
    border-bottom-width: var(--mobile-table-divider-width);
    border-bottom-style: solid;
    border-bottom-color: var(--mobile-table-divider);
  }

  #view-shows .data-table td::before,
  #view-payments .data-table td::before,
  #view-reports .data-table td::before,
  #view-invoices .data-table td::before {
    font-size: var(--mobile-label);
    letter-spacing: 0.02em;
  }

  /* Inline label + value on one line */
  #view-shows .data-table td.mobile-stat-cell,
  #view-payments .data-table td.mobile-stat-cell,
  #view-reports .data-table td.mobile-stat-cell,
  #view-invoices .data-table td.mobile-stat-cell,
  #view-shows .data-table td[data-label="Date"],
  #view-shows .data-table td[data-label="Status"],
  #view-shows .data-table td[data-label="Fee"],
  #view-shows .data-table td[data-label="VJ Fees"],
  #view-payments .data-table td[data-label="Date"],
  #view-payments .data-table td[data-label="Fee"],
  #view-payments .data-table td[data-label="TDS"],
  #view-payments .data-table td[data-label="Received"],
  #view-payments .data-table td[data-label="Balance"],
  #view-payments .data-table td[data-label="State"],
  #view-reports .data-table td[data-label="Month"],
  #view-reports .data-table td[data-label="Fee"],
  #view-reports .data-table td[data-label="Received"],
  #view-reports .data-table td[data-label="Shows"],
  #view-reports .data-table td[data-label="Pending Status"],
  #view-reports .data-table td[data-label="VJ Fees"],
  #invoiceShowsTable td[data-label="Date"],
  #invoiceShowsTable td[data-label="Fee"],
  #invoiceShowsTable td[data-label="Place"],
  #invoiceHistoryTable td[data-label="Invoice #"],
  #invoiceHistoryTable td[data-label="Date"],
  #invoiceHistoryTable td[data-label="Total"] {
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    text-align: left;
  }

  #view-shows .data-table td[data-label="Date"]::before,
  #view-shows .data-table td[data-label="Status"]::before,
  #view-shows .data-table td[data-label="Fee"]::before,
  #view-shows .data-table td[data-label="VJ Fees"]::before,
  #view-payments .data-table td[data-label="Date"]::before,
  #view-payments .data-table td[data-label="Fee"]::before,
  #view-payments .data-table td[data-label="TDS"]::before,
  #view-payments .data-table td[data-label="Received"]::before,
  #view-payments .data-table td[data-label="Balance"]::before,
  #view-payments .data-table td[data-label="State"]::before,
  #view-reports .data-table td::before,
  #invoiceShowsTable td[data-label="Date"]::before,
  #invoiceShowsTable td[data-label="Fee"]::before,
  #invoiceShowsTable td[data-label="Place"]::before,
  #invoiceHistoryTable td[data-label="Invoice #"]::before,
  #invoiceHistoryTable td[data-label="Date"]::before,
  #invoiceHistoryTable td[data-label="Total"]::before {
    margin-bottom: 0;
    min-width: 2.1rem;
    flex-shrink: 0;
  }

  /* Primary title cell — client / name only, no label (except All Shows date+client row) */
  #view-payments .data-table td[data-label="Client"],
  #view-reports .data-table td[data-label="Client"],
  #view-reports .data-table td[data-label="VJ"],
  #invoiceShowsTable td[data-label="Client"] {
    flex-direction: row;
    align-items: center;
    padding: 0.26rem var(--mobile-row-pad-x) 0.1rem;
    font-size: var(--mobile-title);
    font-weight: 600;
    line-height: 1.25;
  }

  #view-payments .data-table td[data-label="Client"]::before,
  #view-reports .data-table td[data-label="Client"]::before,
  #view-reports .data-table td[data-label="VJ"]::before,
  #invoiceShowsTable td[data-label="Client"]::before,
  #invoiceHistoryTable td[data-label="Client"]::before {
    display: none;
  }

  /* Shared mobile stat row typography */
  #view-payments .data-table td[data-label="Date"],
  #view-payments .data-table td[data-label="Fee"],
  #view-payments .data-table td[data-label="TDS"],
  #view-payments .data-table td[data-label="Received"],
  #view-payments .data-table td[data-label="Balance"],
  #view-payments .data-table td[data-label="State"],
  #view-reports .data-table td[data-label="Month"],
  #view-reports .data-table td[data-label="Fee"],
  #view-reports .data-table td[data-label="Received"],
  #view-reports .data-table td[data-label="Pending Status"],
  #view-reports .data-table td[data-label="VJ Fees"],
  #invoiceHistoryTable td[data-label="Invoice #"],
  #invoiceHistoryTable td[data-label="Total"] {
    font-size: var(--mobile-body);
    line-height: 1.25;
  }

  #invoiceHistoryTable td[data-label="Client"] {
    flex-direction: row;
    align-items: center;
    padding: 0.26rem var(--mobile-row-pad-x) 0.08rem;
    font-size: var(--mobile-title);
    font-weight: 600;
    line-height: 1.25;
  }

  /* All Shows — hide secondary fields on mobile */
  #view-shows .data-table td[data-label="Description"],
  #view-shows .data-table td[data-label="Place"] {
    display: none !important;
  }

  #view-shows #showsTable tr.shows-month-header {
    display: block;
    margin-top: 0.65rem;
    margin-bottom: 0.2rem;
    border: none;
    background: transparent;
    border-radius: 0;
    overflow: visible;
  }

  #view-shows #showsTable tr.shows-month-header:first-child {
    margin-top: 0;
  }

  #view-shows #showsTable tr.shows-month-header td {
    display: block;
    width: 100%;
    padding: 0.42rem 0.42rem 0.12rem;
    border: none;
    background: transparent;
    font-size: 0.88rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text);
    text-align: center;
  }

  #view-shows #showsTable tr.shows-month-header td::before {
    display: none;
  }

  #view-shows .data-table tr {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    row-gap: 0.1rem;
    margin-bottom: 0.46rem;
  }

  /* Row 1: date + client + vj name — shared full-width divider via joined cell borders */
  #view-shows .data-table td[data-label="Date"],
  #view-shows .data-table td[data-label="Client"],
  #view-shows .data-table td[data-label="Crew"] {
    padding-top: 0.34rem;
    padding-bottom: 0.34rem;
  }

  #view-shows .data-table td[data-label="Date"] {
    grid-row: 1;
    grid-column: 1;
    flex-direction: row;
    align-items: center;
    white-space: nowrap;
    padding-left: 0.42rem;
    padding-right: 0.1rem;
    font-size: var(--mobile-body);
    color: var(--text-muted);
  }

  #view-shows .data-table td[data-label="Date"]::before {
    display: none;
  }

  #view-shows .data-table td[data-label="Client"] {
    grid-row: 1;
    grid-column: 2 / 4;
    flex-direction: row;
    align-items: center;
    padding-left: 0.08rem;
    padding-right: 0.06rem;
    font-size: var(--mobile-title);
    font-weight: 600;
    min-width: 0;
  }

  #view-shows .data-table td[data-label="Client"]::before {
    display: none;
  }

  #view-shows .data-table td[data-label="Client"] strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #view-shows .data-table td[data-label="Crew"] {
    display: flex !important;
    grid-row: 1;
    grid-column: 4 / 5;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 0.1rem;
    padding-left: 0.06rem;
    padding-right: 0.42rem;
    font-size: var(--mobile-body);
    font-weight: 500;
    line-height: 1.3;
    color: var(--text-muted);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #view-shows .data-table td[data-label="Crew"]::before {
    content: 'VJ';
    color: var(--text-dim);
    font-size: var(--mobile-body);
    font-weight: 500;
    line-height: 1.3;
    min-width: auto;
    margin: 0 0.08rem 0 0;
    flex-shrink: 0;
  }

  /* Row 2: fee | vj fees */
  #view-shows .data-table td[data-label="Fee"],
  #view-shows .data-table td[data-label="VJ Fees"] {
    font-size: var(--mobile-body);
    line-height: 1.3;
    padding: var(--mobile-row-pad-y) 0.36rem;
  }

  #view-shows .data-table td[data-label="Fee"] {
    grid-row: 2;
    grid-column: 1 / 3;
    white-space: nowrap;
  }

  #view-shows .data-table td[data-label="VJ Fees"] {
    grid-row: 2;
    grid-column: 3 / 5;
    white-space: nowrap;
    display: flex !important;
  }

  #view-shows .data-table td[data-label="Fee"]::before,
  #view-shows .data-table td[data-label="VJ Fees"]::before {
    font-size: var(--mobile-label);
    min-width: 1.65rem;
  }

  /* Row 3: status + edit — equal width columns */
  #view-shows .data-table td[data-label="Status"] {
    grid-row: 3;
    grid-column: 1 / 3;
    flex-direction: row;
    align-items: center;
    gap: 0.2rem;
    font-size: var(--mobile-body);
    line-height: 1.3;
    padding: var(--mobile-row-pad-y) 0.14rem 0.32rem 0.42rem;
    border-bottom: none;
  }

  #view-shows .data-table td[data-label="Status"]::before {
    margin-bottom: 0;
    font-size: var(--mobile-label);
    min-width: 1.45rem;
    flex-shrink: 0;
  }

  #view-shows .data-table td:nth-child(9) {
    grid-row: 3;
    grid-column: 3 / 5;
    display: flex;
    align-items: center;
    justify-content: stretch;
    padding: 0.22rem 0.42rem 0.32rem 0.14rem;
    border-bottom: none;
  }

  #view-shows .data-table td:nth-child(9)::before {
    display: none;
  }

  #view-shows .shows-actions {
    width: 100%;
  }

  #view-shows .status-select {
    width: 100%;
    flex: 1 1 auto;
    min-width: 0;
    max-width: 100%;
    margin-left: 0;
    padding: 0.12rem 0.2rem;
    font-size: 0.74rem !important;
    line-height: 1.2;
    min-height: 0;
    height: 1.45rem;
    border-radius: 4px;
  }

  #view-shows .shows-actions .btn {
    width: 100%;
    padding: 0.26rem 0.4rem;
    font-size: 0.78rem;
    min-height: 1.45rem;
    white-space: nowrap;
  }

  /* Payments — hide derived / secondary fields on mobile */
  #view-payments .data-table td[data-label="TDS Amount"],
  #view-payments .data-table td[data-label="GST (18%)"],
  #view-payments .data-table td[data-label="VJ Fees"],
  #view-payments .data-table td[data-label="VJ Payment"] {
    display: none !important;
  }

  #view-payments .data-table tr {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    row-gap: 0;
  }

  #view-payments .data-table td[data-label="Client"] {
    grid-row: 1;
    grid-column: 1 / -1;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.35rem;
  }

  #view-payments .data-table td[data-label="Client"]::before {
    display: none;
  }

  #view-payments .payment-client-invoice {
    display: inline;
    font-size: var(--mobile-muted);
    color: var(--text-muted);
    font-weight: 500;
    line-height: 1.25;
  }

  #view-payments .payment-client-invoice::before {
    content: '· ';
    color: var(--text-dim);
  }

  #view-payments .data-table td[data-label="Invoice Number"] {
    display: none !important;
  }

  #view-payments .data-table td[data-label="Date"] { grid-row: 2; grid-column: 1; }
  #view-payments .data-table td[data-label="Fee"] { grid-row: 2; grid-column: 2; white-space: nowrap; }
  #view-payments .data-table td[data-label="State"] { grid-row: 2; grid-column: 3; }

  #view-payments .data-table td[data-label="TDS"] { grid-row: 3; grid-column: 1; }
  #view-payments .data-table td[data-label="Received"] { grid-row: 3; grid-column: 2; }
  #view-payments .data-table td[data-label="Balance"] { grid-row: 3; grid-column: 3; white-space: nowrap; }

  #view-payments .data-table td[data-label="Actions"] {
    grid-row: 4;
    grid-column: 1 / -1;
    padding: 0.12rem 0.38rem 0.28rem;
    border-bottom: none;
  }

  #view-payments .data-table td[data-label="Actions"]::before {
    display: none;
  }

  #view-payments .payment-state,
  #view-reports .payment-state {
    font-size: 0.62rem;
    padding: 0.12rem 0.38rem;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #view-payments .vj-payment-btn {
    font-size: 0.62rem;
    min-width: 0;
    padding: 0.12rem 0.38rem;
  }

  #view-payments .payment-input,
  #view-payments .tds-input {
    width: 100%;
    max-width: none;
    margin-left: 0;
    padding: 0.12rem 0.28rem;
    font-size: 16px !important;
    line-height: 1.2;
    min-height: 1.65rem;
    height: 1.65rem;
    border-radius: 4px;
    border-width: 1px;
  }

  #view-payments .data-table td[data-label="TDS"] .tds-cell,
  #view-payments .data-table td[data-label="Received"] {
    flex: 1;
    min-width: 0;
    width: auto;
  }

  #view-payments .tds-cell {
    gap: 0.15rem;
  }

  #view-payments .tds-amount {
    display: none;
  }

  /* Reports — hide secondary columns on mobile */
  #reportsMonthlyTable td[data-label="Shows"],
  #reportsMonthlyTable td[data-label="Payment to Studio"],
  #reportsClientsTable td[data-label="Shows"],
  #reportsVjTable td[data-label="Shows"] {
    display: none !important;
  }

  #view-reports .data-table tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    row-gap: 0;
  }

  #view-reports .data-table td {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    text-align: left;
  }

  #reportsMonthlyTable td[data-label="Month"] { grid-row: 1; grid-column: 1; }
  #reportsMonthlyTable td[data-label="Fee"] { grid-row: 1; grid-column: 2; }
  #reportsMonthlyTable td[data-label="Received"] { grid-row: 2; grid-column: 1 / -1; }

  #reportsClientsTable td[data-label="Client"] { grid-row: 1; grid-column: 1 / -1; }
  #reportsClientsTable td[data-label="Fee"] { grid-row: 2; grid-column: 1; }
  #reportsClientsTable td[data-label="Pending Status"] { grid-row: 2; grid-column: 2; }

  #reportsVjTable td[data-label="VJ"] { grid-row: 1; grid-column: 1 / -1; }
  #reportsVjTable td[data-label="VJ Fees"] { grid-row: 2; grid-column: 1; }
  #reportsVjTable td[data-label="Pending Status"] { grid-row: 2; grid-column: 2; }

  #view-payments .insight-grid,
  #view-reports #reportsStats,
  #view-invoices #invoiceStats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.55rem;
    margin-bottom: 0.7rem;
  }

  #view-payments .insight-card,
  #view-reports #reportsStats .insight-card,
  #view-invoices #invoiceStats .insight-card {
    padding: 0.7rem;
  }

  #view-payments .insight-card h3,
  #view-reports #reportsStats .insight-card h3,
  #view-invoices #invoiceStats .insight-card h3 {
    font-size: 0.8rem;
    margin-bottom: 0.15rem;
  }

  #view-payments .stat-card .stat-value,
  #view-reports #reportsStats .stat-card .stat-value,
  #view-invoices #invoiceStats .stat-card .stat-value {
    font-size: 1rem;
    margin-top: 0;
  }

  #view-invoices .data-table td[data-label="Include"]::before {
    display: none;
  }

  /* Invoices: hide secondary columns on mobile */
  #invoiceShowsTable td[data-label="Description"],
  #invoiceShowsTable td[data-label="TDS"],
  #invoiceShowsTable td[data-label="VJ Fees"],
  #invoiceHistoryTable td[data-label="Shows"] {
    display: none !important;
  }

  #invoiceShowsTable .invoice-mobile-vj-col {
    display: flex !important;
  }

  /* Invoices: Select Shows table */
  #invoiceShowsTable tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    row-gap: 0.06rem;
  }

  #invoiceShowsTable td {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    text-align: left;
  }

  #invoiceShowsTable td[data-label="Client"] {
    grid-row: 1;
    grid-column: 1;
    min-width: 0;
    padding: 0.26rem 0.08rem 0.12rem 0.4rem;
  }

  #invoiceShowsTable td[data-label="Include"] {
    grid-row: 1;
    grid-column: 2;
    flex-direction: row;
    align-items: center;
    justify-content: flex-end;
    padding: 0.26rem 0.4rem 0.12rem 0.08rem;
  }

  #invoiceShowsTable td[data-label="Place"] {
    grid-row: 2;
    grid-column: 1;
    flex-direction: row;
    align-items: center;
    gap: 0.22rem;
    padding: 0.14rem 0.08rem 0.14rem 0.4rem;
    font-size: var(--mobile-muted);
    line-height: 1.25;
    color: var(--text-muted);
    min-width: 0;
  }

  #invoiceShowsTable td[data-label="Place"]::before {
    margin-bottom: 0;
    font-size: var(--mobile-label);
    min-width: 1.65rem;
    flex-shrink: 0;
    color: var(--text-dim);
  }

  #invoiceShowsTable td[data-label="VJ"] {
    grid-row: 2;
    grid-column: 2;
    flex-direction: row;
    align-items: center;
    justify-content: flex-end;
    gap: 0.12rem;
    padding: 0.14rem 0.4rem 0.14rem 0.08rem;
    font-size: var(--mobile-muted);
    line-height: 1.25;
    color: var(--text-muted);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #invoiceShowsTable td[data-label="VJ"]::before {
    content: 'VJ-';
    display: block;
    color: var(--text-dim);
    font-size: var(--mobile-body);
    font-weight: 600;
    min-width: auto;
    margin: 0;
    flex-shrink: 0;
  }

  #invoiceShowsTable td[data-label="Date"] {
    grid-row: 3;
    grid-column: 1;
  }

  #invoiceShowsTable td[data-label="Fee"] {
    grid-row: 3;
    grid-column: 2;
  }

  #invoiceShowsTable td[data-label="Date"],
  #invoiceShowsTable td[data-label="Fee"] {
    font-size: var(--mobile-body);
    line-height: 1.25;
    padding: 0.16rem 0.32rem 0.24rem;
  }

  #view-invoices .data-table td[data-label="Include"] {
    flex-direction: row;
    align-items: center;
    justify-content: flex-end;
    text-align: right;
    gap: 0;
  }

  /* Invoices: Created Invoices table */
  #invoiceHistoryTable tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    row-gap: 0;
  }

  #invoiceHistoryTable td {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    text-align: left;
  }

  #invoiceHistoryTable td[data-label="Client"] { grid-row: 1; grid-column: 1 / -1; }
  #invoiceHistoryTable td[data-label="Invoice #"] { grid-row: 2; grid-column: 1; }
  #invoiceHistoryTable td[data-label="Total"] { grid-row: 2; grid-column: 2; white-space: nowrap; }
  #invoiceHistoryTable td[data-label="Date"] {
    grid-row: 3;
    grid-column: 1 / -1;
    padding-bottom: 0.08rem;
    font-size: var(--mobile-muted);
    color: var(--text-muted);
  }

  #invoiceHistoryTable td[data-label="Actions"] {
    grid-row: 4;
    grid-column: 1 / -1;
    padding: 0.12rem 0.38rem 0.28rem;
    border-bottom: none;
    flex-direction: column;
    align-items: stretch;
  }

  #invoiceHistoryTable td[data-label="Actions"]::before {
    display: none;
  }

  #invoiceHistoryTable .invoice-history-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0.22rem;
  }

  #invoiceHistoryTable .invoice-history-actions .btn {
    width: 100%;
    justify-content: center;
    padding: 0.24rem 0.15rem;
    font-size: 0.62rem;
  }

  #view-invoices .insight-card {
    padding: 0.75rem;
  }

  #view-invoices .insight-card h3 {
    font-size: 0.9rem;
    margin-bottom: 0.35rem;
  }

  #view-invoices .invoice-table-filters {
    grid-template-columns: 1fr 1fr;
    gap: 0.45rem;
    margin-bottom: 0.65rem;
  }

  #view-invoices .invoice-table-filters .btn {
    width: 100%;
  }

  #view-invoices .invoice-actions {
    margin-top: 0.55rem;
    margin-bottom: 0.65rem;
  }

  #view-invoices .invoice-actions .btn {
    width: 100%;
  }

  #view-invoices .invoice-editor-totals {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
    font-size: 0.82rem;
  }

  #view-invoices #invoiceStats {
    gap: 0.4rem;
    margin-bottom: 0.55rem;
  }

  #view-invoices #invoiceStats .insight-card {
    padding: 0.55rem;
    border-radius: 8px;
  }

  #view-invoices #invoiceStats .insight-card h3 {
    font-size: 0.72rem;
    margin-bottom: 0.08rem;
  }

  #view-invoices #invoiceStats .stat-card .stat-value {
    font-size: 0.92rem;
    line-height: 1.2;
  }

  /* Form modals — compact footer layout */
  #showModal .modal-footer,
  #crewModal .modal-footer,
  #clientModal .modal-footer,
  #profileModal .modal-footer,
  #invoiceEditorModal .modal-footer {
    flex-direction: column;
    align-items: stretch;
    gap: 0.45rem;
  }

  #showModal .modal-footer-right,
  #crewModal .modal-footer-right,
  #clientModal .modal-footer-right,
  #profileModal .modal-footer-right,
  #invoiceEditorModal .modal-footer-right {
    width: 100%;
    margin-left: 0;
    flex-direction: column;
  }

  #showModal .modal-footer-right .btn,
  #crewModal .modal-footer-right .btn,
  #clientModal .modal-footer-right .btn,
  #profileModal .modal-footer-right .btn,
  #invoiceEditorModal .modal-footer-right .btn {
    width: 100%;
  }

  #clientModal #deleteClientBtn,
  #showModal #deleteShowBtn,
  #crewModal #deleteCrewBtn {
    width: 100%;
  }

  #invoiceEditorModal .form-section-title,
  #clientModal .form-section-title {
    font-size: 0.72rem;
    margin-top: 0.35rem;
  }

  #invoiceEditorItemsTable tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 0.45rem;
    row-gap: 0;
  }

  #invoiceEditorItemsTable td {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    text-align: left;
    gap: 0.18rem;
    padding: 0.32rem 0.4rem;
  }

  #invoiceEditorItemsTable td::before {
    margin-bottom: 0.08rem;
    font-size: 0.62rem;
  }

  #invoiceEditorItemsTable td:nth-child(1) { grid-row: 1; grid-column: 1; }
  #invoiceEditorItemsTable td:nth-child(4) { grid-row: 1; grid-column: 2; }
  #invoiceEditorItemsTable td:nth-child(2) { grid-row: 2; grid-column: 1 / -1; }
  #invoiceEditorItemsTable td:nth-child(3) { grid-row: 3; grid-column: 1 / -1; }

  #invoiceEditorItemsTable .input {
    width: 100%;
    max-width: none;
    margin-left: 0;
  }

  #invoiceEditorModal .compact-table-wrap {
    margin-top: 0.45rem;
  }

  #invoiceEditorModal .invoice-editor-totals {
    margin-top: 0.55rem;
  }

  .invoice-preview-modal-content {
    width: 100%;
    max-width: 100%;
  }

  .invoice-preview-body {
    min-height: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex: 1 1 auto;
    max-height: calc(100dvh - 7.25rem - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  }

  #invoicePreviewFrame {
    flex: 1 1 auto;
    width: 100%;
    min-height: 10rem;
    height: auto;
    max-height: none;
  }

  /* Smaller payment summary boxes */
  #view-payments .insight-grid {
    gap: 0.4rem;
    margin-bottom: 0.55rem;
  }

  #view-payments .insight-card {
    padding: 0.55rem;
    border-radius: 8px;
  }

  #view-payments .insight-card h3 {
    font-size: 0.72rem;
    margin-bottom: 0.08rem;
  }

  #view-payments .stat-card .stat-value {
    font-size: 0.92rem;
    line-height: 1.2;
  }

  #view-payments .payment-actions {
    flex-direction: row;
    gap: 0.3rem;
  }

  #view-payments .payment-actions .btn {
    width: auto;
    flex: 1 1 0;
  }

  #view-reports .reports-detail-grid {
    grid-template-columns: 1fr;
    gap: 0.6rem;
  }

  #view-reports .insight-card {
    padding: 0.75rem;
  }

  #view-reports .insight-card h3 {
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
  }

  #view-reports .compact-table th,
  #view-reports .compact-table td {
    padding: 0.38rem 0.45rem;
  }

  #view-clients .cards-grid,
  #view-crew .cards-grid {
    grid-template-columns: 1fr;
    gap: 0.38rem;
  }

  #view-clients .card,
  #view-crew .card {
    padding: 0.55rem 0.62rem;
  }

  #view-clients .card-header,
  #view-crew .card-header {
    margin-bottom: 0.15rem;
  }

  #view-clients .card-title,
  #view-crew .card-title {
    font-size: 0.86rem;
    line-height: 1.25;
  }

  #view-clients .card-meta,
  #view-crew .card-meta {
    font-size: 0.72rem;
    gap: 0.15rem 0.45rem;
    line-height: 1.3;
  }

  /* Clients: hide billing / tax detail lines on mobile */
  #view-clients .card-meta span:nth-child(n+4) {
    display: none;
  }

  #view-clients .card-actions,
  #view-crew .card-actions {
    margin-top: 0.35rem;
  }

  #view-clients .card-actions .btn,
  #view-crew .card-actions .btn {
    padding: 0.26rem 0.45rem;
    font-size: 0.72rem;
  }

  /* Prevent mobile browser auto-zoom on input focus (requires >= 16px) */
  .input,
  .select,
  .textarea,
  .payment-input,
  .tds-input,
  input[type="date"],
  input[type="number"],
  input[type="text"],
  input[type="search"],
  input[type="email"],
  input[type="tel"],
  textarea,
  select {
    font-size: 16px !important;
  }
}

@media (max-width: 480px) {
  .sidebar {
    padding: 0.55rem;
  }

  .main {
    padding: 0.7rem;
  }

  .topbar h1 {
    font-size: 1.35rem;
  }

  body[data-active-view="shows"] .topbar h1 {
    font-size: 1rem;
  }

  body[data-active-view="shows"] #addShowBtn {
    padding: 0.26rem 0.42rem;
    font-size: 0.66rem;
  }

  .brand-mark,
  .brand-logo {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    max-width: 40px;
    max-height: 40px;
  }

  .day-shows {
    gap: 1px;
  }

  .nav {
    grid-template-columns: 1fr;
  }

  #view-invoices .invoice-table-filters {
    grid-template-columns: 1fr;
  }
}
