/* ═══════════════════════════════════════════════════════════════
   MOBILE UI - PROFESSIONAL SOP GENERATOR
   Full styles for mobile interface
   ═══════════════════════════════════════════════════════════ */

/* ============ RESET & BASE ============ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --accent-gradient: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --primary-color: #667eea;
    --primary-dark: #5568d3;
    --accent-color: #f5576c;
    --bg-light: #f8f9fa;
    --text-dark: #2d3748;
    --text-medium: #4a5568;
    --text-light: #718096;
    --border-color: #e2e8f0;
    --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.15);
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 18px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-light);
    overflow-x: hidden;
    line-height: 1.6;
}

/* ============ PREMIUM MOBILE HEADER ============ */
.mobile-header {
    background: var(--primary-gradient);
    color: white;
    padding: 20px 18px 18px;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.3);
    position: relative;
    overflow: hidden;
}

.mobile-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('data:image/svg+xml,<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg"><defs><pattern id="grid" width="30" height="30" patternUnits="userSpaceOnUse"><path d="M 30 0 L 0 0 0 30" fill="none" stroke="rgba(255,255,255,0.08)" stroke-width="1"/></pattern></defs><rect width="100" height="100" fill="url(%23grid)"/></svg>');
    opacity: 0.5;
}

.header-content {
    position: relative;
    z-index: 1;
}

.mobile-header h1 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-badge {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    backdrop-filter: blur(10px);
}

.mobile-header p {
    font-size: 13px;
    opacity: 0.95;
    margin-bottom: 12px;
}

.header-badge {
    display: inline-block;
    background: rgba(255, 255, 255, 0.25);
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    backdrop-filter: blur(10px);
}

/* ============ TAB NAVIGATION ============ */
.tab-navigation {
    display: flex;
    background: white;
    position: sticky;
    top: 116px;
    z-index: 999;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    border-radius: 0 0 20px 20px;
}

.tab-btn {
    flex: 1;
    padding: 16px;
    border: none;
    background: transparent;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-medium);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.tab-btn::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--primary-gradient);
    transform: scaleX(0);
    transition: transform 0.3s;
}

.tab-btn.active {
    color: var(--primary-color);
    background: linear-gradient(180deg, rgba(102, 126, 234, 0.05) 0%, transparent 100%);
}

.tab-btn.active::after {
    transform: scaleX(1);
}

.tab-btn:active {
    transform: scale(0.95);
}

/* ============ CONTENT ============ */
.mobile-content {
    padding: 18px;
    padding-bottom: 100px;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
    animation: slideIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

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

/* ============ PREMIUM CARDS ============ */
.card {
    background: white;
    border-radius: var(--radius-md);
    padding: 20px;
    margin-bottom: 18px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    transition: all 0.3s;
}

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

.card-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-dark);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--border-color);
}

.card-title::before {
    content: '';
    width: 4px;
    height: 22px;
    background: var(--primary-gradient);
    border-radius: 2px;
    box-shadow: 0 0 10px rgba(102, 126, 234, 0.4);
}

/* ============ FORM ELEMENTS ============ */
.form-group {
    margin-bottom: 16px;
}

label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-medium);
    margin-bottom: 8px;
    letter-spacing: 0.2px;
}

input[type="text"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-family: inherit;
    background: white;
    color: var(--text-dark);
    transition: all 0.3s;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    background: linear-gradient(180deg, rgba(102, 126, 234, 0.02) 0%, white 100%);
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
}

select {
    appearance: none;
    background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 14 14"><path fill="%23667eea" d="M7 10L2 5h10z"/></svg>');
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 42px;
    cursor: pointer;
}

textarea {
    resize: vertical;
    min-height: 110px;
    line-height: 1.6;
}

/* ============ EXPANDABLE SECTIONS ============ */
.expandable {
    margin-bottom: 14px;
}

.expandable-header {
    background: var(--bg-light);
    padding: 16px;
    border-radius: var(--radius-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.3s;
    user-select: none;
}

.expandable-header:active {
    transform: scale(0.98);
}

.expandable.open .expandable-header {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1), rgba(118, 75, 162, 0.1));
    border-color: var(--primary-color);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.expandable-header h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-dark);
}

.expand-icon {
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    color: var(--primary-color);
    font-size: 20px;
    font-weight: bold;
}

.expandable.open .expand-icon {
    transform: rotate(180deg);
}

.expandable-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.expandable.open .expandable-content {
    max-height: 600px;
    padding: 16px;
    border: 2px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    background: white;
}

/* ============ TOGGLE SWITCHES (FIXED) ============ */
.toggle-list {
    display: grid;
    gap: 12px;
}

.toggle-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: var(--bg-light);
    border-radius: var(--radius-sm);
    border: 2px solid transparent;
    transition: all 0.3s;
}

.toggle-item.active {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1), rgba(118, 75, 162, 0.1));
    border-color: var(--primary-color);
}

.toggle-item label {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-dark);
    cursor: pointer;
}

.toggle-switch {
    position: relative;
    width: 52px;
    height: 30px;
}

.toggle-switch input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 100%;      /* ✅ FULL WIDTH */
    height: 100%;     /* ✅ FULL HEIGHT */
    top: 0;
    left: 0;
    z-index: 10;      /* ✅ ABOVE SLIDER */
    cursor: pointer;
    margin: 0;
}

.toggle-switch .slider {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #ccc;
    transition: 0.4s;
    border-radius: 30px;
    pointer-events: none;  /* ✅ LET CLICKS PASS THROUGH */
}

.toggle-switch .slider::before {
    position: absolute;
    content: "";
    height: 24px;
    width: 24px;
    left: 3px;
    bottom: 3px;
    background: white;
    transition: 0.4s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-switch input:checked + .slider {
    background: var(--primary-gradient);
}

.toggle-switch input:checked + .slider::before {
    transform: translateX(22px);
}

/* ============ BOTTOM ACTION BAR ============ */
.bottom-action-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    padding: 14px 18px;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.12);
    display: flex;
    gap: 12px;
    z-index: 1000;
    border-top: 1px solid var(--border-color);
}

.action-btn {
    flex: 1;
    padding: 16px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.action-btn:active {
    transform: scale(0.96);
}

.btn-primary {
    background: var(--primary-gradient);
    color: white;
    box-shadow: 0 4px 14px rgba(102, 126, 234, 0.4);
}

.btn-primary:active {
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.btn-secondary {
    background: linear-gradient(135deg, #6c757d 0%, #5a6268 100%);
    color: white;
    box-shadow: 0 4px 14px rgba(108, 117, 125, 0.3);
}

.btn-secondary:active {
    box-shadow: 0 2px 8px rgba(108, 117, 125, 0.2);
}

/* ============ PREVIEW ============ */
#preview-wrapper {
    margin: 0 -20px;
    padding: 20px;
    background: #f0f3f7;
    border-radius: var(--radius-md);
}

#preview {
    background: white;
    padding: 20px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    min-height: 400px;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-light);
}

.empty-state-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 15px;
    line-height: 1.8;
}

/* ============ CREDIT BADGE ============ */
.credit-badge {
    text-align: center;
    padding: 24px;
    margin-top: 20px;
    background: white;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.credit-badge p {
    font-size: 13px;
    color: var(--text-medium);
    margin-bottom: 6px;
}

.credit-badge a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 700;
    font-size: 15px;
}

.credit-badge a:active {
    opacity: 0.7;
}

/* ============ SUBSECTION TITLE ============ */
.subsection-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--primary-color);
    margin: 20px 0 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border-color);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* ============ SAFE ZONE (iPhone X+) ============ */
@supports(padding: max(0px)) {
    .mobile-header {
        padding-top: max(20px, env(safe-area-inset-top));
        padding-left: max(18px, env(safe-area-inset-left));
        padding-right: max(18px, env(safe-area-inset-right));
    }

    .bottom-action-bar {
        padding-bottom: max(14px, env(safe-area-inset-bottom));
    }
}

/* ============ LANDSCAPE MODE ============ */
@media (max-width: 768px) and (orientation: landscape) {
    .mobile-header {
        padding: 12px 16px;
    }

    .mobile-header h1 {
        font-size: 18px;
    }

    .tab-btn {
        padding: 12px;
        font-size: 13px;
    }
}

/* ============ PRINT STYLES FOR MOBILE ============ */
@media print {
    body {
        visibility: hidden !important;
    }

    #preview, #preview * {
        visibility: visible !important;
    }

    /* ✅ Reset all mobile wrappers */
    body, html, .mobile-content, .tab-panel {
        margin: 0 !important;
        padding: 0 !important;
        position: static !important;
    }

    .card {
        padding: 0 !important;
        margin: 0 !important;
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
        position: static !important;
    }

    .card-title {
        display: none !important;
    }

    #preview-wrapper {
        margin: 0 !important;
        padding: 0 !important;
        background: transparent !important;
        position: static !important;
    }

    /* ✅ KEY FIX: Absolute positioning bypasses ALL wrapper spacing */
    #preview {
        position: absolute !important;  /* ← CHANGED from static */
        top: 0 !important;              /* ← ADDED */
        left: 0 !important;             /* ← ADDED */
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;          /* ← CHANGED from 20mm */
        background: white !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        box-sizing: border-box !important;
    }

    @page {
        size: A4;
        margin: 20mm;  /* ← CHANGED from 0 */
    }
}
