:root {
  --bg: #0b1020;
  --bg-2: #070b16;
  --card: #141a2a;
  --card-2: #11172b;
  --surface: #11172b;
  --surface-hover: #151d36;
  --surface-active: #1a2544;
  --border: #1e2a4a;
  --border-2: #33415f;
  --text: #e7ecff;
  --text-muted: #a8b0c7;
  --muted: #95a1c6;
  --accent: #6ea8fe;
  --accent-2: #8ec5ff;
  --danger: #ff6b6b;
  --success: #2ecc71;
  --warning: #ffb020;
  --shadow: 0 20px 55px rgba(0, 0, 0, 0.35);
  --radius: 16px;
  --footer-h: 56px;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100dvh;
  background:
    radial-gradient(circle at top left, rgba(110, 168, 254, 0.18), transparent 34rem),
    radial-gradient(circle at bottom right, rgba(142, 197, 255, 0.10), transparent 32rem),
    var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--accent);
}

img {
  max-width: 100%;
}

/* -------------------------------------------------------------------------- */
/* Topbar                                                                     */
/* -------------------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid rgba(110, 168, 254, 0.16);
  background: linear-gradient(180deg, #121a31 0%, #11172b 100%);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.18);
}

.brand {
  margin: 0 0 12px 4px;
  font: 800 18px/1 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  letter-spacing: 0.02em;
  color: var(--text) !important;
}

.topbar .brand {
  margin: 0;
}

.topbar .brand a {
  color: var(--text) !important;
  text-decoration: none !important;
}

.logout {
  margin: 0;
}

.logout button {
  width: auto;
  max-width: none;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border-2);
  padding: 0.45rem 0.85rem;
  border-radius: 0.65rem;
}

.logout button:hover {
  color: var(--text);
  background: var(--surface-hover);
}

/* -------------------------------------------------------------------------- */
/* Login page                                                                 */
/* -------------------------------------------------------------------------- */

/*
  Works with your current login.ejs structure:

  <header class="topbar">...</header>
  <main class="content">
    <section class="card narrow">...</section>
  </main>
*/

body:has(.card.narrow) {
  background:
    linear-gradient(rgba(7, 11, 22, 0.72), rgba(7, 11, 22, 0.86)),
    radial-gradient(circle at 20% 10%, rgba(110, 168, 254, 0.25), transparent 26rem),
    radial-gradient(circle at 80% 90%, rgba(142, 197, 255, 0.12), transparent 28rem),
    url("/images/airplane.png") center / cover no-repeat fixed,
    var(--bg);
}

body:has(.card.narrow) .topbar {
  background: rgba(13, 19, 36, 0.72);
  backdrop-filter: blur(10px);
}

main.content:has(.card.narrow) {
  min-height: calc(100dvh - var(--footer-h) - 76px);
  display: grid;
  place-items: center;
  padding: 2rem 1rem calc(var(--footer-h) + 2rem);
  margin: 0;
  max-width: none;
}

.card.narrow {
  width: min(100%, 430px);
  max-width: 430px;
  margin: 0 auto;
  padding: 2.25rem;
  border-radius: 22px;
  background:
    linear-gradient(180deg, rgba(20, 26, 42, 0.95), rgba(17, 23, 43, 0.92));
  border: 1px solid rgba(110, 168, 254, 0.20);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.card.narrow h1 {
  margin: 0 0 1.25rem;
  font-size: clamp(1.75rem, 4vw, 2.2rem);
  line-height: 1.05;
  letter-spacing: -0.03em;
}



.card.narrow form {
  display: grid;
  gap: 0.95rem;
}

.card.narrow label {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.card.narrow input {
  margin-top: 0.4rem;
  min-height: 46px;
  background: rgba(7, 11, 22, 0.76);
  border-color: rgba(110, 168, 254, 0.22);
}

.card.narrow button[type="submit"] {
  margin-top: 0.4rem;
  width: 100%;
  max-width: none;
  min-height: 48px;
  border-radius: 0.75rem;
  color: #061121;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  box-shadow: 0 12px 26px rgba(110, 168, 254, 0.24);
}

.card.narrow button[type="submit"]:hover {
  filter: brightness(1.06);
  transform: translateY(-1px);
}

.card.narrow button[type="submit"]:active {
  transform: translateY(0);
}

/* -------------------------------------------------------------------------- */
/* Layout                                                                     */
/* -------------------------------------------------------------------------- */

.layout {
  display: flex;
  min-height: calc(100dvh - var(--footer-h));
}

.sidebar {
  width: 260px;
  flex: 0 0 260px;
  min-height: calc(100dvh - var(--footer-h) - 76px);
  position: sticky;
  top: 0;
  padding: 16px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  color: var(--text);
  font: 14px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.nav-group {
  margin: 10px 0;
  border: 1px solid transparent;
}

.group-title {
  list-style: none;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px;
  margin: 0;
  font: 700 12px/1 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
}

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

.nav-group > summary::after {
  content: "▾";
  transform: rotate(0deg);
  transition: transform 0.15s ease;
  opacity: 0.8;
}

.nav-group[open] > summary::after {
  transform: rotate(180deg);
}

.nav-list {
  list-style: none;
  padding: 6px 4px 0;
  margin: 0;
}

.nav-list a {
  display: block;
  padding: 10px 12px;
  margin: 2px 0;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
}

.nav-list a:hover {
  background: var(--surface-hover);
}

.nav-list a[aria-current="page"],
.nav-list a.active {
  background: var(--surface-active);
  color: var(--accent);
}

.group-title:focus,
.nav-list a:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

main.content {
  flex: 1;
  max-width: 100%;
  margin: 2rem auto;
  padding: 0 4rem calc(var(--footer-h) + 2rem);
}

/* -------------------------------------------------------------------------- */
/* Footer                                                                     */
/* -------------------------------------------------------------------------- */

footer {
  border-top: 1px solid rgba(149, 161, 198, 0.35);
  text-align: center;
  padding: 12px 0;
  font-size: 14px;
  color: var(--muted);
  background: var(--card);
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--footer-h);
  z-index: 20;
}

/* -------------------------------------------------------------------------- */
/* Cards, forms, buttons                                                       */
/* -------------------------------------------------------------------------- */

.card {
  background: rgba(20, 26, 42, 0.92);
  padding: 2rem;
  border-radius: var(--radius);
  border: 1px solid rgba(110, 168, 254, 0.12);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
}

label {
  display: block;
  margin: 0.6rem 0;
}

input,
select,
textarea,
button {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border-2);
  background: #0d1324;
  color: var(--text);
  font: inherit;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(110, 168, 254, 0.20);
}

input::placeholder,
textarea::placeholder {
  color: var(--muted);
  opacity: 0.85;
}

textarea {
  min-height: 140px;
  resize: vertical;
  line-height: 1.4;
  caret-color: var(--accent);
}

textarea:disabled,
textarea[readonly],
input:disabled,
select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  width: auto;
  max-width: 300px;
  padding: 0.6rem 0.85rem;
  border-radius: 0.5rem;
  border: 1px solid transparent;
  background: var(--accent);
  color: #00122a;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

button:hover,
.btn:hover {
  filter: brightness(1.04);
}

.btn {
  background: #193153;
  color: #cfe3ff;
  border-color: var(--border);
}

.btn.primary,
.table-controls .btn.primary {
  background: orange;
  color: #071c10;
}

.btn.link,
.link {
  color: var(--text);
  border: 1px solid var(--border);
  background: transparent;
}

.btn.link:hover,
.link:hover {
  background: var(--surface-hover);
}

.btn.danger {
  border-color: #7f1d1d;
  color: #ffb4b4;
  background: transparent;
}

.btn.danger:hover {
  background: rgba(255, 107, 107, 0.08);
}

/* Icon button base */
.btn.icon,
button.icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  max-width: 38px;
  padding: 0;
  border-radius: 0.5rem;
  font-size: 1rem;
}

.btn.icon i,
button.icon i {
  font-size: 1rem;
  line-height: 1;
}

.delete-form {
  display: inline-flex;
  margin: 0;
}

.delete-form button {
  background: transparent;
  color: var(--danger);
  border: 1px solid transparent;
}

.delete-form button:hover {
  background: rgba(255, 107, 107, 0.10);
  border-color: rgba(255, 107, 107, 0.24);
}

/* -------------------------------------------------------------------------- */
/* Dashboard                                                                  */
/* -------------------------------------------------------------------------- */

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

.stat {
  display: block;
  background: rgba(20, 26, 42, 0.92);
  border: 1px solid rgba(110, 168, 254, 0.12);
  padding: 1rem;
  border-radius: 1rem;
  color: var(--text);
  text-decoration: none;
  transition: transform 0.15s ease, background 0.15s ease;
}

.stat:hover {
  background: var(--surface-hover);
  transform: translateY(-1px);
}

.stat strong {
  font-size: 2rem;
  display: block;
}

/* -------------------------------------------------------------------------- */
/* Tables                                                                     */
/* -------------------------------------------------------------------------- */

.table-wrapper {
  background: var(--card);
  padding: 1rem;
  border-radius: 1rem;
  margin-top: 1rem;
  overflow: auto;
  border: 1px solid rgba(110, 168, 254, 0.10);
}

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

th,
td {
  padding: 0.6rem;
  border-bottom: 1px solid #223;
  text-align: left;
  vertical-align: top;
}

th a {
  color: var(--text);
  text-decoration: none;
}

tbody tr:hover {
  background: rgba(255, 255, 255, 0.025);
}

td.actions {
  white-space: nowrap;
}

td.actions .btn,
td.actions .delete-form {
  margin-right: 0.4rem;
  vertical-align: middle;
}

td.actions .btn:last-child,
td.actions .delete-form:last-child {
  margin-right: 0;
}

.editable {
  background: #0d1324;
  border-radius: 0.3rem;
}

.editable.saved {
  outline: 2px solid var(--success);
}

.table-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  flex-wrap: wrap;
}

.table-controls .table-left,
.table-controls .table-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.table-controls .table-right {
  margin-left: auto;
}

.table-controls .btn {
  display: inline-flex;
  padding: 0.6rem 0.8rem;
  background: #193153;
  border-radius: 0.5rem;
  color: #cfe3ff;
  text-decoration: none;
}

.table-controls .pageSize {
  width: 70px;
}

.table-controls .table-left input[type="search"] {
  width: min(45vw, 560px);
}

.pagination {
  display: flex;
  gap: 0.4rem;
  justify-content: flex-end;
  padding-top: 0.6rem;
  flex-wrap: wrap;
}

.pagination a {
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--border-2);
  border-radius: 0.4rem;
  color: #cde;
  text-decoration: none;
}

.pagination a.active {
  background: var(--accent);
  color: #012;
}

/* -------------------------------------------------------------------------- */
/* Flash messages                                                              */
/* -------------------------------------------------------------------------- */

.flash {
  margin: 1rem 0;
  padding: 0.75rem 0.85rem;
  border-radius: 0.6rem;
  border: 1px solid transparent;
}

.flash.error {
  background: #3b1e1e;
  color: #ffbdbd;
  border-color: rgba(255, 107, 107, 0.22);
}

.flash.success {
  background: rgba(46, 204, 113, 0.10);
  color: #b9ffd5;
  border-color: rgba(46, 204, 113, 0.22);
}

/* -------------------------------------------------------------------------- */
/* Error pages                                                                 */
/* -------------------------------------------------------------------------- */

.code {
  font-size: clamp(56px, 12vw, 108px);
  line-height: 0.9;
  letter-spacing: -2px;
  margin: 0 0 8px;
  color: var(--accent);
}

.main-404 {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 32px 16px;
  text-align: center;
}

.card-404 {
  max-width: 720px;
  width: 100%;
  padding: 28px 24px;
  background: rgba(17, 23, 43, 0.6);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(4px);
}

/* -------------------------------------------------------------------------- */
/* Detail / view pages                                                         */
/* -------------------------------------------------------------------------- */

.breadcrumbs {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.breadcrumbs a {
  color: var(--text-muted);
  text-decoration: none;
}

.breadcrumbs a:hover {
  color: var(--text);
}

.view .card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.view .title {
  font-size: 20px;
  margin: 0;
}

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

.view .grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 12px;
}

.view .field {
  grid-column: span 6;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

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

.view .label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

.view .value {
  font-size: 15px;
  word-break: break-word;
}

.view .meta {
  margin-top: 12px;
  color: var(--text-muted);
  font-size: 12px;
}

.detail-list {
  display: grid;
  grid-template-columns: minmax(160px, 240px) 1fr;
  gap: 0.6rem 1rem;
  margin: 1rem 0 0;
}

.detail-list dt {
  color: var(--muted);
  font-weight: 700;
}

.detail-list dd {
  margin: 0;
  white-space: pre-wrap;
}

pre {
  background: #0d1324;
  border: 1px solid var(--border-2);
  border-radius: 0.5rem;
  padding: 0.8rem;
  overflow-x: auto;
}

/* -------------------------------------------------------------------------- */
/* CSV import                                                                  */
/* -------------------------------------------------------------------------- */

.import .card {
  background: rgba(17, 23, 43, 0.6);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(4px);
  margin-bottom: 20px;
}

.import h1,
.import h2,
.import h3 {
  margin: 0 0 8px;
}

.import p {
  margin: 0 0 10px;
}

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

.import .grid {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr;
}

.import .rules ul {
  margin: 6px 0 0 18px;
}

.import .summary {
  display: grid;
  grid-template-columns: repeat(5, max-content);
  gap: 10px 18px;
  align-items: center;
}

.import table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  background: rgba(17, 23, 43, 0.35);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.import th,
.import td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.import thead th {
  background: rgba(255, 255, 255, 0.03);
  font-weight: 700;
  color: var(--text);
}

.import tbody td {
  color: var(--text);
}

.import code {
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 6px;
  border-radius: 6px;
}

.import input[type="file"] {
  color: var(--text);
}

/* -------------------------------------------------------------------------- */
/* Utility                                                                     */
/* -------------------------------------------------------------------------- */

.image-container {
  padding-top: 5vh;
  margin: 0;
}

.image-container img {
  display: block;
  max-width: 100%;
  height: auto;
}

textarea::-webkit-scrollbar {
  width: 12px;
}

textarea::-webkit-scrollbar-track {
  background: transparent;
}

textarea::-webkit-scrollbar-thumb {
  background: #2b3a66;
  border-radius: 8px;
  border: 3px solid transparent;
  background-clip: content-box;
}

textarea {
  scrollbar-width: thin;
  scrollbar-color: #2b3a66 transparent;
}

/* -------------------------------------------------------------------------- */
/* Responsive                                                                  */
/* -------------------------------------------------------------------------- */

@media (max-width: 900px) {
  .layout {
    display: block;
  }

  .sidebar {
    width: 100%;
    min-height: 0;
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  main.content {
    padding: 0 1rem calc(var(--footer-h) + 2rem);
  }

  .table-controls .table-right {
    margin-left: 0;
  }

  .table-controls .table-left input[type="search"] {
    width: min(100%, 460px);
  }
}

@media (max-width: 720px) {
  .topbar {
    padding: 1rem;
  }

  .card {
    padding: 1.25rem;
  }

  .card.narrow {
    padding: 1.5rem;
  }

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

  .detail-list {
    grid-template-columns: 1fr;
  }

  .import .summary {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 520px) {
  .table-controls,
  .table-controls .table-left,
  .table-controls .table-right {
    align-items: stretch;
    width: 100%;
  }

  .table-controls .table-left input[type="search"],
  .table-controls .btn,
  .table-controls button {
    width: 100%;
    max-width: none;
  }

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