:root {
  --sidebar-width: 248px;
  --sidebar-collapsed-width: 72px;
  --surface: #ffffff;
  --panel: #f6f7f9;
  --line: #d9dee7;
  --text: #1d2430;
  --muted: #657084;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--panel);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.modal-open {
  overflow: hidden;
}

h1,
h2,
p {
  letter-spacing: 0;
}

.d-none {
  display: none !important;
}

.d-flex {
  display: flex !important;
}

.align-items-start {
  align-items: flex-start !important;
}

.align-items-center {
  align-items: center !important;
}

.justify-content-between {
  justify-content: space-between !important;
}

.gap-1 {
  gap: 4px !important;
}

.gap-2 {
  gap: 8px !important;
}

.mb-0 {
  margin-bottom: 0 !important;
}

.mb-2 {
  margin-bottom: 8px !important;
}

.mb-3 {
  margin-bottom: 12px !important;
}

.mt-1 {
  margin-top: 4px !important;
}

.mt-3 {
  margin-top: 12px !important;
}

.py-4 {
  padding-top: 24px !important;
  padding-bottom: 24px !important;
}

.p-0 {
  padding: 0 !important;
}

.w-100 {
  width: 100% !important;
}

.small {
  font-size: 0.82rem;
}

.fs-5 {
  font-size: 1.25rem !important;
}

.fw-bold {
  font-weight: 700 !important;
}

.text-muted {
  color: var(--muted) !important;
}

.text-center {
  text-align: center !important;
}

.nav {
  display: flex;
}

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

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 7px 12px;
  font: inherit;
  font-weight: 650;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
}

.btn:hover {
  filter: brightness(0.97);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.btn-sm {
  min-height: 32px;
  padding: 5px 10px;
  font-size: 0.88rem;
}

.btn-dark {
  background: #111827;
  border-color: #111827;
  color: #fff;
}

.btn-outline-dark {
  background: #fff;
  border-color: #111827;
  color: #111827;
}

.btn-outline-secondary {
  background: #fff;
  border-color: #c7cfda;
  color: #3d4656;
}

.btn-group {
  display: inline-flex;
}

.btn-group .btn {
  border-radius: 0;
}

.btn-group .btn:first-child {
  border-radius: 8px 0 0 8px;
}

.btn-group .btn:last-child {
  border-radius: 0 8px 8px 0;
  margin-left: -1px;
}

.form-label {
  display: block;
  margin-bottom: 6px;
  font-weight: 650;
}

.form-control,
.form-select {
  width: 100%;
  min-height: 38px;
  border: 1px solid #c7cfda;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
  font: inherit;
}

.form-control:focus,
.form-select:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
  outline: none;
}

.form-text {
  color: var(--muted);
  font-size: 0.82rem;
}

.alert {
  border: 1px solid transparent;
  border-radius: 8px;
  margin-bottom: 16px;
  padding: 12px 14px;
}

.alert-warning {
  background: #fffbeb;
  border-color: #fde68a;
  color: #78350f;
}

.alert-danger {
  background: #fff1f2;
  border-color: #fecdd3;
  color: #9f1239;
}

.alert-info {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1e3a8a;
}

.badge {
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 3px 8px;
  font-size: 0.75rem;
  font-weight: 700;
}

.text-bg-light {
  background: #f8fafc;
  color: #1f2937;
}

.text-bg-danger {
  background: #dc2626;
  color: #fff;
}

.text-bg-dark {
  background: #111827;
  color: #fff;
}

.text-bg-warning {
  background: #f59e0b;
  color: #111827;
}

.text-bg-success {
  background: #16a34a;
  color: #fff;
}

.text-bg-primary {
  background: #2563eb;
  color: #fff;
}

.text-bg-info {
  background: #0891b2;
  color: #fff;
}

.text-bg-secondary {
  background: #64748b;
  color: #fff;
}

.spinner-border {
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.75s linear infinite;
}

.spinner-border-sm {
  width: 14px;
  height: 14px;
  border-width: 2px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns 0.18s ease;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: var(--sidebar-collapsed-width) minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px 16px;
  background: #111827;
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
}

.brand-copy {
  min-width: 0;
}

.sidebar-toggle {
  align-items: center;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  height: 32px;
  justify-content: center;
  margin-left: auto;
  width: 32px;
}

.sidebar-toggle:hover {
  background: rgba(255, 255, 255, 0.14);
}

.sidebar-toggle i {
  transition: transform 0.18s ease;
}

.app-shell.sidebar-collapsed .sidebar {
  padding-left: 12px;
  padding-right: 12px;
}

.app-shell.sidebar-collapsed .brand {
  justify-content: center;
}

.app-shell.sidebar-collapsed .brand-copy,
.app-shell.sidebar-collapsed .nav-label,
.app-shell.sidebar-collapsed .sidebar-footer {
  display: none;
}

.app-shell.sidebar-collapsed .brand-mark {
  width: 36px;
  height: 36px;
}

.app-shell.sidebar-collapsed .sidebar-toggle {
  margin-left: 0;
  position: absolute;
  right: 8px;
  top: 64px;
}

.app-shell.sidebar-collapsed .sidebar-toggle i {
  transform: rotate(180deg);
}

.app-shell.sidebar-collapsed .sidebar .nav-link {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

.app-shell.sidebar-collapsed .sidebar .nav-link i {
  font-size: 1.1rem;
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: #fff;
  color: #111827;
  font-weight: 700;
}

.brand-name {
  font-weight: 700;
  line-height: 1.1;
}

.brand-subtitle {
  color: #b7c0ce;
  font-size: 0.82rem;
}

.sidebar .nav-link {
  color: #dce3ed;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
}

.sidebar .nav-link:hover,
.sidebar .nav-link.active {
  background: #263244;
  color: #fff;
}

.sidebar-footer {
  margin-top: auto;
}

.main-panel {
  min-width: 0;
  padding: 24px;
}

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

.topbar h1 {
  margin: 0;
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: 0;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
}

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

.content {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

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

.metric-card {
  padding: 16px;
}

.metric-label {
  color: var(--muted);
  font-size: 0.84rem;
}

.metric-value {
  margin-top: 8px;
  font-size: 1.8rem;
  font-weight: 700;
}

.panel {
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-header h2 {
  font-size: 1rem;
  margin: 0;
  font-weight: 700;
}

.panel-body {
  padding: 16px;
}

.table {
  border-collapse: collapse;
  width: 100%;
  margin: 0;
  vertical-align: middle;
}

.admin-table {
  min-width: 1180px;
}

.admin-table th,
.admin-table td {
  padding: 10px 12px;
}

.table th {
  white-space: nowrap;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.table thead th {
  border-bottom: 1px solid var(--line);
}

.table tbody td {
  border-top: 1px solid #edf0f5;
}

.table-hover tbody tr:hover {
  background: #f4f7fb;
}

.cell-strong {
  font-weight: 700;
  white-space: nowrap;
}

.cell-compact {
  white-space: nowrap;
}

.cell-wrap {
  min-width: 180px;
  white-space: normal;
  overflow-wrap: anywhere;
}

.cell-wide {
  min-width: 240px;
}

.cell-status {
  min-width: 130px;
}

.cell-image {
  width: 84px;
  min-width: 84px;
}

.row-click {
  cursor: pointer;
}

.row-click:hover {
  background: #f4f7fb;
}

.thumb {
  width: 64px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #eef1f5;
}

.placeholder-thumb {
  width: 64px;
  height: 48px;
  border-radius: 6px;
  border: 1px dashed #bac3d0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  background: #f8fafc;
  font-size: 0.75rem;
}

.placeholder-thumb.broken {
  color: #9f1239;
  border-color: #fecdd3;
  background: #fff1f2;
}

.auth-splash {
  min-height: calc(100vh - 150px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-splash-inner {
  width: min(520px, 100%);
  text-align: center;
  padding: 36px 24px;
}

.status-badge {
  text-transform: capitalize;
}

.filters {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 180px 180px 120px;
  gap: 10px;
}

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

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

.subpanel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
  min-width: 0;
}

.subpanel h3 {
  font-size: 0.9rem;
  margin: 0 0 10px;
}

.link-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.timeline-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.timeline-list li {
  border-left: 2px solid var(--line);
  padding: 0 0 12px 12px;
}

.timeline-list li:last-child {
  padding-bottom: 0;
}

.timeline-main {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.surface-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.surface-preview .placeholder-thumb {
  min-height: 132px;
}

.surface-preview img,
.preview-image {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
}

.modal {
  background: rgba(17, 24, 39, 0.52);
  display: none;
  inset: 0;
  overflow: auto;
  padding: 24px;
  position: fixed;
  z-index: 1050;
}

.modal.show {
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-dialog {
  width: min(520px, 100%);
}

.modal-xl {
  width: min(1140px, 100%);
}

.modal-content {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.28);
  overflow: hidden;
}

.modal-header,
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
}

.modal-header {
  border-bottom: 1px solid var(--line);
}

.modal-footer {
  border-top: 1px solid var(--line);
}

.modal-title {
  margin: 0;
  font-weight: 700;
}

.modal-body {
  padding: 16px;
}

.btn-close {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  height: 32px;
  justify-content: center;
  width: 32px;
}

.btn-close::before {
  content: "x";
  font-size: 1.1rem;
  line-height: 1;
}

.token-input {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
}

.key-value {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  gap: 8px 14px;
}

.key-value dt {
  color: var(--muted);
  font-weight: 600;
}

.key-value dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .app-shell.sidebar-collapsed {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .app-shell.sidebar-collapsed .sidebar {
    height: 64px;
  }

  .app-shell.sidebar-collapsed .sidebar .nav {
    display: none;
  }

  .app-shell.sidebar-collapsed .sidebar-toggle {
    position: static;
  }

  .metric-grid,
  .detail-grid,
  .item-grid,
  .filters {
    grid-template-columns: 1fr;
  }
}
