:root {
  color-scheme: dark;
  --bg: #10100f;
  --ink: #f2f0ea;
  --muted: #aaa49a;
  --line: #383631;
  --panel: #1a1917;
  --panel-soft: #22201d;
  --field: #141312;
  --green: #35b57d;
  --green-soft: #163c2d;
  --blue: #7db3ff;
  --yellow: #d6a84a;
  --red: #f26b6b;
  --red-soft: #472323;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
}

a {
  color: var(--blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.topbar {
  min-height: 86px;
  padding: 18px 26px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.brand {
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand:hover {
  text-decoration: none;
}

.brand strong {
  display: block;
  font-size: 25px;
  line-height: 1.1;
}

.brand small {
  display: block;
  margin-top: 4px;
}

.logo {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
}

.topbar-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.panel h2,
.monitor h3 {
  margin: 0;
  letter-spacing: 0;
}

.monitor p,
.panel-head span,
small {
  color: var(--muted);
}

.monitor p {
  margin: 4px 0 0;
}

button,
.button-like,
input,
select,
textarea {
  font: inherit;
}

button,
.button-like {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-soft);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 11px;
}

button:hover,
.button-like:hover {
  border-color: #6b675d;
  background: #27241f;
  text-decoration: none;
}

button svg,
.button-like svg {
  width: 17px;
  height: 17px;
}

button.primary {
  background: var(--green);
  border-color: var(--green);
  color: #10100f;
  font-weight: 700;
}

button.blue {
  background: #2f7edb;
  border-color: #2f7edb;
  color: #f7fbff;
  font-weight: 700;
}

button.blue:hover {
  background: #246fc6;
  border-color: #246fc6;
}

button.danger {
  color: var(--red);
}

.layout {
  width: min(1480px, calc(100vw - 32px));
  margin: 18px auto 42px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.compact-status {
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}

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

.status {
  padding: 14px;
  min-height: 76px;
}

.status span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.status strong {
  display: block;
  margin-top: 8px;
  font-size: 20px;
  overflow-wrap: anywhere;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 12px;
  margin-bottom: 12px;
}

.panel {
  padding: 16px;
  margin-bottom: 12px;
}

.panel-head {
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head h2 {
  font-size: 18px;
}

.panel-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.filters {
  display: grid;
  grid-template-columns: minmax(116px, 0.8fr) minmax(150px, 1.1fr) repeat(7, minmax(96px, 1fr)) auto;
  gap: 8px;
  align-items: end;
  margin: 4px 0 14px;
}

.loading {
  opacity: 0.68;
  pointer-events: none;
}

.filter-actions {
  display: flex;
  gap: 8px;
}

.listing-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 9px;
}

.listing-tabs a {
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  display: inline-flex;
  gap: 7px;
  align-items: center;
  min-height: 32px;
  padding: 6px 10px;
}

.listing-tabs a.active {
  background: var(--green-soft);
  border-color: #2c8d65;
  color: var(--green);
}

.warn {
  color: var(--red);
  max-width: min(520px, 55vw);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.monitor {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  min-height: 132px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.monitor.muted {
  opacity: 0.55;
}

.monitor h3 {
  font-size: 16px;
}

.sources {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 11px;
}

.sources a,
.chips span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  background: var(--panel-soft);
}

.actions {
  display: flex;
  align-items: start;
  gap: 6px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.form-grid.single {
  grid-template-columns: 1fr;
}

label {
  color: var(--muted);
  font-size: 12px;
}

input,
select,
textarea {
  width: 100%;
  margin-top: 4px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px 10px;
  background: var(--field);
  color: var(--ink);
}

input::placeholder,
textarea::placeholder {
  color: #777166;
}

textarea {
  resize: vertical;
}

.check-row {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  display: flex;
  gap: 8px;
  min-height: 39px;
  padding: 8px 10px;
}

.check-row input {
  margin: 0;
  width: auto;
}

.wide {
  grid-column: 1 / -1;
}

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
}

.login-card {
  width: min(360px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
}

.login-brand {
  display: grid;
  justify-items: center;
  gap: 9px;
  margin-bottom: 18px;
  text-align: center;
}

.login-brand strong {
  font-size: 22px;
  line-height: 1.1;
}

.login-brand .login-logo {
  display: block;
  width: 42px;
  height: 42px;
  min-width: 42px;
  max-width: 42px;
  min-height: 42px;
  max-height: 42px;
  object-fit: contain;
}

.login-form {
  display: grid;
  gap: 11px;
}

.login-form button {
  width: 100%;
  margin-top: 2px;
}

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

.auth-panel {
  width: min(420px, 100%);
  margin: 0;
}

.compact-brand {
  pointer-events: none;
}

.narrow-layout {
  max-width: 720px;
}

.form-error,
.form-ok,
.field-note {
  margin: 0 0 12px;
}

.form-error {
  color: var(--red);
}

.form-ok {
  color: var(--green);
}

.field-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.admin-layout {
  width: min(1400px, calc(100vw - 32px));
}

.admin-table,
.admin-users-table {
  min-width: 0;
}

.admin-users-panel {
  min-width: 0;
}

.admin-users-wrap {
  overflow-x: visible;
}

.admin-users-table {
  table-layout: fixed;
}

.admin-users-table th,
.admin-users-table td {
  padding: 10px 8px;
  vertical-align: middle;
}

.admin-users-table th {
  white-space: nowrap;
}

.admin-users-table td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-users-table tbody tr:hover {
  background: #1d1c19;
}

.admin-col-user {
  width: 13%;
}

.admin-col-status {
  width: 8%;
}

.admin-col-role {
  width: 8%;
}

.admin-col-count {
  width: 7%;
}

.admin-col-base {
  width: 21%;
}

.admin-col-telegram {
  width: 13%;
}

.admin-col-login {
  width: 16%;
}

.admin-col-actions {
  width: 14%;
}

.admin-user-cell strong,
.admin-base-cell span {
  display: block;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-base-cell small {
  display: block;
  line-height: 1.3;
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-status-cell {
  color: var(--green);
}

.admin-status-cell.inactive {
  color: var(--red);
}

.admin-login-cell {
  overflow: visible;
  text-overflow: clip;
}

.admin-count-cell {
  font-variant-numeric: tabular-nums;
}

.admin-actions-cell {
  padding-left: 8px;
  padding-right: 8px;
}

.admin-actions-cell .row-actions {
  justify-content: flex-end;
}

.admin-actions-cell button {
  min-height: 30px;
  padding: 5px;
  width: 30px;
}

.admin-row-actions {
  align-items: center;
}

.admin-row-actions > button.blue {
  gap: 6px;
  min-height: 32px;
  padding: 6px 9px;
  width: auto;
}

.admin-add-user {
  width: 100%;
}

.admin-users-table tfoot td {
  border-top: 1px solid var(--line);
  padding: 12px 8px 2px;
}

.admin-dialog {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  margin: auto;
  padding: 0;
  width: min(680px, calc(100vw - 28px));
}

.admin-dialog::backdrop {
  background: rgba(0, 0, 0, 0.62);
}

.admin-dialog-form {
  padding: 16px;
}

.admin-dialog-head,
.admin-dialog-actions {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.admin-dialog-head {
  border-bottom: 1px solid var(--line);
  margin: -2px 0 14px;
  padding-bottom: 12px;
}

.admin-dialog-head h2 {
  font-size: 18px;
  margin: 0;
}

.admin-dialog-head button {
  min-height: 32px;
  padding: 6px;
  width: 32px;
}

.admin-dialog-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.admin-dialog-grid label > span {
  align-items: center;
  display: flex;
  gap: 6px;
  justify-content: space-between;
}

.municipality-field {
  position: relative;
}

.municipality-results {
  background: var(--field);
  border: 1px solid #5f5a50;
  border-radius: 7px;
  left: 0;
  max-height: 188px;
  overflow-y: auto;
  padding: 4px;
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 30;
}

.municipality-results[hidden] {
  display: none;
}

.municipality-option {
  align-items: flex-start;
  background: transparent;
  border-color: transparent;
  border-radius: 5px;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  gap: 2px;
  justify-content: center;
  min-height: 42px;
  padding: 7px 8px;
  width: 100%;
}

.municipality-option:hover {
  background: #27241f;
  border-color: transparent;
}

.municipality-option strong {
  font-size: 14px;
  font-weight: 650;
  line-height: 1.2;
}

.municipality-option small,
.municipality-empty {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.municipality-empty {
  padding: 9px 8px;
}

.admin-dialog-grid em {
  color: var(--green);
  font-size: 11px;
  font-style: normal;
  font-weight: 650;
}

.admin-dialog-grid em.optional {
  color: var(--muted);
}

.admin-dialog-actions {
  border-top: 1px solid var(--line);
  justify-content: flex-end;
  margin-top: 16px;
  padding-top: 14px;
}

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

.row-actions form {
  margin: 0;
}

.secondary-head {
  border-top: 1px solid var(--line);
  margin-top: 18px;
  padding-top: 16px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1120px;
}

th,
td {
  border-top: 1px solid var(--line);
  padding: 11px 9px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  background: #171614;
  font-size: 12px;
  font-weight: 650;
}

.listing-title {
  color: var(--ink);
  font-weight: 650;
}

.score {
  display: inline-flex;
  width: 38px;
  height: 30px;
  border-radius: 7px;
  align-items: center;
  justify-content: center;
  font-weight: 750;
}

.score-affare {
  background: var(--green);
  color: #10100f;
}

.score-buono {
  background: var(--green-soft);
  color: var(--green);
}

.score-normale {
  background: #1d3047;
  color: var(--blue);
}

.score-scartare {
  background: var(--red-soft);
  color: var(--red);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 7px;
}

.chips span {
  color: var(--yellow);
}

.ignored {
  opacity: 0.45;
}

.empty {
  color: var(--muted);
  height: 72px;
  text-align: center;
  vertical-align: middle;
}

.empty-panel {
  color: var(--muted);
  margin: 0;
}

@media (max-width: 1180px) {
  .monitor-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .split,
  .admin-split {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 720px) {
  body {
    font-size: 14px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
    padding: 12px;
  }

  .brand {
    gap: 10px;
  }

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

  .brand small {
    font-size: 12px;
    line-height: 1.25;
  }

  .logo {
    width: 40px;
    height: 40px;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    justify-content: initial;
  }

  .topbar-actions > *,
  .topbar-actions button,
  .topbar-actions .button-like {
    width: 100%;
  }

  .layout {
    max-width: 1480px;
    width: calc(100% - 12px);
    margin: 8px auto 28px;
  }

  .status-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    margin-bottom: 8px;
  }

  .status {
    min-height: 62px;
    padding: 9px;
  }

  .status span {
    font-size: 11px;
  }

  .status strong {
    font-size: 16px;
    margin-top: 5px;
  }

  .panel {
    border-radius: 7px;
    margin-bottom: 8px;
    padding: 10px;
  }

  .panel-head {
    gap: 10px;
    margin-bottom: 10px;
    min-height: 0;
  }

  .panel-head h2 {
    font-size: 17px;
  }

  .panel-head,
  .panel-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .panel-actions {
    justify-content: flex-start;
  }

  .warn {
    max-width: 100%;
  }

  .monitor-list,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    margin-bottom: 10px;
  }

  .filter-actions {
    display: grid;
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
  }

  input,
  select,
  textarea {
    min-height: 38px;
    padding: 8px 9px;
  }

  label {
    font-size: 11px;
  }

  .listing-tabs {
    flex-wrap: nowrap;
    margin: 8px -10px 0;
    overflow-x: auto;
    padding: 0 10px 2px;
    scrollbar-width: none;
  }

  .listing-tabs::-webkit-scrollbar {
    display: none;
  }

  .listing-tabs a {
    flex: 0 0 auto;
    min-height: 30px;
    padding: 5px 8px;
    white-space: nowrap;
  }

  .table-wrap {
    overflow: visible;
  }

  table,
  thead,
  tbody,
  tfoot,
  tr,
  td {
    display: block;
    width: 100%;
  }

  table {
    min-width: 0;
  }

  .admin-table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 9px;
  }

  tr {
    background: var(--panel-soft);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
  }

  td {
    border: 0;
    display: grid;
    grid-template-columns: 82px minmax(0, 1fr);
    gap: 8px;
    padding: 6px 0;
  }

  td::before {
    color: var(--muted);
    content: attr(data-label);
    font-size: 11px;
    font-weight: 650;
  }

  td:nth-child(1),
  td:nth-child(2),
  td:last-child {
    grid-template-columns: 1fr;
  }

  td:nth-child(1)::before,
  td:nth-child(2)::before,
  td:last-child::before {
    display: none;
  }

  td:nth-child(1) {
    align-items: center;
    display: flex;
    gap: 8px;
    padding-bottom: 3px;
  }

  td:nth-child(2) {
    padding-top: 0;
  }

  td:last-child {
    padding-top: 8px;
  }

  td:last-child form,
  td:last-child button {
    width: 100%;
  }

  .row-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(44px, 1fr));
  }

  .admin-users-table td,
  .admin-users-table td:nth-child(1),
  .admin-users-table td:nth-child(2),
  .admin-users-table td:last-child {
    align-items: start;
    display: grid;
    grid-template-columns: 82px minmax(0, 1fr);
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
  }

  .admin-users-table td:nth-child(1)::before,
  .admin-users-table td:nth-child(2)::before,
  .admin-users-table td:last-child::before {
    display: block;
  }

  .admin-users-table .admin-actions-cell .row-actions {
    grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
  }

  .admin-users-table .admin-actions-cell button {
    width: 100%;
  }

  .admin-users-table tfoot tr {
    background: transparent;
    border: 0;
    padding: 0;
  }

  .admin-users-table tfoot td {
    padding: 6px 0 0;
  }

  .admin-dialog-grid {
    grid-template-columns: 1fr;
  }

  .admin-user-cell strong,
  .admin-base-cell span,
  .admin-base-cell small {
    white-space: normal;
  }

  .listing-title {
    display: block;
    font-size: 15px;
    line-height: 1.25;
  }

  .score {
    height: 28px;
    width: 36px;
  }

  .chips span,
  .sources a {
    font-size: 11px;
  }

  .empty {
    background: transparent;
    border: 0;
    display: table-cell;
  }

  .monitor {
    min-height: 0;
    padding: 10px;
  }

  .monitor h3 {
    font-size: 15px;
  }
}

@media (max-width: 430px) {
  .filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .status strong {
    font-size: 15px;
  }

  .filter-actions {
    grid-template-columns: 1fr;
  }

  td {
    grid-template-columns: 74px minmax(0, 1fr);
  }

  .admin-users-table td,
  .admin-users-table td:nth-child(1),
  .admin-users-table td:nth-child(2),
  .admin-users-table td:last-child {
    grid-template-columns: 74px minmax(0, 1fr);
  }
}

@media (max-width: 340px) {
  .filters {
    grid-template-columns: 1fr;
  }
}
