:root {
  --bg: #070707;
  --surface: #111111;
  --surface-soft: #1b1a19;
  --surface-strong: #211d1a;
  --text: #f7f2ec;
  --muted: #aaa09a;
  --line: #2c2825;
  --accent: #ff5a32;
  --accent-strong: #ff324d;
  --accent-soft: rgba(255, 90, 50, 0.16);
  --amber: #ff9a3d;
  --red: #ff5b63;
  --green: #39d18d;
  --blue: #5da7ff;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.48);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
}

.topbar {
  align-items: center;
  background: rgba(8, 8, 8, 0.94);
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 18px;
  grid-template-columns: auto 1fr auto;
  min-height: 68px;
  padding: 0 26px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  align-items: center;
  display: inline-flex;
  font-weight: 760;
  gap: 10px;
  min-width: 0;
}

.brand > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-mark {
  align-items: center;
  background: #0c0c0c;
  border: 1px solid rgba(255, 90, 50, 0.42);
  border-radius: 7px;
  box-shadow: 0 0 22px rgba(255, 90, 50, 0.18);
  display: inline-flex;
  height: 32px;
  justify-content: center;
  width: 32px;
}

.brand-mark img {
  display: block;
  height: 24px;
  width: 24px;
}

.nav {
  align-items: center;
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.nav a {
  border-radius: 7px;
  color: var(--muted);
  padding: 9px 11px;
}

.nav a.active,
.nav a:hover {
  background: var(--surface-strong);
  color: var(--text);
}

.account {
  align-items: center;
  color: var(--muted);
  display: inline-flex;
  font-size: 14px;
  gap: 10px;
  justify-self: end;
  min-width: 0;
}

.account img {
  border-radius: 50%;
  height: 28px;
  width: 28px;
}

.account span {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-shell {
  margin: 0 auto;
  max-width: 1480px;
  padding: 26px;
}

.auth-screen {
  display: grid;
  min-height: calc(100vh - 130px);
  place-items: center;
}

.auth-panel,
.form-surface,
.empty-state,
.error-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-panel {
  display: grid;
  gap: 20px;
  max-width: 460px;
  padding: 32px;
  width: 100%;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  font-size: 32px;
  line-height: 1.1;
  margin-bottom: 8px;
}

h2 {
  font-size: 18px;
  margin-bottom: 18px;
}

p {
  color: var(--muted);
  line-height: 1.55;
}

.primary-action,
.secondary-action,
.icon-button {
  align-items: center;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  display: inline-flex;
  font-weight: 720;
  gap: 8px;
  justify-content: center;
  min-height: 40px;
  transition:
    background 0.16s ease,
    color 0.16s ease,
    transform 0.16s ease;
}

.primary-action {
  background: var(--accent);
  color: #160907;
  padding: 0 15px;
}

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

.secondary-action {
  background: var(--surface-soft);
  color: var(--text);
  padding: 0 13px;
}

.secondary-action:hover {
  background: #28221f;
}

.primary-action:disabled,
.secondary-action:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.icon-button {
  background: transparent;
  color: var(--muted);
  height: 38px;
  padding: 0;
  width: 38px;
}

.icon-button:hover {
  background: var(--surface-strong);
  color: var(--text);
}

.icon-button.danger:hover {
  background: rgba(255, 91, 99, 0.14);
  color: var(--red);
}

.primary-action svg,
.secondary-action svg,
.icon-button svg {
  height: 18px;
  width: 18px;
}

.stack,
.narrow-stack,
.dashboard-shell {
  display: grid;
  gap: 20px;
}

.narrow-stack {
  margin: 0 auto;
  max-width: 900px;
}

.page-title,
.dashboard-head {
  align-items: end;
  display: flex;
  gap: 16px;
  justify-content: space-between;
}

.page-title p,
.dashboard-head p {
  margin-bottom: 0;
}

.form-surface {
  display: grid;
  gap: 18px;
  padding: 24px;
}

.form-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

label {
  color: var(--muted);
  display: grid;
  font-size: 13px;
  font-weight: 720;
  gap: 7px;
}

input,
select {
  background: #151515;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  min-height: 42px;
  padding: 0 12px;
  width: 100%;
}

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

.switch-row,
.form-actions,
.run-sync-form,
.inline-form,
.chip-row,
.row-actions {
  align-items: center;
  display: flex;
  gap: 10px;
}

.run-sync-form {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.run-sync-form select {
  min-width: 190px;
  width: auto;
}

.switch-row {
  flex-wrap: wrap;
}

.switch {
  align-items: center;
  background: var(--surface-strong);
  border-radius: 7px;
  color: var(--text);
  display: inline-flex;
  min-height: 42px;
  padding: 0 12px;
}

.switch input {
  height: auto;
  min-height: 0;
  width: auto;
}

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  min-width: 860px;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0;
  text-transform: uppercase;
}

td small {
  color: var(--muted);
  display: block;
  margin-top: 3px;
}

tr:last-child td {
  border-bottom: 0;
}

.chip {
  background: rgba(255, 90, 50, 0.13);
  border: 1px solid rgba(255, 90, 50, 0.35);
  border-radius: 999px;
  color: #ff9a75;
  font-size: 12px;
  font-weight: 720;
  padding: 5px 8px;
}

.empty-state,
.error-box {
  padding: 26px;
}

.muted-line {
  color: var(--muted);
  margin: 0;
}

.filter-bar {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) minmax(180px, 1fr);
}

.calendar-layout {
  align-items: start;
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1fr) 320px;
}

.preview-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
  padding: 18px;
}

.preview-head,
.preview-summary {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.preview-summary {
  background: var(--surface-soft);
  border-radius: 7px;
  color: var(--muted);
  flex-wrap: wrap;
  justify-content: flex-start;
  padding: 10px 12px;
}

.preview-summary strong {
  color: var(--text);
}

.preview-group {
  display: grid;
  gap: 10px;
}

.preview-table-wrap table {
  min-width: 980px;
}

.preview-pending {
  background: rgba(255, 154, 61, 0.14);
  border-color: rgba(255, 154, 61, 0.4);
  color: #ffbd7d;
}

.preview-synced {
  background: rgba(57, 209, 141, 0.14);
  border-color: rgba(57, 209, 141, 0.4);
  color: #72e6ae;
}

.preview-skipped {
  background: rgba(93, 167, 255, 0.14);
  border-color: rgba(93, 167, 255, 0.4);
  color: #9dccff;
}

.preview-error {
  background: rgba(255, 91, 99, 0.14);
  border-color: rgba(255, 91, 99, 0.4);
  color: #ff9aa0;
}

#calendar,
.details-pane {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

#calendar {
  min-height: 720px;
  overflow-x: auto;
  padding: 16px;
}

.details-pane {
  display: grid;
  gap: 10px;
  padding: 18px;
  position: sticky;
  top: 88px;
}

dl {
  display: grid;
  gap: 12px;
  margin: 0;
}

dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
  letter-spacing: 0;
  text-transform: uppercase;
}

dd {
  margin: 3px 0 0;
  overflow-wrap: anywhere;
}

.env-list {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 12px;
  margin: 0;
  padding-top: 16px;
}

.env-list div {
  display: flex;
  justify-content: space-between;
}

.env-list dd {
  color: var(--muted);
}

.flash {
  border-radius: 8px;
  font-weight: 700;
  margin-bottom: 18px;
  padding: 12px 14px;
}

.flash-success {
  background: rgba(57, 209, 141, 0.12);
  color: var(--green);
}

.flash-error {
  background: rgba(255, 91, 99, 0.12);
  color: var(--red);
}

.flash-warning {
  background: rgba(255, 91, 31, 0.14);
  color: var(--accent);
}

.fc {
  --fc-border-color: var(--line);
  --fc-button-bg-color: var(--accent);
  --fc-button-border-color: var(--accent);
  --fc-button-text-color: #160907;
  --fc-button-hover-bg-color: var(--accent-strong);
  --fc-button-hover-border-color: var(--accent-strong);
  --fc-button-active-bg-color: var(--accent-strong);
  --fc-button-active-border-color: var(--accent-strong);
  --fc-page-bg-color: var(--surface);
  --fc-neutral-bg-color: #181818;
  --fc-list-event-hover-bg-color: var(--surface-strong);
  --fc-today-bg-color: rgba(255, 106, 61, 0.13);
  font-size: 14px;
  min-width: 0;
}

.fc .fc-toolbar-title {
  font-size: 22px;
}

.fc .fc-toolbar {
  flex-wrap: wrap;
  gap: 8px;
}

.fc .fc-toolbar-chunk {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.fc .fc-daygrid-event {
  overflow: hidden;
}

.fc .fc-event-title,
.fc .fc-event-time {
  overflow: hidden;
  text-overflow: ellipsis;
}

.fc-event {
  border: 0;
  border-radius: 5px;
  padding: 2px 4px;
}

.status-synced {
  background: var(--green) !important;
}

.status-source {
  background: var(--accent) !important;
  color: #160907 !important;
}

.status-update_pending,
.status-pending {
  background: var(--amber) !important;
}

.status-error {
  background: var(--red) !important;
}

.status-skipped,
.status-cancelled,
.status-missing {
  background: var(--blue) !important;
}

@media (max-width: 1180px) {
  .calendar-layout {
    grid-template-columns: 1fr;
  }

  .details-pane {
    position: static;
  }
}

@media (max-width: 1040px) {
  .topbar {
    gap: 10px 14px;
    grid-template-areas:
      "brand account"
      "nav nav";
    grid-template-columns: minmax(0, 1fr) auto;
    min-height: 0;
    padding: 12px 18px;
  }

  .brand {
    grid-area: brand;
  }

  .nav {
    grid-area: nav;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
    white-space: nowrap;
  }

  .nav::-webkit-scrollbar {
    display: none;
  }

  .nav a {
    flex: 0 0 auto;
  }

  .account {
    grid-area: account;
    justify-self: end;
    min-width: 0;
  }

  .page-title,
  .dashboard-head {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .dashboard-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .run-sync-form {
    justify-content: flex-start;
    width: 100%;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .page-shell {
    padding: 18px;
  }
}

@media (max-width: 720px) {
  .page-shell {
    padding: 14px;
  }

  .topbar {
    gap: 12px;
    padding: 12px 14px;
  }

  .account span {
    max-width: 190px;
  }

  .run-sync-form > *,
  .form-actions > *,
  .inline-form > * {
    flex: 1 1 180px;
  }

  .run-sync-form select {
    width: 100%;
  }

  .filter-bar {
    grid-template-columns: 1fr;
  }

  .preview-head {
    align-items: flex-start;
  }

  .preview-head h2 {
    margin-bottom: 0;
  }

  .fc .fc-toolbar-title {
    font-size: 18px;
    line-height: 1.25;
  }

  .fc .fc-button {
    padding: 7px 9px;
  }
}

@media (max-width: 560px) {
  h1 {
    font-size: 26px;
  }

  .brand > span:last-child {
    max-width: 210px;
  }

  .account {
    gap: 6px;
  }

  .account span {
    display: none;
  }

  .nav a {
    padding: 8px 10px;
  }

  .auth-panel,
  .form-surface,
  .empty-state,
  .error-box {
    padding: 20px;
  }

  #calendar {
    min-height: 560px;
    padding: 8px;
  }

  .fc .fc-toolbar {
    align-items: stretch;
    display: grid;
    gap: 8px;
  }

  .fc .fc-toolbar-chunk {
    justify-content: center;
  }

  .fc .fc-toolbar-chunk:first-child,
  .fc .fc-toolbar-chunk:last-child {
    justify-content: stretch;
  }

  .fc .fc-toolbar-chunk:first-child .fc-button-group,
  .fc .fc-toolbar-chunk:last-child .fc-button-group,
  .fc .fc-toolbar-chunk:first-child .fc-button,
  .fc .fc-toolbar-chunk:last-child .fc-button {
    flex: 1 1 auto;
  }

  .fc .fc-col-header-cell-cushion,
  .fc .fc-daygrid-day-number {
    font-size: 12px;
  }

  .fc-event {
    font-size: 12px;
    padding: 1px 3px;
  }
}
