:root {
  color-scheme: dark;
  --bg: #060807;
  --panel: #0f1412;
  --panel-2: #111816;
  --line: #26312d;
  --muted: #8b9992;
  --text: #f4fbf8;
  --green: #43e7bd;
  --green-2: #17c99f;
  --orange: #d56a00;
  --red: #f46d75;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top right, #111815, var(--bg) 38%);
  color: var(--text);
  font: 14px/1.4 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.locked .shell { display: none; }
body:not(.locked) .loginScreen { display: none; }

.loginScreen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
}

.loginBox {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(15, 20, 18, 0.92);
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.55);
}

.loginBox h1 {
  font-size: 20px;
}

.loginError {
  min-height: 20px;
  margin-top: 10px;
  color: var(--red);
  font-weight: 800;
}

button, input, textarea {
  font: inherit;
}

.shell {
  width: min(1480px, calc(100vw - 32px));
  margin: 48px auto;
  border: 1px solid #222b28;
  background: rgba(7, 10, 9, 0.92);
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.55);
}

.topbar, .panelHead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.topbar {
  padding: 18px 20px 14px;
  border-bottom: 1px solid #202925;
}

h1, h2, p { margin: 0; }
h1 { font-size: 16px; letter-spacing: 0; }
h2 { font-size: 14px; letter-spacing: 0; }
p { color: var(--muted); font-size: 12px; margin-top: 6px; }

.actions, .panelTools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.segments {
  display: flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0e1512;
}

.segments button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.segments button.active {
  background: var(--green);
  color: #03120e;
}

input, textarea {
  border: 1px solid var(--line);
  background: #0b1210;
  color: var(--text);
  border-radius: 7px;
  padding: 10px 12px;
  outline: none;
}

textarea { resize: vertical; }
input:focus, textarea:focus { border-color: var(--green); }
#search { width: min(250px, 100%); }
#nicheSearch { width: 220px; }

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  background: #111916;
  padding: 0 14px;
  font-weight: 800;
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: .72;
}

button.primary {
  color: #03120e;
  border-color: var(--green);
  background: var(--green);
}

button.hot {
  background: var(--orange);
  border-color: #f08316;
}

button.ghost:hover, button.hot:hover, button.primary:hover {
  filter: brightness(1.08);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  padding: 20px;
}

.metric, .nicheCard {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
}

.metric {
  min-height: 84px;
  padding: 16px;
}

.label {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
  line-height: 1;
}

.panel, .tablePanel {
  margin: 2px 20px 20px;
  border: 1px solid var(--line);
  background: rgba(15, 20, 18, 0.76);
  border-radius: 10px;
  padding: 18px 14px 14px;
}

.nicheGrid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 16px;
}

.nicheCard {
  min-height: 120px;
  padding: 14px;
  position: relative;
}

.nicheCard:first-child {
  border-color: var(--green);
  box-shadow: inset 0 0 0 1px var(--green);
}

.nicheName {
  max-width: 70%;
  height: 18px;
  border-radius: 8px;
  background: linear-gradient(90deg, #27312d, #111816);
  color: transparent;
}

.revealed .nicheName {
  height: auto;
  background: none;
  color: var(--text);
  font-weight: 900;
}

.rank {
  position: absolute;
  right: 14px;
  top: 14px;
  color: var(--muted);
  font-size: 10px;
}

.gain {
  margin-top: 18px;
  font-size: 22px;
  font-weight: 950;
}

.gain small {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.nicheStats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-top: 1px solid var(--line);
  margin-top: 10px;
  padding-top: 10px;
  color: var(--muted);
  font-size: 10px;
}

.nicheStats strong {
  display: block;
  color: var(--green);
  font-size: 12px;
}

.tableWrap { overflow-x: auto; margin-top: 12px; }
table { width: 100%; border-collapse: collapse; min-width: 980px; }
th, td {
  text-align: left;
  border-bottom: 1px solid #202925;
  padding: 12px 10px;
}
th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
td strong { display: block; }
td a { color: var(--green); text-decoration: none; font-size: 12px; }
.channelCell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.channelCell img {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--line);
  flex: 0 0 auto;
}
.num { font-weight: 900; }
.danger {
  min-height: 30px;
  color: var(--red);
  padding: 0 10px;
}

dialog {
  width: min(620px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0b100f;
  color: var(--text);
  padding: 0;
}

dialog::backdrop { background: rgba(0,0,0,.72); }
form { padding: 18px; }
.dialogHead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.dialogHead button {
  min-width: 34px;
  width: 34px;
  padding: 0;
}
label {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.fieldGrid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.wide { width: 100%; margin-top: 16px; }

@media (max-width: 980px) {
  .shell { margin: 18px auto; width: min(100vw - 18px, 1480px); }
  .topbar, .panelHead { align-items: flex-start; flex-direction: column; }
  .actions, .panelTools { justify-content: flex-start; width: 100%; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .nicheGrid { grid-template-columns: 1fr; }
  #search, #nicheSearch { width: 100%; }
  .fieldGrid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 560px) {
  .metrics { grid-template-columns: 1fr; }
  .segments { width: 100%; overflow-x: auto; }
  .segments button { white-space: nowrap; }
  .fieldGrid { grid-template-columns: 1fr; }
}
