:root {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #6b7280;
  --border: #e3e6ea;
  --side: #23272e;
  --side-text: #c9ced6;
  --accent: #2f7fc1;
  --accent-dark: #24679f;
  --danger: #d9363e;
  --ok: #1f8a4c;
  --radius: 8px;
  font-family: "Open Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 14px; line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; font-weight: 600; margin: 0; }
h2 { font-size: 16px; font-weight: 600; margin: 0; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

/* Shell */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-text); padding: 18px 0; display: flex; flex-direction: column; }
.side .brand { color: #fff; font-weight: 700; font-size: 18px; padding: 0 20px 18px; letter-spacing: .3px; }
.side .brand span { color: #6cb4ee; }
.side nav a, .side nav button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 20px; color: var(--side-text); background: none; border: 0; font: inherit; text-align: left; cursor: pointer; }
.side nav a:hover, .side nav button:hover, .side nav a.active { background: #2e333b; color: #fff; text-decoration: none; }
.side .label { padding: 16px 20px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: #8a919c; }
.side .bottom { margin-top: auto; }
.main { min-width: 0; }
.topbar { background: var(--panel); border-bottom: 1px solid var(--border); padding: 14px 24px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.topbar .spacer { flex: 1; }
.content { padding: 24px; max-width: 1200px; }
.btn.menu-toggle { display: none; }

/* Controls */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--border); background: #fff; color: var(--text); font: inherit; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: #f7f8fa; text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #b92b32; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #cfd4da; border-radius: 6px; font: inherit; background: #fff; color: var(--text);
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc7ea; outline-offset: 0; border-color: var(--accent); }
label { display: block; font-weight: 600; margin-bottom: 4px; }
.field { margin-bottom: 16px; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 4px; font-weight: 400; }
.error { color: var(--danger); font-size: 13px; margin-top: 4px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.panel + .panel { margin-top: 16px; }
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; }
.flash.ok { background: #e7f5ed; color: #14532d; border: 1px solid #bfe3cd; }
.flash.bad { background: #fdecec; color: #7f1d1d; border: 1px solid #f5c2c2; }

/* Dashboard */
.companies { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 18px; }
.company { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: visible; display: flex; flex-direction: column; }
.company-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); border-top: 4px solid var(--brand, var(--accent)); border-radius: var(--radius) var(--radius) 0 0; }
.company-head img { width: 40px; height: 40px; object-fit: contain; }
.company-head .initial { width: 40px; height: 40px; border-radius: 6px; background: var(--brand, var(--accent)); color: #fff; display: grid; place-items: center; font-weight: 700; }
.company-head .meta { flex: 1; min-width: 0; }
.company-head .slug { color: var(--muted); font-size: 12.5px; }
.form-list { list-style: none; margin: 0; padding: 0; }
.form-item { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.form-item:last-child { border-bottom: 0; }
.form-item .name { flex: 1; min-width: 0; }
.form-item .name a { color: var(--text); font-weight: 600; }
.form-item .sub { color: var(--muted); font-size: 12px; }
.empty { padding: 18px 16px; color: var(--muted); }
.pill { font-size: 11.5px; padding: 2px 8px; border-radius: 99px; background: #e7f5ed; color: var(--ok); white-space: nowrap; }
.pill.off { background: #f1f2f4; color: var(--muted); }

/* Action menu */
.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; padding: 4px 8px; border-radius: 6px; border: 1px solid var(--border); background: #fff; }
.menu > summary::-webkit-details-marker { display: none; }
.menu[open] > summary { background: #f1f3f5; }
.menu-items { position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; background: #fff; border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.12); min-width: 200px; padding: 4px 0; }
.menu-items a, .menu-items button { display: flex; gap: 10px; align-items: center; width: 100%; padding: 7px 14px; background: none; border: 0; font: inherit; color: var(--text); text-align: left; cursor: pointer; }
.menu-items a:hover, .menu-items button:hover { background: #f1f3f5; text-decoration: none; }
.menu-items hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
.menu-items .danger { color: var(--danger); }
.menu-items form { margin: 0; }

/* Dialogs */
dialog { border: 0; border-radius: 10px; padding: 0; width: min(460px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20,24,30,.45); }
dialog .dlg-body { padding: 20px; }
dialog .dlg-foot { padding: 12px 20px; background: #f7f8fa; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--border); }

/* Tabs on form pages */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); background: #fff; padding: 0 24px; overflow-x: auto; }
.tabs a { padding: 12px 16px; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--text); }

/* Copy blocks */
.copy-block { display: flex; gap: 8px; align-items: stretch; }
.copy-block input, .copy-block textarea { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; background: #f8f9fb; }
.copy-block textarea { min-height: 64px; }

/* Builder placeholder */
.builder { display: grid; grid-template-columns: 260px 1fr; gap: 16px; }
.palette { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.palette h3 { font-size: 12px; text-transform: uppercase; color: var(--muted); margin: 8px 0; letter-spacing: .6px; }
.palette .chips { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.palette .chip { border: 1px solid var(--border); border-radius: 4px; padding: 5px 8px; font-size: 12px; color: var(--muted); background: #fafbfc; }
.canvas { background: #e9ecef; border-radius: var(--radius); padding: 24px; min-height: 420px; display: grid; place-items: center; }
.canvas .sheet { background: #fff; width: 100%; max-width: 720px; min-height: 360px; border-radius: 4px; padding: 32px; text-align: center; color: var(--muted); }

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 28px; width: min(400px, 100%); }
.auth .brand { font-size: 22px; font-weight: 700; margin-bottom: 18px; text-align: center; }
.auth .brand span { color: var(--accent); }
.qr { display: grid; place-items: center; padding: 12px; }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: #f7f8fa; padding: 12px; border-radius: 6px; }

.nav-backdrop { display: none; }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 50; transform: translateX(-100%); transition: transform .2s; overflow-y: auto; }
  body.nav-open .side { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.35); }
  body.nav-open .nav-backdrop { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(20,24,30,.45); }
  body.nav-open { overflow: hidden; }
  .side nav a, .side nav button { padding: 13px 20px; }
  .btn.menu-toggle { display: inline-flex; }
  .content { padding: 16px; }
  .topbar { padding: 12px 16px; position: sticky; top: 0; z-index: 30; }
  .topbar { gap: 10px; }
  .topbar h1 { font-size: 18px; flex: 1 1 calc(100% - 64px); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar .spacer { display: none; }
  .topbar-search { order: 10; flex-basis: 100%; }
  .topbar-search input { width: 100% !important; }
  .tabs { display: grid; grid-template-columns: 1fr 1fr; padding: 0; }
  .tabs a { padding: 12px 8px; text-align: center; border-bottom-width: 3px; }
  .companies { grid-template-columns: 1fr; }
  .row { grid-template-columns: 1fr; gap: 0; }
  .builder { grid-template-columns: 1fr; }
  .panel { padding: 16px; }

  /* Comfortable tap targets, and 16px text so phones don't zoom into fields */
  .btn { min-height: 44px; padding: 10px 14px; }
  .menu > summary { min-width: 44px; min-height: 44px; display: grid; place-items: center; }
  .menu-items a, .menu-items button { padding: 12px 16px; }
  .form-item { padding: 6px 16px; min-height: 60px; }
  .form-item .name a { display: block; padding: 6px 0 2px; }
  input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], select, textarea { font-size: 16px; padding: 10px 12px; }
  .copy-block { flex-wrap: wrap; }
  .copy-block input, .copy-block textarea { flex-basis: 100%; font-size: 14px; }
  .copy-block .btn { flex: 1; justify-content: center; }
  dialog .dlg-foot .btn { flex: 1; justify-content: center; }
}
.btn[disabled] { opacity: .45; cursor: not-allowed; }

/* Formhub admin area (client accounts, reports) */
.acting-banner { position: sticky; top: 0; z-index: 50; display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; padding: 8px 16px; background: #fff4d6; border-bottom: 1px solid #f0c94a; font-size: 14px; }
.side .who { font-size: 13px; color: #9aa5b1; padding: 0 12px 10px; line-height: 1.4; }
.side .who span { font-size: 12px; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-weight: 600; color: #52606d; font-size: 12px; text-transform: uppercase; letter-spacing: .3px; padding: 8px 10px; border-bottom: 1px solid #e4e7eb; }
.table td { padding: 10px; border-bottom: 1px solid #f0f2f4; vertical-align: top; }
.table tr.muted td { opacity: .55; }
.table form { margin: 0; }
@media (max-width: 820px) {
    .table thead { display: none; }
    .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
    .table tr { border-bottom: 1px solid #e4e7eb; padding: 8px 0; }
    .table td { border: 0; padding: 4px 0; text-align: left !important; }
}

/* Responses */
.resp-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.resp-toolbar .spacer { flex: 1; }
.resp-search { display: flex; gap: 8px; flex: 1 1 320px; max-width: 520px; margin: 0; }
.resp-search input { flex: 1; min-width: 0; }
.resp-panel { padding: 0; }
.resp-table th a { color: inherit; }
.resp-table td.nowrap, .resp-table th { white-space: nowrap; }
.resp-table td { max-width: 260px; overflow-wrap: anywhere; }
.resp-table td.actions { text-align: right; }
/* View and PDF stay in sight however many questions the form has. */
.resp-table td.actions, .resp-table th.actions { position: sticky; right: 0; background: var(--panel, #fff); box-shadow: -8px 0 8px -8px rgba(0,0,0,.18); }
.pill.warn { background: #fdecec; color: var(--danger); margin-left: 6px; }
.pages { display: flex; gap: 10px; align-items: center; justify-content: center; margin-top: 14px; }
.btn.disabled { opacity: .45; pointer-events: none; }
.resp-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.resp-meta form.inline { display: inline; margin-left: 6px; }
.resp-doc { padding: 0; overflow: hidden; }
.resp-frame { display: block; width: 100%; min-height: 400px; border: 0; }
.danger-zone form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 0; }
@media (max-width: 820px) {
    .resp-table td.xtra { display: none; }
    .resp-table td[data-label]::before { content: attr(data-label); display: block; font-size: 11.5px; color: var(--muted); }
    .resp-table td.actions { text-align: left; position: static; box-shadow: none; }
    .resp-search { max-width: none; }
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
