:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --text: #17202a;
  --muted: #667085;
  --line: #d8dee7;
  --primary: #1f6feb;
  --primary-soft: #e8f1ff;
  --ok: #0f766e;
  --warn: #b45309;
  --danger: #b42318;
  --radius: 8px;
  --shadow: 0 12px 28px rgba(15, 23, 42, 0.07);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 34px;
  border-radius: 7px;
  border: 1px solid transparent;
  padding: 0 12px;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
}

button:disabled {
  cursor: default;
  opacity: 0.55;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
}

input,
select {
  min-height: 36px;
  padding: 0 10px;
}

textarea {
  min-height: 92px;
  padding: 9px 10px;
  resize: vertical;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.2;
}

h2 {
  font-size: 18px;
}

h3 {
  font-size: 15px;
}

h4 {
  font-size: 14px;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 14px;
  background: #182230;
  color: #eef4ff;
}

.brand {
  display: grid;
  gap: 4px;
  padding: 6px 8px 22px;
}

.brand strong {
  font-size: 18px;
}

.brand span {
  color: #aab8cc;
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-btn {
  justify-content: flex-start;
  text-align: left;
  color: #d6e1f0;
  background: transparent;
  border-color: transparent;
}

.nav-btn.active,
.nav-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.content {
  padding: 20px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.topbar p {
  margin-top: 4px;
  color: var(--muted);
}

.topbar-actions,
.inline-actions,
.panel-head,
.source-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-actions,
.panel-head,
.source-head {
  justify-content: space-between;
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 14px;
}

.panel,
.subpanel,
.trigger-card,
.rule-card,
.status-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.panel {
  padding: 16px;
  box-shadow: var(--shadow);
}

.subpanel,
.trigger-card,
.rule-card {
  padding: 14px;
}

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

.status-card {
  display: grid;
  gap: 6px;
  min-height: 96px;
  padding: 14px;
}

.status-label,
.field-label,
.muted,
.field-help,
.status-card small,
.category-meta {
  color: var(--muted);
}

.status-card strong {
  font-size: 19px;
}

.ok,
.status-pill.ok {
  color: var(--ok);
}

.warn,
.status-pill.warn {
  color: var(--warn);
}

.status-pill.error {
  color: var(--danger);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  max-width: 260px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.primary {
  color: #ffffff;
  background: var(--primary);
}

.secondary {
  border-color: var(--line);
  background: var(--surface);
}

.danger {
  color: var(--danger);
  background: #fff1f0;
  border-color: #ffd5d2;
}

.link-button,
.crumb,
.category-name,
.help-btn {
  min-height: auto;
  padding: 0;
  border: 0;
  color: var(--primary);
  background: transparent;
}

.help-btn {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
}

.help-text {
  margin-top: 10px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 14px;
}

.hidden {
  display: none;
}

.auth-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(24, 34, 48, 0.62);
}

.auth-modal.hidden {
  display: none;
}

.auth-card {
  display: grid;
  gap: 14px;
  width: min(420px, 100%);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.25);
}

.auth-card p {
  margin-top: 6px;
  color: var(--muted);
}

.auth-error {
  padding: 10px 12px;
  border: 1px solid #ffd5d2;
  border-radius: 7px;
  background: #fff1f0;
  color: var(--danger);
  font-size: 14px;
}

.settings-grid,
.compact-grid {
  display: grid;
  gap: 12px;
}

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

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

.field {
  display: grid;
  gap: 6px;
}

.field-label,
.field-help {
  font-size: 13px;
}

.check-field {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-height: 36px;
}

.check-field input,
.mini-check input,
.category-row input,
.rule-category-row input {
  width: 16px;
  min-height: 16px;
}

.check-field .field-help {
  grid-column: 2;
}

.source-stack {
  display: grid;
  gap: 14px;
}

.source-layout {
  display: grid;
  grid-template-columns: minmax(420px, 1.15fr) minmax(360px, 0.85fr);
  gap: 12px;
  margin-top: 12px;
}

.breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin: 10px 0;
  font-size: 14px;
}

.crumb-separator {
  color: var(--muted);
}

.category-list,
.rule-category-box {
  display: grid;
  gap: 6px;
  max-height: 430px;
  overflow: auto;
  padding-right: 4px;
}

.category-row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto auto;
  gap: 9px;
  align-items: center;
  min-height: 38px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
}

.category-name {
  text-align: left;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-name:not(:disabled) {
  color: var(--primary);
}

.mini-check,
.rule-category-row {
  display: flex;
  gap: 6px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.rules-block {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.rule-card {
  display: grid;
  gap: 10px;
  background: var(--surface-2);
}

.rule-category-box {
  max-height: 190px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px;
  background: var(--surface);
}

.table-wrap {
  overflow: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.data-table th,
.data-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 14px;
}

.data-table th {
  color: var(--muted);
  font-weight: 600;
  background: var(--surface-2);
}

.schedule-preview {
  min-height: 220px;
  margin-top: 12px;
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #101828;
  color: #f2f4f7;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  white-space: pre-wrap;
}

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

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

  .sidebar {
    position: static;
    height: auto;
  }

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

  .content {
    padding: 12px;
  }

  .topbar,
  .topbar-actions,
  .panel-head,
  .source-head,
  .inline-actions {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .category-row {
    grid-template-columns: 18px minmax(0, 1fr);
  }
}
