: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;
  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);
}

.danger-action {
  background: var(--red);
  color: #170607;
}

.danger-action:hover {
  background: #ff3442;
}

.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-section {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 16px;
  padding-top: 18px;
}

.form-section:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.section-heading {
  display: grid;
  gap: 4px;
}

.section-heading h2 {
  font-size: 18px;
  margin: 0;
}

.section-heading p {
  color: var(--muted);
  margin: 0;
}

.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;
}

.settings-form {
  gap: 22px;
}

.settings-tabs {
  display: grid;
  gap: 18px;
}

.settings-tab-input {
  height: 1px;
  opacity: 0;
  pointer-events: none;
  position: absolute;
  width: 1px;
}

.settings-tab-nav {
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  scrollbar-width: none;
}

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

.settings-tab-label {
  align-items: center;
  background: transparent;
  border-radius: 7px;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  flex: 0 0 auto;
  font-size: 15px;
  gap: 8px;
  min-height: 40px;
  padding: 0 13px;
}

.settings-tab-label svg {
  height: 18px;
  width: 18px;
}

#settings-tab-general:checked ~ .settings-tab-nav label[for="settings-tab-general"],
#settings-tab-api:checked ~ .settings-tab-nav label[for="settings-tab-api"],
#settings-tab-realtime:checked ~ .settings-tab-nav label[for="settings-tab-realtime"] {
  background: var(--surface-strong);
  color: var(--text);
}

.settings-tab-panels {
  display: grid;
}

.settings-tab-panel {
  display: none;
  gap: 18px;
}

#settings-tab-general:checked ~ .settings-tab-panels .settings-tab-general,
#settings-tab-api:checked ~ .settings-tab-panels .settings-tab-api,
#settings-tab-realtime:checked ~ .settings-tab-panels .settings-tab-realtime {
  display: grid;
}

.readonly-link-field,
.google-calendar-options {
  display: grid;
  gap: 12px;
}

.readonly-link-field input[readonly] {
  color: var(--muted);
}

.info-strip {
  background: rgba(255, 154, 61, 0.1);
  border: 1px solid rgba(255, 154, 61, 0.24);
  border-radius: 7px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  padding: 12px 14px;
}

.option-card {
  align-items: flex-start;
  gap: 12px;
  padding: 13px 14px;
}

.option-card input {
  margin-top: 2px;
}

.option-card span {
  display: grid;
  gap: 3px;
}

.option-card strong {
  color: var(--text);
  font-size: 14px;
}

.option-card small {
  color: var(--muted);
  font-weight: 560;
  line-height: 1.4;
}

.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;
}

.chip-muted {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--line);
  color: var(--muted);
}

.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: repeat(auto-fit, minmax(180px, 1fr));
}

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

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

.cleanup-summary {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.cleanup-summary div {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  padding: 14px;
}

.cleanup-summary strong {
  font-size: 24px;
}

.cleanup-summary span,
.cleanup-event small {
  color: var(--muted);
}

.cleanup-confirm {
  align-items: end;
}

.cleanup-event {
  display: grid;
  gap: 3px;
}

.cleanup-event + .cleanup-event {
  border-top: 1px solid var(--line);
  margin-top: 10px;
  padding-top: 10px;
}

#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);
}

.toast-root {
  display: grid;
  gap: 10px;
  max-width: min(420px, calc(100vw - 28px));
  position: fixed;
  right: 16px;
  top: 76px;
  width: 100%;
  z-index: 40;
}

.toast {
  background: rgba(18, 18, 18, 0.96);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: var(--text);
  font-weight: 700;
  padding: 12px 14px;
}

.toast-success {
  border-left-color: var(--green);
}

.toast-warning {
  border-left-color: var(--accent);
}

.toast-error {
  border-left-color: var(--red);
}

.sync-loader {
  align-items: center;
  background: rgba(0, 0, 0, 0.34);
  display: flex;
  inset: 0;
  justify-content: center;
  position: fixed;
  z-index: 35;
}

.sync-loader[hidden] {
  display: none;
}

.loader-card {
  align-items: center;
  background: rgba(18, 18, 18, 0.96);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: var(--text);
  display: flex;
  font-weight: 800;
  gap: 12px;
  padding: 14px 18px;
}

.loader-spinner {
  animation: spin 0.85s linear infinite;
  border: 3px solid rgba(255, 255, 255, 0.18);
  border-top-color: var(--accent);
  border-radius: 999px;
  height: 22px;
  width: 22px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.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-active,
.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;
}

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

.source-google {
  background: var(--blue) !important;
}

.source-current {
  background: var(--green) !important;
}

.bridge-target {
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.45);
}

@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;
  }

  .cleanup-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .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;
  }

  .cleanup-summary {
    grid-template-columns: 1fr;
  }

  #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;
  }
}
