/* =====================================================================
   KAMALIG inner pages - same design language as the dashboard
   ---------------------------------------------------------------------
   Every page except the dashboard was built on the older components in
   styles.css (.card, .table, .btn, .badge, .alert, plain form controls),
   which still carry slate / tailwind colours. This sheet restyles those
   components with the dashboard tokens (:root --kg-* in dashboard.css),
   so all pages share one look without editing each page template:

     page title + intro  -> the dashboard's hero band (dark green, gold edge)
     .card               -> kg-card rhythm, section headings
     .table              -> ivory header row, soft row dividers
     .btn / .badge       -> same height, radius and tints as kg-btn / kg-status
     .alert              -> kg-note look (tinted, coloured edge)
     forms               -> 40px controls, green focus ring, custom select arrow

   Loaded after styles / dashboard / commerce / transparency and before
   mobile.css, so the phone layout rules still win. Auth pages are left alone.
   Specificity is kept low (:where) so a page's own style still overrides.
   Remove the <link> in includes/header.php to go back to the old look.
   ===================================================================== */

/* ---------- page rhythm ---------- */
:where(body:not(.auth-page)) .page-card > * + * { margin-top: 16px; }
:where(body:not(.auth-page)) .page-card > :is(.assistant-widget, .fp-drawer, script, style, template) { margin-top: 0; }

/* ---------- title band (matches .kg-welcome--role) ---------- */
:where(body:not(.auth-page)) .page-card > h2:first-child {
  margin: 0; padding: 16px 22px; background: var(--kg-green-dark); color: #fff;
  border-left: 5px solid var(--kg-gold); border-radius: var(--kg-radius);
  font-family: var(--kg-font-display); font-size: 1.3rem; font-weight: 800; letter-spacing: -0.01em; line-height: 1.25;
}
:where(body:not(.auth-page)) .page-card > h2:first-child:has(+ p.muted) { padding-bottom: 2px; border-radius: var(--kg-radius) var(--kg-radius) 0 0; }
:where(body:not(.auth-page)) .page-card > h2:first-child + p.muted {
  margin: 0; padding: 0 22px 16px; background: var(--kg-green-dark); color: rgba(255,255,255,0.86);
  border-left: 5px solid var(--kg-gold); border-radius: 0 0 var(--kg-radius) var(--kg-radius);
  font-size: 0.87rem; line-height: 1.5;
}
:where(body:not(.auth-page)) .page-card > h2:first-child + p.muted a { color: var(--kg-gold-light); text-decoration: underline; }
:where(body:not(.auth-page)) .page-card > h2:first-child + p.muted strong { color: #fff; }

/* section headings further down the page */
:where(body:not(.auth-page)) .page-card > h2:not(:first-child) { margin: 24px 0 0; font-size: 1.05rem; font-weight: 800; color: var(--kg-green-dark); }
:where(body:not(.auth-page)) .page-card > h3 { margin: 20px 0 0; font-size: 1rem; font-weight: 700; color: var(--kg-text); }

/* Transparency pages build their own header (tp_header): same band */
:where(body:not(.auth-page)) .page-card .tp-head {
  padding: 16px 22px; background: var(--kg-green-dark); color: #fff;
  border-left: 5px solid var(--kg-gold); border-radius: var(--kg-radius);
}
:where(body:not(.auth-page)) .page-card .tp-nav + .tp-head { margin-top: 0; }
:where(body:not(.auth-page)) .page-card .tp-head h2 { margin: 0 0 4px; color: #fff; font-size: 1.3rem; font-weight: 800; }
:where(body:not(.auth-page)) .page-card .tp-head .tp-lead { margin: 0 0 10px; max-width: 70ch; color: rgba(255,255,255,0.86); font-size: 0.87rem; line-height: 1.5; }
:where(body:not(.auth-page)) .page-card .tp-head .tp-pill { border: 1px solid rgba(255,255,255,0.35); background: rgba(255,255,255,0.14); color: #fff; }
:where(body:not(.auth-page)) .page-card .tp-head .tp-help summary { color: var(--kg-gold-light); font-size: 0.84rem; }
:where(body:not(.auth-page)) .page-card .tp-head .tp-help ul { color: rgba(255,255,255,0.86); font-size: 0.84rem; }

/* ---------- cards ---------- */
:where(body:not(.auth-page)) .page-card .card > h3:first-child,
:where(body:not(.auth-page)) .page-card .card > h4:first-child { margin: 0 0 12px; font-size: 1rem; font-weight: 700; color: var(--kg-text); }
:where(body:not(.auth-page)) .page-card .card > h3:first-child + p.muted,
:where(body:not(.auth-page)) .page-card .card > h3:first-child + p { margin-top: -6px; }
:where(body:not(.auth-page)) .page-card .stat { margin: 4px 0; font-size: 1.6rem; font-weight: 800; letter-spacing: -0.01em; line-height: 1.15; }
:where(body:not(.auth-page)) .page-card .grid > .card { height: 100%; }

/* ---------- tables ---------- */
:where(body:not(.auth-page)) .page-card .table-responsive { border: 1px solid var(--kg-border); border-radius: var(--kg-radius-sm); background: var(--kg-card); }
:where(body:not(.auth-page)) .page-card .card .table-responsive { border: 0; border-radius: 0; background: transparent; }
:where(body:not(.auth-page)) .page-card .table thead th {
  padding: 10px 12px; background: var(--kg-bg); color: var(--kg-text-secondary);
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  border-bottom: 1px solid var(--kg-border);
}
:where(body:not(.auth-page)) .page-card .table td { padding: 11px 12px; font-size: 0.88rem; vertical-align: middle; border-bottom: 1px solid var(--kg-surface-soft); }
:where(body:not(.auth-page)) .page-card .table tbody tr:last-child td { border-bottom: 0; }
:where(body:not(.auth-page)) .page-card .table tbody tr:hover { background: var(--kg-green-light); }

/* ---------- buttons (same height / radius as .kg-btn) ---------- */
:where(body:not(.auth-page)) .page-card .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 0 16px; border-radius: 9px; border: 1px solid transparent;
  font-family: inherit; font-size: 0.83rem; font-weight: 700; line-height: 1.2; text-decoration: none; cursor: pointer;
}
:where(body:not(.auth-page)) .page-card .btn-sm { min-height: 32px; padding: 0 12px; font-size: 0.78rem; }
:where(body:not(.auth-page)) .page-card .btn-primary { background: var(--kg-green); color: #fff; }
:where(body:not(.auth-page)) .page-card .btn-primary:hover { background: var(--kg-green-dark); }
:where(body:not(.auth-page)) .page-card .btn-secondary { background: #fff; color: var(--kg-green-dark); border-color: var(--kg-border); }
:where(body:not(.auth-page)) .page-card .btn-secondary:hover { background: var(--kg-green-light); border-color: var(--kg-green); }
:where(body:not(.auth-page)) .page-card .btn-danger { background: var(--kg-red-light); color: #991B1B; border-color: transparent; }
:where(body:not(.auth-page)) .page-card .btn-danger:hover { background: var(--kg-red); color: #fff; }
:where(body:not(.auth-page)) .page-card .btn[disabled], :where(body:not(.auth-page)) .page-card .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }

/* ---------- badges (same tints as .kg-status) ---------- */
:where(body:not(.auth-page)) .page-card .badge { display: inline-flex; align-items: center; padding: 3px 10px; font-size: 0.72rem; font-weight: 700; line-height: 1.4; white-space: nowrap; }
:where(body:not(.auth-page)) .page-card .badge-available { background: var(--kg-green-light); color: var(--kg-green-dark); }
:where(body:not(.auth-page)) .page-card .badge-sold-out { background: var(--kg-gold-light); color: var(--kg-gold-dark); }
:where(body:not(.auth-page)) .page-card .badge-draft { background: var(--kg-amber-light); color: #9A5A17; }
:where(body:not(.auth-page)) .page-card .badge-archived { background: var(--kg-surface-soft); color: var(--kg-text-secondary); }
:where(body:not(.auth-page)) .page-card .badge-rejected { background: var(--kg-red-light); color: #991B1B; }
:where(body:not(.auth-page)) .page-card .badge-info { background: var(--kg-blue-light); color: #1E3A8A; }

/* ---------- alerts (same look as .kg-note) ---------- */
:where(body:not(.auth-page)) .page-card .alert { padding: 12px 16px; border: 1px solid transparent; border-left-width: 4px; border-radius: var(--kg-radius-sm); font-size: 0.88rem; line-height: 1.5; }
:where(body:not(.auth-page)) .page-card .alert-error { background: var(--kg-red-light); color: #991B1B; border-color: rgba(220,38,38,0.22); border-left-color: var(--kg-red); }
:where(body:not(.auth-page)) .page-card .alert-success { background: var(--kg-green-light); color: var(--kg-green-dark); border-color: rgba(38,115,77,0.22); border-left-color: var(--kg-green); }

/* ---------- forms ---------- */
:where(body:not(.auth-page)) .page-card .form-group > label { display: block; margin-bottom: 6px; }
:where(body:not(.auth-page)) .page-card label:has(> input[type="checkbox"]), :where(body:not(.auth-page)) .page-card label:has(> input[type="radio"]) { display: inline-flex; align-items: center; gap: 8px; margin: 0; font-weight: 600; cursor: pointer; }
:where(body:not(.auth-page)) .page-card input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="hidden"]):not([type="submit"]):not([type="button"]),
:where(body:not(.auth-page)) .page-card select, :where(body:not(.auth-page)) .page-card textarea {
  min-height: 40px; padding: 9px 12px; background-color: #fff; color: var(--kg-text);
  border: 1px solid var(--kg-border); border-radius: var(--kg-radius-sm); font-family: inherit; font-size: 0.9rem; line-height: 1.3;
}
:where(body:not(.auth-page)) .page-card textarea { min-height: 96px; resize: vertical; }
:where(body:not(.auth-page)) .page-card select:not([multiple]) {
  appearance: none; -webkit-appearance: none; padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23566058' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; background-size: 15px;
}
:where(body:not(.auth-page)) .page-card input::placeholder, :where(body:not(.auth-page)) .page-card textarea::placeholder { color: #7C857D; }
:where(body:not(.auth-page)) .page-card input[disabled], :where(body:not(.auth-page)) .page-card select[disabled], :where(body:not(.auth-page)) .page-card textarea[disabled], :where(body:not(.auth-page)) .page-card input[readonly] { background-color: var(--kg-surface-soft); color: var(--kg-text-secondary); }
:where(body:not(.auth-page)) .page-card input[type="checkbox"], :where(body:not(.auth-page)) .page-card input[type="radio"] { accent-color: var(--kg-green); width: 16px; height: 16px; padding: 0; }
:where(body:not(.auth-page)) .page-card input[type="file"] { max-width: 100%; font-size: 0.85rem; }

/* ---------- small screens: keep the band compact ---------- */
@media (max-width: 640px) {
  :where(body:not(.auth-page)) .page-card > h2:first-child { padding: 14px 16px; font-size: 1.15rem; }
  :where(body:not(.auth-page)) .page-card > h2:first-child:has(+ p.muted) { padding-bottom: 2px; }
  :where(body:not(.auth-page)) .page-card > h2:first-child + p.muted { padding: 0 16px 14px; }
  :where(body:not(.auth-page)) .page-card .tp-head { padding: 14px 16px; }
}

/* ---------- print: receipts and reports stay ink-friendly ---------- */
@media print {
  :where(body:not(.auth-page)) .page-card > h2:first-child, :where(body:not(.auth-page)) .page-card > h2:first-child + p.muted, :where(body:not(.auth-page)) .page-card .tp-head {
    background: none; color: #000; border-left: 0; border-bottom: 1px solid #999; border-radius: 0; padding-left: 0;
  }
  :where(body:not(.auth-page)) .page-card > h2:first-child + p.muted, :where(body:not(.auth-page)) .page-card .tp-head .tp-lead, :where(body:not(.auth-page)) .page-card .tp-head .tp-help ul { color: #333; }
}

/* ---------- Back navigation (Patch 7) ----------
   One shared Back link above the page title. Same tokens as the other secondary controls;
   44px tall tap target on phones, visible keyboard focus. */
.kg-back { margin: 0 0 10px; }
.kg-back__link {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px 0 8px;
  border: 1px solid var(--kg-border); border-radius: var(--kg-radius-sm); background: #fff;
  color: var(--kg-green-dark); font-size: 0.84rem; font-weight: 600; text-decoration: none;
}
.kg-back__link:hover { background: var(--kg-green-light); border-color: var(--kg-green); }
.kg-back__link:focus-visible { outline: 3px solid var(--kg-gold); outline-offset: 2px; }
@media (max-width: 760px) { .kg-back__link { min-height: 44px; } }
@media print { .kg-back { display: none; } }

/* Roadmap UX: two-column form grid for long forms (one column on phones) and right-aligned numeric table columns. */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.form-grid > .form-group { margin-bottom: 12px; min-width: 0; }
.form-grid > .form-group--full, .form-grid > .full { grid-column: 1 / -1; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }
.table th.num, .table td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
