:root {
  --bg: #0f1117;
  --bg-soft: #171b25;
  --bg-elev: #1d2330;
  --line: #2b3344;
  --text: #e4e9f2;
  --muted: #9ea9bf;
  --primary: #3cc8a7;
  --danger: #ef6a6a;
  --warning: #d8a64d;
  --radius: 12px;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(circle at 5% 5%, #1a2438, var(--bg) 35%), var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Helvetica Neue", sans-serif;
  min-height: 100vh;
}

a { color: #8adfcd; text-decoration: none; }
a:hover { text-decoration: underline; }

.shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, #111722, #0d111a);
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

.brand {
  display: flex;
  gap: 0.8rem;
  align-items: center;
}

.brand-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--primary);
  box-shadow: 0 0 14px rgba(60, 200, 167, 0.8);
}

.brand small {
  display: block;
  color: var(--muted);
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.menu-link {
  color: var(--muted);
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
}

.menu-link:hover,
.menu-link.is-active {
  background: rgba(60, 200, 167, 0.12);
  color: var(--text);
  text-decoration: none;
}

.logout-form { margin-top: auto; }

.main {
  padding: 1.4rem;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.page-header h1 {
  margin: 0;
  font-size: 1.4rem;
}

.page-header p { margin: 0.2rem 0 0; }

.row-space {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.row-gap {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.card {
  background: linear-gradient(160deg, rgba(255,255,255,0.01), rgba(255,255,255,0)), var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

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

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.8rem;
}

.stat-card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9rem;
}

.stat-card h3 {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.stat-card p {
  margin: 0.5rem 0 0;
  font-size: 1.4rem;
  font-weight: 700;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
}

.form-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  align-items: end;
}

.form-inline label {
  flex: 1 1 190px;
}

label span {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.86rem;
}

input,
select,
textarea {
  width: 100%;
  padding: 0.62rem 0.68rem;
  border-radius: 9px;
  border: 1px solid #384257;
  background: #0f1520;
  color: var(--text);
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(60, 200, 167, 0.35);
  border-color: #49d1b2;
}

.full-width { grid-column: 1 / -1; }

.btn {
  border: 1px solid #3e4a63;
  background: #1f2b3f;
  color: var(--text);
  border-radius: 9px;
  padding: 0.56rem 0.9rem;
  cursor: pointer;
}

.btn:hover { filter: brightness(1.12); text-decoration: none; }
.btn-primary { background: linear-gradient(135deg, #26b493, var(--primary)); border-color: transparent; color: #061c17; font-weight: 700; }
.btn-danger { background: #4b1d2b; border-color: #793141; color: #ffd7de; }
.btn-ghost { background: transparent; border-color: #3a4a68; }
.btn-sm { padding: 0.38rem 0.6rem; font-size: 0.84rem; }
.btn-full { width: 100%; }

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

.table th,
.table td {
  text-align: left;
  border-bottom: 1px solid #283044;
  padding: 0.62rem 0.45rem;
  vertical-align: top;
}

.table th { color: var(--muted); font-size: 0.82rem; }

.table td[colspan] {
  text-align: center;
  color: var(--muted);
}

.actions-cell {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.inline-form { display: inline-flex; gap: 0.4rem; align-items: center; }

.pill {
  padding: 0.22rem 0.5rem;
  border-radius: 999px;
  font-size: 0.78rem;
  text-transform: capitalize;
  border: 1px solid transparent;
}

.pill-active,
.pill-done,
.pill-paid { background: rgba(60, 200, 167, 0.17); border-color: rgba(60, 200, 167, 0.45); }
.pill-paused,
.pill-open,
.pill-in_progress,
.pill-overdue { background: rgba(216, 166, 77, 0.18); border-color: rgba(216, 166, 77, 0.45); }
.pill-cancelled { background: rgba(239, 106, 106, 0.2); border-color: rgba(239, 106, 106, 0.5); }

.alert {
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  margin-bottom: 0.75rem;
  border: 1px solid;
}

.alert-success { background: rgba(35, 149, 124, 0.22); border-color: rgba(58, 185, 157, 0.45); }
.alert-error { background: rgba(130, 40, 57, 0.24); border-color: rgba(202, 86, 110, 0.5); }

.alert ul { margin: 0.4rem 0 0 1rem; }

.meta-list {
  display: grid;
  gap: 0.55rem;
}

.meta-list dt { color: var(--muted); }
.meta-list dd { margin: 0.15rem 0 0; }

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

.pagination {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-top: 0.8rem;
}

.api-key-card code {
  display: block;
  font-size: 0.94rem;
  padding: 0.65rem;
  border-radius: 8px;
  background: #111726;
  border: 1px solid #2f3b55;
  overflow-wrap: anywhere;
}

.key-row {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}

.guest-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
}

.guest-wrap {
  width: min(520px, 94vw);
}

.auth-card {
  margin-top: 1rem;
}

.records-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}

.record-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.9rem;
  background: var(--bg-elev);
}

.record-card h3,
.record-card h4 {
  margin: 0.2rem 0 0.55rem;
}

.record-card p {
  margin: 0.22rem 0;
}

@media (max-width: 1100px) {
  .shell { grid-template-columns: 90px 1fr; }
  .brand strong,
  .brand small,
  .menu-link { font-size: 0.75rem; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 840px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .menu { flex-direction: row; flex-wrap: wrap; }
  .main { padding: 1rem; }
  .split-grid,
  .form-grid { grid-template-columns: 1fr; }
  .records-grid { grid-template-columns: 1fr; }

  .row-space {
    flex-direction: column;
    align-items: stretch;
  }

  .form-inline {
    flex-direction: column;
    align-items: stretch;
  }

  .form-inline label,
  .form-inline .btn {
    width: 100%;
  }

  .table {
    display: block;
  }

  .table thead {
    display: none;
  }

  .table tbody {
    display: block;
  }

  .table tr {
    display: block;
    margin-bottom: 0.8rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--bg-elev);
    overflow: hidden;
  }

  .table td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.8rem;
    border-bottom: 1px dashed #2d3446;
    padding: 0.6rem 0.7rem;
  }

  .table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 600;
    min-width: 42%;
    max-width: 42%;
  }

  .table td:last-child {
    border-bottom: 0;
  }

  .table td[colspan] {
    display: block;
    text-align: left;
  }

  .table td[colspan]::before {
    content: "";
    display: none;
  }

  .actions-cell {
    justify-content: flex-start;
  }

  .actions-cell::before {
    margin-top: 0.25rem;
  }

  .inline-form {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .inline-form select,
  .inline-form .btn {
    width: 100%;
  }
}
