/* ==========================================================================
   Dhanyah Partnership Automation — styles.css
   Mobile-First, Desktop Split-View Ready Legal & Compliance PWA Stylesheet
   ========================================================================== */

:root {
  --primary:        #15304d;
  --primary-dark:   #0e2238;
  --primary-light:  #25578a;
  --accent:         #c8a94b;
  --accent-light:   #ebd484;
  --accent-bg:      #fbf6e6;
  --bg:             #f4f3ee;
  --card-bg:        #ffffff;
  --text:           #18202c;
  --text-muted:     #5f6b7a;
  --border:         #d5d9e0;
  --border-soft:    #e8ebf0;
  --success:        #15803d;
  --success-light:  #dcfce7;
  --danger:         #dc2626;
  --danger-light:   #fee2e2;
  --warning:        #d97706;
  --warning-light:  #fef3c7;
  --info:           #1d4ed8;
  --info-light:     #dbeafe;
  --gray-50:        #f8fafc;
  --gray-100:       #f1f5f9;
  --gray-200:       #e2e8f0;

  --font-legal: 'Bookman Old Style', Georgia, 'Times New Roman', serif;
  --font-ui:    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --deed-font-size: 12pt;
  --deed-line-height: 1.5;

  --radius-sm:   6px;
  --radius:      10px;
  --radius-lg:   14px;
  --radius-xl:   20px;
  --radius-pill: 9999px;

  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow:    0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 10px 28px rgba(15, 23, 42, 0.14);

  --top-nav-h:    62px;
  --bottom-nav-h: 66px;
  --transition:   0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  font-family: var(--font-ui);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

img, svg, canvas {
  display: block;
  max-width: 100%;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* ==========================================================================
   NAVIGATION
   ========================================================================== */

#top-nav {
  display: none;
  position: sticky;
  top: 0;
  z-index: 1000;
  height: var(--top-nav-h);
  background: linear-gradient(90deg, var(--primary-dark) 0%, var(--primary) 100%);
  border-bottom: 2px solid var(--accent);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  padding: 0 1.5rem;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  cursor: pointer;
  flex-shrink: 0;
}

.nav-emblem {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-light) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

.nav-brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.nav-title {
  font-family: var(--font-legal);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent-light);
  letter-spacing: 0.02em;
}

.nav-subtitle {
  font-size: 0.68rem;
  color: rgba(255, 255, 255, 0.72);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.nav-link {
  color: rgba(255, 255, 255, 0.85);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius-pill);
  transition: background-color var(--transition), color var(--transition);
  white-space: nowrap;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.nav-link.active {
  background: var(--accent);
  color: var(--primary-dark);
  font-weight: 700;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-shrink: 0;
}

.btn-nav-outline {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: var(--radius-pill);
  padding: 0.4rem 0.9rem;
  font-size: 0.8125rem;
  font-weight: 500;
  min-height: 36px;
}

.btn-nav-outline:hover {
  background: rgba(255, 255, 255, 0.18);
}

.btn-nav-outline.active {
  background: var(--accent-light);
  color: var(--primary-dark);
  border-color: var(--accent);
  font-weight: 700;
}

.desktop-only {
  display: none;
}

/* Mobile Bottom Nav */
#bottom-nav {
  display: flex;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 1000;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
}

.bottom-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.6875rem;
  font-weight: 500;
  cursor: pointer;
  padding: 0.4rem 0.2rem;
  position: relative;
  transition: color var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.bottom-tab .tab-icon {
  font-size: 1.25rem;
  line-height: 1;
  transition: transform var(--transition);
}

.bottom-tab.active {
  color: var(--primary);
  font-weight: 700;
}

.bottom-tab.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 22%;
  right: 22%;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--accent);
}

.bottom-tab.active .tab-icon {
  transform: translateY(-2px);
}

/* Protocol Banner */
.protocol-banner {
  background: #fef9e7;
  border-bottom: 1px solid #f0d78c;
  color: #6b4f00;
  padding: 0.5rem 1rem;
  font-size: 0.8125rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.btn-icon-plain {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  padding: 0.25rem 0.4rem;
  color: inherit;
}

/* ==========================================================================
   MAIN LAYOUT & TABS
   ========================================================================== */

#app-container {
  flex: 1;
  width: 100%;
}

#app-main {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
}

.tab-content {
  display: none;
  animation: fadeIn 0.22s ease;
}

.tab-content.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.page-top-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.15rem;
}

.page-heading {
  font-family: var(--font-legal);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--primary);
}

.page-desc {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.page-top-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ==========================================================================
   HOME / DASHBOARD
   ========================================================================== */

.home-hero {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 55%, var(--primary-light) 100%);
  color: #fff;
  padding: 2rem 1.25rem;
  border-radius: var(--radius-xl);
  text-align: center;
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
  border-bottom: 4px solid var(--accent);
}

.hero-badge {
  display: inline-block;
  padding: 0.3rem 0.85rem;
  border-radius: var(--radius-pill);
  background: rgba(200, 169, 75, 0.2);
  border: 1px solid rgba(200, 169, 75, 0.55);
  color: var(--accent-light);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 0.75rem;
}

.home-title {
  font-family: var(--font-legal);
  font-size: clamp(1.5rem, 4.5vw, 2.25rem);
  font-weight: 700;
  letter-spacing: 0.01em;
  margin-bottom: 0.5rem;
}

.home-subtitle {
  color: rgba(255, 255, 255, 0.88);
  font-size: 0.9375rem;
  max-width: 640px;
  margin: 0 auto;
}

.resume-banner {
  margin: 1.25rem auto 0;
  max-width: 560px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: var(--radius-lg);
  padding: 0.65rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.resume-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
}

.resume-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 8px #4ade80;
}

.section-container {
  margin-top: 1.5rem;
}

.section-header-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
}

.section-subheading {
  font-family: var(--font-legal);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary);
}

.section-hint {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.quickstart-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.9rem;
}

.quickstart-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
  position: relative;
}

.quickstart-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
  border-color: var(--accent);
}

.quickstart-card-accent {
  background: linear-gradient(180deg, #fffdf6 0%, #fbf5e2 100%);
  border-color: #e3cd87;
}

.quickstart-card .card-icon {
  font-size: 1.85rem;
  line-height: 1;
  margin-bottom: 0.25rem;
}

.quickstart-card .card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary);
}

.quickstart-card .card-desc {
  font-size: 0.8125rem;
  color: var(--text-muted);
  flex: 1;
}

.quickstart-card .card-cta {
  margin-top: 0.4rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--primary-light);
}

.info-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.9rem;
  margin-top: 1.5rem;
}

.info-card {
  background: var(--card-bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
}

.info-icon {
  font-size: 1.5rem;
  line-height: 1;
  flex-shrink: 0;
}

.info-card h3 {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 0.2rem;
}

.info-card p {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* ==========================================================================
   CARDS & ACCORDIONS
   ========================================================================== */

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

details.accordion-card {
  margin-bottom: 1rem;
  overflow: hidden;
}

summary.accordion-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.95rem 1.15rem;
  cursor: pointer;
  list-style: none;
  font-weight: 700;
  color: var(--primary);
  font-size: 0.95rem;
  background: linear-gradient(180deg, #ffffff 0%, #fafbfc 100%);
  user-select: none;
  min-height: 52px;
}

summary.accordion-summary::-webkit-details-marker {
  display: none;
}

.summary-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.summary-pill {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-pill);
  background: var(--gray-100);
  color: var(--text-muted);
  margin-left: auto;
}

summary.accordion-summary::after {
  content: '▸';
  font-size: 1rem;
  color: var(--text-muted);
  transition: transform var(--transition);
  margin-left: 0.25rem;
}

details[open] > summary.accordion-summary::after {
  transform: rotate(90deg);
}

.accordion-body {
  padding: 1.1rem;
  border-top: 1px solid var(--border-soft);
}

/* ==========================================================================
   FORMS & TOUCH CONTROLS
   ========================================================================== */

.form-grid-2,
.form-grid-3 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
}

.form-grid-2-tight {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 0.5rem;
}

.form-group {
  margin-bottom: 0.85rem;
}

.form-grid-2 > .form-group,
.form-grid-3 > .form-group {
  margin-bottom: 0;
}

.form-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.35rem;
}

.form-control {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 0.55rem 0.8rem;
  font-size: 16px;
  line-height: 1.4;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-control:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(37, 87, 138, 0.16);
}

.form-control[readonly] {
  background: var(--gray-100);
}

textarea.form-control {
  min-height: 84px;
  resize: vertical;
}

select.form-control {
  cursor: pointer;
}

.form-fieldset {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 0.9rem;
  margin-top: 0.9rem;
  background: var(--gray-50);
}

.form-fieldset legend {
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--primary);
  padding: 0 0.45rem;
}

/* Toggle Switch */
.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  min-height: 44px;
  user-select: none;
}

.toggle-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  position: relative;
  width: 42px;
  height: 24px;
  background: #cbd5e1;
  border-radius: var(--radius-pill);
  flex-shrink: 0;
  transition: background-color var(--transition);
}

.toggle-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform var(--transition);
}

.toggle-input:checked + .toggle-track {
  background: var(--primary);
}

.toggle-input:checked + .toggle-track::after {
  transform: translateX(18px);
}

/* Repeater items (Prior Deeds / Amended Clauses) */
.repeater-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-bottom: 0.65rem;
}

.repeater-item {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.repeater-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

/* ==========================================================================
   PARTNER CARDS & SIGNATURE STUDIO
   ========================================================================== */

.partner-summary-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  background: var(--gray-50);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin-bottom: 1rem;
}

.summary-metric {
  text-align: center;
}

.metric-label {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.summary-metric strong {
  font-size: 0.95rem;
  color: var(--primary);
}

.partner-card {
  background: #fff;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-lg);
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.partner-card.collapsed .partner-card-body {
  display: none;
}

.partner-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--gray-50);
  border-bottom: 1px solid var(--border-soft);
  flex-wrap: wrap;
}

.partner-header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.partner-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--primary);
  color: var(--accent-light);
  font-weight: 700;
  font-size: 0.9rem;
}

.partner-name-preview {
  font-weight: 700;
  color: var(--text);
  font-size: 0.95rem;
}

.partner-header-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.partner-card-body {
  padding: 1rem;
}

.status-badge {
  display: inline-block;
  padding: 0.12rem 0.55rem;
  border-radius: var(--radius-pill);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.status-badge.continuing { background: var(--success-light); color: var(--success); }
.status-badge.incoming   { background: var(--info-light); color: var(--info); }
.status-badge.outgoing   { background: var(--warning-light); color: var(--warning); }

.remove-partner-btn {
  color: var(--danger);
  border-color: var(--border);
  background: #fff;
}

.remove-partner-btn:hover {
  background: var(--danger-light);
  border-color: var(--danger);
}

/* Signature Studio */
.sig-studio-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.sig-container {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 0.65rem;
  background: #fff;
  text-align: center;
}

.sig-canvas {
  border: 1px solid var(--border-soft);
  background: #fff;
  border-radius: var(--radius-sm);
  margin: 0 auto;
  touch-action: none;
  cursor: crosshair;
}

.sig-controls {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.55rem;
}

.sig-preview-box {
  min-height: 110px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background-color: #ffffff;
  background-image:
    linear-gradient(45deg, #f1f5f9 25%, transparent 25%),
    linear-gradient(-45deg, #f1f5f9 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f1f5f9 75%),
    linear-gradient(-45deg, transparent 75%, #f1f5f9 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
}

.sig-upload-preview {
  max-width: 260px;
  max-height: 95px;
  object-fit: contain;
}

.witness-sig-preview-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.threshold-slider {
  width: 100%;
  accent-color: var(--primary);
  height: 24px;
  cursor: pointer;
}

/* Floating PSR Badge */
#psr-badge {
  position: fixed;
  bottom: calc(var(--bottom-nav-h) + 12px);
  right: 14px;
  z-index: 950;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: #fff;
  border: 2px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 0.4rem 0.9rem;
  font-size: 0.8125rem;
  font-weight: 700;
  box-shadow: var(--shadow);
}

#psr-badge.psr-ok {
  border-color: var(--success);
  color: var(--success);
  background: #f0fdf4;
}

#psr-badge.psr-error {
  border-color: var(--danger);
  color: var(--danger);
  background: #fef2f2;
}

/* ==========================================================================
   CUSTOMIZER & VARIABLE TAG CHIPS
   ========================================================================== */

.optional-chips-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.chip-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.38rem 0.75rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--gray-50);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.chip-toggle input {
  accent-color: var(--primary);
}

.chip-toggle:has(input:checked) {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--primary-dark);
}

.var-tags-panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
}

.var-tags-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
  font-size: 0.8125rem;
}

.var-tags-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.var-tag-btn {
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: var(--primary);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.73rem;
  font-weight: 600;
  padding: 0.25rem 0.55rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}

.var-tag-btn:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.clause-item {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem;
  margin-bottom: 0.75rem;
  box-shadow: var(--shadow-sm);
}

.clause-item.clause-disabled {
  opacity: 0.58;
  background: var(--gray-50);
}

.clause-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  margin-bottom: 0.55rem;
  flex-wrap: wrap;
}

.clause-header-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 200px;
}

.clause-num {
  font-weight: 700;
  color: var(--primary);
  font-size: 0.9rem;
}

.clause-heading-input {
  flex: 1;
  min-width: 140px;
  font-weight: 700;
  color: var(--primary);
  border: 1px solid transparent;
  background: transparent;
  padding: 0.25rem 0.45rem;
  border-radius: var(--radius-sm);
}

.clause-heading-input:focus {
  border-color: var(--border);
  background: #fff;
  outline: none;
}

.clause-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-pill);
  background: var(--accent-bg);
  color: #7c5c00;
  border: 1px solid #e3cd87;
}

.clause-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.clause-text-area {
  width: 100%;
  min-height: 92px;
  padding: 0.6rem;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  font-family: var(--font-legal);
  font-size: 0.92rem;
  line-height: 1.5;
  resize: vertical;
  outline: none;
}

.clause-text-area:focus {
  border-color: var(--primary-light);
}

/* ==========================================================================
   LIVE A4 PREVIEW & EXPORT TOOLBAR
   ========================================================================== */

.preview-sticky-header {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  overflow: hidden;
}

.preview-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-soft);
}

.toolbar-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}

.preview-controls {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.7rem 1rem;
  background: var(--gray-50);
}

.margin-slider-group {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.preview-toggles-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

#a4-wrapper {
  overflow-x: auto;
  background: #64748b;
  padding: 1.25rem 0.75rem;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  min-height: 60vh;
}

.a4-page {
  width: 210mm;
  min-height: 297mm;
  background: #fff;
  margin: 0 auto;
  padding: 20mm 22mm 22mm 26mm;
  font-family: var(--font-legal);
  font-size: var(--deed-font-size);
  line-height: var(--deed-line-height);
  text-align: justify;
  color: #111;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.32);
  transform-origin: top left;
}

.fit-screen #a4-wrapper {
  overflow-x: hidden;
}

.deed-heading {
  text-align: center;
  font-weight: 700;
  font-size: 14.5pt;
  text-transform: uppercase;
  text-decoration: underline;
  letter-spacing: 0.04em;
  margin-bottom: 0.35em;
}

.deed-subheading {
  text-align: center;
  font-weight: 700;
  font-size: 11.5pt;
  margin-bottom: 1.4em;
  color: #222;
}

.deed-para {
  margin-bottom: 1em;
  text-align: justify;
}

.deed-clause-title {
  font-weight: 700;
  text-transform: uppercase;
  font-size: 11.5pt;
  margin-bottom: 0.25em;
}

.deed-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.85em 0;
  font-size: 10.5pt;
  text-align: left;
}

.deed-table th,
.deed-table td {
  border: 1px solid #111;
  padding: 5px 8px;
  vertical-align: top;
}

.deed-table th {
  background: #f3f1e9;
  font-weight: 700;
  text-align: center;
}

.sig-table td {
  text-align: center;
  vertical-align: bottom;
  padding: 12px 8px;
}

.deed-sig-img {
  max-width: 135px;
  max-height: 55px;
  margin: 0 auto 6px;
  object-fit: contain;
}

.deed-sig-line {
  width: 135px;
  height: 44px;
  border-bottom: 1px solid #111;
  margin: 0 auto 6px;
}

.deed-footer-initials {
  margin-top: 2em;
  padding-top: 0.65em;
  border-top: 1px dashed #999;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: flex-end;
  gap: 1.25rem;
  font-size: 9pt;
}

.footer-initial-item {
  text-align: center;
}

.footer-initial-item img {
  max-width: 72px;
  max-height: 28px;
  margin: 0 auto 2px;
  object-fit: contain;
}

/* ==========================================================================
   ANCILLARY TOOLS (FORM 94 & STAMP GENERATOR)
   ========================================================================== */

.sub-tab-nav {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.sub-tab-btn {
  flex: 1;
  min-width: 180px;
  min-height: 46px;
  padding: 0.6rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--text-muted);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.sub-tab-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.tools-action-bar {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-bottom: 0.9rem;
  flex-wrap: wrap;
}

.form94-sheet {
  background: #fff;
  border: 2px solid #1e293b;
  border-radius: var(--radius-sm);
  padding: 1.25rem;
  font-family: var(--font-legal);
  box-shadow: var(--shadow);
}

.form94-header-box {
  position: relative;
  text-align: center;
  border-bottom: 2px solid #1e293b;
  padding-bottom: 0.85rem;
  margin-bottom: 1rem;
}

.form94-badge {
  position: absolute;
  top: 0;
  right: 0;
  background: var(--primary);
  color: var(--accent-light);
  font-family: var(--font-ui);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-sm);
}

.form94-title {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.form94-subtitle {
  font-size: 0.95rem;
  font-weight: 700;
  margin-top: 0.2rem;
}

.form94-act-ref {
  font-size: 0.82rem;
  color: #475569;
  font-style: italic;
}

.form94-section {
  border: 1px solid #94a3b8;
  padding: 0.75rem;
  margin-bottom: 0.85rem;
}

.form94-label {
  display: block;
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--primary);
  margin-bottom: 0.45rem;
}

.ao-code-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.6rem;
}

.ao-field label {
  display: block;
  font-family: var(--font-ui);
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.ao-input {
  text-align: center;
  font-family: ui-monospace, monospace;
  font-weight: 700;
  text-transform: uppercase;
}

.char-boxes {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
}

.char-box {
  width: 24px;
  height: 28px;
  border: 1px solid #1e293b;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: ui-monospace, monospace;
  font-weight: 700;
  font-size: 0.9rem;
  background: #fff;
}

.char-sep {
  display: inline-flex;
  align-items: center;
  padding: 0 3px;
  font-weight: 700;
}

.table-scroll {
  overflow-x: auto;
}

.form94-verify-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.form94-sig-box {
  border: 1px dashed #64748b;
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 130px;
}

.sig-embed-box img {
  max-width: 180px;
  max-height: 80px;
  margin: 0.4rem auto 0;
  object-fit: contain;
}

.doc-checklist-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.45rem;
  font-family: var(--font-ui);
  font-size: 0.85rem;
}

.checklist-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

/* Stamp Generator */
.stamp-studio-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.stamp-previews-col {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.stamp-card-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 0.75rem;
  text-align: center;
}

.stamp-canvas-bg {
  background: var(--gray-50);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  justify-content: center;
  align-items: center;
}

.stamp-canvas {
  background: transparent;
}

.color-swatches-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.color-swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.color-swatch.selected {
  border-color: var(--accent);
  transform: scale(1.1);
}

/* ==========================================================================
   BUTTONS
   ========================================================================== */

.btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 44px;
  padding: 0.55rem 1.05rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn:active { transform: scale(0.98); }

.btn-sm {
  min-height: 36px;
  padding: 0.38rem 0.75rem;
  font-size: 0.8rem;
}

.btn-icon {
  min-width: 36px;
  min-height: 36px;
  padding: 0.3rem;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-accent {
  background: var(--accent);
  color: var(--primary-dark);
  border-color: var(--accent);
}
.btn-accent:hover { background: var(--accent-light); }

.btn-outline {
  background: #fff;
  color: var(--text);
  border-color: var(--border);
}
.btn-outline:hover { background: var(--gray-50); border-color: var(--primary-light); }

.btn-outline-primary {
  background: #fff;
  color: var(--primary);
  border-color: var(--primary);
}
.btn-outline-primary:hover { background: var(--primary); color: #fff; }

.btn-danger {
  background: var(--danger);
  color: #fff;
}

/* ==========================================================================
   TOAST, LOADING & iOS TIP
   ========================================================================== */

#toast {
  position: fixed;
  bottom: calc(var(--bottom-nav-h) + 18px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-pill);
  background: var(--primary-dark);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  max-width: 92vw;
}

#toast.toast-success { background: var(--success); }
#toast.toast-error   { background: var(--danger); }
#toast.toast-warning { background: var(--warning); }
#toast.toast-info    { background: var(--primary); }

#loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.85);
  z-index: 9998;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

#ios-install-tip {
  position: fixed;
  bottom: calc(var(--bottom-nav-h) + 12px);
  left: 50%;
  transform: translateX(-50%);
  width: min(92vw, 360px);
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  text-align: center;
  box-shadow: var(--shadow-lg);
  z-index: 9997;
}

.ios-tip-close {
  position: absolute;
  top: 8px;
  right: 10px;
  border: none;
  background: none;
  font-size: 1rem;
  cursor: pointer;
  color: var(--text-muted);
}

.ios-tip-heading {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary);
  margin: 0.25rem 0;
}

.ios-tip-text {
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* ==========================================================================
   UTILITY HELPERS
   ========================================================================== */

.w-full { width: 100%; }
.mb-0 { margin-bottom: 0 !important; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.p-4  { padding: 1rem; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.items-center { align-items: center; }
.gap-2 { gap: 0.5rem; }
.text-xs { font-size: 0.75rem; }
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-center { text-align: center; }
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 700;
}
.badge-accent { background: var(--accent-bg); color: var(--primary-dark); border: 1px solid #e3cd87; }
.badge-info   { background: var(--info-light); color: var(--info); }

/* ==========================================================================
   RESPONSIVE BREAKPOINTS
   ========================================================================== */

@media (min-width: 768px) {
  :root { --bottom-nav-h: 0px; }
  body { padding-bottom: 0; }
  #top-nav { display: flex; }
  #bottom-nav { display: none; }
  #app-main { padding: 1.5rem; }

  .quickstart-grid { grid-template-columns: repeat(2, 1fr); }
  .info-grid       { grid-template-columns: repeat(3, 1fr); }
  .form-grid-2     { grid-template-columns: repeat(2, 1fr); }
  .form-grid-3     { grid-template-columns: repeat(3, 1fr); }
  .sig-studio-grid { grid-template-columns: 1.1fr 0.9fr; }
  .form94-verify-grid { grid-template-columns: 1.3fr 0.7fr; }
  .doc-checklist-grid { grid-template-columns: repeat(2, 1fr); }
  .stamp-studio-grid  { grid-template-columns: 1fr 1.2fr; }
  #psr-badge { bottom: 18px; right: 20px; }
  #toast { bottom: 24px; }
}

@media (min-width: 1024px) {
  .desktop-only { display: inline-flex; }
  .quickstart-grid { grid-template-columns: repeat(3, 1fr); }

  /* Split-Screen Desktop Mode */
  body.split-mode #app-main {
    max-width: 100%;
    padding: 1rem 1.25rem;
  }

  body.split-mode #workspace-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
    align-items: start;
  }

  body.split-mode #workspace-split #variables,
  body.split-mode #workspace-split #customizer,
  body.split-mode #workspace-split #preview {
    max-height: calc(100vh - var(--top-nav-h) - 2rem);
    overflow-y: auto;
    padding-right: 0.25rem;
  }

  body.split-mode #workspace-split #preview {
    display: block !important;
  }
}

/* ==========================================================================
   PRINT STYLES
   ========================================================================== */

@media print {
  body {
    padding: 0 !important;
    background: #fff !important;
  }

  #top-nav,
  #bottom-nav,
  #file-protocol-banner,
  .page-top-bar,
  .preview-sticky-header,
  .sub-tab-nav,
  .tools-action-bar,
  .no-print,
  #psr-badge,
  #toast,
  #loading-overlay,
  #ios-install-tip {
    display: none !important;
  }

  #app-main {
    max-width: 100% !important;
    padding: 0 !important;
  }

  body:not(.printing-form94) #home,
  body:not(.printing-form94) #variables,
  body:not(.printing-form94) #customizer,
  body:not(.printing-form94) #tools {
    display: none !important;
  }

  body:not(.printing-form94) #preview {
    display: block !important;
  }

  body.printing-form94 #home,
  body.printing-form94 #variables,
  body.printing-form94 #customizer,
  body.printing-form94 #preview,
  body.printing-form94 #stamp-gen {
    display: none !important;
  }

  body.printing-form94 #tools,
  body.printing-form94 #form94 {
    display: block !important;
  }

  #a4-wrapper {
    background: transparent !important;
    padding: 0 !important;
    overflow: visible !important;
  }

  .a4-page {
    width: 100% !important;
    min-height: auto !important;
    margin: 0 !important;
    box-shadow: none !important;
    transform: none !important;
  }

  .form94-sheet {
    border: 1.5px solid #000 !important;
    box-shadow: none !important;
    padding: 10mm !important;
  }

  .deed-para, .deed-table tr {
    page-break-inside: avoid;
  }

  @page {
    size: A4;
    margin: 12mm;
  }
}
