:root {
  color-scheme: light;
  --bg: #f8f7f4;
  --panel: #ffffff;
  --panel-soft: #f2f1ed;
  --line: #e4e0d8;
  --line-strong: #cfc8bc;
  --text: #202124;
  --muted: #6f716d;
  --green: #2f7d57;
  --green-soft: #e3f3ea;
  --blue: #356f94;
  --blue-soft: #e2eff7;
  --red: #a84c5d;
  --red-soft: #f8e5ea;
  --gold: #9a6b21;
  --gold-soft: #f5ecd7;
  --shadow: 0 10px 28px rgba(32, 33, 36, 0.07);
  --radius: 8px;
  --font: Inter, "Helvetica Neue", Arial, "Noto Sans KR", "Apple SD Gothic Neo", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  overflow-y: scroll;
  scrollbar-gutter: stable;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  letter-spacing: 0;
  line-height: 1.45;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

.container {
  align-content: start;
  display: grid;
  gap: 12px;
  max-width: 1480px;
  min-height: 100vh;
  padding: 14px 18px 20px;
  width: 100%;
}

.header,
.tabs,
.tab-content,
.form-card,
.schedule-card,
.condition-card,
.app-alert {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.header,
.tabs,
.tab-content,
.app-alert {
  min-width: 0;
  width: 100%;
}

.header {
  align-items: center;
  display: flex;
  gap: 14px;
  justify-content: space-between;
  min-height: 58px;
  padding: 12px 15px;
  box-shadow: var(--shadow);
}

.header h1 {
  margin-bottom: 2px;
  font-size: 1.45rem;
  font-weight: 760;
}

.header p,
.subtle-text {
  color: var(--muted);
  font-size: 0.78rem;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.app-alert {
  background: var(--gold-soft);
  color: var(--gold);
  padding: 11px 13px;
}

.btn {
  align-items: center;
  border: 1px solid transparent;
  border-radius: 7px;
  display: inline-flex;
  gap: 6px;
  justify-content: center;
  min-height: 34px;
  padding: 8px 13px;
  text-decoration: none;
  font-size: 0.84rem;
  font-weight: 760;
  line-height: 1.1;
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease;
  white-space: nowrap;
}

.btn-primary,
.btn-success {
  background: #202124;
  color: #fff;
}

.btn-primary:hover,
.btn-success:hover {
  background: #333638;
}

.btn-secondary {
  background: var(--panel);
  border-color: var(--line-strong);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--panel-soft);
}

.btn-danger {
  background: var(--red-soft);
  border-color: #e8c2c9;
  color: var(--red);
}

.btn-danger:hover {
  background: #f2d7dd;
}

.btn-sm {
  min-height: 28px;
  padding: 6px 9px;
  font-size: 0.76rem;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  min-height: 46px;
  padding: 5px;
}

.tab {
  align-items: center;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  display: inline-flex;
  font-size: 0.82rem;
  font-weight: 760;
  height: 36px;
  justify-content: center;
  line-height: 1;
  min-width: 0;
  overflow: hidden;
  padding: 0 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
}

.tab:hover {
  background: var(--panel-soft);
  color: var(--text);
}

.tab.active {
  background: #202124;
  color: #fff;
}

.tab-content {
  padding: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.section-title-row,
.action-bar,
.form-card-head,
.schedule-row,
.modal-actions {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.section-title-row.compact {
  margin-bottom: 10px;
}

.tab-panel h2,
.form-card h3,
.schedule-section-top h3,
.condition-header h3 {
  margin-bottom: 0;
  font-size: 1rem;
  font-weight: 760;
}

.action-bar {
  flex-wrap: wrap;
  margin: 14px 0;
}

.inline-form {
  display: flex;
  flex: 1;
  gap: 8px;
  min-width: 280px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
  font-size: 0.84rem;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(53, 111, 148, 0.12);
  outline: none;
}

label span,
.form-group label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 760;
}

.status-bar {
  background: var(--blue-soft);
  border: 1px solid #c7ddeb;
  border-radius: var(--radius);
  color: var(--blue);
  margin-bottom: 14px;
  padding: 11px 13px;
}

.status-bar.error {
  background: var(--red-soft);
  border-color: #e8c2c9;
  color: var(--red);
}

.status-bar.success {
  background: var(--green-soft);
  border-color: #b9ddc8;
  color: var(--green);
}

.progress-bar-container {
  height: 7px;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.08);
}

.progress-bar {
  height: 100%;
  border-radius: 999px;
  background: var(--blue);
  transition: width 180ms ease;
}

.progress-text {
  font-size: 0.82rem;
  font-weight: 760;
}

.table-scroll {
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  font-size: 0.83rem;
  min-width: 860px;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px 9px;
  text-align: left;
  vertical-align: top;
}

.data-table th {
  background: var(--panel-soft);
  color: #4f5654;
  font-size: 0.76rem;
  font-weight: 820;
}

.data-table th[data-sort] {
  cursor: pointer;
  position: relative;
  user-select: none;
}

.data-table tbody tr:hover {
  background: #faf9f7;
}

.data-table .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.data-table td.ports-cell {
  max-width: 310px;
  overflow-wrap: anywhere;
  white-space: normal;
}

.history-summary {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 760;
  margin: 10px 0 4px;
}

.history-table {
  min-width: 980px;
}

.history-table small {
  color: var(--muted);
  font-size: 0.72rem;
}

.history-wrap {
  overflow-wrap: anywhere;
  white-space: normal;
}

.form-card,
.schedule-card {
  margin: 12px 0 16px;
  padding: 14px;
}

.form-card {
  background: #fbfaf8;
}

.form-card-head {
  margin-bottom: 12px;
}

.form-grid,
.form-row {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 12px;
}

.channel-base-grid {
  grid-template-columns: minmax(240px, 1fr) 180px;
}

.channel-fields {
  border-top: 1px solid var(--line);
  margin-top: 10px;
  padding-top: 12px;
}

.form-group {
  min-width: 0;
  margin-bottom: 12px;
}

.range-inputs {
  align-items: center;
  display: flex;
  gap: 8px;
}

.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.checkbox-group label,
.checkbox-inline {
  align-items: center;
  display: inline-flex;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: #4f5654;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 680;
  min-height: 32px;
  padding: 6px 9px;
}

.checkbox-inline {
  justify-content: space-between;
  min-width: 250px;
}

.checkbox-inline input,
.checkbox-group input {
  width: 16px;
  min-height: 16px;
  height: 16px;
}

.compact-toggle {
  align-self: end;
  min-width: 0;
}

.schedule-section-top {
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
  padding-bottom: 14px;
}

.schedule-card {
  border-left: 4px solid var(--green);
}

.schedule-row {
  align-items: flex-end;
  flex-wrap: wrap;
  justify-content: flex-start;
}

.schedule-switch-row {
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.schedule-options-row {
  align-items: flex-start;
  gap: 14px;
}

.schedule-options-row .form-group {
  margin-bottom: 0;
}

.schedule-days-group {
  flex: 1 1 420px;
}

.schedule-time-group {
  flex: 0 0 150px;
}

#scrapeScheduleOptions {
  border-top: 1px dashed var(--line-strong);
  margin-top: 10px;
  padding-top: 10px;
}

.checkbox-group.compact {
  gap: 6px;
}

.cards-container {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  margin-top: 14px;
}

.condition-card {
  border-left: 4px solid var(--blue);
  padding: 14px;
}

.condition-card.inactive {
  border-left-color: var(--line-strong);
  opacity: 0.68;
}

.condition-header {
  align-items: center;
  display: flex;
  gap: 9px;
  margin-bottom: 9px;
}

.condition-header input {
  width: 16px;
  min-height: 16px;
  height: 16px;
}

.condition-card .details,
.condition-card .schedule-info {
  color: var(--muted);
  font-size: 0.8rem;
  margin: 6px 0;
}

.condition-card .card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}

.monitoring-channel-tools {
  align-items: start;
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(240px, 0.8fr) minmax(0, 1.45fr);
}

.channel-selection-panel {
  min-width: 0;
}

.channel-selection-panel > label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 760;
  margin-bottom: 8px;
}

.channel-recipient-list {
  align-content: start;
  display: grid;
  gap: 7px;
}

.channel-recipient-item {
  align-items: stretch;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 32px;
  min-height: 34px;
  overflow: hidden;
}

.channel-recipient-list .channel-recipient-choice {
  background: transparent;
  border: 0;
  border-radius: 0;
  justify-content: flex-start;
  margin: 0;
  min-height: 32px;
  min-width: 0;
  padding: 6px 9px;
  width: 100%;
}

.channel-recipient-text {
  color: var(--muted);
  font-size: 0.82rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.channel-delete-btn {
  align-items: center;
  border: 0;
  border-left: 1px solid var(--line);
  background: var(--red-soft);
  color: var(--red);
  display: inline-flex;
  font-size: 0.76rem;
  font-weight: 860;
  justify-content: center;
  min-height: 100%;
  padding: 0;
}

.channel-delete-btn:hover {
  background: #f2d7dd;
}

.credential-preview {
  background: #f7f6f2;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

.inline-channel-editor {
  margin: 0;
  min-width: 0;
}

.badge,
.channel-pill {
  align-items: center;
  border-radius: 999px;
  display: inline-flex;
  min-height: 24px;
  padding: 4px 8px;
  font-size: 0.74rem;
  font-weight: 800;
  white-space: nowrap;
}

.badge-active {
  background: var(--green-soft);
  color: var(--green);
}

.badge-inactive {
  background: var(--red-soft);
  color: var(--red);
}

.badge-muted {
  background: #f0eee9;
  color: var(--muted);
}

.badge-running {
  background: var(--blue-soft);
  color: var(--blue);
}

.channel-telegram {
  background: var(--blue-soft);
  color: var(--blue);
}

.channel-email {
  background: var(--green-soft);
  color: var(--green);
}

.channel-slack {
  background: #ece7f7;
  color: #7256a4;
}

.modal {
  align-items: center;
  background: rgba(32, 33, 36, 0.44);
  display: none;
  inset: 0;
  justify-content: center;
  padding: 18px;
  position: fixed;
  z-index: 1000;
}

.modal.show {
  display: flex;
}

.modal-content {
  width: min(980px, 100%);
  max-height: 92vh;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(32, 33, 36, 0.22);
  padding: 18px;
}

.modal-content h2 {
  margin-bottom: 18px;
  font-size: 1.15rem;
}

.modal-content h3 {
  margin: 18px 0 10px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 860;
  text-transform: uppercase;
}

.modal-actions {
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
  justify-content: flex-end;
  margin-top: 18px;
  padding-top: 14px;
}

@media (max-width: 820px) {
  .container {
    padding: 10px;
  }

  .header,
  .section-title-row,
  .form-card-head,
  .action-bar,
  .inline-form {
    align-items: stretch;
    flex-direction: column;
  }

  .tab {
    font-size: 0.7rem;
    padding: 0 3px;
  }

  .form-grid,
  .form-row,
  .channel-base-grid,
  .monitoring-channel-tools {
    grid-template-columns: 1fr;
  }

  .checkbox-inline {
    width: 100%;
  }
}
