/* ==========================================================================
   GridPiggy — signed-in app (business dashboard, admin console, log in)
   Builds on style.css tokens: same green, same pills, denser layout.
   ========================================================================== */

body.app-body { background: var(--surface); font-size: 15px; }

/* --------------------------------------------------------------------------
   Shell
   -------------------------------------------------------------------------- */
.app { display: grid; grid-template-columns: 256px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column;
  background: #fff; border-right: 1px solid var(--line);
  padding: 20px 14px 16px;
}
.sidebar__top { display: flex; align-items: center; justify-content: space-between; padding: 0 8px 14px; }
.sidebar__brand img { height: 36px; width: auto; }
.sidebar .sidebar__close { display: none; }
.sidebar__area {
  padding: 0 12px 10px; font-size: 11px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--green-deep);
}
.sidenav { display: grid; gap: 2px; }
.sidenav a, .sidenav__btn {
  display: flex; align-items: center; gap: 12px; width: 100%;
  min-height: 44px; padding: 0 14px; border: 0; border-radius: var(--r-pill);
  background: none; color: var(--ink); font-size: 15px; font-weight: 500; text-align: left;
}
.sidenav a > span:first-of-type, .sidenav__btn span { flex: 1; }
.sidenav svg { width: 19px; height: 19px; color: var(--muted); flex: none; }
.sidenav a:hover, .sidenav__btn:hover { background: var(--surface); }
.sidenav a.is-active { background: var(--brand-tint); font-weight: 700; }
.sidenav a.is-active svg { color: var(--green-deep); }
.sidenav__count {
  min-width: 22px; height: 22px; padding: 0 7px; border-radius: 999px;
  background: var(--pink); color: #fff; font-size: 12px; font-weight: 700;
  display: inline-grid; place-items: center;
}
.sidenav--bottom { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); }
.whoami { display: flex; align-items: center; gap: 10px; padding: 12px 10px 0; min-width: 0; }
.whoami__avatar {
  width: 34px; height: 34px; flex: none; border-radius: 50%;
  background: var(--brand-tint); color: var(--green-deep); font-weight: 800;
  display: grid; place-items: center;
}
.whoami__text { min-width: 0; font-size: 13px; line-height: 1.3; }
.whoami__text b, .whoami__text small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.whoami__text small { color: var(--muted); }

.app-bar, .app-scrim { display: none; }
.app-iconbtn {
  width: 44px; height: 44px; flex: none; border: 0; border-radius: 50%;
  display: grid; place-items: center; background: none; color: var(--ink);
}
.app-iconbtn:hover { background: var(--surface); }
.app-iconbtn svg { width: 22px; height: 22px; }

.app-main { padding: 32px 36px 64px; min-width: 0; }
.app-main:focus { outline: none; }
.app-loading, .app-empty { padding: 56px 16px; text-align: center; color: var(--muted); }
.app-empty h2 { font-size: 20px; color: var(--ink); margin-bottom: 6px; }
.app-empty .btn { margin-top: 18px; }
.app-setup { max-width: 540px; margin: 12vh auto; padding: 0 20px; }
.app-setup h1 { font-size: 24px; margin-bottom: 10px; }
.app-setup p + p { margin-top: 16px; }

/* --------------------------------------------------------------------------
   Page furniture
   -------------------------------------------------------------------------- */
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head h1 { font-size: 28px; }
.page-head__actions { margin-left: auto; display: flex; gap: 10px; flex-wrap: wrap; }
.back-link { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 12px; font-size: 14px; font-weight: 600; color: var(--muted); }
.back-link svg { width: 16px; height: 16px; }
.back-link:hover { color: var(--ink); }

.panel { background: #fff; border: 1px solid var(--line); border-radius: var(--r-sm); }
.panel + .panel, .stack > * + * { margin-top: 16px; }
.panel__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px 0; }
.panel__title { font-size: 17px; }
.panel__body { padding: 18px 22px 22px; }
.panel__foot { padding: 0 22px 20px; display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.cols > .panel + .panel { margin-top: 0; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat-card { background: #fff; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 16px 18px; display: block; }
a.stat-card:hover { border-color: var(--brand); }
.stat-card__label { font-size: 13px; color: var(--muted); }
.stat-card__value { margin-top: 2px; font-family: var(--font-display); font-weight: 800; font-size: 28px; line-height: 1.1; }
.stat-card__value--alert { color: var(--pink); }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar .searchbox { flex: 1 1 260px; }
.searchbox { display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 16px; background: #fff; border: 1px solid var(--line-strong); border-radius: var(--r-pill); }
.searchbox svg { width: 17px; height: 17px; color: var(--muted-soft); flex: none; }
.searchbox input { flex: 1; min-width: 0; border: 0; outline: 0; font: inherit; background: transparent; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; background: #fff; border: 1px solid var(--line); border-radius: var(--r-pill); }
.seg button { border: 0; background: none; padding: 7px 14px; border-radius: var(--r-pill); font-size: 14px; font-weight: 600; color: var(--muted); }
.seg button.is-active { background: var(--brand-tint); color: var(--ink); }
.seg button span { color: var(--muted-soft); font-weight: 500; margin-left: 2px; }

.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.list-item:last-child { border-bottom: 0; }
.list-item__main { flex: 1; min-width: 0; }
.list-item__main b { display: block; }
.list-item__main small { color: var(--muted); }
a.list-item:hover b { color: var(--green-deep); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Badges */
.badge { display: inline-flex; align-items: center; height: 24px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge--ok { background: var(--brand-tint); color: var(--green-deep); }
.badge--warn { background: #fff4dc; color: #8a5a00; }
.badge--bad { background: #fde8ef; color: #b0225f; }
.badge--info { background: #eef4fb; color: #2c5f92; }
.badge--muted { background: #f0f2f1; color: var(--muted); }

/* Tables → stacked cards on small screens */
.table-wrap { overflow-x: auto; }
.dtable { width: 100%; border-collapse: collapse; font-size: 14px; }
.dtable th, .dtable td { padding: 12px 16px; text-align: left; vertical-align: middle; }
.dtable thead th { font-size: 12.5px; font-weight: 600; color: var(--muted); background: var(--surface); border-bottom: 1px solid var(--line); white-space: nowrap; }
.dtable tbody td { border-bottom: 1px solid var(--line); }
.dtable tbody tr:last-child td { border-bottom: 0; }
.dtable tr[data-href] { cursor: pointer; }
.dtable tr[data-href]:hover td { background: var(--brand-tint-2); }
.dtable .num { font-variant-numeric: tabular-nums; }
.dtable .actions { text-align: right; white-space: nowrap; }
.dtable td b { font-weight: 700; }
.dtable td small { display: block; color: var(--muted); }
.dtable .pick { width: 1%; padding-right: 0; }
.dtable .pick input { width: 18px; height: 18px; accent-color: var(--brand); cursor: pointer; vertical-align: middle; }
/* Bulk actions for the selected rows of a table */
.bulkbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 12px; padding: 10px 16px; background: var(--brand-tint); border-radius: var(--r-pill); font-size: 14px; }
.bulkbar[hidden] { display: none; }
.bulkbar b { margin-right: auto; }
.toolbar select { height: 44px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: var(--r-pill); background: #fff; font: inherit; font-size: 14px; }

/* Key–value */
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 10px 14px; margin: 0; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }

/* Quote / message body */
.quote-text { white-space: pre-wrap; background: var(--surface); border-radius: 14px; padding: 12px 14px; font-size: 14px; }

/* Buttons the site doesn't have */
.btn--danger { background: #fff; color: #b0225f; box-shadow: inset 0 0 0 1px #f3b6cc; }
.btn--danger:hover { background: #fde8ef; }
.btn--xs { min-height: 34px; padding: 8px 14px; font-size: 13.5px; }

/* Forms inside panels */
.form--dense { gap: 14px; }
.form--dense .field input, .form--dense .field select, .form--dense .field textarea { min-height: 46px; }
.check-grid { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.check-grid label { display: inline-flex; align-items: center; gap: 8px; font-size: 14.5px; font-weight: 500; }
.check-grid input { width: 18px; height: 18px; accent-color: var(--brand); }

/* Modal */
.modal { border: 0; padding: 0; border-radius: var(--r-md); width: min(520px, calc(100vw - 32px)); box-shadow: 0 24px 64px rgba(44, 62, 80, .25); }
.modal::backdrop { background: rgba(38, 38, 38, .45); }
.modal__form { padding: 24px; display: grid; gap: 16px; }
.modal__title { font-size: 20px; }
.modal__body { display: grid; gap: 14px; color: var(--muted); }
.modal__body .field label { color: var(--ink); }
.modal__actions { display: flex; justify-content: flex-end; gap: 10px; }

/* Toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 100; display: grid; gap: 8px; max-width: calc(100vw - 32px); }
.toast { padding: 12px 18px; border-radius: 16px; background: var(--ink); color: #fff; font-size: 14px; box-shadow: var(--shadow-md); transition: opacity .3s, transform .3s; }
.toast--error { background: #b0225f; }
.toast.is-out { opacity: 0; transform: translateY(6px); }

/* Log in page */
.auth { max-width: 440px; margin: 0 auto; padding: 48px 20px 80px; }
.auth h1 { font-size: 30px; }
.auth__lede { margin: 8px 0 26px; color: var(--muted); }
.auth__notice { display: grid; gap: 10px; padding: 16px 18px; border-radius: var(--r-sm); background: #fff8e6; border: 1px solid #f0cf7a; font-size: 14.5px; color: #5c4300; }
.auth__notice-done { color: var(--green-deep); font-weight: 600; }
.auth__alt { text-align: center; font-size: 14px; color: var(--muted); }
.auth__alt a, .auth__alt button { color: var(--green-deep); font-weight: 600; background: none; border: 0; padding: 0; font: inherit; font-weight: 600; cursor: pointer; }

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 960px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .app-bar {
    position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 8px;
    height: 60px; padding: 0 10px; background: #fff; border-bottom: 1px solid var(--line);
  }
  .app-bar__brand img { height: 30px; width: auto; }
  .app-bar__title { margin-left: auto; padding-right: 8px; font-weight: 700; font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sidebar {
    position: fixed; z-index: 50; top: 0; left: 0; bottom: 0; width: min(300px, 86vw); height: 100%;
    transform: translateX(-100%); transition: transform .22s ease; box-shadow: 0 10px 40px rgba(0, 0, 0, .18);
  }
  .sidebar .sidebar__close { display: grid; }
  .app-scrim { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(38, 38, 38, .4); opacity: 0; pointer-events: none; transition: opacity .22s; }
  .app.is-open .sidebar { transform: none; }
  .app.is-open .app-scrim { opacity: 1; pointer-events: auto; }
  .app-main { padding: 20px 16px 48px; }
  .page-head h1 { font-size: 23px; }
  .page-head__actions { margin-left: 0; width: 100%; }
  .page-head__actions .btn { flex: 1; }
  .cols { grid-template-columns: minmax(0, 1fr); }
  .panel__head { padding: 16px 16px 0; }
  .panel__body { padding: 14px 16px 18px; }
  .panel__foot { padding: 0 16px 16px; }
  .panel__foot .btn { flex: 1; }
  .kv { grid-template-columns: 110px 1fr; }

  /* Tables become cards: each cell labelled with its column */
  .dtable--stack thead { display: none; }
  .dtable--stack, .dtable--stack tbody, .dtable--stack tr, .dtable--stack td { display: block; width: 100%; }
  .dtable--stack tr { padding: 12px 16px; border-bottom: 1px solid var(--line); }
  .dtable--stack tbody tr:last-child { border-bottom: 0; }
  .dtable--stack td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 4px 0; border: 0 !important; text-align: right; }
  .dtable--stack td::before { content: attr(data-label); flex: none; font-size: 12.5px; color: var(--muted); text-align: left; }
  .dtable--stack td.lead { display: block; text-align: left; padding-bottom: 6px; }
  .dtable--stack td.lead::before { content: none; }
  .dtable--stack td.actions { justify-content: flex-end; padding-top: 10px; }
  .dtable--stack td.actions::before { content: none; }
  .dtable--stack td small { text-align: inherit; }
}
@media (max-width: 520px) {
  .stat-card { padding: 12px 14px; }
  .stat-card__value { font-size: 22px; }
  .modal__actions .btn { flex: 1; }
}
