/* ========================================
   SIGNFLOW — DARK GLASSMORPHISM UI
   Mobile-first, 4px grid, clamp fonts
   ======================================== */

/* --- RESET & VARIABLES --- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg-base: #06070b;
    --bg-surface: #0c0d14;
    --bg-elevated: #12131a;
    --bg-glass: rgba(18, 19, 26, 0.65);
    --bg-glass-hover: rgba(18, 19, 26, 0.8);
    --border-glass: rgba(255, 255, 255, 0.06);
    --border-glass-hover: rgba(255, 255, 255, 0.1);
    --border-input: rgba(255, 255, 255, 0.08);
    --border-input-focus: var(--accent);

    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #475569;
    --text-inverse: #0f172a;

    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-subtle: rgba(59, 130, 246, 0.12);
    --success: #22c55e;
    --success-subtle: rgba(34, 197, 94, 0.12);
    --warning: #f59e0b;
    --warning-subtle: rgba(245, 158, 11, 0.12);
    --danger: #ef4444;
    --danger-subtle: rgba(239, 68, 68, 0.12);

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);

    --font: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --fs-xs: clamp(0.6875rem, 0.5vw + 0.5rem, 0.75rem);
    --fs-sm: clamp(0.75rem, 0.6vw + 0.55rem, 0.875rem);
    --fs-base: clamp(0.875rem, 0.8vw + 0.6rem, 1rem);
    --fs-lg: clamp(1rem, 1vw + 0.65rem, 1.125rem);
    --fs-xl: clamp(1.125rem, 1.3vw + 0.7rem, 1.375rem);
    --fs-2xl: clamp(1.375rem, 2vw + 0.75rem, 1.75rem);
    --fs-3xl: clamp(1.75rem, 2.5vw + 0.8rem, 2.25rem);

    --transition: 200ms ease;
    --transition-slow: 320ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-spring: 400ms cubic-bezier(0.34, 1.56, 0.64, 1);
    --transition-bounce: 500ms cubic-bezier(0.22, 1, 0.36, 1);
}

html { scroll-behavior: smooth; }

/* --- KEYFRAMES --- */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

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

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes pulse-soft {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* --- REDUCED MOTION --- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

body {
    font-family: var(--font);
    font-size: var(--fs-base);
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-base);
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-hover); }

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

/* --- GLASS CARD --- */
.glass {
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: var(--shadow);
}

.glass:hover {
    border-color: var(--border-glass-hover);
}

/* --- LAYOUT --- */
.admin-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 240px;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-glass);
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform var(--transition);
}

.sidebar.open { transform: translateX(0); }

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 8px 24px;
    border-bottom: 1px solid var(--border-glass);
    margin-bottom: 24px;
}

.sidebar-brand img {
    height: 28px;
    width: auto;
}

.sidebar-brand span {
    font-size: var(--fs-lg);
    font-weight: 700;
    color: var(--text-primary);
}

.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 4px; }

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: var(--fs-sm);
    font-weight: 500;
    transition: all var(--transition);
    position: relative;
}

.sidebar-link::before {
    content: '';
    position: absolute;
    left: 0; top: 50%;
    width: 3px; height: 0;
    background: var(--accent);
    border-radius: 0 4px 4px 0;
    transform: translateY(-50%);
    transition: height var(--transition-spring);
}

.sidebar-link:hover,
.sidebar-link.active {
    color: var(--text-primary);
    background: var(--accent-subtle);
    transform: translateX(2px);
}

.sidebar-link.active { color: var(--accent); }
.sidebar-link.active::before { height: 20px; }

.sidebar-link svg {
    width: 18px; height: 18px;
    flex-shrink: 0;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sidebar-footer {
    padding-top: 16px;
    border-top: 1px solid var(--border-glass);
    margin-top: auto;
}

.main-content {
    flex: 1;
    min-height: 100vh;
    padding: 20px 16px;
    width: 100%;
    animation: fadeInUp 400ms var(--transition-bounce) both;
}

/* --- MOBILE NAV TOGGLE --- */
.nav-toggle {
    position: fixed;
    top: 12px; left: 12px;
    z-index: 60;
    width: 44px; height: 44px;
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    backdrop-filter: blur(16px);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-primary);
}

.nav-toggle svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.5; }

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 40;
    opacity: 0;
    visibility: hidden;
    transition: opacity 300ms ease, visibility 300ms ease;
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* --- TOP BAR (mobile) --- */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0 20px;
    margin-left: 48px;
}

.page-title {
    font-size: var(--fs-2xl);
    font-weight: 700;
    color: var(--text-primary);
    animation: slideInLeft 400ms var(--transition-bounce) both;
}

/* --- CARDS & PANELS --- */
.card {
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 24px;
    transition: border-color var(--transition), transform var(--transition-slow), box-shadow var(--transition-slow);
    animation: fadeInUp 400ms var(--transition-bounce) both;
}

.card:hover {
    border-color: var(--border-glass-hover);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.card-title {
    font-size: var(--fs-lg);
    font-weight: 600;
    color: var(--text-primary);
}

/* --- STATS ROW --- */
.stats-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius);
    padding: 16px;
    backdrop-filter: blur(16px);
    transition: transform var(--transition-slow), border-color var(--transition), box-shadow var(--transition-slow);
    animation: scaleIn 400ms var(--transition-bounce) both;
}

.stat-card:nth-child(1) { animation-delay: 50ms; }
.stat-card:nth-child(2) { animation-delay: 100ms; }
.stat-card:nth-child(3) { animation-delay: 150ms; }
.stat-card:nth-child(4) { animation-delay: 200ms; }

.stat-card:hover {
    transform: translateY(-2px);
    border-color: var(--border-glass-hover);
    box-shadow: var(--shadow);
}

.stat-value {
    font-size: var(--fs-2xl);
    font-weight: 700;
    color: var(--text-primary);
}

.stat-label {
    font-size: var(--fs-xs);
    color: var(--text-muted);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

/* --- FORMS --- */
.form-group { margin-bottom: 20px; }

.form-label {
    display: block;
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-input);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: var(--fs-base);
    transition: border-color 250ms ease, box-shadow 250ms ease, background 250ms ease;
    outline: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-subtle), 0 2px 8px rgba(59, 130, 246, 0.08);
    background: rgba(18, 19, 26, 0.9);
}

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

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
    padding-right: 40px;
}

.form-hint {
    font-size: var(--fs-xs);
    color: var(--text-muted);
    margin-top: 4px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

.form-check {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    cursor: pointer;
}

.form-check input[type="checkbox"] {
    width: 20px; height: 20px;
    margin-top: 2px;
    accent-color: var(--accent);
    flex-shrink: 0;
    transition: transform 150ms ease;
}

.form-check input[type="checkbox"]:checked {
    transform: scale(1.1);
}

.form-check input[type="checkbox"]:active {
    transform: scale(0.9);
}

/* --- BUTTONS --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: var(--fs-sm);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition), transform 120ms ease;
    text-decoration: none;
    white-space: nowrap;
    min-height: 44px;
    position: relative;
    overflow: hidden;
}

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

.btn svg {
    width: 16px; height: 16px;
    stroke: currentColor; fill: none;
    stroke-width: 2;
    transition: transform var(--transition);
}

.btn:hover svg {
    transform: translateX(1px);
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 0 0 0 rgba(59, 130, 246, 0);
}
.btn-primary:hover {
    background: var(--accent-hover);
    color: #fff;
    box-shadow: 0 4px 16px rgba(59, 130, 246, 0.25);
}

.btn-success {
    background: var(--success);
    color: #fff;
}
.btn-success:hover {
    background: #16a34a;
    color: #fff;
    box-shadow: 0 4px 16px rgba(34, 197, 94, 0.25);
}

.btn-danger {
    background: var(--danger-subtle);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
}
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-glass);
}
.btn-ghost:hover { background: var(--bg-glass); color: var(--text-primary); }

.btn-sm { padding: 8px 16px; font-size: var(--fs-xs); min-height: 36px; }

.btn-block { width: 100%; }

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* --- BADGES --- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 100px;
    font-size: var(--fs-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    transition: transform var(--transition);
}

.badge-draft { background: rgba(148,163,184,0.12); color: #94a3b8; }
.badge-sent { background: var(--accent-subtle); color: var(--accent); }
.badge-viewed { background: var(--warning-subtle); color: var(--warning); }
.badge-client-signed {
    background: rgba(168,85,247,0.12);
    color: #a855f7;
    animation: pulse-soft 2s ease-in-out infinite;
}
.badge-completed { background: var(--success-subtle); color: var(--success); }
.badge-expired { background: var(--danger-subtle); color: var(--danger); }
.badge-cancelled { background: rgba(148,163,184,0.08); color: #64748b; }

/* --- TABLE --- */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    padding: 12px 16px;
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border-glass);
}

td {
    padding: 14px 16px;
    font-size: var(--fs-sm);
    color: var(--text-secondary);
    border-bottom: 1px solid rgba(255,255,255,0.03);
}

tr:hover td { background: rgba(255,255,255,0.02); transition: background var(--transition); }

/* --- DOCUMENT LIST (mobile cards) --- */
.doc-cards { display: flex; flex-direction: column; gap: 12px; }

.doc-card {
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius);
    padding: 16px;
    display: block;
    color: inherit;
    transition: border-color var(--transition), transform var(--transition-slow), box-shadow var(--transition-slow);
    animation: fadeInUp 400ms var(--transition-bounce) both;
}

.doc-cards .doc-card:nth-child(1) { animation-delay: 0ms; }
.doc-cards .doc-card:nth-child(2) { animation-delay: 50ms; }
.doc-cards .doc-card:nth-child(3) { animation-delay: 100ms; }
.doc-cards .doc-card:nth-child(4) { animation-delay: 150ms; }
.doc-cards .doc-card:nth-child(5) { animation-delay: 200ms; }
.doc-cards .doc-card:nth-child(n+6) { animation-delay: 250ms; }

.doc-card:hover {
    border-color: var(--border-glass-hover);
    color: inherit;
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.doc-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.doc-card-ref {
    font-weight: 600;
    color: var(--text-primary);
    font-size: var(--fs-sm);
}

.doc-card-signer {
    font-size: var(--fs-sm);
    color: var(--text-secondary);
}

.doc-card-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
    font-size: var(--fs-xs);
    color: var(--text-muted);
}

/* --- FLASH MESSAGES --- */
.flash {
    padding: 14px 20px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    font-size: var(--fs-sm);
    font-weight: 500;
    animation: slideInDown 400ms var(--transition-bounce) both;
}

.flash-success { background: var(--success-subtle); color: var(--success); border: 1px solid rgba(34,197,94,0.2); }
.flash-error { background: var(--danger-subtle); color: var(--danger); border: 1px solid rgba(239,68,68,0.2); }

/* --- SIGNATURE PAD --- */
.sig-pad-wrap {
    background: #fff;
    border-radius: var(--radius);
    padding: 4px;
    max-width: 500px;
    animation: scaleIn 500ms var(--transition-bounce) both;
    transition: box-shadow var(--transition-slow);
}

.sig-pad-wrap:focus-within {
    box-shadow: 0 0 0 3px var(--accent-subtle);
}

.sig-pad-wrap canvas {
    display: block;
    width: 100%;
    height: 200px;
    border-radius: 8px;
    touch-action: none;
}

.sig-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

/* --- SIGNING PAGE (public) --- */
.signing-layout {
    max-width: 720px;
    margin: 0 auto;
    padding: 20px 16px;
    animation: fadeIn 500ms ease both;
}

.signing-header {
    text-align: center;
    padding: 24px 0 20px;
    animation: fadeInUp 500ms var(--transition-bounce) both;
}

.signing-header img { height: 32px; margin: 0 auto 12px; }

.signing-doc {
    background: #fff;
    color: #1e293b;
    border-radius: var(--radius);
    padding: 32px 24px;
    line-height: 1.7;
    font-size: var(--fs-base);
    animation: fadeInUp 500ms var(--transition-bounce) 100ms both;
    transition: box-shadow var(--transition-slow);
}

.signing-doc:hover {
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.3);
}

.signing-doc h2 { font-size: var(--fs-xl); margin: 24px 0 12px; color: #0f172a; }
.signing-doc h3 { font-size: var(--fs-lg); margin: 20px 0 8px; color: #1e293b; }
.signing-doc h4 { font-size: var(--fs-base); margin: 16px 0 8px; color: #334155; font-weight: 600; }
.signing-doc p { margin-bottom: 12px; }
.signing-doc ul, .signing-doc ol { margin: 0 0 12px 24px; }
.signing-doc li { margin-bottom: 4px; }
.signing-doc hr { border: none; border-top: 1px solid #e2e8f0; margin: 20px 0; }

.signing-form {
    margin-top: 24px;
    animation: fadeInUp 500ms var(--transition-bounce) 200ms both;
}

/* --- EMPTY STATE --- */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
    animation: fadeInUp 500ms var(--transition-bounce) both;
}

.empty-state svg {
    width: 48px; height: 48px;
    stroke: var(--text-muted);
    fill: none;
    margin: 0 auto 16px;
    opacity: 0.5;
    animation: fadeIn 600ms ease 200ms both;
}

.empty-state p { margin-bottom: 16px; }

/* --- RICH TEXT EDITOR OVERRIDES --- */
.ql-toolbar.ql-snow {
    background: var(--bg-elevated) !important;
    border-color: var(--border-input) !important;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0 !important;
}

.ql-container.ql-snow {
    background: var(--bg-elevated) !important;
    border-color: var(--border-input) !important;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm) !important;
    color: var(--text-primary) !important;
    font-family: var(--font) !important;
    font-size: var(--fs-base) !important;
    min-height: 200px;
}

.ql-editor { min-height: 200px; }
.ql-editor p { margin-bottom: 4px; }
.ql-editor h2 { margin-top: 16px; margin-bottom: 8px; }
.ql-editor h3 { margin-top: 12px; margin-bottom: 4px; }
.ql-editor h4 { margin-top: 8px; margin-bottom: 4px; }
.ql-editor ul, .ql-editor ol { margin-bottom: 4px; }
.ql-editor.ql-blank::before { color: var(--text-muted) !important; }
.ql-snow .ql-stroke { stroke: var(--text-secondary) !important; }
.ql-snow .ql-fill { fill: var(--text-secondary) !important; }
.ql-snow .ql-picker-label { color: var(--text-secondary) !important; }
.ql-snow .ql-picker-options { background: var(--bg-elevated) !important; border-color: var(--border-input) !important; }

/* --- UTILITY --- */
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.gap-3 { gap: 12px; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: var(--fs-sm); }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none; }

/* ========================================
   RESPONSIVE — TABLET+
   ======================================== */
@media (min-width: 768px) {
    .sidebar {
        transform: translateX(0);
        position: fixed;
    }

    .nav-toggle { display: none !important; }
    .sidebar-overlay { opacity: 0 !important; visibility: hidden !important; }

    .main-content {
        margin-left: 240px;
        padding: 32px;
    }

    .top-bar { margin-left: 0; }

    .stats-row { grid-template-columns: repeat(4, 1fr); }

    .form-row { grid-template-columns: 1fr 1fr; }

    .signing-doc { padding: 48px 40px; }
}

/* ========================================
   RESPONSIVE — DESKTOP
   ======================================== */
@media (min-width: 1024px) {
    .main-content { padding: 40px 48px; }
    .signing-layout { padding: 32px 20px; }
}

@media (min-width: 1280px) {
    .main-content { max-width: calc(100% - 240px); }
}
