/*
 * Signed-in account pages: dashboard, partner, super admin (these pages do not load style.css).
 * Same language as the landing page: white blocks with a solid bottom edge, blue keys. Colours come from tokens.css.
 */
@import url('/css/tokens.css');

:root {
  --bg: var(--bg-deep);
  --paper: #fff;
  --ink: var(--text-primary);
  --muted: var(--text-muted);
  --line: var(--glass-border);
  --edge: var(--glass-border-strong);
  --primary: var(--color-primary);
  --primary-edge: var(--color-primary-hover);
  --danger: #9b1c1c;
  --ok: #1c6b34;
  --warn: #7a5200;
  --font: var(--font-sans);
  --mono: ui-monospace, 'Cascadia Mono', Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font: 400 15px/1.55 var(--font);
  color: var(--ink);
  background: var(--bg);
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.2;
  text-wrap: balance;
}

a {
  color: inherit;
}

:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

/* ── top bar ── */
.navbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--paper);
  box-shadow: 0 4px 0 var(--line);
}

.navbar__inner,
.page {
  width: min(72rem, 100%);
  margin: 0 auto;
  padding-inline: clamp(1rem, 4vw, 2.25rem);
}

.navbar__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 0.7rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 44px;
  font-size: 1.25rem;
  font-weight: 800;
  text-decoration: none;
}

.brand img {
  width: 34px;
  height: auto;
}

.page {
  padding-block: clamp(1.4rem, 4vw, 2.6rem) 5rem;
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
}

/* ── headings ── */
.eyebrow {
  margin: 0 0 0.2rem;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--primary);
}

.head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.8rem;
}

.head h1,
.welcome h1 {
  font-size: clamp(1.7rem, 3.4vw, 2.3rem);
  font-weight: 800;
  letter-spacing: -0.03em;
}

/* ── buttons: blocks that go down when pressed ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 44px;
  padding: 0 1.1rem;
  font: 700 0.9rem var(--font);
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
  background: var(--paper);
  border: 1.5px solid var(--edge);
  border-radius: 14px;
  box-shadow: 0 4px 0 var(--edge);
  cursor: pointer;
  transition: transform 90ms ease-out, box-shadow 90ms ease-out;
}

.btn:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: 0 0 0 var(--edge);
}

.btn:hover:not(:disabled) {
  border-color: var(--primary);
}

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

.btn--primary {
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 4px 0 var(--primary-edge);
}

.btn--wide {
  width: 100%;
}

.btn--subtle {
  color: var(--muted);
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

.btn--logout {
  width: 100%;
  color: var(--danger);
}

.btn--logout:hover:not(:disabled) {
  border-color: var(--danger);
}

.link {
  min-height: 44px;
  padding: 0;
  font: inherit;
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  white-space: nowrap;
  background: none;
  border: 0;
  cursor: pointer;
}

/* ── fields ── */
.field {
  display: block;
  margin-bottom: 0.9rem;
}

.field__label {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.8rem;
  font-weight: 700;
}

.field__input {
  width: 100%;
  min-height: 44px;
  padding: 0.5rem 0.85rem;
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1.5px solid var(--edge);
  border-radius: var(--radius-sm);
}

.field__input:disabled {
  background: var(--bg);
  color: var(--muted);
}

.field__error {
  display: none;
  margin: 0.3rem 0 0;
  font-size: 0.8rem;
  color: var(--danger);
}

.field--invalid .field__error {
  display: block;
}

.field--invalid .field__input {
  border-color: var(--danger);
}

.hint {
  margin: 0.3rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

/* ── messages ── */
.status-banner {
  display: none;
  margin-bottom: 1rem;
  padding: 0.7rem 0.95rem;
  font-size: 0.875rem;
  border: 1.5px solid currentColor;
  border-radius: 0.8rem;
}

.status-banner--visible {
  display: block;
}

.status-banner--success {
  color: var(--ok);
}

.status-banner--error {
  color: var(--danger);
}

.status-banner--info {
  color: var(--primary);
}

.toast {
  position: fixed;
  z-index: 110;
  bottom: 1rem;
  left: 50%;
  width: min(30rem, calc(100% - 2rem));
  margin: 0;
  background: var(--paper);
  box-shadow: var(--shadow-soft);
  transform: translateX(-50%);
  cursor: pointer;
}

.notice,
.verify-banner {
  margin: 0;
  padding: 0.8rem 1rem;
  color: var(--warn);
  background: rgb(168 85 8 / 0.08);
  border: 1.5px solid rgb(168 85 8 / 0.55);
  border-radius: 1rem;
}

.verify-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem 1.2rem;
}

/* ── profile menu ── */
.profile-menu {
  position: relative;
}

.profile-menu__trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 46px;
  padding: 0.25rem 0.9rem 0.25rem 0.3rem;
  font: 600 0.9rem var(--font);
  color: var(--ink);
  background: var(--paper);
  border: 1.5px solid var(--edge);
  border-radius: 14px;
  box-shadow: 0 4px 0 var(--edge);
  cursor: pointer;
}

.profile-menu__avatar,
.profile-edit__avatar {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  overflow: hidden;
  color: #fff;
  font-weight: 800;
  text-transform: uppercase;
  background: var(--primary);
  border-radius: 50%;
}

.profile-menu__avatar {
  width: 36px;
  height: 36px;
}

.profile-menu__name {
  max-width: 11rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-menu__chevron {
  font-size: 0.75rem;
  color: var(--muted);
}

.profile-menu__dropdown {
  position: absolute;
  top: calc(100% + 0.6rem);
  right: 0;
  z-index: 40;
  display: none;
  width: 17rem;
  padding: 1rem;
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-elevated);
}

.profile-menu__dropdown--visible {
  display: block;
}

.profile-menu__info {
  padding-bottom: 0.8rem;
  border-bottom: 1px solid var(--line);
}

.profile-menu__info-name {
  font-weight: 700;
}

.profile-menu__info-email {
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.8rem;
  color: var(--muted);
}

.profile-menu__link {
  display: flex;
  align-items: center;
  min-height: 44px;
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px solid var(--line);
}

.profile-menu__link:hover {
  text-decoration: underline;
}

.profile-menu__logout {
  margin-top: 0.8rem;
}

/* ── apps: a coloured block per app that can be opened, a plain list for the rest ── */
.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  gap: 1.3rem;
}

.app-card {
  --face: #123f86;
  --side: #09234f;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 0 0 1.3rem;
  overflow: hidden;
  font: inherit;
  color: var(--ink);
  text-align: left;
  background: var(--paper);
  border: 0;
  border-radius: var(--radius-xl);
  box-shadow: 0 7px 0 var(--side), 0 22px 40px -24px rgb(22 26 46 / 0.5);
  cursor: pointer;
  transition: transform 150ms ease-out, box-shadow 150ms ease-out;
}

.app-card--care {
  --face: #8a1f2c;
  --side: #53101a;
}

.app-card--bistro {
  --face: #a85a12;
  --side: #6e3a08;
}

.app-card:hover:not(:disabled) {
  transform: translateY(-4px);
  box-shadow: 0 11px 0 var(--side), 0 26px 44px -24px rgb(22 26 46 / 0.55);
}

.app-card:active:not(:disabled) {
  transform: translateY(5px);
  box-shadow: 0 2px 0 var(--side);
}

.app-card:disabled {
  cursor: progress;
}

/* the picture: a coloured stage with a few round ornaments behind the drawing */
.app-card__art {
  position: relative;
  display: grid;
  place-items: center;
  align-self: stretch;
  height: 10.5rem;
  margin-bottom: 1.1rem;
  overflow: hidden;
  background: var(--face);
}

.app-card__art::before,
.app-card__art::after {
  content: '';
  position: absolute;
  border-radius: 50%;
}

.app-card__art::before {
  top: -4.5rem;
  right: -3rem;
  width: 11rem;
  height: 11rem;
  background: rgb(255 255 255 / 0.1);
}

.app-card__art::after {
  bottom: -2.2rem;
  left: -1.2rem;
  width: 6rem;
  height: 6rem;
  border: 0.9rem solid rgb(255 255 255 / 0.1);
}

.app-card__art svg {
  position: relative;
  z-index: 1;
  width: 10rem;
  height: auto;
  transition: transform 200ms ease-out;
}

.app-card:hover:not(:disabled) svg {
  transform: translateY(-4px) scale(1.04);
}

.app-card__art .w {
  fill: #fff;
}

.app-card__art .f {
  fill: var(--face);
}

.app-card__art .s {
  fill: var(--side);
}

.app-card__art .a {
  fill: #ffc53d;
}

.app-card__art .line {
  fill: none;
  stroke: #fff;
  stroke-width: 5;
  stroke-linecap: round;
}

.app-card__who {
  margin: 0 1.3rem;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--face);
}

.app-card__name {
  margin: 0 1.3rem;
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.app-card__text {
  flex: 1;
  margin: 0.5rem 1.3rem 1.1rem;
  color: var(--text-secondary);
}

.app-card__open {
  margin: 0 1.3rem;
  padding: 0.6rem 1.1rem;
  font-weight: 800;
  color: #fff;
  background: var(--face);
  border-radius: 14px;
  box-shadow: 0 4px 0 var(--side);
}

.soon {
  margin-top: 0.6rem;
}

.soon h2 {
  margin-bottom: 0.7rem;
  font-size: 1.05rem;
  font-weight: 800;
}

.soon__list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  gap: 0.7rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.soon__list li {
  display: grid;
  align-content: start;
  padding: 0.8rem 1rem;
  border: 1.5px dashed var(--edge);
  border-radius: var(--radius-md);
}

.soon__list span {
  font-size: 0.875rem;
  color: var(--muted);
}

/* ── cards ── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
  gap: 1.2rem;
}

.card,
.settings-card,
.stat {
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
}

.card,
.settings-card {
  padding: clamp(1.1rem, 3vw, 1.6rem);
}

.card h2,
.settings-card__title {
  font-size: 1.15rem;
  font-weight: 800;
}

.card > p,
.settings-card__desc {
  margin: 0.4rem 0 1rem;
  color: var(--muted);
}

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

.stat {
  padding: 1rem 1.15rem;
}

.stat p {
  margin: 0;
}

.stat__label {
  font-size: 0.85rem;
  font-weight: 700;
}

.stat__value {
  font-size: 1.75rem;
  font-weight: 800;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.code-big {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin: 0 0 1rem;
}

.code-big strong {
  font: 700 1.7rem var(--mono);
  letter-spacing: 0.04em;
  overflow-wrap: anywhere;
}

.row-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.6rem;
}

.row-form > .field {
  flex: 1 1 12rem;
  margin: 0;
}

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

.rates li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--line);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.4rem;
  margin-top: 0.6rem;
}

.profile-edit {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.profile-edit__avatar {
  width: 76px;
  height: 76px;
  font-size: 1.7rem;
}

.profile-edit__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.profile-edit__summary {
  margin-bottom: 1.1rem;
  padding: 0.8rem 1rem;
  background: rgb(22 26 46 / 0.045);
  border-radius: 0.9rem;
}

.profile-edit__summary p {
  margin: 0;
}

.profile-edit__summary-name {
  font-weight: 700;
}

.profile-edit__summary-phone {
  font-size: 0.85rem;
  color: var(--muted);
}

.security-actions,
.stack {
  display: grid;
  gap: 0.7rem;
}

.reset-link-box {
  margin-bottom: 1rem;
}

.glass-inset {
  padding: 0.7rem 0.9rem;
  font-size: 0.85rem;
  word-break: break-all;
  border: 1.5px dashed var(--line);
  border-radius: 0.8rem;
}

/* ── dialogs: .modal-overlay (dashboard, existing script) and <dialog class="sheet"> ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 1rem;
  visibility: hidden;
  opacity: 0;
  background: rgb(22 26 46 / 0.55);
}

.modal-overlay--visible {
  visibility: visible;
  opacity: 1;
}

.modal,
.sheet {
  width: min(28rem, calc(100% - 2rem));
  max-height: calc(100dvh - 2rem);
  overflow: auto;
  padding: clamp(1.2rem, 3vw, 1.6rem);
  color: var(--ink);
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-elevated);
}

.modal {
  width: min(28rem, 100%);
}

.sheet--wide {
  width: min(46rem, calc(100% - 2rem));
}

.sheet::backdrop {
  background: rgb(22 26 46 / 0.55);
}

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

.modal__title {
  font-size: 1.2rem;
  font-weight: 800;
}

.modal__close {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  color: var(--ink);
  background: transparent;
  border: 1.5px solid var(--edge);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.modal form > .btn {
  width: 100%;
}

.rule-row {
  display: grid;
  grid-template-columns: 6rem minmax(0, 1fr) 8rem;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

/* ── tabs, toolbar, tables ── */
.tabs {
  display: flex;
  gap: 0.4rem;
  padding: 0.35rem;
  overflow-x: auto;
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 0 var(--line);
}

.tab {
  display: inline-flex;
  flex: 1 0 auto;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0 1rem;
  font: 700 0.9rem var(--font);
  color: var(--ink);
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.tab:focus-visible {
  outline-offset: -3px;
}

.tab[aria-selected='true'] {
  color: #fff;
  background: var(--primary);
}

.count {
  min-width: 1.5rem;
  padding: 0 0.4rem;
  font-size: 0.75rem;
  letter-spacing: 0;
  color: var(--ink);
  background: var(--bg);
  border-radius: 999px;
}

.count--alert {
  color: #fff;
  background: var(--danger);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 0.9rem;
}

.toolbar input {
  flex: 1 1 14rem;
  width: auto;
}

.toolbar select {
  flex: 0 1 13rem;
  width: auto;
}

.table-wrap {
  overflow-x: auto;
}

.table {
  width: 100%;
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
  border-collapse: collapse;
}

.table th,
.table td {
  padding: 0.6rem 0.5rem;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--line);
}

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

.sub {
  display: block;
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.code {
  font-family: var(--mono);
  white-space: nowrap;
}

.owed {
  font-weight: 800;
  color: var(--danger);
  white-space: nowrap;
}

.badge {
  display: inline-block;
  padding: 0.1rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
  border: 1.5px solid currentColor;
  border-radius: 999px;
}

.badge--active {
  color: var(--ok);
}

.badge--pending,
.badge--trial {
  color: var(--warn);
}

.badge--inactive,
.badge--rejected,
.badge--ended {
  color: var(--danger);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
}

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

.requests li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.8rem 0;
  border-bottom: 1px solid var(--line);
}

.requests li:last-child {
  border-bottom: 0;
}

.note {
  max-width: 40rem;
  margin: 0.4rem 0 0;
  padding: 0.5rem 0.8rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
  overflow-wrap: anywhere;
}

textarea.field__input {
  resize: vertical;
}

.empty {
  margin: 0.5rem 0 0;
  color: var(--muted);
}

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-top: 0.9rem;
}

#view {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

/* ── narrower screens: table rows become cards ── */
@media (max-width: 900px) {
  .table,
  .table tbody,
  .table tr,
  .table td {
    display: block;
  }

  .table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .table tr {
    margin-bottom: 0.8rem;
    padding: 0.3rem 0.8rem;
    border: 1.5px solid var(--line);
    border-radius: 0.9rem;
  }

  .table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.45rem 0;
    text-align: right;
  }

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

  .table td::before {
    content: attr(data-label);
    flex: none;
    font-size: 0.75rem;
    color: var(--muted);
    text-align: left;
  }

  /* the first cell is the card's title; a cell without a heading holds buttons */
  .table td:first-child {
    justify-content: flex-start;
    text-align: left;
  }

  .table td:first-child::before,
  .table td[data-label='']::before {
    content: none;
  }

  .table .actions {
    flex: 1;
  }

  .table .actions .btn {
    flex: 1;
  }
}

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

@media (max-width: 560px) {
  .profile-menu__name,
  .profile-menu__chevron {
    display: none;
  }

  .profile-menu__trigger {
    padding: 0.25rem;
  }

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

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

  .stat {
    padding: 0.8rem 0.9rem;
  }

  .stat__value {
    font-size: 1.3rem;
  }

  .tabs {
    flex-wrap: wrap;
  }

  .tab {
    flex: 1 1 40%;
    gap: 0.4rem;
    padding: 0 0.4rem;
  }

  .toolbar > *,
  .toolbar input,
  .toolbar select {
    flex: 1 1 100%;
    width: 100%;
  }

  .rule-row {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn,
  .app-card,
  .app-card__art svg {
    transition: none;
  }
}
