:root {
  --ink: #17221d;
  --muted: #68736d;
  --line: #e1e8e3;
  --paper: #ffffff;
  --wash: #f3f7f4;
  --brand: #276749;
  --brand-2: #1b4332;
  --mint: #dff3e8;
  --danger: #b42318;
  --gold: #a66b12;
  --radius: 16px;
  --shadow: 0 14px 40px rgba(35, 67, 50, .08);
}

[hidden] { display: none !important; }
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--wash); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; }
button, input, select { font: inherit; }
button { cursor: pointer; }
.portal-shell { min-height: 100vh; display: grid; grid-template-columns: 240px 1fr; }
.side { background: #173c2c; color: white; padding: 28px 18px; display: flex; flex-direction: column; gap: 26px; }
.brand { display: flex; gap: 11px; align-items: center; color: white; text-decoration: none; font-weight: 800; font-size: 18px; }
.brand-mark { width: 34px; height: 34px; border-radius: 11px; background: #fff; color: var(--brand); display: grid; place-items: center; }
.side-nav { display: grid; gap: 7px; }
.side-nav button, .side-nav a { border: 0; color: rgba(255,255,255,.72); background: transparent; text-align: left; text-decoration: none; border-radius: 10px; padding: 11px 12px; font-weight: 650; }
.side-nav button:hover, .side-nav button.active, .side-nav a:hover { background: rgba(255,255,255,.1); color: white; }
.side-foot { margin-top: auto; color: rgba(255,255,255,.55); font-size: 12px; }
.main { min-width: 0; }
.topbar { height: 76px; background: rgba(255,255,255,.88); border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 32px; position: sticky; top: 0; z-index: 5; backdrop-filter: blur(12px); }
.topbar h1 { margin: 0; font-size: 21px; }
.user-chip { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.avatar { width: 35px; height: 35px; border-radius: 50%; display: grid; place-items: center; background: var(--mint); color: var(--brand); font-weight: 800; }
.content { padding: 28px 32px 60px; max-width: 1320px; margin: 0 auto; }
.hero-grid { display: grid; grid-template-columns: 1.45fr .85fr; gap: 18px; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-pad { padding: 24px; }
.member-banner { background: linear-gradient(135deg, #194d37 0%, #2d7655 66%, #3b8c67 100%); color: white; border: 0; position: relative; overflow: hidden; }
.member-banner::after { content: ""; position: absolute; width: 220px; height: 220px; right: -60px; top: -110px; border: 38px solid rgba(255,255,255,.08); border-radius: 50%; }
.eyebrow { color: rgba(255,255,255,.72); font-size: 12px; letter-spacing: .12em; text-transform: uppercase; }
.member-banner h2 { margin: 8px 0 5px; font-size: 28px; }
.member-banner p { margin: 0; color: rgba(255,255,255,.76); }
.banner-meta { display: flex; gap: 28px; margin-top: 27px; }
.banner-meta strong { display: block; font-size: 20px; }
.banner-meta span { font-size: 12px; color: rgba(255,255,255,.65); }
.credit-card { display: flex; flex-direction: column; justify-content: space-between; }
.credit-value { font-size: 42px; font-weight: 820; color: var(--brand); line-height: 1; margin: 14px 0 8px; }
.muted { color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin: 18px 0; }
.stat { padding: 20px; }
.stat .num { font-size: 28px; font-weight: 820; }
.stat .label { color: var(--muted); font-size: 13px; margin-top: 3px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 16px; }
.section-head h2 { margin: 0; font-size: 18px; }
.dashboard-monthly { margin-bottom: 18px; }
.dashboard-monthly .section-head, #dashboardMonthForm { flex-wrap: wrap; }
#dashboardMonthForm { display: flex; align-items: center; gap: 10px; }
#dashboardMonthForm label { color: var(--muted); font-size: 13px; }
#dashboardMonth { padding: 8px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); }
.dashboard-monthly .stats { grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr)); margin: 0; }
.dashboard-monthly .stat { padding: 12px; min-width: 0; overflow-wrap: anywhere; }
.btn { border: 1px solid var(--line); border-radius: 10px; padding: 9px 14px; background: white; color: var(--ink); font-weight: 700; }
.btn:hover { border-color: #b7c9be; }
.btn.primary { border-color: var(--brand); background: var(--brand); color: white; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--danger); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 14px; border-bottom: 1px solid var(--line); text-align: left; font-size: 13px; white-space: nowrap; }
th { color: var(--muted); font-weight: 700; background: #fafcfb; }
tr:last-child td { border-bottom: 0; }
.status { display: inline-flex; padding: 4px 8px; border-radius: 99px; font-size: 12px; font-weight: 700; background: #eef2ef; color: var(--muted); }
.payment-readiness { margin-top: 18px; }
.payment-checks { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
.payment-check { display: flex; align-items: center; gap: 9px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fbfdfb; font-size: 13px; }
.payment-check-mark { width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; font-weight: 800; }
.payment-check-mark.ok { color: #137b5f; background: #e3f5ed; }
.payment-check-mark.bad { color: #b6483d; background: #fbe9e6; }
.status.done, .status.active { color: #177245; background: #e5f7ed; }
.status.failed, .status.inactive { color: var(--danger); background: #ffebe9; }
.form-grid { display: grid; gap: 14px; }
.capability-switches { display: grid; gap: 9px; }
.capability-switch { display: flex; align-items: flex-start; gap: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; background: #fbfdfb; cursor: pointer; }
.capability-switch input { width: 18px; height: 18px; margin-top: 1px; accent-color: var(--brand); flex: 0 0 auto; }
.capability-switch strong { display: block; color: var(--ink); }
.capability-switch span { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; font-weight: 400; }
.template-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.template-card { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: #fbfdfb; }
.template-card.template-disabled { opacity: .64; }
.template-preview { aspect-ratio: 16 / 9; background: #e9efeb; overflow: hidden; }
.template-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.template-card-body { padding: 15px; }
.template-card-body .section-head { align-items: flex-start; margin-bottom: 8px; }
.template-card-body p { min-height: 38px; margin: 8px 0 14px; }
.template-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.template-mode-options { display: flex; flex-wrap: wrap; gap: 8px 14px; }
.template-mode-options label { color: var(--ink); font-weight: 500; }
.template-modal-card { width: min(680px, 100%); }
.modal-card.guide-modal-card { width: min(860px, 100%); }
.guide-settings { display: grid; grid-template-columns: minmax(220px, 1fr) 180px auto; gap: 12px; align-items: end; padding: 16px; margin-bottom: 18px; border: 1px solid var(--line); border-radius: 14px; background: #fafcfb; }
.guide-settings .error { grid-column: 1 / -1; min-height: 0; }
.guide-icon-editor { display: grid; grid-template-columns: 72px minmax(140px, 1fr) minmax(120px, .7fr) minmax(120px, .7fr); gap: 12px; align-items: end; }
.guide-icon-preview { width: 58px; height: 58px; display: grid; place-items: center; border-radius: 17px; background: #eaf6f1; color: #137b5f; font-weight: 800; font-size: 20px; }
.guide-icon-editor input[type="color"] { height: 44px; padding: 4px; cursor: pointer; }
.guide-media-section hr { border: 0; border-top: 1px solid var(--line); margin: 26px 0 20px; }
.guide-media-upload { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) 140px max-content; gap: 12px; align-items: end; }
.guide-media-upload .field { min-width: 0; }
.guide-media-upload .btn { white-space: nowrap; }
.guide-media-list { display: grid; gap: 10px; margin-top: 14px; }
.guide-media-row { display: grid; grid-template-columns: 96px minmax(160px, 1fr) 100px 110px auto; gap: 12px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 12px; }
.guide-media-thumb { width: 96px; height: 62px; border-radius: 8px; object-fit: cover; background: #edf2ef; }
.guide-media-video-mark { width: 96px; height: 62px; border-radius: 8px; display: grid; place-items: center; color: white; background: #173c2c; font-weight: 800; }
.guide-media-row input, .guide-media-row select { width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 9px; }
.field { display: grid; gap: 6px; }
.field label { color: var(--muted); font-size: 13px; font-weight: 700; }
.field input, .field select, .field textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; outline: 0; background: white; }
.field textarea { resize: vertical; line-height: 1.6; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(39,103,73,.1); }
@media (max-width: 760px) { .guide-settings, .guide-icon-editor, .guide-media-upload, .guide-media-row { grid-template-columns: 1fr; } .guide-settings .btn { width: 100%; } }
.auth-screen { min-height: 100vh; display: grid; grid-template-columns: 1.1fr .9fr; }
.auth-story { padding: 9vw; color: white; background: linear-gradient(145deg, #123c2a, #2c7454); display: flex; flex-direction: column; justify-content: center; }
.auth-story h1 { font-size: clamp(36px, 5vw, 64px); line-height: 1.08; margin: 18px 0; max-width: 650px; }
.auth-story p { color: rgba(255,255,255,.73); max-width: 540px; font-size: 17px; }
.auth-box { display: grid; place-items: center; padding: 28px; }
.auth-card { width: min(430px, 100%); padding: 32px; }
.auth-card h2 { margin: 0 0 5px; font-size: 25px; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; background: var(--wash); padding: 4px; border-radius: 11px; margin: 22px 0; }
.auth-tabs button { border: 0; border-radius: 8px; padding: 9px; background: transparent; color: var(--muted); font-weight: 700; }
.auth-tabs button.active { background: white; color: var(--ink); box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.error { color: var(--danger); font-size: 13px; min-height: 20px; }
.action-message { min-height: 20px; color: var(--danger); font-size: 13px; font-weight: 650; }
.action-message.success { color: #177245; }
.empty { padding: 36px; text-align: center; color: var(--muted); }
.plan-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.plan-card { min-height: 245px; border: 1px solid var(--line); border-radius: 14px; padding: 20px; display: flex; flex-direction: column; justify-content: space-between; gap: 18px; background: #fbfdfb; }
.plan-card.current { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.plan-card h3 { margin: 7px 0; font-size: 21px; }
.plan-card p { min-height: 42px; }
.plan-card .btn { width: 100%; margin-top: 16px; }
.plan-price { display: block; color: var(--brand); font-size: 28px; margin-bottom: 5px; }
.eyebrow.dark { color: var(--brand); }
.view { display: none; }
.view.active { display: block; }
.toolbar { display: flex; gap: 10px; align-items: center; }
.toolbar input { border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; min-width: 260px; }
.modal { position: fixed; inset: 0; background: rgba(11,31,22,.48); display: none; align-items: center; justify-content: center; padding: 20px; z-index: 20; }
.modal.open { display: flex; }
.modal-card { width: min(560px, 100%); max-height: 88vh; overflow: auto; background: white; border-radius: 18px; padding: 24px; }
@media (max-width: 860px) {
  .portal-shell { grid-template-columns: 1fr; }
  .side { padding: 13px 16px; position: sticky; top: 0; z-index: 10; gap: 10px; }
  .side-nav { display: flex; overflow-x: auto; }
  .side-nav button, .side-nav a { white-space: nowrap; }
  .side-foot { display: none; }
  .topbar { top: 105px; padding: 0 18px; }
  .content { padding: 20px 16px 45px; }
  .hero-grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr; }
  .plan-grid { grid-template-columns: 1fr; }
  .template-grid { grid-template-columns: 1fr; }
  .auth-screen { grid-template-columns: 1fr; }
  .auth-story { min-height: 280px; padding: 48px 28px; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .toolbar input { min-width: 0; }
}

/* Keep detailed failure text inside the status cell instead of widening the whole table. */
.job-failure { min-width: 240px; max-width: 340px; margin-top: 8px; white-space: normal; }
.failure-kind { display: inline-block; padding: 3px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; }
.failure-kind.input { color: #82500b; background: #fff4d8; }
.failure-kind.system { color: #a32121; background: #ffe9e9; }
.failure-kind.review { color: #46566a; background: #edf1f7; }
.job-failure-reason { margin: 7px 0; line-height: 1.65; overflow-wrap: anywhere; }
.job-failure details { margin-top: 7px; font-size: 12px; line-height: 1.6; }
.job-failure summary { color: #386a57; cursor: pointer; }
.job-failure details p { margin: 5px 0; }
