/* App shell on top of Bootstrap 5. Desktop: sidebar. Mobile: app bar + bottom tab bar. */
:root { --sidebar-w: 240px; --appbar-h: 56px; --tabbar-h: 64px; --brand: #101935; }
body { background: #f4f6fa; min-height: 100vh; }

/* Sidebar (desktop) */
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); background: var(--brand); color: #c9d3ee; flex-direction: column; padding: 20px 12px; z-index: 1030; }
.sidebar-brand { color: #fff; font-weight: 700; font-size: 18px; padding: 4px 12px 20px; }
.sidebar .nav-link { color: #c9d3ee; border-radius: 8px; padding: 10px 12px; display: flex; gap: 10px; align-items: center; }
.sidebar .nav-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar .nav-link.active { background: rgba(255,255,255,.14); color: #fff; font-weight: 600; }
.sidebar-foot { margin-top: auto; border-top: 1px solid rgba(255,255,255,.12); padding-top: 12px; }
.sidebar-foot .small { padding: 0 12px 6px; }
.app-main { padding: 28px 32px 40px; margin-left: var(--sidebar-w); max-width: calc(1180px + var(--sidebar-w)); }

/* Mobile app bar + bottom tabs */
.appbar { position: sticky; top: 0; z-index: 1030; height: calc(var(--appbar-h) + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top);
  background: var(--brand); color: #fff; display: flex; align-items: center; gap: 4px; padding-left: 4px; padding-right: 4px; }
.appbar-title { flex: 1; font-weight: 600; font-size: 17px; }
.appbar-btn { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; color: #fff; font-size: 20px; text-decoration: none; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030; background: #fff; border-top: 1px solid #e3e7ef;
  display: flex; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: #7a8399; text-decoration: none; font-size: 11px; }
.tabbar a i { font-size: 21px; }
.tabbar a.active { color: var(--bs-primary); font-weight: 600; }
@media (max-width: 991.98px) {
  .app-main { margin-left: 0; padding: 16px 16px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom)); }
  .page-title { display: none; } /* the app bar shows the title */
  .btn { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
  .btn-sm { min-height: 36px; }
  .form-control, .form-select { min-height: 46px; font-size: 16px; } /* 16px stops iOS zooming */
}

/* Public pages (login) */
.public-main { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px;
  background: linear-gradient(160deg, #101935 0%, #1d2b5c 100%); }
.auth-card { width: 100%; max-width: 400px; border: 0; border-radius: 16px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }

/* Common pieces */
.card { border-color: #e3e7ef; border-radius: 12px; }
.card-header { background: #fff; font-weight: 600; border-color: #e3e7ef; }
.stat-card { text-decoration: none; color: inherit; transition: transform .15s, box-shadow .15s; }
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(16,25,53,.08); }
.stat-card .stat-num { font-size: 28px; font-weight: 700; line-height: 1.1; }
.stat-card .stat-icon { width: 40px; height: 40px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; font-size: 20px; }

/* Mobile list rows (replace tables on small screens) */
.list-row { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid #eef1f6; color: inherit; text-decoration: none; background: #fff; }
.list-row:last-child { border-bottom: 0; }
.list-row:active { background: #f4f6fa; }
.list-row .avatar { width: 40px; height: 40px; border-radius: 50%; background: #e8edfb; color: var(--bs-primary); display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; }
.list-row .grow { flex: 1; min-width: 0; }

.empty-state { text-align: center; padding: 48px 16px; color: #7a8399; }
.empty-state i { font-size: 40px; display: block; margin-bottom: 8px; color: #b9c2d6; }

/* The agreement shown like a paper document */
.doc { background: #fff; border: 1px solid #dee2e6; border-radius: 8px; padding: 48px 56px; box-shadow: 0 2px 10px rgba(16,25,53,.06); }
@media (max-width: 640px) { .doc { padding: 20px 16px; } }
.doc-scroll { max-height: 70vh; overflow-y: auto; }

/* Sticky action bar at the bottom of a form on mobile */
.action-bar { position: sticky; bottom: 0; background: rgba(244,246,250,.96); backdrop-filter: blur(6px); padding: 12px 0; margin-top: 16px; z-index: 5; }
@media (max-width: 991.98px) {
  .action-bar { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  .action-bar .btn { flex: 1; }
}

/* Signature pad */
.sigpad { position: relative; border: 2px dashed #b9c2d6; border-radius: 10px; background: #fcfdff; height: 200px; touch-action: none; }
.sigpad canvas { width: 100%; height: 100%; display: block; cursor: crosshair; border-radius: 10px; }
.sigpad-hint { position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%); text-align: center; color: #9aa4ba; pointer-events: none; padding: 0 16px; }
.sigpad.has-ink .sigpad-hint { display: none; }
.sigpad::after { content: ""; position: absolute; left: 24px; right: 24px; bottom: 44px; border-bottom: 1px solid #d5dbe7; pointer-events: none; }
.sigpad-clear { position: absolute; right: 8px; top: 8px; }
.sigpad-error { border-color: #dc3545; }

/* Editor */
.editor-wrap .ql-toolbar { border-radius: 10px 10px 0 0; background: #fafbfd; position: sticky; top: 0; z-index: 4; }
.editor-wrap .ql-container { border-radius: 0 0 10px 10px; font-size: 15px; }
.editor-wrap .ql-editor { min-height: 420px; max-height: 70vh; font-family: "Times New Roman", Times, serif; font-size: 15px; line-height: 1.55; }
@media (max-width: 991.98px) { .editor-wrap .ql-toolbar { top: var(--appbar-h); } }
.ph-chip { font-family: ui-monospace, Consolas, monospace; font-size: 12px; cursor: pointer; }

.link-input { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 0 0 14px 22px; font-size: 13px; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 6px; width: 9px; height: 9px; border-radius: 50%; background: var(--bs-primary); }
.timeline li::after { content: ""; position: absolute; left: 8px; top: 16px; bottom: 0; width: 1px; background: #d5dbe7; }
.timeline li:last-child::after { display: none; }
