:root {
  --bg-0: #05070f;
  --bg-1: #0a1020;
  --bg-2: #0d1630;
  --panel: rgba(10, 16, 34, 0.82);
  --panel-strong: #101a36;
  --surface: #131f41;
  --surface-hover: #182955;
  --border: #22386b;
  --border-soft: #1b2f5b;
  --text: #eef3ff;
  --muted: #9aaad2;
  --accent: #4a6fe3;
  --accent-strong: #3557c6;
  --danger: #f97070;
  --success: #7ea0ff;
  --warning: #f6c563;
  --shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
  --radius: 10px;
  --radius-lg: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body { min-height: 100%; }

body.modal-open {
  overflow: hidden;
}

body {
  font-family: "Avenir Next", "Nunito Sans", "Segoe UI", sans-serif;
  background:
    radial-gradient(1200px 700px at 82% -10%, rgba(74, 111, 227, 0.16), transparent 55%),
    radial-gradient(900px 540px at -10% 100%, rgba(35, 69, 165, 0.18), transparent 60%),
    linear-gradient(130deg, var(--bg-0), var(--bg-1) 50%, var(--bg-2));
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  overflow-x: hidden;
}

.bg-orb {
  position: fixed;
  z-index: -1;
  border-radius: 50%;
  filter: blur(40px);
  opacity: 0.45;
  pointer-events: none;
}

.bg-orb-a {
  width: 320px;
  height: 320px;
  right: -120px;
  top: -110px;
  background: rgba(74, 111, 227, 0.32);
}

.bg-orb-b {
  width: 260px;
  height: 260px;
  left: -80px;
  bottom: -90px;
  background: rgba(33, 54, 112, 0.5);
}

.muted { color: var(--muted); }
.error { color: var(--danger); margin-top: 8px; }
.error-list {
  margin: 8px 0 0 18px;
  color: var(--danger);
}
.error-list li { margin: 2px 0; }

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: rgba(8, 13, 30, 0.95);
  color: var(--text);
  font-size: 14px;
  transition: border-color .2s ease, box-shadow .2s ease, background .2s ease;
}

input::placeholder,
textarea::placeholder { color: #7e8fbd; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(74, 111, 227, 0.22);
  background: #0f1a3a;
}

button {
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 9px;
  background: linear-gradient(180deg, #5b7cf0, #3f63d4);
  color: #050a1b;
  font-weight: 700;
  padding: 9px 14px;
  font-size: 13px;
  letter-spacing: .02em;
  transition: transform .16s ease, filter .16s ease, box-shadow .16s ease;
  box-shadow: 0 6px 16px rgba(41, 68, 159, 0.35);
}

button:hover { filter: brightness(1.05); transform: translateY(-1px); }
button:active { transform: translateY(0); }
button:disabled { opacity: .55; cursor: not-allowed; transform: none; }

button.with-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

button.with-icon .ph,
.sidebar a .ph {
  font-size: 15px;
  line-height: 1;
}

.btn-sm { padding: 5px 9px; font-size: 11px; border-radius: 8px; }

.btn-outline {
  background: rgba(12, 20, 44, 0.55);
  border-color: var(--border);
  color: var(--text);
  box-shadow: none;
}

.btn-danger {
  background: linear-gradient(180deg, #ff8f8f, #ef6666);
  color: #2f0606;
  box-shadow: 0 6px 16px rgba(188, 58, 58, 0.26);
}

.btn-success {
  background: linear-gradient(180deg, #7f98ff, #5f7fe8);
  color: #09183d;
}

.btn-warning {
  background: linear-gradient(180deg, #ffd887, #efbd57);
  color: #3c2a02;
}

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-box {
  width: min(380px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 30px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: linear-gradient(170deg, rgba(18, 32, 72, 0.92), rgba(11, 19, 44, 0.9));
  box-shadow: var(--shadow);
  animation: riseIn .45s ease both;
}

.login-box h1 {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: .01em;
}

.login-logo {
  width: 140px;
  max-width: 60%;
  height: auto;
  align-self: center;
  margin-bottom: 6px;
  filter: drop-shadow(0 8px 16px rgba(16, 32, 84, 0.45));
}

/* App layout */
.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  grid-template-rows: 72px minmax(0, 1fr);
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
}

.sidebar {
  grid-area: sidebar;
  background: linear-gradient(180deg, rgba(10, 17, 37, 0.95), rgba(8, 13, 28, 0.95));
  border-right: 1px solid var(--border-soft);
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  backdrop-filter: blur(8px);
}

.brand-wrap {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px 10px 12px;
  border-bottom: 1px solid var(--border-soft);
}

.brand-logo {
  width: 52px;
  height: 52px;
  object-fit: contain;
  filter: drop-shadow(0 6px 12px rgba(20, 38, 92, 0.45));
}

.brand-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 6px rgba(49, 196, 141, 0.15);
}

.brand {
  font-size: 17px;
  font-weight: 800;
  color: #e8eeff;
  letter-spacing: .01em;
}

.brand-subtitle {
  margin-top: 1px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #7d90bf;
}

.sidebar ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.sidebar a {
  display: block;
  padding: 10px 11px;
  border-radius: 9px;
  color: #c7d4f6;
  text-decoration: none;
  font-weight: 600;
  transition: background .2s ease, color .2s ease, transform .2s ease;
}

.sidebar a.with-icon {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar a:hover {
  background: rgba(40, 60, 112, 0.52);
  color: #eff4ff;
  transform: translateX(2px);
}

.sidebar a.active {
  background: linear-gradient(180deg, rgba(74, 111, 227, 0.22), rgba(74, 111, 227, 0.12));
  border: 1px solid rgba(91, 125, 229, 0.45);
  color: #eef3ff;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--border-soft);
}

.topbar {
  grid-area: topbar;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 22px;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(11, 18, 39, 0.86);
  backdrop-filter: blur(8px);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.menu-toggle {
  display: none;
}

.app.mobile-menu-open .menu-toggle {
  border-color: #7695ff;
  background: rgba(62, 89, 177, 0.28);
}

.topbar span:first-child {
  font-size: 16px;
  font-weight: 800;
  color: #f3f6ff;
}

#current-section {
  font-size: 16px;
  font-weight: 800;
  color: #f3f6ff;
}

#admin-name {
  display: flex;
  align-items: center;
  gap: 8px;
}

.main {
  grid-area: main;
  padding: 22px;
  overflow-x: auto;
  animation: fadeIn .35s ease;
}

/* Cards */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.card {
  background: linear-gradient(160deg, rgba(18, 31, 69, 0.86), rgba(11, 21, 48, 0.86));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.02);
  animation: riseIn .35s ease both;
}

.card .label {
  color: #9eaeda;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.card .value {
  font-size: 26px;
  font-weight: 800;
  margin-top: 3px;
  color: #f5f7ff;
}

/* Toolbar */
.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 13px;
}

.toolbar input,
.toolbar select {
  width: auto;
  min-width: 145px;
}

/* Table */
.table-wrap {
  background: linear-gradient(160deg, rgba(17, 30, 67, 0.9), rgba(10, 19, 43, 0.9));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  text-align: left;
  padding: 11px 13px;
  color: #93a5d8;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 10px 13px;
  border-bottom: 1px solid rgba(36, 58, 108, 0.72);
  vertical-align: middle;
}

tbody tr:hover { background: rgba(27, 45, 87, 0.66); }

td.mono {
  font-family: "SF Mono", Menlo, Monaco, monospace;
  font-size: 12px;
  color: #d5e1ff;
}

.actions { display: flex; gap: 6px; white-space: nowrap; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  border: 1px solid transparent;
}

.badge.ok,
.badge.SUCCESS,
.badge.VERIFIED {
  background: rgba(74, 111, 227, 0.18);
  color: #b9c9ff;
  border-color: rgba(106, 138, 238, 0.45);
}

.badge.warn,
.badge.PENDING,
.badge.OPEN {
  background: rgba(235, 182, 57, 0.13);
  color: #f9d98d;
  border-color: rgba(244, 196, 91, 0.3);
}

.badge.err,
.badge.FAILED,
.badge.REJECTED {
  background: rgba(237, 94, 94, 0.14);
  color: #ffc0c0;
  border-color: rgba(240, 107, 107, 0.35);
}

.badge.info,
.badge.IN_PROGRESS,
.badge.CLOSED {
  background: rgba(92, 139, 255, 0.16);
  color: #b6d3ff;
  border-color: rgba(121, 157, 255, 0.35);
}

.pagination {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
  font-size: 12px;
  color: var(--muted);
}

.pagination button { padding: 4px 10px; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 20, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  animation: fadeIn .18s ease;
}

.modal {
  width: min(560px, 92vw);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: linear-gradient(165deg, #12204a, #0c1738);
  box-shadow: var(--shadow);
  animation: riseIn .22s ease;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 22px;
  border-bottom: 1px solid var(--border-soft);
  position: sticky;
  top: 0;
  background: rgba(12, 20, 46, 0.92);
  z-index: 1;
}

.modal-body {
  padding: 20px 22px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: min(60vh, 640px);
}

.modal-footer {
  padding: 16px 22px 18px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  align-items: center;
  background: rgba(10, 16, 34, 0.55);
  position: sticky;
  bottom: 0;
}

.modal-footer button:first-child {
  margin-right: auto;
}

.btn-close {
  background: transparent;
  border-color: transparent;
  color: #dbe5ff;
  font-size: 22px;
  padding: 0 6px;
  box-shadow: none;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: 12px;
  color: #95a7d7;
}

.checkbox-field {
  margin-top: 2px;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.switch-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.switch-track {
  position: relative;
  width: 44px;
  height: 24px;
  border-radius: 999px;
  background: #1a2c5a;
  border: 1px solid #2a4e9d;
  transition: background .2s ease, border-color .2s ease;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #c5d6ff;
  transition: transform .2s ease;
}

.switch-input:checked + .switch-track {
  background: linear-gradient(180deg, #5b7cf0, #3f63d4);
  border-color: #7695ff;
}

.switch-input:checked + .switch-track::after {
  transform: translateX(20px);
}

.switch-input:focus-visible + .switch-track {
  box-shadow: 0 0 0 3px rgba(74, 111, 227, 0.24);
}

.switch-text {
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.detail {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}

.detail .field {
  padding: 10px;
  background: rgba(10, 16, 34, 0.75);
  border: 1px solid var(--border-soft);
  border-radius: 9px;
}

.empty {
  padding: 26px;
  text-align: center;
  color: var(--muted);
}

/* Debug panel */
.debug-panel {
  position: fixed;
  right: 14px;
  bottom: 14px;
  width: min(560px, calc(100vw - 28px));
  max-height: 46vh;
  border: 1px solid #2a4486;
  border-radius: var(--radius-lg);
  background: rgba(10, 17, 37, 0.93);
  box-shadow: var(--shadow);
  z-index: 60;
  overflow: hidden;
}

.debug-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-soft);
}

.debug-content {
  max-height: calc(46vh - 46px);
  overflow: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.debug-entry {
  border: 1px solid var(--border-soft);
  border-radius: 9px;
  background: rgba(10, 16, 34, 0.82);
  padding: 6px 8px;
}

.debug-entry summary {
  cursor: pointer;
  font-size: 12px;
  color: #c8d5ff;
}

.debug-entry pre,
.debug-inline {
  margin-top: 8px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  font-family: "SF Mono", Menlo, Monaco, monospace;
  color: #dbe6ff;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes riseIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

  .brand-subtitle { font-size: 0; }

  .sidebar a.with-icon {
    justify-content: center;
  }

  .sidebar a.with-icon span {
    display: none;
  }

  .sidebar a .ph {
    font-size: 17px;
  }

  .brand { font-size: 0; }
  .brand-logo {
    width: 42px;
    height: 42px;
  }
  .brand-copy {
    font-size: 0;
  }
  .sidebar-footer button { width: 100%; }
}

@media (max-width: 760px) {
  .login-screen { padding: 14px; }
  .login-box { padding: 22px; }

  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
    grid-template-areas:
      "topbar"
      "sidebar"
      "main";
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    padding: 10px 12px;
  }

  .menu-toggle {
    display: inline-flex;
  }

  .sidebar {
    display: none;
    height: auto;
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--border-soft);
    padding: 8px 8px 10px;
  }

  .app.mobile-menu-open .sidebar {
    display: flex;
  }

  .brand-wrap {
    border-bottom: 0;
    padding: 4px 8px;
  }

  .brand,
  .brand-subtitle,
  .sidebar a { font-size: inherit; }

  .brand-copy {
    font-size: inherit;
  }

  .brand-logo {
    width: 36px;
    height: 36px;
  }

  .sidebar ul {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
  }

  .sidebar a {
    padding: 6px 9px;
    border: 1px solid var(--border-soft);
  }

  .sidebar a.with-icon {
    gap: 6px;
  }

  .sidebar a.with-icon span {
    display: inline;
  }

  .main { padding: 14px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .toolbar input,
  .toolbar select,
  .toolbar button {
    width: 100%;
    min-width: 0;
  }

  .actions { flex-wrap: wrap; }

  .debug-panel {
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
    max-height: 42vh;
  }

  .modal {
    width: min(96vw, 96vw);
  }

  .modal-header {
    padding: 14px 14px;
  }

  .modal-body {
    padding: 14px;
    gap: 12px;
  }

  .modal-footer {
    padding: 12px 14px 14px;
    justify-content: stretch;
  }

  .modal-footer button {
    width: 100%;
    margin-right: 0;
  }
}