/* =========================================================
   PISTACHIO PAPI — DESIGN SYSTEM
   Drop-in stylesheet for any internal Papi web app.
   See BRAND_GUIDE.md for usage notes and rationale.

   Pair with this <head> block:
     <link rel="preconnect" href="https://fonts.googleapis.com">
     <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
     <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Bebas+Neue&family=Albert+Sans:wght@300;400;500;600;700&family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,700&display=swap">
     <link rel="stylesheet" href="papi-design.css">
   ========================================================= */


/* ---------- 1. TOKENS ---------- */

:root {
  /* Brand palette */
  --papi-bright:   #b5c434;
  --papi-bright-2: #c8d850;
  --papi-olive:    #8e9839;
  --papi-dark:     #30351c;
  --papi-darker:   #1d2010;
  --papi-crimson:  #ba3243;
  --papi-burgundy: #4a1b20;

  /* Cream / ink for dark surfaces */
  --cream:         #f4eed8;

  /* Surfaces */
  --bg:            #f7f4ec;
  --bg-card:       #fffdf6;
  --bg-elevated:   #ffffff;
  --bg-soft:       #efeadc;
  --bg-deep:       #e8e2cf;

  /* Ink */
  --ink:           #1d2010;
  --ink-2:         #45492d;
  --ink-3:         #76795c;
  --ink-mute:      #9c9d83;

  /* Lines */
  --line:          #d8d2bd;
  --line-soft:     #e6e0cb;

  /* Status */
  --ok:            #2c7a4b;
  --warn:          #c98a17;
  --bad:           #ba3243;

  /* Status pill colour pairs (background + text) */
  --ok-bg:    #e2f0e7;  --ok-fg:    #1f5d36;
  --warn-bg:  #fbecd1;  --warn-fg:  #875a0f;
  --bad-bg:   #f9dde1;  --bad-fg:   #7d1c2a;

  /* Type families */
  --display: 'Bebas Neue', 'Oswald', sans-serif;
  --serif:   'Fraunces', Georgia, serif;
  --body:    'Albert Sans', system-ui, sans-serif;

  /* Geometry */
  --r-sm: 4px;
  --r-md: 8px;
  --r-lg: 14px;

  /* Shadows */
  --shadow-s: 0 1px 2px rgba(29,32,16,0.04), 0 1px 3px rgba(29,32,16,0.06);
  --shadow-m: 0 2px 6px rgba(29,32,16,0.06), 0 8px 24px rgba(29,32,16,0.06);
  --shadow-l: 0 12px 36px rgba(29,32,16,0.14), 0 2px 8px rgba(29,32,16,0.06);

  /* Focus ring */
  --focus-ring: 0 0 0 3px rgba(181,196,52,0.18);
}


/* ---------- 2. RESET + BASE ---------- */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: var(--body);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  letter-spacing: -0.005em;
  font-feature-settings: "ss01","cv11";
  -webkit-font-smoothing: antialiased;
  background-image:
    radial-gradient(circle at 20% 10%, rgba(181,196,52,0.05), transparent 50%),
    radial-gradient(circle at 80% 90%, rgba(186,50,67,0.025), transparent 50%);
}

/* Optional richer wash for marketing / sign-in pages: add class="rich-bg" to body */
body.rich-bg {
  background-image:
    radial-gradient(ellipse 60% 45% at 18% 12%, rgba(181,196,52,0.10), transparent 60%),
    radial-gradient(ellipse 55% 40% at 85% 88%, rgba(186,50,67,0.05),  transparent 60%),
    radial-gradient(ellipse 80% 60% at 50% 110%, rgba(142,152,57,0.08), transparent 70%);
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; padding: 0; }
input, textarea, select { font-family: inherit; color: inherit; }
a { color: inherit; }

::selection { background: rgba(181,196,52,0.35); color: var(--ink); }


/* ---------- 3. TYPOGRAPHY ---------- */

h1, h2, h3, h4, h5 {
  font-family: var(--display);
  color: var(--ink);
  margin: 0;
  line-height: 1;
  letter-spacing: 0.04em;
  font-weight: 400;
}
h1 { font-size: 30px; }
h2 { font-size: 22px; letter-spacing: 0.05em; }
h3 { font-size: 17px; letter-spacing: 0.06em; }
h4 { font-size: 15px; letter-spacing: 0.06em; }
h5 { font-size: 13px; letter-spacing: 0.06em; }

p  { margin: 0 0 10px; }

.subtitle, .caption-italic {
  font-family: var(--serif);
  font-style: italic;
  font-size: 13px;
  color: var(--ink-3);
}

.label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.label.sm { font-size: 9.5px; letter-spacing: 0.18em; }

.tabular { font-variant-numeric: tabular-nums; }


/* ---------- 4. SCROLLBARS ---------- */

::-webkit-scrollbar       { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 99px;
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--ink-mute); }


/* ---------- 5. APP SHELL ---------- */

.app {
  display: grid;
  grid-template-columns: 224px 1fr;
  grid-template-rows: 56px 1fr;
  height: 100vh;
}


/* ---------- 6. TOP BAR ---------- */

.topbar {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 224px 1fr auto;
  align-items: center;
  background: var(--papi-darker);
  color: var(--cream);
  border-bottom: 1px solid #000;
  position: relative;
  z-index: 50;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 0 18px;
  border-right: 1px solid rgba(255,255,255,0.08);
  height: 100%;
}
.brand-mark {
  width: 30px; height: 30px;
  background: var(--papi-bright);
  border-radius: 50%;
  position: relative;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,0.18);
  flex-shrink: 0;
}
.brand-mark::after {
  content: "";
  position: absolute; inset: 6px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--papi-olive) 0%, var(--papi-dark) 100%);
}
.brand-name {
  font-family: var(--display);
  font-size: 19px;
  letter-spacing: 0.08em;
  color: var(--cream);
  line-height: 1;
}
.brand-name small {
  display: block;
  font-family: var(--body);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--papi-bright);
  margin-top: 2px;
}

.searchbar {
  margin: 0 24px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 999px;
  display: flex; align-items: center;
  padding: 0 14px;
  height: 34px;
  max-width: 520px;
  transition: border-color .15s, background .15s;
}
.searchbar:focus-within {
  background: rgba(255,255,255,0.12);
  border-color: var(--papi-bright);
}
.searchbar input {
  flex: 1;
  background: transparent;
  border: 0; outline: 0;
  color: var(--cream);
  font-size: 13px;
  padding: 0 10px;
}
.searchbar input::placeholder { color: rgba(244,238,216,0.5); }

.topbar-right {
  /* Anchor to grid column 3 so the Live/Notifications/User chip stays
     pinned to the right edge of the topbar even when the searchbar
     (column 2) is hidden. Without this, .topbar-right falls into the
     first available slot (column 2's 1fr track) and gets stretched
     across the middle of the bar — feedback #129, 2026-05-26. */
  grid-column: 3;
  display: flex; align-items: center; gap: 4px;
  padding-right: 14px;
}
.icon-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 8px;
  position: relative;
  color: rgba(244,238,216,0.85);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: rgba(255,255,255,0.08); color: #fff; }
.icon-btn .badge {
  position: absolute;
  top: 4px; right: 4px;
  background: var(--papi-crimson);
  color: #fff;
  font-size: 9px; font-weight: 700;
  min-width: 16px; height: 16px;
  border-radius: 999px;
  display: grid; place-items: center;
  padding: 0 4px;
  border: 2px solid var(--papi-darker);
}

.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 10px 4px 4px;
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.06);
  margin-left: 8px;
}
.user-chip .name { font-size: 12.5px; color: var(--cream); font-weight: 500; }
.user-chip .role {
  font-size: 9px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--papi-bright); font-weight: 600;
}


/* ---------- 7. SIDEBAR ---------- */

.sidebar {
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
  padding: 18px 12px;
  display: flex; flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}
.nav-section { margin-top: 14px; }
.nav-label {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-3);
  padding: 0 10px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
  cursor: pointer;
  transition: background .12s, color .12s;
  position: relative;
}
.nav-item:hover { background: var(--bg-deep); color: var(--ink); }
.nav-item.active {
  background: var(--papi-dark);
  color: var(--cream);
}
.nav-item.active::before {
  content: "";
  position: absolute; left: -12px; top: 4px; bottom: 4px;
  width: 3px; background: var(--papi-bright);
  border-radius: 0 3px 3px 0;
}
.nav-item .count {
  margin-left: auto;
  font-size: 11px; font-weight: 600;
  background: var(--bg-card);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  padding: 1px 7px;
  color: var(--ink-3);
}
.nav-item.active .count {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.15);
  color: var(--papi-bright);
}


/* ---------- 8. VIEW HEADER ---------- */

.view-header {
  padding: 18px 28px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  display: flex; align-items: center; gap: 18px;
  flex-wrap: wrap;
}
.view-title h1 {
  font-family: var(--display);
  font-size: 30px;
  letter-spacing: 0.04em;
  color: var(--ink);
  line-height: 1;
}
.view-title .subtitle {
  font-family: var(--serif);
  font-style: italic;
  font-size: 13px;
  color: var(--ink-3);
  margin-top: 4px;
}
.view-tabs { display: flex; gap: 2px; margin-left: auto; }
.view-tab {
  padding: 7px 14px;
  font-size: 12.5px; font-weight: 500;
  color: var(--ink-3);
  border-radius: 999px;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background .12s, color .12s;
}
.view-tab:hover { background: var(--bg-soft); color: var(--ink); }
.view-tab.active { background: var(--papi-dark); color: var(--cream); }


/* ---------- 9. BUTTONS ---------- */

.btn {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
  background: var(--papi-bright);
  color: var(--papi-darker);
  display: inline-flex; align-items: center; gap: 6px;
  transition: transform .08s, background .12s, border-color .12s, color .12s;
}
.btn:hover  { background: var(--papi-bright-2); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn[disabled], .btn.disabled { opacity: 0.5; pointer-events: none; }

.btn.ghost { background: transparent; color: var(--ink-2); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--bg-card); color: var(--ink); }

.btn.dark { background: var(--papi-dark); color: var(--cream); }
.btn.dark:hover { background: var(--papi-darker); }

.btn.danger { background: var(--papi-crimson); color: #fff; }
.btn.danger:hover { background: var(--papi-burgundy); }

.btn.sm { padding: 4px 10px; font-size: 11.5px; }
.btn.lg { padding: 10px 20px; font-size: 14px; }


/* ---------- 10. CHIPS ---------- */

.chip {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  color: var(--ink-2);
  font-weight: 500;
  display: inline-flex; align-items: center; gap: 5px;
  transition: background .12s, border-color .12s;
}
.chip:hover  { background: var(--bg-soft); border-color: var(--ink-3); }
.chip.active { background: var(--papi-dark); color: var(--cream); border-color: var(--papi-dark); }


/* ---------- 11. TAGS ---------- */

.tag {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--bg-soft);
  color: var(--ink-2);
  border: 1px solid var(--line-soft);
  display: inline-block;
}


/* ---------- 12. STATUS PILLS ---------- */

.status-pill {
  font-size: 11px; font-weight: 600;
  padding: 4px 10px; border-radius: 999px;
  display: inline-flex; align-items: center; gap: 6px;
}
.status-pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-pill.ok   { background: var(--ok-bg);   color: var(--ok-fg); }
.status-pill.warn { background: var(--warn-bg); color: var(--warn-fg); }
.status-pill.bad  { background: var(--bad-bg);  color: var(--bad-fg); }


/* ---------- 13. CARDS ---------- */

.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-s);
  transition: transform .12s, box-shadow .12s, border-color .12s;
}
.card.hoverable:hover {
  border-color: var(--papi-olive);
  box-shadow: var(--shadow-m);
  transform: translateY(-1px);
}
.card.priority { border-left: 3px solid var(--papi-crimson); }


/* ---------- 14. INPUTS ---------- */

input, textarea, select {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 7px 10px;
  font-size: 13px;
  outline: 0;
  transition: border-color .12s, box-shadow .12s;
  color: var(--ink);
}
input:focus, textarea:focus, select:focus {
  border-color: var(--papi-bright);
  box-shadow: var(--focus-ring);
}
input::placeholder, textarea::placeholder { color: var(--ink-mute); }
textarea { min-height: 80px; resize: vertical; line-height: 1.45; }

label.field {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 10.5px; font-weight: 700;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-3);
}
label.field input, label.field textarea, label.field select {
  font-size: 13px; font-weight: 400;
  letter-spacing: -0.005em; text-transform: none;
  color: var(--ink);
}

.checkbox, .radio {
  width: 16px; height: 16px;
  border: 1.5px solid var(--line);
  border-radius: 4px;
  background: var(--bg-card);
  display: inline-grid; place-items: center;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.radio { border-radius: 50%; }
.checkbox.checked, .radio.checked {
  background: var(--papi-olive);
  border-color: var(--papi-olive);
  color: #fff;
}


/* ---------- 15. TABLES ---------- */

.t-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow: hidden;
}
.t-table th {
  background: var(--papi-dark);
  color: var(--papi-bright);
  padding: 8px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 10.5px;
  letter-spacing: 0.10em;
  text-transform: uppercase;
}
.t-table td { padding: 8px 12px; }
.t-table tr + tr td { border-top: 1px solid var(--line-soft); }
.t-table tr:hover td { background: var(--bg-soft); }
.t-table td.num, .t-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.t-table tr.total td { background: var(--bg-soft); font-weight: 700; }


/* ---------- 16. KPI TILES ---------- */

.kpi {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px 14px;
}
.kpi .lbl {
  font-size: 10px; font-weight: 700;
  letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--ink-3);
}
.kpi .val {
  font-family: var(--display);
  font-size: 26px;
  line-height: 1;
  letter-spacing: 0.02em;
  color: var(--ink);
  margin-top: 4px;
}
.kpi .delta { font-size: 11px; margin-top: 4px; color: var(--ink-3); }
.kpi .delta.up   { color: var(--ok); }
.kpi .delta.down { color: var(--bad); }


/* ---------- 17. AVATAR ---------- */

.avatar {
  width: 24px; height: 24px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 10px; font-weight: 700;
  color: #fff;
  letter-spacing: 0.02em;
  flex-shrink: 0;
  border: 1.5px solid var(--bg-card);
  box-shadow: 0 1px 2px rgba(29,32,16,0.15);
  background: var(--papi-olive);  /* default — override per-user */
}
.avatar.sm { width: 20px; height: 20px; font-size: 9px; }
.avatar.lg { width: 32px; height: 32px; font-size: 12px; }


/* ---------- 18. SIDE PANEL (slide-in) ---------- */

.scrim {
  position: fixed; inset: 0;
  background: rgba(29,32,16,0.45);
  backdrop-filter: blur(2px);
  z-index: 100;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
.scrim.open { opacity: 1; pointer-events: auto; }

.panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 760px; max-width: 92vw;
  background: var(--bg-card);
  z-index: 101;
  box-shadow: var(--shadow-l);
  display: flex; flex-direction: column;
  transform: translateX(110%);
  transition: transform .25s cubic-bezier(.2,.8,.2,1);
}
.panel.open { transform: translateX(0); }
.panel-head {
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
}
.panel-body { flex: 1; overflow-y: auto; padding: 22px 24px 60px; }
.panel-close {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: grid; place-items: center;
  color: var(--ink-2);
  background: var(--bg-soft);
}
.panel-close:hover { background: var(--bg-deep); color: var(--ink); }


/* ---------- 19. MODAL (centred) ---------- */

.modal {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -52%);
  width: 480px; max-width: 92vw;
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-l);
  z-index: 101;
  opacity: 0; pointer-events: none;
  transition: opacity .15s, transform .15s;
}
.modal.open {
  opacity: 1; pointer-events: auto;
  transform: translate(-50%, -50%);
}
.modal-head { padding: 18px 22px 8px; }
.modal-head h3 { font-family: var(--display); font-size: 20px; letter-spacing: 0.04em; }
.modal-body { padding: 8px 22px 18px; }
.modal-foot {
  padding: 12px 22px;
  border-top: 1px solid var(--line);
  display: flex; gap: 8px; justify-content: flex-end;
  background: var(--bg-soft);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
}


/* ---------- 20. TOAST ---------- */

.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--papi-darker);
  color: var(--cream);
  padding: 12px 18px;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-l);
  display: flex; align-items: center; gap: 12px;
  font-size: 13px;
  border: 1px solid rgba(244,238,216,0.1);
  opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 1000;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}
.toast .check {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--papi-bright); color: var(--papi-darker);
  display: grid; place-items: center;
}


/* ---------- 21. TOOLTIP / POPOVER ---------- */

.tip {
  position: fixed;
  background: var(--papi-darker);
  color: var(--cream);
  padding: 10px 14px;
  border-radius: var(--r-md);
  font-size: 12.5px;
  line-height: 1.5;
  z-index: 300;
  box-shadow: var(--shadow-l);
  pointer-events: none;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity .15s, transform .15s;
  max-width: 280px;
}
.tip.open { opacity: 1; transform: translateY(0); }
.tip h5 {
  font-family: var(--display);
  font-size: 14px; letter-spacing: 0.06em;
  margin: 0 0 4px;
  color: var(--papi-bright);
}


/* ---------- 22. KEY-VALUE GRID ---------- */

.kv-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 24px;
  background: var(--bg-soft);
  padding: 14px 18px;
  border-radius: var(--r-md);
}
.kv .k {
  font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--ink-3); font-weight: 700; margin-bottom: 3px;
}
.kv .v { font-size: 13.5px; color: var(--ink); font-weight: 500; }


/* ---------- 23. GHOST WORDMARK ---------- */

.ghost-bg {
  position: fixed;
  right: -3vw; bottom: -8vh;
  font-family: var(--display);
  font-size: clamp(18rem, 42vw, 32rem);
  line-height: 0.85;
  color: transparent;
  -webkit-text-stroke: 1px rgba(48,53,28,0.05);
  pointer-events: none;
  user-select: none;
  letter-spacing: -0.02em;
  z-index: 0;
}


/* ---------- 24. UTILITY HELPERS ---------- */

.hidden  { display: none !important; }
.row     { display: flex; align-items: center; gap: 8px; }
.row.gap-sm  { gap: 4px; }
.row.gap-lg  { gap: 16px; }
.col     { display: flex; flex-direction: column; gap: 8px; }
.spacer  { flex: 1; }
.muted   { color: var(--ink-3); }
.center  { text-align: center; }
.right   { text-align: right; }


/* ---------- 25. PRINT / PDF ---------- */

@media print {
  body { background: var(--bg-card); }
  body::before, body::after { display: none; }
  .topbar, .sidebar, .view-tabs, .filter-bar, .scrim, .panel-close { display: none !important; }
  .card, .kpi, .t-table { box-shadow: none; }
  @page { size: A4; margin: 18mm 16mm; }
}
