:root {
  --bg-0: #eef6f8;
  --bg-1: #dbe9ee;
  --ink: #13242f;
  --ink-soft: #5f7482;
  --card: #ffffff;
  --line: #d4e0e6;
  --accent: #0d7a73;
  --accent-dark: #0a5f5a;
  --warning: #bf5122;
  --nav: #0f2630;
  --nav-soft: #2f4854;
  --danger: #b42828;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Manrope", "Helvetica Neue", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 20% 10%, #f7fbfc 0%, var(--bg-0) 45%, var(--bg-1) 100%);
  overflow-x: hidden;
}

.global-loader {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(15, 31, 40, 0.32);
  display: grid;
  place-items: center;
}

.loader-card {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 1px solid #c8dce4;
  border-radius: 12px;
  padding: 12px 14px;
  color: #163847;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
}

.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #c6dce5;
  border-top-color: #0d7a73;
  animation: spin 0.8s linear infinite;
}

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

.app-shell {
  display: grid;
  grid-template-columns: minmax(240px, 320px) minmax(0, 1fr);
  min-height: 100vh;
  width: 100%;
  max-width: 100%;
}

.sidebar {
  background: linear-gradient(180deg, #102933 0%, #153848 100%);
  color: #e8f3f8;
  padding: 20px 16px;
  border-right: 1px solid #35515f;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 18px;
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.4px;
}

.brand p {
  margin: 4px 0 0;
  color: #bfd4de;
  font-size: 13px;
}

.menu {
  display: grid;
  gap: 8px;
}

.menu-item {
  border: 1px solid #325060;
  background: transparent;
  color: #e7f3f8;
  border-radius: 10px;
  text-align: left;
  padding: 10px 12px;
  font: inherit;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease;
}

.menu-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.menu-item.active {
  background: linear-gradient(90deg, #1e4f63, #236a73);
  border-color: #5aa6b8;
}

.portal-card {
  margin-top: auto;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 12px;
}

.portal-label {
  margin: 0 0 6px;
  font-size: 12px;
  text-transform: uppercase;
  color: #a7c3cf;
}

.portal-text {
  margin: 0;
  font-size: 13px;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.content-area {
  padding: 18px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 14px;
  min-width: 0;
}

.topbar {
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  backdrop-filter: blur(6px);
}

.topbar h2 {
  margin: 0;
  font-size: 20px;
  overflow-wrap: anywhere;
}

.status-chip {
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid #b8d3dc;
  color: #1f5f72;
  background: #eff8fb;
}

.tab-panel {
  display: none;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  min-width: 0;
}

.tab-panel.active {
  display: grid;
}

.tab-panel[data-panel="history"],
.tab-panel[data-panel="billing"] {
  grid-template-columns: 1fr;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 8px 24px rgba(24, 52, 61, 0.08);
  min-width: 0;
}

.card h3 {
  margin: 0 0 12px;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

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

label {
  display: grid;
  gap: 6px;
  font-size: 14px;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  border: 1px solid var(--line);
  background: #f9fcfd;
  border-radius: 10px;
  padding: 9px 10px;
  color: var(--ink);
}

select.js-custom-select {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.cselect {
  position: relative;
}

.cselect-btn {
  width: 100%;
  border: 1px solid var(--line);
  background: #f9fcfd;
  border-radius: 10px;
  padding: 9px 12px;
  color: var(--ink);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  text-align: left;
}

.cselect-btn::after {
  content: "";
  width: 8px;
  height: 8px;
  border-right: 2px solid #587483;
  border-bottom: 2px solid #587483;
  transform: rotate(45deg);
  margin-top: -4px;
  flex: 0 0 auto;
}

.cselect.open .cselect-btn {
  border-color: #84b2c2;
  box-shadow: 0 0 0 3px rgba(95, 164, 187, 0.15);
}

.cselect-menu {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  z-index: 35;
  border: 1px solid #cadee6;
  border-radius: 10px;
  background: #fff;
  max-height: 230px;
  overflow: auto;
  box-shadow: 0 16px 28px rgba(20, 49, 61, 0.16);
}

.cselect-search {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 8px;
  background: #fff;
  border-bottom: 1px solid #edf3f6;
}

.cselect-search input {
  width: 100%;
  border: 1px solid #d4e3ea;
  border-radius: 8px;
  padding: 8px 9px;
  font-size: 13px;
  background: #f8fbfd;
}

.cselect-option {
  width: 100%;
  border: 0;
  border-bottom: 1px solid #edf3f6;
  border-radius: 0;
  background: #fff;
  color: #183748;
  padding: 9px 10px;
  text-align: left;
}

.cselect-option:last-child {
  border-bottom: 0;
}

.cselect-option:hover {
  background: #f2f8fb;
}

.cselect-option.selected {
  background: #e6f2f7;
  color: #0f607a;
  font-weight: 600;
}

.cselect-empty {
  margin: 0;
  padding: 10px;
  color: #6e8592;
  font-size: 13px;
}

fieldset {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  display: grid;
  gap: 8px;
}

legend {
  padding: 0 6px;
  color: #3b5967;
  font-size: 13px;
}

.entities,
.spa-types,
.toggles,
.actions {
  grid-column: 1 / -1;
}

#jobForm .inline-actions {
  grid-column: 1 / -1;
}

.entities {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.entities label,
.toggles label,
.spa-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.25;
}

.option-item {
  align-items: flex-start !important;
}

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

.option-item strong {
  font-size: 14px;
}

.option-item small {
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.35;
}

.entities input[type="checkbox"],
.toggles input[type="checkbox"],
.spa-list input[type="checkbox"] {
  margin: 0;
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

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

.actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.datetime-picker {
  position: relative;
}

.datetime-trigger {
  width: 100%;
  text-align: left;
}

.datetime-popover {
  position: absolute;
  z-index: 30;
  top: calc(100% + 8px);
  left: 0;
  width: min(360px, 94vw);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 16px 36px rgba(18, 36, 47, 0.22);
  padding: 10px;
}

.calendar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.calendar-nav {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #f2f8fa;
  color: var(--ink);
  padding: 0;
}

.calendar-weekdays,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}

.calendar-weekdays span {
  text-align: center;
  font-size: 11px;
  color: var(--ink-soft);
  padding: 4px 0;
}

.calendar-day {
  border: 1px solid #dbe8ee;
  background: #fff;
  border-radius: 8px;
  min-height: 32px;
  padding: 5px 0;
  font-size: 13px;
  color: var(--ink);
}

.calendar-day.muted {
  opacity: 0.35;
}

.calendar-day.active {
  background: linear-gradient(90deg, var(--accent), #0f8f87);
  color: #fff;
  border-color: var(--accent);
}

.calendar-day.today {
  border-color: #86becd;
}

.calendar-time {
  margin-top: 8px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.calendar-time label {
  font-size: 12px;
  gap: 4px;
}

.calendar-time select {
  padding: 7px 8px;
}

.calendar-actions {
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

button {
  border: 0;
  border-radius: 10px;
  padding: 9px 12px;
  cursor: pointer;
}

.btn-primary {
  background: linear-gradient(90deg, var(--accent), #0f8f87);
  color: #fff;
}

.btn-secondary,
.inline-actions button,
button.alt {
  background: #edf4f7;
  border: 1px solid #c8dce4;
  color: #204152;
}

button.danger {
  background: #fdeceb;
  border: 1px solid #f3c7c4;
  color: var(--danger);
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  border-bottom: 1px solid #e2edf1;
  padding: 9px 8px;
  vertical-align: top;
  font-size: 14px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

th {
  color: #49616d;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.result {
  margin: 0;
  background: #0d1e28;
  color: #d8ebf4;
  border-radius: 10px;
  padding: 12px;
  min-height: 130px;
  max-height: 420px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.muted {
  color: var(--ink-soft);
}

.billing-card ul {
  margin-top: 8px;
  margin-bottom: 10px;
}

.hidden {
  display: none;
}

@media (max-width: 1000px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    grid-template-rows: auto;
    margin: 8px;
    border-radius: 14px;
    width: auto;
  }

  .portal-card {
    margin-top: 0;
  }

  .tab-panel.active {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1400px) {
  .app-shell {
    grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  }
}

@media (min-width: 1500px) {
  .tab-panel[data-panel="dashboard"] {
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  }
}

@media (max-width: 760px) {
  .content-area {
    padding: 10px;
  }

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

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

  .spa-list {
    grid-template-columns: 1fr;
  }

  .actions {
    flex-direction: column;
  }

  .datetime-popover {
    width: min(330px, calc(100vw - 36px));
  }
}
