:root {
  color-scheme: light;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  background: #f5f7fb;
  color: #182033;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 24px;
  background: linear-gradient(135deg, #1f5eff, #5936d8);
  color: white;
  box-shadow: 0 6px 18px rgba(31, 94, 255, .18);
}

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

h2 {
  margin: 0 0 12px;
  font-size: 18px;
  letter-spacing: 0;
}

main {
  width: 100%;
  max-width: 100vw;
}

button {
  border: 0;
  border-radius: 8px;
  padding: 8px 12px;
  background: #2457ff;
  color: white;
  cursor: pointer;
  font-weight: 600;
  min-height: 36px;
}

button:hover {
  filter: brightness(.95);
}

button.secondary,
#clearUserFormBtn,
#clearSettingFormBtn,
#logoutBtn {
  background: #eef3ff;
  color: #2457ff;
  border: 1px solid #c9d7ff;
}

button.danger {
  background: #fff1f1;
  color: #b42318;
  border: 1px solid #ffd0d0;
}

input,
select,
textarea {
  box-sizing: border-box;
  width: 100%;
  border: 1px solid #d9deea;
  border-radius: 8px;
  padding: 9px 10px;
  background: white;
  color: #182033;
  font: inherit;
}

textarea {
  resize: vertical;
}

.raw-field {
  position: absolute;
  width: 1px;
  height: 1px;
  min-height: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
}

label input[type="checkbox"] {
  width: auto;
}

#settingForm .check input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

.toolbar,
.top-actions,
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  min-width: 0;
}

.hidden {
  display: none !important;
}

.login-panel {
  width: min(430px, calc(100vw - 28px));
  margin: 18px auto;
  background: white;
  border: 1px solid #e7eaf2;
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 8px 24px rgba(24, 32, 51, .06);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.tabs button {
  background: #eef3ff;
  color: #2457ff;
  border: 1px solid #c9d7ff;
}

.tabs button.active {
  background: #2457ff;
  color: white;
  border-color: #2457ff;
}

.login-form,
.inline-form,
.setting-form {
  display: grid;
  gap: 10px;
}

.login-form label,
.setting-form label,
.inline-form label {
  display: grid;
  align-items: start;
  gap: 6px;
  color: #344054;
  font-weight: 600;
}

.login-form button {
  margin-top: 2px;
}

#appPanel {
  display: grid;
  grid-template-columns: minmax(340px, 42%) minmax(0, 1fr);
  align-items: start;
  gap: 14px;
  padding: 14px;
  width: 100%;
  max-width: 100vw;
}

#appPanel.user-mode {
  grid-template-columns: minmax(340px, 42%) minmax(0, 1fr);
}

.app-column {
  display: grid;
  align-content: start;
  gap: 14px;
  min-width: 0;
}

.panel {
  min-width: 0;
  background: white;
  border: 1px solid #e7eaf2;
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 8px 24px rgba(24, 32, 51, .06);
}

#settingsPanel {
  container-type: inline-size;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 8px;
}

.panel-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-title-row h2 {
  margin-bottom: 0;
}

.compact-filter {
  display: flex !important;
  align-items: center !important;
  gap: 6px !important;
  color: #344054 !important;
  font-weight: 600;
  white-space: nowrap;
}

.compact-filter.hidden {
  display: none !important;
}

.compact-filter select {
  width: min(230px, 38vw);
}

.metric {
  border: 1px solid #e7eaf2;
  border-radius: 12px;
  padding: 10px;
  background: #fbfcff;
}

.metric span {
  display: block;
  color: #667085;
  font-size: 12px;
}

.metric b {
  display: block;
  margin-top: 3px;
  overflow-wrap: anywhere;
}

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

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

.setting-form textarea,
.setting-form .form-actions {
  grid-column: span 2;
}

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

.grid-field {
  display: block !important;
  min-width: 0;
}

.grid-field .slot-grid {
  margin-top: 6px;
}

.slot-grid {
  width: 100%;
  min-width: 0;
}

.slot-grid-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid #e7eaf2;
  border-radius: 12px;
  background: white;
}

.slot-grid table {
  width: 100%;
  min-width: 620px;
  table-layout: fixed;
  border-collapse: collapse;
}

.slot-grid col.time-col {
  width: 124px;
}

.slot-grid col.day-col {
  width: 70px;
}

.slot-grid th,
.slot-grid td {
  border-bottom: 1px solid #edf0f7;
  border-right: 1px solid #edf0f7;
  padding: 4px;
  text-align: center;
}

.slot-grid th:last-child,
.slot-grid td:last-child {
  border-right: 0;
}

.slot-grid tr:last-child th,
.slot-grid tr:last-child td {
  border-bottom: 0;
}

.slot-grid th {
  background: #f6f8ff;
  color: #344054;
  font-size: 12px;
  font-weight: 700;
}

.slot-head,
.slot-cell {
  width: 100%;
  min-height: 30px;
  border-radius: 7px;
  padding: 5px 4px;
}

.slot-head {
  background: #eef3ff;
  color: #2457ff;
  border: 1px solid #d8e2ff;
  white-space: nowrap;
}

.slot-head.time-head {
  font-size: 12px;
}

.slot-cell {
  border: 1px solid #d9deea;
  background: #f8fafc;
}

.slot-cell.selected {
  background: #2457ff;
  border-color: #2457ff;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .28);
}

.slot-cell.selected::after {
  content: "";
  display: block;
  width: 7px;
  height: 12px;
  margin: 2px auto 0;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.check {
  display: flex !important;
  align-items: center !important;
  gap: 6px !important;
  color: #344054 !important;
}

.message {
  margin-top: 12px;
  border: 1px solid #c9f2d9;
  border-radius: 12px;
  padding: 10px 12px;
  background: #f0fdf4;
  color: #087443;
  font-weight: 600;
}

.message.error {
  border-color: #ffd0d0;
  background: #fff1f1;
  color: #b42318;
}

.list,
.tasks {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  min-width: 0;
}

#usersList {
  max-height: 350px;
  overflow-y: auto;
  padding: 2px 8px 2px 2px;
  scrollbar-gutter: stable;
}

#settingsList {
  max-height: 390px;
  overflow-y: auto;
  padding: 2px 8px 2px 2px;
  scrollbar-gutter: stable;
}

.item,
.task {
  border: 1px solid #e7eaf2;
  border-radius: 12px;
  padding: 12px;
  background: #fbfcff;
}

.task {
  cursor: pointer;
}

.task.selected {
  border-color: #2457ff;
  box-shadow: inset 0 0 0 1px #2457ff;
}

.task-main {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.task small {
  display: block;
  margin-top: 4px;
  color: #667085;
  overflow-wrap: anywhere;
}

.setting-item {
  cursor: pointer;
}

.setting-item:hover {
  border-color: #c9d7ff;
  background: #f6f8ff;
}

.item-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.item-title {
  font-weight: 700;
}

.item-meta {
  display: block;
  margin-top: 4px;
  color: #667085;
  overflow-wrap: anywhere;
  font-size: 12px;
}

.item-actions,
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

@container (max-width: 1180px) {
  .time-grids {
    grid-template-columns: 1fr;
  }
}

.detail-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.query-log {
  min-width: 0;
  width: 100%;
  min-height: 260px;
  max-height: 520px;
  margin: 12px 0 0;
  border: 0;
  border-radius: 12px;
  padding: 14px;
  overflow: auto;
  background: #101828;
  color: #d1e9ff;
  font: 13px/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.badge {
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  background: #e8edf8;
  color: #3b465c;
  white-space: nowrap;
}

.badge.on {
  background: #d9fbe6;
  color: #087443;
}

.badge.off {
  background: #ffe0e0;
  color: #b42318;
}

.badge.completed {
  background: #d9fbe6;
  color: #087443;
}

.badge.running {
  background: #fff3cf;
  color: #8a5a00;
}

.badge.failed {
  background: #ffe0e0;
  color: #b42318;
}

.badge.stopped,
.badge.stopping {
  background: #eceff5;
  color: #475467;
}

.muted {
  color: #667085;
}

@media (max-width: 1100px) {
  #appPanel {
    grid-template-columns: 1fr;
  }

  #statusPanel,
  #adminUsersPanel,
  #settingsPanel,
  #settingStatusPanel,
  .detail-panel {
    grid-column: 1;
    grid-row: auto;
  }

  .status-grid {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  }
}

@media (max-width: 720px) {
  header {
    align-items: flex-start;
    padding: 14px;
    gap: 12px;
  }

  h1 {
    font-size: 19px;
  }

  #appPanel {
    padding: 10px;
  }

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

  .setting-form textarea,
  .setting-form .form-actions,
  .time-grids {
    grid-column: span 1;
  }

  .time-grids {
    grid-template-columns: 1fr;
  }
}
