:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1d2330;
  --muted: #6b7280;
  --border: #dde1e7;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-text: #ffffff;
  --error-bg: #fdecec;
  --error-text: #a61b1b;
  --success-bg: #e8f6ec;
  --success-text: #17663a;
  --row-hover: #f0f3f8;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --surface: #1c2027;
    --text: #e6e8eb;
    --muted: #9aa1ac;
    --border: #2f3540;
    --accent: #4f8cff;
    --accent-hover: #6b9dff;
    --accent-text: #0b0e13;
    --error-bg: #3a1d1f;
    --error-text: #ffb4b4;
    --success-bg: #173024;
    --success-text: #9ee0b5;
    --row-hover: #232833;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 18px; margin: 0; }
.muted { color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
}

/* ---------- Controls ---------- */

label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }

input, select {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-weight: 400;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input:user-invalid { border-color: var(--error-text); }

.btn {
  font: inherit;
  border-radius: 6px;
  padding: 8px 14px;
  border: 1px solid transparent;
  cursor: pointer;
}
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--row-hover); }

.alert { margin: 0; padding: 10px 12px; border-radius: 6px; }
.alert-error { background: var(--error-bg); color: var(--error-text); }
.alert-success { background: var(--success-bg); color: var(--success-text); }

/* ---------- Login ---------- */

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; }

/* ---------- App shell ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; }
.spacer { flex: 1; }
.tabs { display: flex; gap: 4px; }
.tabs a {
  color: var(--muted);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 6px;
}
.tabs a:hover { color: var(--text); background: var(--row-hover); }
.tabs a.active { color: var(--text); background: var(--row-hover); font-weight: 600; }

.content { max-width: 1200px; margin: 0 auto; padding: 24px; display: block; }
.content section { display: flex; flex-direction: column; gap: 16px; }
.section-head { display: flex; align-items: center; justify-content: space-between; }

/* ---------- Deal list ---------- */

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}
table.deals { width: 100%; border-collapse: collapse; }
.deals th, .deals td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.deals th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.deals tbody tr:last-child td { border-bottom: none; }
.deals tbody tr:hover { background: var(--row-hover); }
.deals .num { font-variant-numeric: tabular-nums; color: var(--muted); }
.deals .nowrap { white-space: nowrap; }

.loading .table-wrap { opacity: 0.5; transition: opacity 0.15s; }

.pager { display: flex; align-items: center; justify-content: center; gap: 16px; }

/* ---------- New deal form ---------- */

.form-grid { display: flex; flex-direction: column; gap: 20px; max-width: 760px; }
fieldset {
  border: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 16px;
}
legend { font-weight: 700; margin-bottom: 10px; font-size: 15px; }
.span-2 { grid-column: span 2; }
.form-actions { display: flex; gap: 10px; }

/* ---------- Partners ---------- */

h3 { font-size: 16px; margin: 0; }
.sources-bar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 20px; }
.partner-form { display: flex; flex-direction: column; gap: 14px; max-width: 760px; }
.partner-form-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.hint { margin: 0; font-size: 13px; }
.actions { display: flex; gap: 6px; justify-content: flex-end; white-space: nowrap; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-ok { background: var(--success-bg); color: var(--success-text); }
.badge-off { background: var(--error-bg); color: var(--error-text); }
.row-off td:not(:last-child) { opacity: 0.6; }
label.checkbox { flex-direction: row; align-items: center; gap: 8px; align-self: end; padding-bottom: 8px; }
.badge-muted { background: var(--row-hover); color: var(--muted); }
.badge-accent { background: var(--accent); color: var(--accent-text); }
.head-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

@media (max-width: 640px) {
  .partner-form-fields { grid-template-columns: 1fr; }
  .sources-bar { flex-direction: column; align-items: stretch; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
  fieldset { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  fieldset > span:empty { display: none; }
}
