:root {
  --pf-navy: #0f2942;
  --pf-navy-light: #163a5c;
  --pf-teal: #1aa896;
  --pf-teal-dark: #128574;
  --pf-amber: #f2a93b;
  --pf-bg: #f4f6fb;
  --pf-card: #ffffff;
  --pf-border: #e6eaf1;
  --pf-text: #1e293b;
  --pf-text-mute: #64748b;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(15, 41, 66, 0.06);
  --shadow-lg: 0 14px 34px rgba(15, 41, 66, 0.14);
  /* User panel gets its own accent so it feels like a distinct app from Admin */
  --pf-user-accent: #6d5ef0;
  --pf-user-accent-dark: #584bd1;
  --pf-user-navy: #201c3d;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--pf-bg);
  color: var(--pf-text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, .pf-logo, .brand { font-family: 'Poppins', 'Inter', sans-serif; }
a { text-decoration: none; color: inherit; }
.container { max-width: 1180px; margin: 0 auto; padding: 0 20px; }
::selection { background: rgba(26,168,150,.25); }

/* ---------- Topbar ---------- */
.pf-topbar {
  background: var(--pf-navy);
  color: #fff;
  position: sticky; top: 0; z-index: 50;
  box-shadow: var(--shadow);
}
.pf-topbar .container { display: flex; align-items: center; justify-content: space-between; height: 66px; }
.pf-logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; letter-spacing: .3px; }
img.logo-img { height: 32px !important; width: 32px !important; max-height: 32px !important; max-width: 32px !important; object-fit: contain; border-radius: 6px; vertical-align: middle; }
.pf-logo .mark {
  width: 36px; height: 36px; border-radius: 9px;
  background: linear-gradient(135deg, var(--pf-teal), var(--pf-amber));
  display: flex; align-items: center; justify-content: center; font-weight: 800; color: #0f2942;
}
.pf-nav { display: flex; gap: 26px; }
.pf-nav a { color: #cfe0ee; font-size: 15px; transition: color .15s; }
.pf-nav a:hover { color: #fff; }
.pf-topbar .actions { display: flex; gap: 12px; align-items: center; }
@media (max-width: 760px) {
  .pf-topbar .container { flex-wrap: wrap; height: auto; padding: 12px 20px; gap: 10px; }
  .pf-nav { gap: 14px; flex-wrap: wrap; order: 3; width: 100%; }
  .pf-nav a { font-size: 13px; }
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 20px; border-radius: 9px; border: none; cursor: pointer;
  font-size: 14.5px; font-weight: 600; transition: transform .1s, box-shadow .15s, opacity .15s, background .15s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--pf-teal); color: #fff; box-shadow: 0 4px 14px rgba(26,168,150,.28); }
.btn-primary:hover { background: var(--pf-teal-dark); }
.btn-ghost { background: rgba(255,255,255,.08); color: #fff; border: 1px solid rgba(255,255,255,.25); }
.btn-outline { background: transparent; border: 1px solid var(--pf-border); color: var(--pf-text); }
.btn-outline:hover { border-color: var(--pf-teal); color: var(--pf-teal); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- Hero ---------- */
.pf-hero {
  background: radial-gradient(1200px 500px at 80% -10%, #16406b 0%, var(--pf-navy) 55%);
  color: #fff; padding: 70px 0 90px; position: relative; overflow: hidden;
}
.pf-hero h1 { font-size: 42px; max-width: 680px; margin: 0 0 16px; font-weight: 800; }
.pf-hero p { font-size: 17px; color: #c9dbea; max-width: 560px; margin-bottom: 30px; }
.pf-search {
  background: #fff; border-radius: 12px; padding: 6px; display: flex; gap: 8px;
  max-width: 620px; box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
.pf-search input {
  flex: 1; border: none; outline: none; padding: 12px 16px; font-size: 15px; border-radius: 8px; color: var(--pf-text);
}
.pf-hero-stats { display: flex; gap: 40px; margin-top: 40px; }
.pf-hero-stats div b { display: block; font-size: 26px; color: var(--pf-amber); }
.pf-hero-stats div span { font-size: 13px; color: #b9cfe3; }

/* ---------- Sections ---------- */
.pf-section { padding: 56px 0; }
.pf-section h2 { font-size: 26px; margin-bottom: 6px; }
.pf-section .sub { color: var(--pf-text-mute); margin-bottom: 28px; }

.pf-grid { display: grid; gap: 18px; }
.pf-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.pf-grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .pf-grid.cols-3, .pf-grid.cols-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .pf-grid.cols-3, .pf-grid.cols-4 { grid-template-columns: 1fr; } }

.pf-card {
  background: var(--pf-card); border: 1px solid var(--pf-border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.pf-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: rgba(26,168,150,.35); }
.pf-card .icon {
  width: 46px; height: 46px; border-radius: 12px; background: rgba(26,168,150,.12); color: var(--pf-teal);
  display: flex; align-items: center; justify-content: center; margin-bottom: 14px; font-size: 20px;
}
.pf-card h3 { margin: 0 0 6px; font-size: 16.5px; font-family: 'Poppins', sans-serif; font-weight: 600; }
.pf-card p { color: var(--pf-text-mute); font-size: 13.5px; margin: 0; }
.pf-tag { display: inline-block; font-size: 11.5px; background: rgba(242,169,59,.15); color: #9c6a12; padding: 3px 9px; border-radius: 20px; margin-bottom: 8px; }

.pf-category-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 26px; }
.pf-chip {
  padding: 8px 16px; border-radius: 20px; border: 1px solid var(--pf-border); background: #fff; font-size: 13.5px; cursor: pointer;
}
.pf-chip.active { background: var(--pf-navy); color: #fff; border-color: var(--pf-navy); }

/* ---------- Footer ---------- */
.pf-footer { background: var(--pf-navy); color: #b9cfe3; padding: 40px 0; font-size: 13.5px; }
.pf-footer .container { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 20px; }

/* ---------- Auth pages ---------- */
.pf-auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--pf-navy); padding: 20px; }
.pf-auth-card { background: #fff; border-radius: 16px; padding: 38px 34px; width: 380px; max-width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.pf-auth-card h2 { margin-top: 0; }
.pf-field { margin-bottom: 16px; }
.pf-field label { display: block; font-size: 13.5px; font-weight: 600; margin-bottom: 6px; color: var(--pf-text-mute); }
.pf-field input, .pf-field select, .pf-field textarea {
  width: 100%; padding: 11px 13px; border: 1px solid var(--pf-border); border-radius: 9px; font-size: 14.5px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.pf-field input:focus, .pf-field select:focus, .pf-field textarea:focus { border-color: var(--pf-teal); box-shadow: 0 0 0 3px rgba(26,168,150,.15); }
.pf-msg { font-size: 13.5px; padding: 10px 12px; border-radius: 9px; margin-bottom: 14px; }
.pf-msg.error { background: #fde8e8; color: #b42318; }
.pf-msg.success { background: #e7f8f2; color: #0f7a5f; }

/* ---------- Dashboard layout ---------- */
.pf-dash { display: flex; min-height: 100vh; position: relative; }
.pf-sidebar {
  width: 250px; background: linear-gradient(180deg, var(--pf-navy), var(--pf-navy-light)); color: #fff; padding: 24px 14px; flex-shrink: 0;
}
.pf-sidebar .brand {
  font-weight: 800; font-size: 17px; margin-bottom: 28px; padding: 0 10px;
  display: flex; align-items: center; gap: 10px; letter-spacing: .2px;
}
.pf-sidebar .brand img.logo-img { flex-shrink: 0; }
.pf-sidebar a {
  display: flex; align-items: center; gap: 12px; padding: 10.5px 12px; border-radius: 9px;
  color: #b9cfe3; font-size: 14px; font-weight: 500; margin-bottom: 3px; transition: background .15s, color .15s;
}
.pf-sidebar a i { width: 18px; text-align: center; font-size: 14px; opacity: .9; }
.pf-sidebar a:hover { background: rgba(255,255,255,.08); color: #fff; }
.pf-sidebar a.active { background: var(--pf-teal); color: #fff; font-weight: 600; box-shadow: 0 4px 14px rgba(26,168,150,.35); }
.pf-main { flex: 1; padding: 30px 36px; min-width: 0; }
.pf-topheader { display: flex; justify-content: space-between; align-items: center; margin-bottom: 26px; flex-wrap: wrap; gap: 10px; }
.pf-topheader h1 { font-size: 21px; margin: 0; font-weight: 700; color: var(--pf-navy); }

/* User panel gets its own indigo accent, distinct from Admin's navy/teal */
.user-portal .pf-sidebar { background: linear-gradient(180deg, var(--pf-user-navy), #2c2657); }
.user-portal .pf-sidebar a.active { background: var(--pf-user-accent); box-shadow: 0 4px 14px rgba(109,94,240,.4); }
.user-portal .btn-primary { background: var(--pf-user-accent); box-shadow: 0 4px 14px rgba(109,94,240,.3); }
.user-portal .btn-primary:hover { background: var(--pf-user-accent-dark); }
.user-portal .pf-field input:focus, .user-portal .pf-field select:focus, .user-portal .pf-field textarea:focus {
  border-color: var(--pf-user-accent); box-shadow: 0 0 0 3px rgba(109,94,240,.15);
}
.user-portal .pf-card:hover { border-color: rgba(109,94,240,.35); }

/* ---------- Mobile hamburger drawer (injected by dashboard.js) ---------- */
.pf-mobile-topbar { display: none; }
.pf-sidebar-backdrop { display: none; }
@media (max-width: 900px) {
  .pf-dash { flex-direction: column; }
  .pf-mobile-topbar {
    display: flex; align-items: center; justify-content: space-between;
    background: var(--pf-navy); color: #fff; padding: 13px 16px; position: sticky; top: 0; z-index: 120;
  }
  .user-portal .pf-mobile-topbar { background: var(--pf-user-navy); }
  .pf-mobile-topbar .hamburger-btn {
    background: rgba(255,255,255,.12); border: none; color: #fff; width: 36px; height: 36px; border-radius: 8px;
    font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center;
  }
  .pf-mobile-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-family: 'Poppins', sans-serif; font-size: 14.5px; }
  .pf-sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; z-index: 200; width: 270px;
    transform: translateX(-105%); transition: transform .28s cubic-bezier(.4,0,.2,1);
    overflow-y: auto; box-shadow: 16px 0 40px rgba(0,0,0,.25);
  }
  .pf-sidebar.open { transform: translateX(0); }
  .pf-sidebar-backdrop {
    display: block; position: fixed; inset: 0; background: rgba(10,15,25,.5); z-index: 190;
    opacity: 0; pointer-events: none; transition: opacity .25s ease;
  }
  .pf-sidebar-backdrop.open { opacity: 1; pointer-events: auto; }
  .pf-main { padding: 18px 16px; }
  .pf-stat-row, .pf-grid.cols-4 { grid-template-columns: repeat(2, 1fr) !important; }
}
@media (max-width: 480px) {
  .pf-stat-row, .pf-grid.cols-3, .pf-grid.cols-4 { grid-template-columns: 1fr !important; }
  .pf-topheader h1 { font-size: 18px; }
  table.pf-table { font-size: 12px; }
  table.pf-table th, table.pf-table td { padding: 9px 8px; }
}

.pf-stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 28px; }
.pf-stat { background: #fff; border-radius: var(--radius); padding: 20px; border: 1px solid var(--pf-border); }
.pf-stat b { font-size: 25px; display: block; font-family: 'Poppins', sans-serif; color: var(--pf-navy); }
.pf-stat span { color: var(--pf-text-mute); font-size: 12.5px; text-transform: uppercase; letter-spacing: .3px; }

.pf-stat-card {
  background: #fff; border-radius: var(--radius); padding: 16px 18px; border: 1px solid var(--pf-border);
  display: flex; align-items: center; gap: 13px; border-left: 3px solid var(--c, var(--pf-teal));
  transition: transform .15s ease, box-shadow .15s ease;
}
.pf-stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.pf-stat-card .stat-icon {
  width: 44px; height: 44px; border-radius: 11px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.pf-stat-card b { font-size: 21px; display: block; font-family: 'Poppins', sans-serif; color: var(--pf-navy); line-height: 1.2; }
.pf-stat-card span { color: var(--pf-text-mute); font-size: 11.5px; }

table.pf-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--pf-border); }
table.pf-table th, table.pf-table td { padding: 13px 15px; text-align: left; border-bottom: 1px solid var(--pf-border); font-size: 13.6px; }
table.pf-table th { background: #f8fafc; color: var(--pf-text-mute); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .3px; }
table.pf-table tr:last-child td { border-bottom: none; }
table.pf-table tr:hover td { background: #fafcfe; }
.status-pill { padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 700; }
.status-published, .status-active, .status-completed { background: #e7f8f2; color: #0f7a5f; }
.status-draft, .status-waiting, .status-processing { background: #fff4e0; color: #92620b; }
.status-disabled, .status-failed, .status-blocked { background: #fde8e8; color: #b42318; }

/* ---------- Visual Form Builder ---------- */
.builder-wrap { display: flex; gap: 16px; height: calc(100vh - 130px); }
.builder-canvas-wrap { flex: 1; overflow: auto; background: #e9edf2; border-radius: var(--radius); padding: 20px; position: relative; }
#builderCanvasStage { position: relative; margin: 0 auto; background: #fff; box-shadow: 0 4px 18px rgba(0,0,0,.15); }
#builderCanvasStage img { display: block; width: 100%; height: 100%; }
.field-box {
  position: absolute; border: 2px solid var(--pf-teal); background: rgba(26,168,150,.14); cursor: move;
  font-size: 11px; color: var(--pf-navy); display: flex; align-items: center; padding: 2px 4px; overflow: hidden;
}
.field-box.selected { border-color: var(--pf-amber); background: rgba(242,169,59,.18); }
.field-box .resize-handle { position: absolute; right: -4px; bottom: -4px; width: 10px; height: 10px; background: var(--pf-teal); cursor: nwse-resize; }
.builder-panel { width: 300px; background: #fff; border-radius: var(--radius); padding: 16px; overflow-y: auto; border: 1px solid var(--pf-border); }
.builder-toolbox { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.builder-toolbox button { padding: 9px 6px; font-size: 12.5px; border: 1px solid var(--pf-border); background: #f8fafc; border-radius: 7px; cursor: pointer; }
.builder-toolbox button:hover { background: #eef2f6; }
@media (max-width: 900px) {
  .builder-wrap { flex-direction: column; height: auto; }
  .builder-panel { width: 100%; }
}

.fill-form-layout { display: grid; grid-template-columns: 1fr; gap: 14px; max-width: 640px; margin: 0 auto; }
.upload-box { border: 2px dashed var(--pf-border); border-radius: 10px; padding: 24px; text-align: center; cursor: pointer; }
.upload-box:hover { border-color: var(--pf-teal); }
canvas.sig-pad { border: 1px solid var(--pf-border); border-radius: 8px; touch-action: none; background: #fff; max-width: 100%; }
