:root {
  color-scheme: light dark;
  --bg: #f7f8f4;
  --card: #ffffff;
  --card-2: #eef1e8;
  --border: #e3e6df;
  --text: #373633;
  --muted: #6d6a62;
  --olive: #596b3f;
  --olive-soft: #e9eee3;
  --olive-soft-hover: #dde5d4;
  --olive-dark: #465330;
  --orange: #f0522f;
  --orange-soft: #fbe4de;
  --shadow: 0 10px 30px rgba(55, 54, 51, 0.06);
}
* { box-sizing: border-box; }

body.client-portal {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Inter, Arial, sans-serif;
  line-height: 1.5;
}

.client-shell { width: min(1320px, calc(100% - 32px)); margin: 0 auto; }
.muted { color: var(--muted); }

/* --- Shell: sidebar + main ------------------------------------------- */
.portal-shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; align-items: start; }

.portal-nav {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 28px 18px;
  border-right: 1px solid var(--border);
}
.portal-nav-header { padding: 4px 12px 20px; display: flex; flex-direction: column; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.portal-nav-header strong { font-size: 1rem; }
.portal-nav-group { margin-bottom: 20px; }
.portal-nav-label { margin: 0 0 6px; padding: 0 12px; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.portal-nav-links { display: flex; flex-direction: column; gap: 2px; }
.portal-nav-links a {
  display: block;
  padding: 10px 12px;
  border-radius: 9px;
  color: var(--text);
  text-decoration: none;
  font-weight: 650;
  font-size: 0.92rem;
}
.portal-nav-links a:hover { background: var(--olive-soft); }
.portal-nav-links a.is-active { background: var(--olive); color: #fff; }
.portal-nav-signout button { width: 100%; }

.portal-main { padding: 32px 32px 72px; min-width: 0; }

.client-header { margin-bottom: 24px; }
.client-header h1 { margin: 0.1rem 0; font-size: 1.7rem; letter-spacing: -0.01em; }
.eyebrow { margin: 0; color: var(--olive); font-size: 0.78rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; }

/* --- Cards & layout --------------------------------------------------- */
.overview-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(280px, 0.9fr); gap: 20px; align-items: start; }
.portal-card {
  margin-bottom: 22px;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card);
  box-shadow: var(--shadow);
  scroll-margin-top: 20px;
}
.portal-card.narrow { max-width: 560px; }
.portal-card.danger-zone { border-color: #dc9a94; border-left: 4px solid #b91c1c; }
.portal-form button.button-danger { background: #b91c1c; }
.portal-form button.button-danger:hover { background: #991b1b; }
.portal-card h2 { margin-top: 0; font-size: 1.2rem; }

/* --- Forms -------------------------------------------------------------- */
.portal-form { display: grid; gap: 10px; }
.portal-form label, .portal-form legend { font-weight: 700; font-size: 0.92rem; }
.portal-form input, .portal-form select, .portal-form textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid #c9d0c6;
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  font: inherit;
}
.portal-form input:focus, .portal-form select:focus, .portal-form textarea:focus {
  outline: 2px solid var(--olive);
  outline-offset: 1px;
}
.portal-form fieldset { margin: 10px 0; padding: 0; border: 0; }
.portal-form .check-row { display: flex; align-items: center; gap: 10px; }
.portal-form .check-row input { width: auto; padding: 0; }
.staff-addon-checks { display: flex; flex-wrap: wrap; gap: 8px 20px; margin: 10px 0; }

.skin-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.skin-option input { position: absolute; opacity: 0; pointer-events: none; }
.skin-swatch {
  display: block;
  min-height: 86px;
  padding: 10px;
  border: 3px solid var(--swatch-bg);
  border-radius: 12px;
  background: var(--swatch-paper, var(--swatch-card));
  background-color: var(--swatch-card);
  color: var(--swatch-ink);
  cursor: pointer;
}
.skin-swatch i {
  display: block;
  width: 55%;
  height: 20px;
  margin-bottom: 12px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--swatch-a), var(--swatch-b));
}
.skin-swatch b { font-size: 0.8rem; }
.skin-option input:checked + .skin-swatch,
.skin-option input:focus-visible + .skin-swatch { outline: 3px solid var(--olive); outline-offset: 2px; }

/* --- Buttons ------------------------------------------------------------ */
.portal-form button, .copy-row button, .portal-button {
  display: inline-block;
  padding: 11px 18px;
  border: 0;
  border-radius: 9px;
  background: var(--olive);
  color: #fff;
  font: inherit;
  font-weight: 750;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.12s ease;
}
.portal-form button:hover, .copy-row button:hover, .portal-button:hover { background: var(--olive-dark); }
.secondary, .portal-button.secondary { background: var(--olive-soft) !important; color: var(--olive-dark) !important; }
.secondary:hover, .portal-button.secondary:hover { background: var(--olive-soft-hover) !important; }
.btn { display: inline-block; padding: 9px 16px; border-radius: 9px; font-weight: 700; text-decoration: none; font-size: 0.88rem; }

.portal-preview { display: block; width: 100%; height: 650px; border: 0; border-radius: 14px; background: #111; }
.notice, .error { padding: 13px 16px; border-radius: 10px; }
.notice { background: var(--olive-soft); color: var(--olive-dark); }
.error { background: var(--orange-soft); color: #9a3412; }
.copy-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: start; }
.code-box {
  width: 100%;
  padding: 12px;
  border: 1px solid #c9d0c6;
  border-radius: 9px;
  background: var(--card-2);
  color: var(--text);
  font: 13px/1.45 ui-monospace, SFMono-Regular, Consolas, monospace;
  resize: vertical;
}
.delivery-card h3 { margin-top: 1.6rem; }
.delivery-card code { font-size: 0.9em; }

.notice-row { padding: 14px 0; border-top: 1px solid var(--border); }
.notice-row:first-of-type { border-top: 0; padding-top: 0; }
.notice-row legend { font-weight: 700; margin-bottom: 6px; padding: 0; }
.notice-editor { min-height: 116px; resize: none; overflow: hidden; }
.notice-more { margin-top: 8px; }
.notice-more summary { cursor: pointer; font-weight: 700; }
.notice-more .muted { margin: 0.4rem 0; }
.notice-dates { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
.notice-dates label { font-weight: 600; font-size: 0.85rem; }
.size-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
#noticesCounter { font-weight: 700; }
#noticesCounter.error-text { color: var(--orange); }

.answer-meter { height: 0.6rem; margin: 0.7rem 0 0; border-radius: 999px; background: var(--card-2); overflow: hidden; }
.answer-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--olive), #7a8f57); }
.answer-fill.is-warning { background: linear-gradient(90deg, #d97706, #b45309); }
.answer-fill.is-full { background: linear-gradient(90deg, var(--orange), #b91c1c); }

.delivery-note { margin-top: 14px; padding: 14px 16px; border-radius: 12px; background: var(--card-2); border: 1px solid var(--border); }
.delivery-note p { margin: 0 0 8px; }
.delivery-note ul { margin: 0; padding-left: 20px; }
.delivery-note li { margin: 0 0 6px; font-size: 0.92rem; line-height: 1.5; }
.delivery-note li:last-child { margin-bottom: 0; }

.addon-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 0; border-top: 1px solid var(--border); }
.addon-row:first-of-type { border-top: 0; padding-top: 6px; }
.addon-row p { margin: 0.2rem 0 0; font-size: 0.88rem; }
.addon-row .addon-tag { padding: 4px 10px; border-radius: 999px; background: var(--olive-soft); color: var(--olive-dark); font-size: 0.76rem; font-weight: 700; white-space: nowrap; }
.addon-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
/* Distinct from the green "Active"/"Included" tag - this one sits beside a
   still-visible Buy button, so it needs to read as a warning ("you already
   have some, think before buying more"), not a status confirmation. */
.addon-actions .addon-tag-owned { background: var(--amber-soft, #fdf1d6); color: var(--amber-dark, #8a5a00); }

@media (max-width: 1000px) {
  .overview-grid { grid-template-columns: 1fr; }
}

@media (max-width: 850px) {
  .portal-shell { grid-template-columns: 1fr; }
  .portal-nav {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
  }
  .portal-nav-links { flex-direction: row; }
  .portal-nav-links a { white-space: nowrap; }
  .portal-nav-signout { margin-left: 8px; flex-shrink: 0; }
  .portal-nav-signout button { width: auto; }
  .portal-preview { height: 580px; }
}

@media (max-width: 600px) {
  .portal-main { padding: 20px 16px 56px; }
  .skin-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .size-grid { grid-template-columns: 1fr; }
  .copy-row { grid-template-columns: 1fr; }
  .portal-card { padding: 17px; }
  .portal-preview { height: 560px; }
  .addon-row { flex-wrap: wrap; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14170f;
    --card: #1c2016;
    --card-2: #232819;
    --border: #333a27;
    --text: #eaecdf;
    --muted: #a7ad98;
    --olive-soft: #263420;
    --olive-soft-hover: #324a2b;
    --olive-dark: #b7d69a;
    --orange-soft: #3a1f14;
    --amber-soft: #3a2f10;
    --amber-dark: #e8c675;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  }
  .eyebrow { color: #9fd47a; }
  .portal-form input, .portal-form select, .portal-form textarea, .code-box {
    border-color: #3d4530;
    background: var(--bg);
    color: var(--text);
  }
  .notice { color: #d7f0c2; }
  .error { color: #f6c9c4; }
  .answer-fill.is-full { background: linear-gradient(90deg, #ef4444, #b91c1c); }
  .portal-card.danger-zone { border-color: #6b2b26; border-left-color: #dc2626; }
}
