:root {
  --bg: #f2f0e8;
  --surface: #fffefb;
  --ink: #1a1a1a;
  --muted: #6a6861;
  --accent: #005f73;
  --accent-2: #ca6702;
  --ok: #1f7a3a;
  --warn: #9a6700;
  --bad: #a11a1a;
  --line: #e4dfd2;
  --shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top left, #dce8dd, transparent 30%),
    radial-gradient(circle at 80% 20%, #ffe7cc, transparent 38%),
    var(--bg);
}

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

.hidden {
  display: none !important;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.login-card {
  width: min(100%, 420px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 1rem;
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

.login-card h1 {
  margin: 0 0 0.4rem;
}

.auth-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  margin: 0.9rem 0 1rem;
  background: #efebe1;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  padding: 0.3rem;
}

.auth-tab {
  border: 0;
  border-radius: 0.55rem;
  background: transparent;
  color: var(--muted);
  padding: 0.52rem 0.72rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.auth-tab.active {
  background: #111827;
  color: #fff;
}

.auth-hint {
  margin-top: 0.8rem;
}

.sidebar {
  background: #111827;
  color: #f8fafc;
  padding: 1.2rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand-tag {
  margin: 0;
  color: #67e8f9;
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.brand h1 {
  margin: 0.25rem 0 1.1rem;
  font-size: 1.6rem;
}

.nav {
  display: grid;
  gap: 0.4rem;
}

.nav-link {
  border: 0;
  background: transparent;
  color: #d5d9df;
  text-align: left;
  padding: 0.72rem;
  border-radius: 0.6rem;
  cursor: pointer;
  font: inherit;
}

.nav-link:hover,
.nav-link.active {
  background: rgba(255, 255, 255, 0.09);
  color: #fff;
}

.main {
  padding: 1.2rem 1.4rem 2rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
}

h2 {
  margin: 0.25rem 0 0;
}

.menu-btn {
  display: none;
  border: 0;
  font-size: 1.3rem;
  background: #fff;
  border-radius: 0.4rem;
  padding: 0.28rem 0.55rem;
  box-shadow: var(--shadow);
}

.admin-pill {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.5rem 0.9rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #22c55e;
}

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

.card,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  box-shadow: var(--shadow);
}

.card {
  padding: 1rem;
}

.card p,
.card small {
  margin: 0;
  color: var(--muted);
}

.card h3 {
  margin: 0.4rem 0;
  font-size: 1.7rem;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

.grid {
  display: grid;
  gap: 0.8rem;
  margin-top: 0.8rem;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.panel {
  padding: 1rem;
}

.panel-head {
  margin-bottom: 0.8rem;
}

.panel-head h3 {
  margin: 0;
}

.bars {
  display: grid;
  gap: 0.72rem;
}

.bar-row {
  display: grid;
  gap: 0.3rem;
}

.bar-row span {
  font-size: 0.9rem;
  color: var(--muted);
}

.bar {
  height: 11px;
  background: #ece9de;
  border-radius: 999px;
  overflow: hidden;
}

.bar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

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

.action-btn,
button[type="submit"],
.tiny,
.logout {
  border: 0;
  border-radius: 0.6rem;
  padding: 0.62rem 0.82rem;
  cursor: pointer;
  font: inherit;
}

.action-btn,
button[type="submit"] {
  background: #111827;
  color: #fff;
}

.tiny {
  background: #e8eefc;
  padding: 0.42rem 0.68rem;
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid transparent;
  transition: all 0.18s ease;
}

.delete-btn {
  background: #fee2e2;
  color: #991b1b;
  margin-left: 0.35rem;
}

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

.billing-actions .tiny {
  margin: 0;
}

.tiny-pay {
  background: #0f766e;
  color: #ffffff;
}

.tiny-pay:hover {
  background: #0b5f58;
}

.tiny-view {
  background: #eef2ff;
  color: #312e81;
  border-color: #c7d2fe;
}

.tiny-view:hover {
  background: #e0e7ff;
}

.tiny-download {
  background: #f3f4f6;
  color: #111827;
  border-color: #d1d5db;
}

.tiny-download:hover {
  background: #e5e7eb;
}

.tiny-muted {
  background: #fff7ed;
  color: #9a3412;
  border-color: #fed7aa;
}

.tiny-muted:hover {
  background: #ffedd5;
}

.logout {
  margin-top: 0.8rem;
  background: #fee2e2;
  color: #991b1b;
}

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

th,
td {
  text-align: left;
  padding: 0.65rem 0.3rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.93rem;
}

th {
  color: var(--muted);
  font-weight: 600;
}

.status {
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  font-size: 0.8rem;
}

.status.ok {
  background: #dcfce7;
  color: var(--ok);
}

.status.warn {
  background: #fef3c7;
  color: var(--warn);
}

.status.bad {
  background: #fee2e2;
  color: var(--bad);
}

.form {
  display: grid;
  gap: 0.7rem;
}

label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.9rem;
}

.field-label {
  display: inline-block;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cbc5b6;
  border-radius: 0.5rem;
  padding: 0.58rem 0.65rem;
  font: inherit;
  background: #fff;
}

textarea {
  resize: vertical;
  min-height: 90px;
}

.multiline-cell {
  white-space: pre-line;
}

.feed {
  margin: 0;
  padding-left: 1rem;
  display: grid;
  gap: 0.55rem;
}

.rule-note {
  margin: 0.8rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.users-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.9rem;
  margin-bottom: 0.9rem;
}

.users-toolbar h3 {
  margin: 0;
}

.users-count {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.users-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.users-actions input[type="search"] {
  width: 230px;
}

.role-select {
  min-width: 110px;
  padding: 0.38rem 0.55rem;
  font-size: 0.86rem;
}

.invite-stats {
  align-items: center;
  margin-top: 0.8rem;
  margin-bottom: 0.6rem;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.58);
  display: none;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: 1.2rem 1rem;
  z-index: 20;
}

.modal-backdrop.open {
  display: flex;
}

.modal-card {
  width: min(100%, 440px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  padding: 1rem;
  box-shadow: var(--shadow);
  margin: auto 0;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.8rem;
}

.modal-head h3 {
  margin: 0;
}

.modal-close {
  border: 0;
  background: #f3f4f6;
  border-radius: 0.45rem;
  width: 30px;
  height: 30px;
  cursor: pointer;
}

.invoice-modal-card {
  width: min(100%, 760px);
  max-height: calc(100vh - 2.4rem);
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.invoice-sheet {
  padding: 1.2rem 1.3rem 1rem;
  background: #ffffff;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  flex: 1;
  overflow: auto;
}

.inv-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.2rem;
}

.inv-head h4 {
  margin: 0;
  font-size: 2.15rem;
}

.inv-head h5 {
  margin: 0;
  color: #7a7a7a;
  font-size: 2rem;
  font-weight: 700;
}

.inv-meta p {
  margin: 0 0 0.35rem;
  display: grid;
  grid-template-columns: 140px auto;
  gap: 0.8rem;
  font-size: 0.92rem;
}

.inv-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  justify-self: start;
  width: fit-content;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  border: 1px solid #d7d7d7;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.2;
  background: #fafafa;
}

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

.inv-parties p {
  margin: 0 0 0.2rem;
  font-size: 0.92rem;
}

.inv-title {
  font-weight: 700;
  margin-bottom: 0.45rem !important;
}

.inv-due {
  margin: 1rem 0 1.2rem;
  font-size: 2rem;
  font-weight: 700;
}

.inv-table {
  border-top: 1px solid #222;
}

.inv-tr {
  display: grid;
  grid-template-columns: 1fr 70px 120px 120px;
  gap: 0.6rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid #ddd;
  font-size: 0.9rem;
}

.inv-th {
  font-weight: 700;
  border-bottom: 1px solid #222;
}

.inv-totals {
  width: min(100%, 420px);
  margin-left: auto;
  margin-top: 0.55rem;
}

.inv-totals p {
  margin: 0;
  display: flex;
  justify-content: space-between;
  padding: 0.25rem 0;
  font-size: 0.9rem;
  border-bottom: 1px solid #ececec;
}

.inv-grand {
  margin-top: 0.3rem !important;
  font-size: 1.4rem !important;
  font-weight: 700;
  border-bottom: 0 !important;
}

.invoice-actions {
  padding: 0.8rem 1rem 1rem;
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  background: var(--surface);
}

.stripe-mode-toggle {
  display: inline-flex;
  gap: 0.45rem;
}

.stripe-mode-toggle .tiny.active {
  background: #111827;
  color: #fff;
  border-color: #111827;
}

.payment-result-card {
  width: min(100%, 460px);
}

.payment-result-body {
  padding: 1rem;
  display: grid;
  gap: 0.8rem;
}

.payment-result-body .action-btn {
  justify-self: start;
}

.gateway-list {
  display: grid;
  gap: 0.8rem;
}

.gateway-form {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: end;
  margin-bottom: 0.9rem;
}

.gateway-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding-bottom: 0.55rem;
}

.gateway-checkbox input {
  width: auto;
}

.gateway-list-wrap {
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  padding: 0.55rem 0.65rem;
}

.gateway {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px dashed #ccc4b1;
  border-radius: 0.7rem;
  padding: 0.8rem;
}

.gateway h4 {
  margin: 0 0 0.2rem;
}

.gateway p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.toggle {
  position: relative;
  width: 50px;
  height: 28px;
}

.toggle input {
  display: none;
}

.toggle span {
  position: absolute;
  inset: 0;
  background: #ccc;
  border-radius: 999px;
  transition: 0.2s;
}

.toggle span::before {
  content: "";
  width: 22px;
  height: 22px;
  background: #fff;
  border-radius: 50%;
  position: absolute;
  left: 3px;
  top: 3px;
  transition: 0.2s;
}

.toggle input:checked + span {
  background: #22c55e;
}

.toggle input:checked + span::before {
  transform: translateX(22px);
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  background: #111827;
  color: #fff;
  padding: 0.7rem 0.9rem;
  border-radius: 0.7rem;
  opacity: 0;
  transform: translateY(10px);
  transition: 0.22s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

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

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 240px;
    transform: translateX(-100%);
    transition: 0.22s;
    z-index: 10;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .menu-btn {
    display: inline-block;
  }

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

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

@media (max-width: 620px) {
  .topbar {
    flex-wrap: wrap;
  }

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

  th,
  td {
    font-size: 0.84rem;
  }

  .users-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .users-actions {
    width: 100%;
    flex-direction: column;
  }

  .users-actions input[type="search"] {
    width: 100%;
  }

  .invoice-modal-card {
    max-height: calc(100vh - 1.2rem);
  }

  .gateway-form {
    grid-template-columns: 1fr;
  }

  .inv-head {
    flex-direction: column;
    gap: 0.4rem;
  }

  .inv-head h4 {
    font-size: 1.7rem;
  }

  .inv-head h5 {
    font-size: 1.5rem;
  }

  .inv-meta p {
    grid-template-columns: 120px auto;
  }

  .inv-parties {
    grid-template-columns: 1fr;
  }

  .inv-due {
    font-size: 1.35rem;
  }

  .inv-tr {
    grid-template-columns: 1fr 42px 90px 90px;
    font-size: 0.82rem;
  }
}
