:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --panel: #12151c;
  --panel-2: #171b24;
  --border: #262b36;
  --text: #e7e9ee;
  --muted: #8a91a3;
  --accent: #22a447;
  --accent-hover: #1c8a3c;
  --danger: #e5484d;
  --radius: 10px;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #f0f1f4;
  --border: #dde1e8;
  --text: #14161c;
  --muted: #5b6172;
  --accent: #1f9142;
  --accent-hover: #197a38;
  --danger: #d0353a;
}

* {
  box-sizing: border-box;
}

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

.hidden {
  display: none !important;
}

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

#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#boot-loading {
  min-height: 100vh;
  /* This screen has the least content of any screen, so it's the one most
     exposed to 100vh over/undershooting on mobile browsers with a
     dynamic address bar. 100dvh tracks the actual visible viewport;
     browsers that don't understand it just ignore this line. */
  min-height: 100dvh;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
}

.login-card h1 {
  font-size: 20px;
  margin: 0 0 4px;
}

.subtitle {
  color: var(--muted);
  margin: 0 0 24px;
  font-size: 14px;
}

/* ---- Layout ---- */

#app-screen,
#dash-screen {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 20px 80px;
  min-height: 100vh;
  background: var(--bg);
}

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

header.topbar h1 {
  font-size: 18px;
  margin: 0;
}

header.topbar .user-email {
  color: var(--muted);
  font-size: 13px;
}

/* ---- Form controls ---- */

label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="url"],
select {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
}

select {
  width: auto;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
}

.field {
  margin-bottom: 14px;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 16px;
}

button.primary {
  background: var(--accent);
  color: #fff;
}

button.primary:hover {
  background: var(--accent-hover);
}

button.primary:disabled {
  opacity: 0.5;
  cursor: default;
}

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

button.secondary {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
}

button.link {
  background: none;
  color: var(--muted);
  padding: 4px 8px;
  font-weight: 500;
}

button.link:hover {
  color: var(--text);
}

.error-text {
  color: var(--danger);
  font-size: 13px;
  margin-top: 8px;
  min-height: 16px;
}

/* ---- Cards / table ---- */

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.panel h2 {
  font-size: 15px;
  margin: 0 0 16px;
}

.stat-row {
  display: grid;
  /* auto-fit so this works regardless of how many tiles a given page puts
     in it (admin page: 5, influencer dashboard: 4) without per-page
     column-count mismatches. */
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-tile {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.stat-tile .label {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.stat-tile .value {
  font-size: 22px;
  font-weight: 700;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

th.sortable:hover {
  color: var(--text);
}

.sort-indicator {
  display: inline-block;
  width: 12px;
  margin-left: 2px;
}

td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td {
  border-bottom: none;
}

td.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.link-url {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

.contact-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.contact-links a {
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  border-radius: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
}

.contact-links a:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 600;
}

/* Matches the size of a standard button (see `button` above) - used where a
   badge sits next to buttons and should read as the same size, e.g. next to
   the theme toggle in the dashboard header. */
.badge-lg {
  padding: 10px 16px;
  font-size: 14px;
}

.badge.active {
  background: rgba(34, 164, 71, 0.15);
  color: var(--accent);
}

.badge.inactive {
  background: rgba(229, 72, 77, 0.15);
  color: var(--danger);
}

.empty-state {
  color: var(--muted);
  font-size: 14px;
  padding: 24px 0;
  text-align: center;
}

.row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.new-link-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.new-link-form .field.full {
  grid-column: 1 / -1;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 60px 20px;
  overflow-y: auto;
}

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 640px;
}

.modal h2 {
  margin-top: 0;
}

@media (max-width: 640px) {
  .new-link-form {
    grid-template-columns: 1fr;
  }
  table, thead, tbody, th, td, tr {
    display: block;
  }
  thead {
    display: none;
  }
  tr {
    border-bottom: 1px solid var(--border);
    padding: 10px 0;
  }
  td {
    border-bottom: none;
    padding: 4px 0;
  }
  td::before {
    content: attr(data-label);
    display: block;
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
  }
}
