:root {
  --bg: #f4f7f9;
  --panel: #ffffff;
  --ink: #1f2227;
  --muted: #66717a;
  --line: #d8d9db;
  --line-strong: #b8babd;
  --brand-blue: #36a0de;
  --brand-blue-strong: #008dc6;
  --brand-blue-dark: #006f9f;
  --brand-gray: #d8d9db;
  --danger: #b42318;
  --ok: #1b7f4a;
  --warning: #a15c00;
  --shadow: 0 8px 18px rgba(31, 34, 39, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Univia Pro", "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  letter-spacing: 0;
}

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

a:hover { color: var(--brand-blue-strong); }

.topbar {
  min-height: 52px;
  padding: 6px 16px;
  background: #fff;
  border-bottom: 3px solid var(--brand-blue-strong);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 4px 18px rgba(31, 34, 39, 0.05);
}

.brand {
  color: var(--ink);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 230px;
  font-size: 14px;
}

.brand img {
  display: block;
  width: 156px;
  height: auto;
}

.brand span {
  max-width: 280px;
  line-height: 1.18;
}

.topnav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 3px;
  font-size: 13px;
}

.topnav a,
.link-button {
  border-radius: 6px;
  color: var(--ink);
  padding: 4px 6px;
}

.topnav a:hover,
.link-button:hover {
  background: #edf7fc;
  color: var(--brand-blue-dark);
}

.topnav a.active {
  font-weight: 700;
  color: var(--brand-blue-dark);
  background: #edf7fc;
}

.topnav form { margin: 0; }

.page {
  width: calc(100% - 16px);
  margin: 10px auto 24px;
}

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

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

.intro {
  border-left: 4px solid var(--brand-blue-strong);
}

.intro h1,
.activation-card h1 {
  margin: 0 0 5px;
  font-size: 24px;
  letter-spacing: 0;
  line-height: 1.16;
}

.intro p,
.muted,
.support {
  color: var(--muted);
  line-height: 1.32;
}

.support {
  border-top: 1px solid var(--line);
  margin: 8px 0 0;
  padding-top: 8px;
}

.narrow { max-width: 520px; }

.form-grid {
  display: grid;
  gap: 7px;
}

.form-grid.columns {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.issue-form {
  grid-template-columns: repeat(6, minmax(0, 1fr));
  align-items: end;
}

.issue-master {
  grid-column: span 2;
}

.issue-computer {
  grid-column: span 4;
}

.issue-company {
  grid-column: span 3;
}

.issue-tax {
  grid-column: span 1;
}

.issue-name {
  grid-column: span 2;
}

.master-key-create-form {
  grid-template-columns: minmax(220px, 1.25fr) minmax(150px, 0.8fr) minmax(90px, 110px) minmax(90px, 110px) minmax(105px, 130px);
  align-items: end;
}

.master-key-create-form .short-field input,
.table-number-input {
  text-align: right;
}

.table-number-input {
  width: 76px;
  min-width: 76px;
  padding: 7px 8px;
}

.validity-input {
  width: 96px;
  min-width: 96px;
}

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

label {
  display: grid;
  gap: 3px;
  font-weight: 700;
  font-size: 13px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 5px 7px;
  font: inherit;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--brand-blue-strong);
  box-shadow: 0 0 0 3px rgba(0, 141, 198, 0.16);
}

textarea {
  min-height: 86px;
  resize: vertical;
}

.field-action-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 5px;
}

.field-action-row button {
  white-space: nowrap;
}

.actions,
.panel-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.panel-header {
  justify-content: space-between;
  margin-bottom: 6px;
}

.panel-header h2,
.panel h2 {
  margin: 0 0 8px;
  font-size: 18px;
  line-height: 1.2;
}

button,
.button {
  border: 0;
  border-radius: 6px;
  background: var(--brand-blue-strong);
  color: #fff;
  padding: 5px 9px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 30px;
}

button:hover,
.button:hover {
  background: var(--brand-blue-dark);
  color: #fff;
}

button.secondary {
  background: #57565b;
}

button.secondary:hover {
  background: #373437;
}

button.danger {
  background: var(--danger);
}

button.danger:hover {
  background: #7f1d16;
}

.button.ghost,
button.ghost {
  background: #edf1f3;
  color: var(--ink);
  border: 1px solid var(--line);
}

.button.ghost:hover,
button.ghost:hover {
  background: #dfe7eb;
  color: var(--ink);
}

.link-button {
  background: transparent;
  color: var(--ink);
  min-height: 0;
  padding: 4px 6px;
  font-weight: 400;
}

.small-button {
  padding: 4px 6px;
  min-height: 24px;
  font-size: 12px;
}

.wide {
  width: 100%;
  justify-content: center;
  margin-top: 10px;
}

.notice {
  margin-bottom: 8px;
  padding: 7px 9px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
}

.notice.error,
.error-panel {
  border-color: rgba(180, 35, 24, 0.38);
  border-left-color: var(--danger);
}

.notice.success {
  border-color: rgba(27, 127, 74, 0.38);
  border-left: 6px solid var(--ok);
}

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

.metric {
  padding: 9px;
  border-top: 3px solid var(--brand-blue);
}

.metric span {
  color: var(--muted);
  display: block;
  margin-bottom: 3px;
}

.metric strong {
  font-size: 26px;
}

.activation-card {
  padding: 12px;
  margin-bottom: 8px;
  border-top: 4px solid var(--brand-blue-strong);
}

.activation-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 8px;
}

.field-title {
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 3px;
}

.big-code {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f1f8fc;
  padding: 9px;
  font-family: Consolas, monospace;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0;
  margin-bottom: 6px;
  overflow-wrap: anywhere;
}

.status-pill {
  display: inline-flex;
  border-radius: 999px;
  background: #e6f4fb;
  color: var(--brand-blue-dark);
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 700;
}

.status-inactive {
  background: #f4e8e6;
  color: var(--danger);
}

.status-comment {
  min-width: 180px;
  max-width: 360px;
  white-space: pre-wrap;
}

.status-comment-row {
  display: inline-flex;
  align-items: flex-start;
  gap: 6px;
  max-width: 100%;
}

.status-comment-row .status-comment {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inline-form {
  display: grid;
  gap: 4px;
  margin: 4px 0 0;
  min-width: 190px;
}

.inline-form textarea {
  min-height: 58px;
  padding: 6px;
  font-size: 12px;
}

.compact-form {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 3px;
  margin: 0;
}

.instruction-columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.instruction-column h3 {
  margin: 0 0 4px;
  font-size: 15px;
}

.instruction-column p {
  margin: 0;
  color: var(--muted);
  line-height: 1.32;
}

.command-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.command-list code {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7fafb;
  padding: 5px 7px;
}

.important {
  font-weight: 700;
}

.log-export-form {
  grid-template-columns: repeat(2, minmax(150px, 200px)) auto;
  align-items: end;
}

.notification-smtp-form {
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  align-items: end;
}

.notification-recipient-form {
  grid-template-columns: minmax(160px, 1fr) minmax(200px, 1.2fr);
  align-items: end;
}

.checkbox-line,
.checkbox-grid label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
}

.checkbox-line input,
.checkbox-grid input,
td input[type="checkbox"] {
  width: auto;
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 6px 10px;
}

.backup-actions {
  display: grid;
  grid-template-columns: auto minmax(280px, 1fr);
  align-items: end;
  gap: 8px;
}

.backup-upload-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  align-items: end;
  gap: 6px;
}

.sql-console-form textarea {
  min-height: 120px;
}

.sql-result-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin: 8px 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.sql-result-wrap {
  max-height: 48vh;
}

.sql-result-table {
  table-layout: auto;
  min-width: max-content;
}

.sql-result-table th,
.sql-result-table td {
  max-width: 520px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.table-wrap {
  overflow: auto;
  max-height: 72vh;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  table-layout: fixed;
  min-width: 100%;
}

.enhanced-table {
  width: 100%;
  min-width: 100%;
}

.fit-content-table {
  table-layout: auto;
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

.fit-content-table th,
.fit-content-table td {
  max-width: min(36ch, 26vw);
}

.fit-content-table [data-column-id="actions"],
.fit-content-table [data-column-id="status"] {
  width: 1%;
  max-width: 18ch;
  white-space: nowrap;
}

.fit-content-table [data-column-id="status_comment"] {
  max-width: min(42ch, 30vw);
}

th,
td {
  padding: 4px 6px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  position: relative;
}

th {
  position: sticky;
  top: 0;
  background: #eaf2f6;
  z-index: 1;
  font-size: 11px;
  padding-right: 12px;
}

tbody tr:nth-child(even) {
  background: #fafcfd;
}

.enhanced-table.show-full-text th,
.enhanced-table.show-full-text td {
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
}

.table-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: wrap;
  margin: 0 0 6px;
}

.table-search-group {
  display: flex;
  align-items: end;
  flex: 1;
  min-width: min(520px, 100%);
  gap: 6px;
}

.table-toolbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
}

.table-search {
  min-width: min(280px, 100%);
  max-width: 400px;
  flex: 1;
}

.table-search span {
  color: var(--muted);
}

.column-settings {
  position: relative;
}

.column-settings-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 3px);
  width: min(420px, calc(100vw - 32px));
  max-height: 440px;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 12;
}

.column-settings-list {
  display: grid;
  gap: 4px;
  margin-top: 5px;
}

.column-settings-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px 28px;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px;
  background: #fbfdfe;
}

.column-settings-item label {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-weight: 600;
}

.column-settings-item label span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.column-settings-item input {
  width: auto;
}

.icon-button {
  width: 26px;
  min-width: 26px;
  min-height: 26px;
  padding: 0;
}

.table-text-input {
  width: 24ch;
  min-width: 18ch;
  padding: 5px 6px;
}

.company-input {
  width: 20ch;
}

.sort-button {
  width: 100%;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  display: inline-flex;
  justify-content: flex-start;
  gap: 6px;
  font-size: inherit;
  line-height: 1.18;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sort-button span:first-child {
  display: inline-block;
  max-width: none;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sort-button:hover {
  background: transparent;
  color: var(--brand-blue-dark);
}

.sort-indicator {
  min-width: 10px;
  color: var(--brand-blue-dark);
}

.filter-row th {
  top: 38px;
  z-index: 1;
  background: #f4f8fa;
}

.filter-row input {
  min-width: 120px;
  padding: 5px 6px;
  font-size: 12px;
  font-weight: 400;
}

.table-comment-input {
  width: 220px;
  min-height: 32px;
  padding: 5px 6px;
  font-size: 12px;
  white-space: normal;
}

.master-keys-table [data-column-id="company"] {
  width: 20ch;
}

.master-keys-table [data-column-id="activation_limit"],
.master-keys-table [data-column-id="used_activations"],
.master-keys-table [data-column-id="remaining_activations"],
.master-keys-table [data-column-id="reissue_limit"],
.master-keys-table [data-column-id="used_reissues"],
.master-keys-table [data-column-id="remaining_reissues"],
.master-keys-table [data-column-id="validity_days"],
.master-keys-table [data-column-id="created_at"],
.master-keys-table [data-column-id="first_activation"],
.master-keys-table [data-column-id="expires_at"],
.master-keys-table [data-column-id="last_activation"] {
  text-align: center;
}

.master-keys-table [data-column-id="activation_limit"] input,
.master-keys-table [data-column-id="reissue_limit"] input,
.master-keys-table [data-column-id="validity_days"] input {
  text-align: center;
}

.status-button {
  width: auto;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
}

.status-button:hover {
  background: transparent;
  color: inherit;
}

.column-resizer {
  position: absolute;
  top: 0;
  right: -3px;
  width: 7px;
  height: 100%;
  cursor: col-resize;
  z-index: 3;
  user-select: none;
  touch-action: none;
}

.column-resizer:hover,
body.resizing-column .column-resizer {
  background: rgba(0, 141, 198, 0.22);
}

body.resizing-column {
  cursor: col-resize;
  user-select: none;
}

.mono-value {
  font-family: Consolas, "Courier New", monospace;
}

.details-table { min-width: 100%; }
.details-table th { width: 220px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 14px;
  background: rgba(31, 34, 39, 0.42);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-panel {
  width: min(560px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 12px;
}

.modal-panel h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 8px;
}

.copy-state {
  min-height: 18px;
  margin-top: 6px;
  color: var(--ok);
  font-weight: 700;
}

.contact-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 10px;
}

.contact-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfdfe;
}

.contact-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.contact-item strong {
  display: block;
  line-height: 1.45;
}

@media (max-width: 860px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 8px 12px;
  }

  .brand {
    min-width: 0;
  }

  .brand img {
    width: 150px;
  }

  .brand span {
    max-width: none;
  }

  .topnav {
    justify-content: flex-start;
  }

  .page {
    width: min(100%, calc(100% - 12px));
    margin-top: 8px;
  }

  .panel,
  .activation-card {
    padding: 10px;
  }

  .master-key-create-form,
  .issue-form,
  .log-export-form,
  .notification-smtp-form,
  .notification-recipient-form,
  .backup-actions,
  .backup-upload-form {
    grid-template-columns: 1fr;
  }

  .issue-master,
  .issue-computer,
  .issue-company,
  .issue-tax,
  .issue-name {
    grid-column: auto;
  }

  .intro h1,
  .activation-card h1 {
    font-size: 21px;
  }

  .big-code {
    font-size: 24px;
  }
}

@media (max-width: 520px) {
  .brand {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }

  button,
  .button {
    width: 100%;
  }

  .status-button,
  .compact-form .icon-button,
  .field-action-row button,
  .status-comment-row .icon-button,
  .client-activations-table [data-column-id="actions"] button,
  .table-search-group button,
  .table-toolbar-actions button {
    width: auto;
  }

  .modal-actions {
    flex-direction: column;
  }

  .topnav a,
  .topnav form,
  .link-button {
    width: auto;
  }

  .column-settings {
    width: 100%;
  }

  .column-settings-panel {
    left: 0;
    right: auto;
  }

  .column-settings-item .icon-button {
    width: 28px;
  }
}
