:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --danger: #dc2626;
  --border: #e2e8f0;
  --shadow: 0 18px 40px rgba(15, 23, 42, 0.12);
  font-family: "Montserrat", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: linear-gradient(135deg, #e2e8f0, #f8fafc 50%, #e0f2fe);
  color: var(--ink);
  min-height: 100vh;
}

.muted {
  color: var(--muted);
}

header:not(.topbar) {
  padding: 20px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

header:not(.topbar) a {
  text-decoration: none;
  color: var(--accent);
  font-weight: 600;
  margin-left: 16px;
}

main {
  max-width: 920px;
  margin: 0 auto;
  padding: 16px 24px 48px;
}

/* Cabinet pages should be fluid and desktop-friendly (legacy auth pages keep the global max-width). */
.cabinet-layout main {
  max-width: none;
  margin: 0;
  padding: 0;
}

.cabinet-layout .section {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px;
  box-shadow: var(--shadow);
}

h1, h2 {
  margin: 0 0 12px;
}

p {
  color: var(--muted);
}

form {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

input, textarea, select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 14px;
}

input[type="checkbox"],
input[type="radio"] {
  width: auto;
  padding: 0;
  margin: 0;
  border-radius: 4px;
  accent-color: var(--accent);
  flex: 0 0 auto;
}

label.card-row input[type="checkbox"],
label.card-row input[type="radio"] {
  margin-top: 1px;
}

input:focus-visible,
textarea:focus-visible,
select:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

button {
  background: var(--accent);
  border: none;
  color: white;
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
}

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

button.secondary {
  background: #0f172a;
}

button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--ink);
}

.cabinet-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #0f172a;
  color: #e2e8f0;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sidebar-brand {
  font-weight: 700;
  font-size: 18px;
}

.sidebar-role {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #94a3b8;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-nav a {
  color: #e2e8f0;
  text-decoration: none;
  padding: 8px 10px;
  border-radius: 10px;
  font-weight: 600;
}

.sidebar-nav a.active,
.sidebar-nav a:hover {
  background: rgba(148, 163, 184, 0.2);
}

.content {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(8px);
}

.topbar-title {
  font-size: 20px;
  font-weight: 700;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.section {
  padding: 24px;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) minmax(160px, 200px) auto;
  gap: 12px;
  margin-bottom: 16px;
}

.table-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 8px 0 12px;
}

.pager {
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.metric {
  font-size: 28px;
  font-weight: 700;
  margin: 8px 0;
}

.code-block {
  margin-top: 12px;
  padding: 12px;
  border-radius: 12px;
  background: #0f172a;
  color: #e2e8f0;
  min-height: 60px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: auto;
  max-height: 420px;
}

.state {
  display: none;
  padding: 14px 16px;
  border-radius: 12px;
  background: #f1f5f9;
  color: var(--muted);
}

.state.state-error {
  background: #fee2e2;
  color: #991b1b;
}

.state.state-empty {
  background: #e2e8f0;
}

.state.state-ready {
  display: block;
  background: transparent;
  padding: 0;
}

.state.state-loading {
  display: block;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.modal.show {
  display: flex;
}

.modal-content {
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  max-width: 520px;
  width: 100%;
  box-shadow: var(--shadow);
}

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  max-width: 420px;
  width: 100%;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid-span-all {
  grid-column: 1 / -1;
}

@media (min-width: 760px) {
  .grid.two {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 760px) {
  .cabinet-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
  }

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

  .section {
    padding: 16px;
  }

  .toolbar {
    grid-template-columns: 1fr;
  }

  header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 16px 18px;
  }

  header nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 12px;
  }

  header a {
    margin-left: 0;
    font-size: 13px;
  }

  main {
    padding: 12px 16px 36px;
  }

  .card {
    padding: 18px;
  }

  .table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .table th,
  .table td {
    white-space: nowrap;
  }

  button,
  input,
  select,
  textarea {
    font-size: 15px;
  }
}

.table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
}

.table th, .table td {
  border-bottom: 1px solid var(--border);
  padding: 10px 6px;
  text-align: left;
  font-size: 13px;
}

@media (min-width: 1024px) {
  .cabinet-layout .section {
    max-width: 1440px;
  }

  .sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: auto;
  }

  button,
  input,
  select,
  textarea {
    font-size: 15px;
  }

  .table th, .table td {
    font-size: 14px;
    padding: 12px 10px;
  }
}

.badge {
  display: inline-flex;
  padding: 2px 8px;
  border-radius: 999px;
  background: #e0f2fe;
  color: #0369a1;
  font-size: 12px;
  font-weight: 600;
}

.notice {
  background: #fef3c7;
  border: 1px solid #fde68a;
  color: #92400e;
  padding: 10px 12px;
  border-radius: 12px;
}

.error {
  color: var(--danger);
  font-weight: 600;
}

.field-error {
  border-color: #dc2626;
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.15);
}

.password-field {
  position: relative;
  display: flex;
  align-items: center;
}

.password-field input {
  padding-right: 44px;
}

.password-toggle {
  position: absolute;
  right: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
}

.menu-wrapper {
  position: relative;
  display: inline-block;
}

.menu {
  position: absolute;
  right: 0;
  top: 36px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 6px;
  display: none;
  min-width: 160px;
  z-index: 5;
}

.menu.show {
  display: block;
}

.menu button {
  width: 100%;
  background: transparent;
  color: var(--ink);
  text-align: left;
  border: none;
  padding: 8px 10px;
  border-radius: 8px;
}

.menu button:hover {
  background: #f1f5f9;
}

.details {
  margin-top: 20px;
}

.details-summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 14px;
  border: 1px dashed var(--border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.55);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.details-summary::-webkit-details-marker {
  display: none;
}

.details[open] .details-summary {
  border-style: solid;
  background: rgba(255, 255, 255, 0.8);
}

.cell-details {
  margin: 0;
}

.cell-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 10px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.55);
  max-width: 520px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cell-details > summary::-webkit-details-marker {
  display: none;
}

.cell-pre {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: #0f172a;
  color: #e2e8f0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  max-height: 220px;
  overflow: auto;
}

.table td.event-params {
  max-width: 560px;
  white-space: normal;
  overflow-wrap: anywhere;
}


.field-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.check-row {
  align-items: flex-start;
}

.check-label {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  line-height: 1.35;
}

.hint-tip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 1px solid #94a3b8;
  color: #475569;
  font-size: 12px;
  font-weight: 700;
  cursor: help;
  background: #fff;
  flex: 0 0 auto;
}

.hint-tip::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%);
  width: min(320px, 75vw);
  padding: 8px 10px;
  border-radius: 8px;
  background: #0f172a;
  color: #e2e8f0;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.35;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 40;
}

.hint-tip:hover::after,
.hint-tip:focus-visible::after {
  opacity: 1;
}
