* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: Arial, Helvetica, sans-serif;
}

[hidden] {
  display: none !important;
}

:root {
  --bg: #f4f7fb;
  --sidebar: #022e51;
  --accent: #0f766e;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --panel: #ffffff;
  --soft: #f9fafb;
  --blue-soft: #dbeafe;
  --blue: #1d4ed8;
  --green-soft: #dcfce7;
  --green: #166534;
  --yellow-soft: #fef3c7;
  --yellow: #92400e;
  --red-soft: #fee2e2;
  --red: #991b1b;
  --shadow: 0 8px 20px rgba(0, 0, 0, 0.05);
}

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  font-weight: 700;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 250px;
  flex: 0 0 250px;
  background: var(--sidebar);
  color: white;
  padding: 24px 18px;
}

.logo {
  margin-bottom: 35px;
  font-size: 22px;
  font-weight: 700;
}

.menu {
  display: grid;
  gap: 8px;
}

.menu-link {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 0 15px;
  border-radius: 10px;
  background: transparent;
  color: #dbeafe;
  text-align: left;
  font-size: 15px;
  font-weight: 400;
}

.menu-link:hover,
.menu-link.active {
  background: var(--accent);
  color: white;
}

.main {
  flex: 1;
  min-width: 0;
  padding: 25px;
}

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

.topbar h1 {
  margin-bottom: 6px;
  color: var(--sidebar);
  font-size: 26px;
}

.topbar p,
.message,
.footer-info {
  color: var(--muted);
  font-size: 14px;
}

.status-online {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: 20px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 14px;
  font-weight: 700;
}

.admin-field {
  max-width: 460px;
  margin-bottom: 10px;
}

.message {
  min-height: 22px;
  margin-bottom: 18px;
}

.message.error,
.error {
  color: #dc2626;
  font-weight: 700;
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 20px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
}

.card,
.panel,
.mini-card {
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.card {
  padding: 20px;
}

.card h3,
.mini-card h3 {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 14px;
}

.number {
  color: var(--sidebar);
  font-size: 28px;
  font-weight: 700;
}

.detail {
  margin-top: 8px;
  color: #16a34a;
  font-size: 13px;
}

.danger-detail {
  color: #dc2626;
}

.grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
}

.panel {
  padding: 20px;
}

.panel h2 {
  margin-bottom: 18px;
  color: var(--sidebar);
  font-size: 18px;
}

.panel-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

#result-count {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.security-stack {
  display: grid;
  gap: 14px;
}

.mini-card {
  padding: 18px;
  background: var(--soft);
  box-shadow: none;
}

.endpoints {
  display: grid;
  gap: 12px;
}

.endpoint {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-left: 5px solid var(--accent);
  border-radius: 10px;
  background: var(--soft);
  font-size: 14px;
}

.badge {
  display: inline-grid;
  min-height: 25px;
  place-items: center;
  padding: 0 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
}

.get {
  background: var(--blue-soft);
  color: var(--blue);
}

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

.patch,
.put {
  background: var(--yellow-soft);
  color: var(--yellow);
}

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

.ok {
  color: #16a34a;
  font-weight: 700;
}

.protected {
  color: var(--accent);
  font-weight: 700;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(170px, 1fr));
  gap: 14px;
  align-items: end;
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  color: #374151;
  font-size: 14px;
  font-weight: 700;
}

.field input,
.field textarea {
  width: 100%;
  min-height: 46px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #ffffff;
  color: var(--ink);
  outline: none;
}

.field textarea {
  min-height: 92px;
  padding: 12px 13px;
  resize: vertical;
}

.field input:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

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

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

.secondary-button {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--accent);
}

.danger-button {
  border: 1px solid #fecaca;
  background: #ffffff;
  color: #dc2626;
}

.empty-state {
  display: grid;
  gap: 6px;
  padding: 22px;
  border: 1px dashed #cbd5e1;
  border-radius: 10px;
  background: var(--soft);
  color: var(--muted);
}

.empty-state strong {
  color: var(--ink);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}

.logs-table {
  border: 0;
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  padding: 13px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  background: var(--soft);
  color: #374151;
  white-space: nowrap;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.appointments-table {
  min-width: 1360px;
}

.appointments-table th:nth-child(8),
.appointments-table td:nth-child(8) {
  min-width: 150px;
}

.appointments-table th:nth-child(9),
.appointments-table td:nth-child(9) {
  min-width: 300px;
}

.appointments-table td:nth-child(9) {
  white-space: normal;
  line-height: 1.45;
}

.scope-control {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.scope-control label {
  cursor: pointer;
}

.scope-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.scope-control span {
  display: grid;
  min-height: 40px;
  place-items: center;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #ffffff;
  color: var(--muted);
  font-weight: 700;
}

.scope-control input:checked + span {
  border-color: var(--accent);
  background: #d9f2ee;
  color: var(--accent);
}

.new-key-box {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  padding: 14px;
  border: 1px solid #a9d7cf;
  border-radius: 10px;
  background: #edf9f7;
}

.new-key-box code {
  overflow-x: auto;
  padding: 10px;
  border-radius: 8px;
  background: #ffffff;
  white-space: nowrap;
}

.keys-list {
  display: grid;
  gap: 12px;
}

.key-item {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) max-content;
  gap: 16px;
  align-items: start;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--soft);
}

.muted-key {
  opacity: 0.82;
}

.key-info {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.key-title-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.status-pill {
  display: inline-grid;
  min-height: 26px;
  place-items: center;
  padding: 0 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
}

.status-pill.active {
  background: var(--green-soft);
  color: var(--green);
}

.status-pill.inactive {
  background: var(--red-soft);
  color: var(--red);
}

.key-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 6px 12px;
  color: var(--muted);
  font-size: 13px;
}

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

.key-edit {
  margin-top: 6px;
}

.key-edit summary {
  width: fit-content;
  cursor: pointer;
  color: var(--accent);
  font-weight: 700;
}

.key-edit-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #ffffff;
}

.footer-info {
  margin-top: 18px;
}

canvas {
  width: 100%;
  max-width: 100%;
}

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

  .grid,
  .form-grid,
  .key-item,
  .key-meta,
  .key-edit-form {
    grid-template-columns: 1fr;
  }

  .form-grid > *,
  .field,
  .panel {
    min-width: 0;
  }

  .field input,
  .field textarea {
    max-width: 100%;
  }
}

@media (max-width: 600px) {
  .main {
    width: 100%;
    max-width: 100vw;
    padding: 18px;
    overflow-x: hidden;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .cards,
  .access-cards {
    grid-template-columns: 1fr;
  }

  .actions-row,
  .key-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  button {
    width: 100%;
  }
}
