/* ==================== SmoovSign - Digital Signature System ==================== */
:root {
    --primary: #2563eb;
    --primary-light: #dbeafe;
    --primary-dark: #1d4ed8;
    --success: #16a34a;
    --success-light: #dcfce7;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --text: #1e293b;
    --text-light: #64748b;
    --text-muted: #94a3b8;
    --bg: #f1f5f9;
    --card: #ffffff;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 14px;
    --font: 'Heebo', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; direction: rtl; }
input, select, textarea, button { font-family: var(--font); }

/* ==================== Top Bar ==================== */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px; height: 56px; background: var(--card);
    border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 100;
}
.topbar-right { display: flex; align-items: center; gap: 20px; }
.topbar-left { display: flex; align-items: center; gap: 8px; }
.topbar-nav { display: flex; gap: 4px; }
.logo { display: flex; align-items: center; gap: 8px; }
.logo-svg { flex-shrink: 0; border-radius: 6px; }
.logo-text { font-weight: 800; font-size: 1.1em; color: var(--primary); letter-spacing: -0.5px; }
.nav-btn {
    padding: 6px 16px; border-radius: 8px; border: none; background: none;
    font-weight: 600; font-size: 0.88em; cursor: pointer; color: var(--text-light);
    transition: all 0.15s;
}
.nav-btn:hover { background: var(--bg); color: var(--text); }
.nav-btn.active { background: var(--primary-light); color: var(--primary); }

/* Mobile menu button - hidden on desktop */
.mobile-menu-btn {
    display: none; background: none; border: none; padding: 6px;
    cursor: pointer; color: var(--text-light); border-radius: 6px;
}
.mobile-menu-btn:hover { background: var(--bg); color: var(--text); }

/* Mobile dropdown menu */
.mobile-menu {
    position: fixed; top: 56px; left: 0; right: 0; background: var(--card);
    border-bottom: 1px solid var(--border); box-shadow: var(--shadow-lg);
    z-index: 99; padding: 8px; animation: slideDown 0.2s ease;
}
.mobile-menu.hidden { display: none; }
.mobile-menu-item {
    display: flex; align-items: center; gap: 10px; width: 100%; padding: 12px 16px;
    border: none; background: none; border-radius: 8px; font-family: var(--font);
    font-size: 0.95em; font-weight: 600; color: var(--text); cursor: pointer;
    text-decoration: none; transition: background 0.15s;
}
.mobile-menu-item:hover { background: var(--bg); }
.mobile-menu-divider { height: 1px; background: var(--border); margin: 4px 12px; }

@keyframes slideDown { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

/* Hide on mobile helper */
.hide-mobile { }

/* ==================== Buttons ==================== */
.btn {
    display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px;
    border-radius: var(--radius-sm); border: none; font-weight: 600;
    font-size: 0.88em; cursor: pointer; transition: all 0.15s; white-space: nowrap;
}
.btn:hover { opacity: 0.9; transform: translateY(-1px); }
.btn:active { transform: scale(0.97); opacity: 0.85; transition: none; }
.btn-primary { background: var(--primary); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-outline { background: var(--card); border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-ghost { background: none; color: var(--text-light); }
.btn-ghost:hover { color: var(--text); background: var(--bg); }
.btn-sm { padding: 5px 12px; font-size: 0.82em; }
.btn-lg { padding: 12px 24px; font-size: 1em; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ==================== Dashboard ==================== */
.dashboard { max-width: 1100px; margin: 0 auto; padding: 24px; }
.dashboard-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.dashboard-header h1 { font-size: 1.5em; font-weight: 800; }
.dashboard-stats { display: flex; gap: 12px; margin-bottom: 24px; }
.stat-card {
    flex: 1; background: var(--card); border-radius: var(--radius); padding: 16px;
    border: 1px solid var(--border); box-shadow: var(--shadow);
}
.stat-card .stat-num { font-size: 1.8em; font-weight: 800; color: var(--primary); }
.stat-card .stat-label { font-size: 0.82em; color: var(--text-light); margin-top: 2px; }
.doc-list { display: flex; flex-direction: column; gap: 8px; }
.doc-card {
    display: flex; align-items: center; gap: 16px; padding: 16px;
    background: var(--card); border-radius: var(--radius); border: 1px solid var(--border);
    box-shadow: var(--shadow); cursor: pointer; transition: all 0.15s;
}
.doc-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.doc-thumb {
    width: 48px; height: 62px; background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius-sm); overflow: hidden; flex-shrink: 0;
}
.doc-thumb img { width: 100%; height: 100%; object-fit: cover; }
.doc-info { flex: 1; min-width: 0; }
.doc-info h3 { font-size: 0.95em; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-meta { font-size: 0.78em; color: var(--text-light); margin-top: 3px; }
.doc-progress { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.progress-bar { flex: 1; max-width: 140px; height: 4px; background: var(--bg); border-radius: 2px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 2px; transition: width 0.3s; }
.doc-status { font-size: 0.72em; font-weight: 700; }
.doc-actions { display: flex; gap: 4px; }

/* Status colors */
.status-complete { color: var(--success); }
.status-pending { color: var(--warning); }
.status-waiting { color: var(--text-muted); }

/* ==================== Empty State ==================== */
.empty-state {
    text-align: center; padding: 80px 20px; color: var(--text-light);
}
.empty-state svg { margin-bottom: 16px; }
.empty-state h2 { font-size: 1.2em; font-weight: 700; margin-bottom: 6px; color: var(--text); }
.empty-state p { font-size: 0.88em; margin-bottom: 20px; }

/* ==================== Wizard (Create/Edit Document) ==================== */
.wizard { display: flex; flex-direction: column; height: calc(100vh - 56px); background: var(--bg); }
.wizard-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 24px; background: var(--card); border-bottom: 1px solid var(--border);
}
.wizard-stepper {
    display: flex; align-items: center; justify-content: center; gap: 0;
    padding: 12px 20px; background: var(--card); border-bottom: 1px solid var(--border);
}
.step-dot {
    width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center;
    justify-content: center; font-size: 0.78em; font-weight: 700; border: 2px solid var(--border);
    background: var(--card); color: var(--text-light); transition: all 0.2s;
}
.step-dot.active { background: var(--primary); color: white; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(37,99,235,0.15); }
.step-dot.done { background: var(--success); color: white; border-color: var(--success); cursor: pointer; }
.step-label { font-size: 0.72em; margin-top: 4px; white-space: nowrap; }
.step-label.active { color: var(--primary); font-weight: 600; }
.step-line { flex: 1; max-width: 80px; height: 2px; background: var(--border); }
.step-line.done { background: var(--primary); }
.wizard-body { flex: 1; overflow: hidden; }
.wizard-footer {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 24px; background: var(--card); border-top: 1px solid var(--border);
}

/* ==================== Step 1: Upload ==================== */
.upload-area {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    height: 100%; padding: 40px;
}
.upload-card {
    width: 100%; max-width: 600px; background: var(--card); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md); border: 1px solid var(--border); overflow: hidden; padding: 24px;
}
.upload-dropzone {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    height: 220px; border: 2px dashed var(--border); border-radius: var(--radius);
    cursor: pointer; transition: all 0.2s;
}
.upload-dropzone:hover { border-color: var(--primary); background: rgba(37,99,235,0.02); }
.upload-icon { background: var(--primary-light); padding: 14px; border-radius: 14px; margin-bottom: 14px; }
.file-preview {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px; background: var(--primary-light); border: 1px solid #93c5fd;
    border-radius: var(--radius); margin-bottom: 12px;
}
.doc-preview-img { border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; max-height: 400px; overflow-y: auto; margin-top: 12px; }
.doc-preview-img img { width: 100%; display: block; }

/* ==================== Step 2: Recipients ==================== */
.recipients-area { max-width: 700px; margin: 0 auto; padding: 24px; height: 100%; overflow-y: auto; }
.recipient-card {
    display: flex; align-items: center; gap: 12px; padding: 14px;
    background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
    border: 1px solid var(--border); margin-bottom: 8px;
}
.recipient-num { font-size: 1.5em; color: var(--border); width: 30px; text-align: center; font-weight: 300; }
.recipient-fields { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.input-wrap { position: relative; }
.input-wrap input, .input-wrap select {
    width: 100%; padding: 10px 36px 10px 10px; background: var(--bg);
    border: 1px solid var(--border); border-radius: 8px; font-family: var(--font); font-size: 0.88em;
}
.input-wrap input:focus, .input-wrap select:focus { outline: none; border-color: var(--primary); }
.input-icon { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.add-recipient-btn {
    width: 100%; padding: 14px; border: 2px dashed var(--border); border-radius: var(--radius);
    background: none; color: var(--text-light); font-weight: 600; cursor: pointer;
    font-family: var(--font); font-size: 0.9em; margin-top: 12px; transition: all 0.15s;
}
.add-recipient-btn:hover { border-color: var(--primary); color: var(--primary); }
.chip {
    display: inline-flex; align-items: center; gap: 4px; padding: 4px 12px;
    border-radius: 20px; font-size: 0.78em; font-weight: 600; cursor: pointer;
    border: 1px solid var(--border); background: var(--bg); transition: all 0.15s;
}
.chip:hover { border-color: var(--primary); background: var(--primary-light); }
.chip.added { background: var(--success-light); border-color: var(--success); color: var(--success); cursor: default; }

/* ==================== Step 3: Field Editor ==================== */
.editor { display: flex; height: 100%; overflow: hidden; }
.editor-sidebar {
    width: 220px; background: var(--card); border-left: 1px solid var(--border);
    display: flex; flex-direction: column; overflow-y: auto;
}
.editor-sidebar.sidebar-mini { width: 180px; }
.editor-canvas {
    flex: 1; overflow: auto; background: #e2e8f0; padding: 16px;
    display: flex; flex-direction: column; align-items: center;
}
.editor-tools {
    width: 220px; background: var(--card); border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
}
.tools-header { padding: 14px; border-bottom: 1px solid var(--border); }
.tools-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 14px; }
.tool-btn {
    display: flex; align-items: center; gap: 8px; padding: 10px;
    background: var(--primary-light); border: 1px solid #bfdbfe; border-radius: 8px;
    color: var(--primary); cursor: pointer; font-family: var(--font); font-weight: 600;
    font-size: 0.82em; transition: all 0.15s; text-align: right;
}
.tool-btn:hover { background: #bfdbfe; transform: translateY(-1px); }
.tool-btn:active { background: #93c5fd; transform: scale(0.96); transition: none; }
.tool-icon { background: white; padding: 4px 8px; border-radius: 6px; box-shadow: var(--shadow); }

/* Zoom controls */
.zoom-controls {
    position: sticky; top: 8px; z-index: 50; display: flex; align-items: center;
    gap: 4px; background: var(--card); border: 1px solid var(--border);
    border-radius: 8px; padding: 4px 8px; box-shadow: var(--shadow-md);
    margin-bottom: 12px; width: fit-content; align-self: center;
}
.zoom-btn {
    width: 30px; height: 30px; border: 1px solid var(--border); border-radius: 6px;
    background: var(--card); cursor: pointer; font-size: 1.1em; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    color: var(--text); transition: all 0.15s; font-family: var(--font);
}
.zoom-btn:hover { background: var(--bg); border-color: var(--primary); color: var(--primary); }
.zoom-label { font-size: 0.78em; font-weight: 700; color: var(--text-light); min-width: 40px; text-align: center; }

/* Document on canvas */
.doc-container {
    position: relative; background: white; box-shadow: var(--shadow-lg);
    width: 800px; flex-shrink: 0;
}
.doc-container img { width: 100%; display: block; pointer-events: none; user-select: none; }
.fields-layer { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }

/* Fields on document */
.field-box {
    position: absolute; cursor: move; touch-action: none; transition: box-shadow 0.1s;
}
.field-inner {
    width: 100%; height: 100%; border-radius: 3px; display: flex; align-items: center;
    justify-content: center; overflow: hidden; font-size: 0.8em; font-weight: 500;
}
.field-box:not(.selected) .field-inner { background: rgba(255,255,255,0.9); border: 1.5px dashed #6b7280; color: #374151; font-weight: 600; }
.field-box.selected .field-inner { border-width: 2px; border-style: solid; }
.field-label-tag {
    position: absolute; top: -24px; right: 0; color: white; font-size: 0.72em;
    padding: 2px 8px; border-radius: 5px 5px 0 0; font-weight: 700; white-space: nowrap; z-index: 30;
}
.field-toolbar {
    position: absolute; bottom: -32px; right: 0; background: #1e293b; color: white;
    border-radius: 8px; display: flex; align-items: center; gap: 2px;
    padding: 3px 6px; z-index: 50; box-shadow: var(--shadow-md);
}
.field-toolbar button {
    padding: 3px 5px; background: none; border: none; color: #94a3b8;
    cursor: pointer; font-size: 0.78em;
}
.field-toolbar button:hover { color: white; }
.resize-handle {
    position: absolute; width: 10px; height: 10px; background: white;
    border: 2px solid; border-radius: 50%; z-index: 40;
}

/* Field Props Panel */
.field-props { display: flex; flex-direction: column; height: 100%; }
.field-props-header {
    padding: 14px; border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
}
.field-props-body { padding: 14px; flex: 1; overflow-y: auto; }
.form-group { margin-bottom: 14px; }
.form-label { font-size: 0.72em; font-weight: 700; color: var(--text-light); display: block; margin-bottom: 4px; }
.form-input {
    width: 100%; padding: 10px; background: var(--bg); border: 1px solid var(--border);
    border-radius: 8px; font-family: var(--font); font-size: 0.88em;
}
.form-input:focus { outline: none; border-color: var(--primary); }

/* ==================== Step 4: Send ==================== */
.send-area { max-width: 750px; margin: 0 auto; padding: 24px; height: 100%; overflow-y: auto; }
.send-grid { display: grid; grid-template-columns: 1fr 2fr; gap: 20px; }
.send-card {
    background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
    border: 1px solid var(--border); padding: 18px;
}

/* ==================== Template Editor ==================== */
.template-card {
    display: flex; align-items: center; gap: 16px; padding: 16px;
    background: var(--card); border-radius: var(--radius); border: 1px solid var(--border);
    box-shadow: var(--shadow); margin-bottom: 8px; cursor: pointer; transition: all 0.15s;
}
.template-card:hover { box-shadow: var(--shadow-md); }
.template-icon {
    width: 48px; height: 48px; border-radius: var(--radius-sm); display: flex;
    align-items: center; justify-content: center; font-size: 1.5em; flex-shrink: 0;
}

/* ==================== Signing Page ==================== */
.sign-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 24px; background: var(--card); border-bottom: 1px solid var(--border);
}
.sign-body { flex: 1; overflow: auto; display: flex; position: relative; }
.sign-doc { flex: 1; overflow: auto; background: #e2e8f0; padding: 20px; display: flex; justify-content: center; align-items: flex-start; }
.sign-sidebar { width: 260px; background: var(--card); border-right: 1px solid var(--border); padding: 16px; overflow-y: auto; }
.sign-field {
    position: absolute; z-index: 10; border-radius: 4px; display: flex;
    align-items: center; justify-content: center; overflow: hidden;
    transition: box-shadow 0.15s, transform 0.1s;
}
.sign-field.mine { cursor: pointer; }
.sign-field.mine:hover { filter: brightness(0.92); box-shadow: 0 2px 8px rgba(0,0,0,0.15); }
.sign-field.mine:active { transform: scale(0.97); }

/* ==================== Signature Canvas Modal ==================== */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 9999;
    display: flex; align-items: center; justify-content: center;
}
.modal-card {
    background: var(--card); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
    width: 460px; max-width: 92vw; padding: 24px;
}
.sign-canvas {
    width: 100%; display: block; cursor: crosshair; touch-action: none;
    border: 2px solid var(--border); border-radius: 8px; background: white;
}

/* ==================== Toast ==================== */
.toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
    padding: 10px 24px; border-radius: var(--radius); font-weight: 600;
    font-size: 0.88em; z-index: 10000; box-shadow: var(--shadow-lg); transition: all 0.3s;
}
.toast.hidden { opacity: 0; pointer-events: none; transform: translateX(-50%) translateY(10px); }
.toast.success { background: var(--success); color: white; }
.toast.error { background: var(--danger); color: white; }
.toast.info { background: var(--primary); color: white; }

/* ==================== Color Themes for Recipients ==================== */
.color-blue { --fc-bg: #dbeafe; --fc-border: #3b82f6; --fc-text: #2563eb; --fc-fill: #3b82f6; }
.color-purple { --fc-bg: #f3e8ff; --fc-border: #a855f7; --fc-text: #9333ea; --fc-fill: #a855f7; }
.color-green { --fc-bg: #dcfce7; --fc-border: #22c55e; --fc-text: #16a34a; --fc-fill: #22c55e; }
.color-orange { --fc-bg: #ffedd5; --fc-border: #f97316; --fc-text: #ea580c; --fc-fill: #f97316; }

/* ==================== Badges ==================== */
.badge {
    display: inline-flex; align-items: center; padding: 2px 10px; border-radius: 20px;
    font-size: 0.72em; font-weight: 700; white-space: nowrap;
}
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-primary { background: var(--primary-light); color: var(--primary); }

/* ==================== Sign Progress Bar ==================== */
.sign-progress {
    position: relative; height: 28px; background: var(--bg);
    border-bottom: 1px solid var(--border); overflow: hidden;
}
.sign-progress-fill {
    height: 100%; background: linear-gradient(90deg, var(--primary), var(--success));
    transition: width 0.5s ease; border-radius: 0;
}
.sign-progress-label {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    font-size: 0.75em; font-weight: 700; color: var(--text); z-index: 1;
}

/* ==================== Completion Banner ==================== */
.completion-banner {
    display: flex; align-items: center; gap: 16px; padding: 16px 24px;
    background: linear-gradient(135deg, #16a34a, #059669); color: white;
    font-weight: 600; font-size: 0.95em;
}
.expiry-banner {
    padding: 10px 24px; background: var(--danger-light); color: var(--danger);
    font-weight: 600; font-size: 0.85em; text-align: center;
    border-bottom: 1px solid var(--danger);
}

/* ==================== Audit Panel ==================== */
.audit-panel {
    position: absolute; top: 0; left: 0; width: 360px; height: 100%;
    background: var(--card); border-left: 1px solid var(--border);
    box-shadow: var(--shadow-lg); z-index: 200; display: flex; flex-direction: column;
    animation: slideInLeft 0.2s ease;
}
.audit-panel.hidden { display: none; }
.audit-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 16px; border-bottom: 1px solid var(--border); font-size: 0.95em;
}
.audit-list { flex: 1; overflow-y: auto; padding: 8px; }
.audit-item {
    display: flex; align-items: flex-start; gap: 10px; padding: 10px;
    border-bottom: 1px solid var(--border);
}
.audit-icon { font-size: 1.1em; width: 24px; text-align: center; flex-shrink: 0; }
@keyframes slideInLeft { from { transform: translateX(-100%); } to { transform: translateX(0); } }

/* ==================== Mini Progress Bar ==================== */
.mini-progress { height: 3px; background: var(--bg); border-radius: 2px; overflow: hidden; }
.mini-progress-fill { height: 100%; border-radius: 2px; transition: width 0.3s; }

/* ==================== Recipient Status Card ==================== */
.recipient-status-card {
    padding: 10px; background: var(--bg); border-radius: 8px;
    margin-bottom: 8px; border: 1px solid var(--border);
}

/* ==================== Dashboard Enhancements ==================== */
.stat-card.clickable { cursor: pointer; transition: all 0.15s; }
.stat-card.clickable:hover { border-color: var(--primary); transform: translateY(-1px); }
.stat-card.stat-active { border-color: var(--primary); background: var(--primary-light); }
.dashboard-search { margin-bottom: 16px; }
.status-expired { color: var(--danger); }

/* ==================== Signer Verification Screen ==================== */
.verify-screen {
    display: flex; align-items: center; justify-content: center;
    min-height: calc(100vh - 56px); background: var(--bg); padding: 24px;
}
.verify-card {
    background: var(--card); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
    border: 1px solid var(--border); padding: 40px; max-width: 440px; width: 100%;
    text-align: center;
}
.verify-card h2 { font-size: 1.4em; font-weight: 800; margin-bottom: 8px; }
.verify-icon { margin-bottom: 20px; }
.verify-card .form-group { text-align: right; }

/* ==================== Pulse Animation for Field Highlight ==================== */
@keyframes fieldPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(37,99,235,0.4); }
    50% { box-shadow: 0 0 0 8px rgba(37,99,235,0); }
}
.sign-field.pulse { animation: fieldPulse 1s ease 2; }

/* ==================== Mobile Responsive ==================== */
@media (max-width: 768px) {
    .topbar { padding: 0 12px; }
    .topbar-left { gap: 4px; }
    .topbar-nav { display: none; }
    .hide-mobile { display: none !important; }
    .mobile-menu-btn { display: flex; }

    .dashboard { padding: 16px; }
    .dashboard-header { flex-direction: column; align-items: flex-start; gap: 10px; }
    .dashboard-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
    .stat-card { padding: 12px; }
    .stat-card .stat-num { font-size: 1.4em; }

    .doc-card { padding: 12px; gap: 10px; }
    .doc-thumb { width: 40px; height: 52px; }
    .doc-actions { flex-direction: column; }

    .send-grid { grid-template-columns: 1fr; }

    /* Field editor - stacked layout on mobile */
    .editor { flex-direction: column; }
    .editor-sidebar { width: 100%; max-height: 180px; border-left: none; border-top: 1px solid var(--border); order: 3; }
    .editor-tools { width: 100%; border-right: none; border-bottom: 1px solid var(--border); order: -1; max-height: none; }
    .tools-header { padding: 8px 12px; }
    .tools-header select { font-size: 0.82em; padding: 6px 10px; }
    .tools-grid { grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 8px; }
    .tool-btn { padding: 6px 4px; gap: 3px; font-size: 0.7em; flex-direction: column; text-align: center; }
    .tool-icon { padding: 3px 6px; font-size: 0.95em; }
    .editor-canvas { padding: 8px; overflow: auto; -webkit-overflow-scrolling: touch; }
    .doc-container { width: 100%; min-width: 320px; }
    .zoom-controls { margin-bottom: 8px; padding: 3px 6px; }
    .zoom-btn { width: 28px; height: 28px; font-size: 1em; }
    .zoom-label { font-size: 0.72em; min-width: 34px; }

    .recipient-fields { grid-template-columns: 1fr; }
    .recipient-card { padding: 10px; gap: 8px; }
    .recipients-area { padding: 16px; }

    /* Signing view - sidebar as compact bar on mobile */
    .sign-body { flex-direction: column; }
    .sign-sidebar { width: 100%; border-right: none; border-top: 1px solid var(--border); max-height: 100px; overflow-y: auto; padding: 8px 16px; }
    .sign-doc { padding: 10px; overflow: auto; -webkit-overflow-scrolling: touch; flex: 1; }
    .sign-doc-container { width: 800px !important; }
    .sign-header { padding: 10px 16px; }
    .sign-header h3 { font-size: 0.88em; max-width: 50vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

    .wizard-header { padding: 10px 16px; }
    .wizard-footer { padding: 10px 16px; }
    .wizard-stepper { padding: 8px 12px; }
    .step-dot { width: 26px; height: 26px; font-size: 0.7em; }
    .step-label { font-size: 0.65em; }
    .step-line { max-width: 40px; }

    .upload-area { padding: 20px; }
    .upload-card { padding: 16px; }
    .upload-dropzone { height: 160px; }
    .doc-preview-img { max-height: 300px; }

    .btn-lg { padding: 10px 18px; }

    .template-card { flex-wrap: wrap; }
    .template-card .doc-actions { width: 100%; justify-content: flex-end; }

    /* Signature modal */
    .modal-card { width: 95vw; padding: 16px; }
    .sign-canvas { height: 140px; }

    /* Field label/toolbar on mobile */
    .field-label-tag { font-size: 0.65em; top: -20px; padding: 2px 6px; }
    .field-toolbar { bottom: -28px; padding: 2px 4px; }
    .field-toolbar button { font-size: 0.72em; padding: 2px 4px; }

    /* Toast */
    .toast { bottom: 16px; max-width: 90vw; font-size: 0.82em; padding: 8px 18px; }

    /* Send area */
    .send-area { padding: 16px; }

    /* Audit panel */
    .audit-panel { width: 100%; }

    /* Completion banner */
    .completion-banner { padding: 12px 16px; gap: 12px; font-size: 0.88em; }
    .completion-banner svg { width: 28px; height: 28px; }

    /* Sign progress */
    .sign-progress { height: 24px; }
    .sign-progress-label { font-size: 0.68em; }

    /* Dashboard search */
    .dashboard-search input { max-width: 100% !important; }
}

/* Small phones */
@media (max-width: 400px) {
    .topbar { height: 48px; }
    .logo-svg { width: 26px; height: 26px; }
    .logo-text { font-size: 0.95em; }
    .btn-sm { padding: 4px 8px; font-size: 0.78em; }
    .dashboard { padding: 12px; }
    .dashboard-stats { grid-template-columns: 1fr 1fr; gap: 6px; }
    .stat-card .stat-num { font-size: 1.2em; }
    .stat-card .stat-label { font-size: 0.72em; }
    .tools-grid { grid-template-columns: repeat(3, 1fr); }
    .doc-card { flex-wrap: wrap; }
    .doc-card .doc-actions { width: 100%; margin-top: 4px; flex-direction: row; justify-content: flex-end; }
    .wizard-stepper { gap: 0; padding: 6px 8px; }
    .step-line { max-width: 24px; }
    .modal-card { padding: 12px; }
    .sign-canvas { height: 120px; }
    .editor-sidebar { max-height: 140px; }
}

/* ==================== LOGIN SCREEN ==================== */
.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(160deg, #f0f4ff 0%, #dbeafe 40%, #c7d8ff 70%, #bfdbfe 100%);
    padding: 20px;
    position: relative;
    overflow: hidden;
}

.login-screen::before {
    content: '';
    position: absolute;
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, rgba(37, 99, 235, 0.08) 0%, transparent 70%);
    top: -150px;
    right: -100px;
    border-radius: 50%;
}

.login-screen::after {
    content: '';
    position: absolute;
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, rgba(99, 102, 241, 0.06) 0%, transparent 70%);
    bottom: -100px;
    left: -80px;
    border-radius: 50%;
}

.login-card {
    background: #fff;
    border-radius: 24px;
    padding: 52px 44px 40px;
    text-align: center;
    box-shadow: 0 24px 64px rgba(37, 99, 235, 0.12), 0 0 0 1px rgba(37, 99, 235, 0.04);
    max-width: 420px;
    width: 100%;
    position: relative;
    z-index: 1;
}

.login-logo-wrap {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
    background: linear-gradient(135deg, #2563eb 0%, #4f46e5 100%);
    border-radius: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(37, 99, 235, 0.3);
}

.login-logo-wrap svg { filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1)); }

.login-card h1 {
    font-size: 30px;
    font-weight: 800;
    color: var(--text);
    margin: 0 0 6px;
    letter-spacing: -0.5px;
}

.login-card > p {
    color: var(--text-muted);
    margin: 0 0 36px;
    font-size: 16px;
    font-weight: 400;
}

.google-signin-btn {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 14px 36px;
    border: 2px solid #e5e7eb;
    border-radius: 14px;
    background: #fff;
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    transition: all 0.25s;
    font-family: inherit;
}

.google-signin-btn:hover {
    border-color: #2563eb;
    background: #f8faff;
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.18);
    transform: translateY(-1px);
}

.google-signin-btn:active { transform: translateY(0); }

.login-footer {
    margin-top: 28px;
    color: var(--muted);
    white-space: nowrap;
    font-size: 12px;
}

.login-footer small { font-size: inherit; }

.login-footer a { color: var(--primary); text-decoration: none; }
.login-footer a:hover { text-decoration: underline; }

/* ==================== USER MENU ==================== */
.user-menu {
    position: relative;
    margin-right: 8px;
}

.user-avatar-btn {
    background: none;
    border: 2px solid transparent;
    border-radius: 50%;
    padding: 2px;
    cursor: pointer;
    transition: border-color 0.2s;
}

.user-avatar-btn:hover { border-color: var(--primary); }

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.user-dropdown {
    position: absolute;
    left: 0;
    top: 100%;
    margin-top: 8px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.12);
    min-width: 220px;
    z-index: 1000;
    overflow: hidden;
}

.user-dropdown.hidden { display: none; }

.user-dropdown-info {
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.user-dropdown-info strong { font-size: 14px; color: var(--text); }
.user-dropdown-info small { font-size: 12px; color: var(--muted); }

.user-dropdown hr {
    margin: 0;
    border: none;
    border-top: 1px solid var(--border);
}

.user-dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 12px 16px;
    border: none;
    background: none;
    font-size: 14px;
    color: var(--text);
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
}

.user-dropdown-item:hover { background: #f3f4f6; }
