:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-2: #eef3f7;
  --text: #18232c;
  --muted: #617181;
  --line: #d7e0e8;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --accent-soft: #dff7f3;
  --danger: #b42318;
  --danger-soft: #fee4df;
  --warning: #a16207;
  --shadow: 0 14px 36px rgba(24, 35, 44, 0.08);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select {
  font: inherit;
}
button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  padding: 0.58rem 0.82rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
button:hover, .button:hover {
  background: var(--accent-strong);
  color: white;
  text-decoration: none;
}
.secondary, .ghost {
  background: white;
  border-color: var(--line);
  color: var(--text);
}
.secondary:hover, .ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}
.danger {
  background: var(--danger-soft);
  color: var(--danger);
}
.danger:hover {
  background: var(--danger);
  color: white;
}
input, select {
  width: 100%;
  min-width: 0;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.58rem 0.72rem;
  background: white;
  color: var(--text);
  outline: none;
}
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}
code {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border-radius: 6px;
  background: var(--surface-2);
  padding: 0.1rem 0.28rem;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 248px;
  padding: 1rem;
  background: #101820;
  color: white;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: 8px 0 32px rgba(16, 24, 32, 0.12);
}
.brand {
  color: white;
  font-weight: 850;
  font-size: 1.2rem;
  letter-spacing: 0;
}
.tenant-pill {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 0.72rem;
  background: rgba(255, 255, 255, 0.06);
}
.tenant-pill span {
  display: block;
  color: #aebbc5;
  font-size: 0.75rem;
}
.tenant-pill strong {
  display: block;
  margin-top: 0.18rem;
  overflow-wrap: anywhere;
}
.sidebar nav {
  display: grid;
  gap: 0.18rem;
}
.sidebar nav a, .logout button {
  display: block;
  width: 100%;
  border-radius: 8px;
  color: #dbe5ec;
  padding: 0.62rem 0.7rem;
  text-align: left;
}
.sidebar nav a:hover, .logout button:hover {
  background: rgba(255, 255, 255, 0.08);
  color: white;
  text-decoration: none;
}
.logout {
  margin-top: auto;
}
.logout button {
  border: 0;
  background: transparent;
}

.main {
  margin-left: 248px;
  padding: 1.4rem;
}
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}
h1 {
  margin: 0;
  font-size: 1.5rem;
  line-height: 1.2;
}
h2 {
  margin: 0 0 0.8rem;
  font-size: 1rem;
  line-height: 1.3;
}
.muted { color: var(--muted); }

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.85rem;
  margin-bottom: 1rem;
}
.metrics div, .panel, .grid > div, .opportunity, .settings-grid div, table, .integration-panel, .notice {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.metrics div {
  padding: 1rem;
}
.metrics span {
  display: block;
  font-size: 1.65rem;
  font-weight: 850;
}
.metrics small {
  color: var(--muted);
  font-weight: 600;
}
.grid.two {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}
.grid > div, .panel {
  padding: 1rem;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
}
th, td {
  padding: 0.68rem 0.72rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  text-align: left;
  font-size: 0.9rem;
}
th {
  color: var(--muted);
  background: #f1f5f8;
  font-weight: 750;
}
tr:last-child td {
  border-bottom: 0;
}
.editable-table td {
  vertical-align: middle;
}
.row-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.filters, .toolbar, .approval, .settings-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}
.filters {
  justify-content: flex-end;
}
.filters input, .filters select {
  width: 170px;
}
.toolbar {
  margin-bottom: 1rem;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.toolbar input, .toolbar select {
  width: 190px;
}
.add-watch input:first-of-type {
  width: min(420px, 100%);
  flex: 1 1 260px;
}

.opportunity-list {
  display: grid;
  gap: 0.85rem;
}
.opportunity {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 1rem;
  padding: 1rem;
}
.opportunity img {
  width: 120px;
  height: 120px;
  object-fit: contain;
  border-radius: 8px;
  background: #f2f5f7;
}
.op-body h2 {
  font-size: 1rem;
  line-height: 1.35;
}
dl {
  display: grid;
  grid-template-columns: repeat(6, minmax(96px, 1fr));
  gap: 0.5rem;
  margin: 0.75rem 0;
}
dt {
  color: var(--muted);
  font-size: 0.76rem;
}
dd {
  margin: 0.15rem 0 0;
  font-weight: 800;
}
.reason {
  color: var(--muted);
  margin: 0.5rem 0;
}
.approval {
  margin-top: 0.65rem;
}
.approval input[name="message_title"] {
  flex: 1 1 220px;
}
.approval input[name="affiliate_link"] {
  flex: 2 1 320px;
}
.approval input[name="scheduled_at"], .approval input[name="publication_priority"] {
  width: 180px;
}
.inline-actions {
  display: inline-block;
  margin-top: 0.6rem;
  margin-right: 0.4rem;
}
.empty, .error {
  color: var(--danger);
}

.notice {
  margin-bottom: 1rem;
  padding: 0.78rem 0.9rem;
}
.notice.success {
  border-color: #8bd5c6;
  background: var(--accent-soft);
  color: var(--accent-strong);
}
.notice.error {
  border-color: #f4b0aa;
  background: #fff7f5;
}
.integration-panel {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  padding: 1rem;
}
.integration-panel p {
  margin: 0.35rem 0 0;
  color: var(--muted);
}
.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.85rem;
  margin: 1rem 0;
}
.settings-grid div {
  padding: 0.9rem;
  min-width: 0;
}
.settings-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 750;
}
.settings-grid strong {
  display: block;
  margin-top: 0.25rem;
  overflow-wrap: anywhere;
}
.settings-form {
  display: grid;
  gap: 1rem;
}
fieldset {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
  margin: 0;
  padding: 0;
  border: 0;
}
legend {
  grid-column: 1 / -1;
  margin-bottom: -0.25rem;
  font-weight: 850;
}
label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 650;
}
.check-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--text);
}
.check-row input {
  width: auto;
  min-height: 0;
}
.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.switch span {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: #cbd5df;
}
.switch span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
  transition: transform 0.16s ease;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.22);
}
.switch input:checked + span {
  background: var(--accent);
}
.switch input:checked + span::after {
  transform: translateX(18px);
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #101820, #1f3130);
}
.login-box {
  width: min(390px, calc(100vw - 2rem));
  display: grid;
  gap: 0.8rem;
  border-radius: 8px;
  background: white;
  padding: 1.25rem;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.22);
}
.login-box button {
  width: 100%;
}

@media (max-width: 980px) {
  .sidebar {
    position: static;
    width: auto;
  }
  .sidebar nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .main {
    margin-left: 0;
    padding: 0.9rem;
  }
  .page-head, .integration-panel {
    display: grid;
    align-items: stretch;
  }
  .metrics, .grid.two, .settings-grid, fieldset {
    grid-template-columns: 1fr;
  }
  .filters {
    justify-content: stretch;
  }
  .filters input, .filters select, .toolbar input, .toolbar select {
    width: 100%;
  }
  .opportunity {
    grid-template-columns: 1fr;
  }
  .opportunity img {
    width: 100%;
    height: 180px;
  }
  dl {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  table {
    display: block;
    overflow-x: auto;
  }
}
