/* ============================================================
   TailorPro — Custom CSS (complements Tailwind)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ── Root variables ──────────────────────────────────────── */
:root {
    --navy:        #0f2340;
    --navy-mid:    #1a3356;
    --navy-light:  #1e3a5f;
    --gold:        #d4a017;
    --gold-light:  #f0c040;
    --gold-muted:  rgba(212,160,23,0.15);
    --bg:          #f1f5f9;
    --white:       #ffffff;
    --text:        #1e293b;
    --text-mid:    #64748b;
    --text-light:  #94a3b8;
    --border:      #e2e8f0;
    --success:     #10b981;
    --warning:     #f59e0b;
    --danger:      #ef4444;
    --radius:      0.75rem;
    --shadow:      0 4px 24px rgba(0,0,0,0.06);
    --shadow-lg:   0 8px 40px rgba(0,0,0,0.10);
}

/* ── Base ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
}

html {
    scroll-behavior: smooth;
}

/* ── Sidebar ─────────────────────────────────────────────── */
#sidebar {
    background: var(--navy);
    width: 256px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    /* Mobile: off-canvas */
    position: fixed;
    top: 0; left: 0; bottom: 0;
    height: 100vh;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    overflow: hidden; /* sidebar clips; inner nav handles scrolling */
}

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

/* Desktop: sidebar is fixed */
@media (min-width: 1024px) {
    #sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        height: 100vh;
        transform: translateX(0);
        flex-shrink: 0;
    }
    #main-wrapper {
        margin-left: 256px;
        width: calc(100% - 256px);
    }
}

/* Sidebar links */
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 0.875rem;
    border-radius: 0.5rem;
    color: var(--text-light);
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    transition: background 0.2s, color 0.2s;
    margin-bottom: 2px;
}

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

.sidebar-link.active {
    background: var(--gold-muted);
    color: var(--gold-light);
    border-left: 3px solid var(--gold);
    padding-left: calc(0.875rem - 3px);
}

.sidebar-link svg {
    flex-shrink: 0;
    width: 1.125rem;
    height: 1.125rem;
}

.sidebar-section-label {
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: rgba(255,255,255,0.25);
    padding: 1.25rem 0.875rem 0.35rem;
}

/* ── Overlay for mobile ──────────────────────────────────── */
#sidebarOverlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 25;
}

#sidebarOverlay.active {
    display: block;
}

/* ── Card ────────────────────────────────────────────────── */
.card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

/* ── Stat card ───────────────────────────────────────────── */
.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: transform 0.2s, box-shadow 0.2s;
}

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

/* ── Form elements ───────────────────────────────────────── */
.form-input {
    width: 100%;
    border: 1.5px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.625rem 0.875rem;
    font-size: 0.875rem;
    color: var(--text);
    background: var(--white);
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
    font-family: inherit;
}

.form-input:focus {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(212,160,23,0.12);
}

.form-input:disabled {
    background: #f8fafc;
    color: var(--text-mid);
    cursor: not-allowed;
}

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

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

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    text-decoration: none;
    transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
    white-space: nowrap;
    font-family: inherit;
}

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

.btn-primary {
    background: var(--navy-light);
    color: #fff;
}
.btn-primary:hover { background: var(--navy-mid); }

.btn-gold {
    background: var(--gold);
    color: #fff;
}
.btn-gold:hover { background: var(--gold-light); }

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

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

.btn-outline {
    background: transparent;
    border: 1.5px solid var(--border);
    color: var(--text-mid);
}
.btn-outline:hover { background: var(--bg); }

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-lg {
    padding: 0.875rem 2rem;
    font-size: 1rem;
}

/* ── Badge ───────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.badge-pending    { background: #fef3c7; color: #92400e; }
.badge-in_progress { background: #dbeafe; color: #1e40af; }
.badge-completed  { background: #d1fae5; color: #065f46; }
.badge-delivered  { background: #e0e7ff; color: #3730a3; }
.badge-paid       { background: #d1fae5; color: #065f46; }
.badge-partial    { background: #fef3c7; color: #92400e; }
.badge-unpaid     { background: #fee2e2; color: #991b1b; }
.badge-active     { background: #d1fae5; color: #065f46; }
.badge-inactive   { background: #f1f5f9; color: #64748b; }
.badge-scheduled  { background: #dbeafe; color: #1e40af; }
.badge-cancelled  { background: #fee2e2; color: #991b1b; }

/* ── Table ───────────────────────────────────────────────── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.data-table th {
    text-align: left;
    padding: 0.75rem 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-mid);
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table td {
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }

.data-table tr:hover td {
    background: #f8fafc;
}

/* ── Order card (add_customer repeatable block) ──────────── */
.order-block {
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    position: relative;
    margin-bottom: 1rem;
}

.order-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.order-number {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-mid);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.remove-order-btn {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 0.8rem;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}
.remove-order-btn:hover { background: #fee2e2; }

/* ── Measurements grid ───────────────────────────────────── */
.measurements-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

@media (min-width: 640px) {
    .measurements-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ── Payment summary bar ─────────────────────────────────── */
.payment-bar {
    height: 8px;
    background: var(--border);
    border-radius: 9999px;
    overflow: hidden;
    margin: 0.5rem 0;
}

.payment-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success), #34d399);
    border-radius: 9999px;
    transition: width 0.5s ease;
}

/* ── Alert flash ─────────────────────────────────────────── */
.flash-success {
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    color: #065f46;
    padding: 0.875rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.flash-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
    padding: 0.875rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: all;
}

.modal-box {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 480px;
    transform: scale(0.95);
    transition: transform 0.2s;
}

.modal-overlay.open .modal-box {
    transform: scale(1);
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    font-size: 1rem;
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-body { padding: 1.5rem; }

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* ── Print / Invoice styles ──────────────────────────────── */
@media print {
    body { background: #fff !important; font-family: 'Inter', sans-serif; }

    #sidebar,
    #sidebarOverlay,
    .no-print,
    button,
    .btn { display: none !important; }

    #main-wrapper { margin-left: 0 !important; flex: 1; }

    .invoice-print {
        max-width: 800px;
        margin: 0 auto;
    }

    .invoice-print * {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .page-break { page-break-before: always; }
}

/* ── Login page ──────────────────────────────────────────── */
.login-bg {
    min-height: 100vh;
    background: linear-gradient(135deg, #0f2340 0%, #1a3356 40%, #0f2340 100%);
    position: relative;
    overflow: hidden;
}

.login-bg::before {
    content: '';
    position: absolute;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(212,160,23,0.12) 0%, transparent 70%);
    top: -150px;
    right: -150px;
}

.login-bg::after {
    content: '';
    position: absolute;
    width: 400px;
    height: 400px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(30,58,95,0.4) 0%, transparent 70%);
    bottom: -100px;
    left: -100px;
}

.login-card {
    background: rgba(255,255,255,0.08);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 1.25rem;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

/* ── Misc utilities ──────────────────────────────────────── */
.text-gold { color: var(--gold); }
.bg-navy   { background: var(--navy); }
.divider   { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }

.section-title {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-mid);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--gold);
    display: inline-block;
}

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

/* Scroll fade on cards */
.card-scroll { overflow-y: auto; }

/* ============================================================
   RESPONSIVE — Mobile-first approach
   ============================================================ */

/* ── Responsive helper classes ──────────────────────────────── */
.responsive-grid-2 {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

.responsive-grid-3 {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

.responsive-sidebar-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.25rem;
}

/* ── Mobile base (up to 640px) ──────────────────────────────── */
@media (max-width: 639px) {
    /* Force everything to fit */
    html, body {
        font-size: 14px;
        overflow-x: hidden;
        overflow-x: clip; /* Modern reliable way to prevent horizontal scroll */
        width: 100%;
        max-width: 100vw;
    }

    #main-wrapper {
        width: 100%;
        max-width: 100%;
        overflow-x: visible;
    }

    main {
        padding: 0.75rem !important;
    }

    /* Top bar compact */
    header {
        padding: 0.625rem 0.75rem !important;
    }



    /* KPI stat cards - 2 per row */
    .stat-card {
        padding: 0.875rem;
    }

    .stat-card > div:first-child > div:first-child {
        width: 34px !important;
        height: 34px !important;
        border-radius: 8px !important;
    }

    /* Tables */
    .data-table {
        font-size: 0.8rem;
    }
    .data-table th {
        padding: 0.5rem 0.625rem;
        font-size: 0.65rem;
    }
    .data-table td {
        padding: 0.625rem;
        white-space: nowrap; /* Prevent wrapping to force horizontal scroll */
    }
    
    .table-wrap {
        width: 100% !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        display: block !important;
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-x; /* Help mobile browsers handle swipe */
        border-radius: 0 0 0.5rem 0.5rem;
        position: relative;
    }
    
    .data-table {
        min-width: 800px !important; /* Even wider to guarantee overflow */
        width: max-content;
        border-collapse: separate;
    }

    /* Cards */
    .card {
        border-radius: 0.5rem;
    }

    /* Buttons */
    .btn {
        padding: 0.5rem 0.875rem;
        font-size: 0.8125rem;
    }
    .btn-lg {
        padding: 0.75rem 1.5rem;
        font-size: 0.9rem;
    }
    .btn-sm {
        padding: 0.3rem 0.5rem;
        font-size: 0.75rem;
    }

    /* Forms */
    .form-input {
        padding: 0.5rem 0.75rem;
        font-size: 0.8125rem;
    }
    .form-label {
        font-size: 0.75rem;
    }

    /* Section title */
    .section-title {
        font-size: 0.7rem;
    }

    /* Order blocks */
    .order-block {
        padding: 0.875rem;
    }
    .order-block-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    /* Measurements grid - 2 cols on mobile */
    .measurements-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.5rem;
    }

    /* Modal */
    .modal-box {
        max-width: calc(100vw - 2rem);
        margin: 0 1rem;
    }
    .modal-header {
        padding: 1rem;
        font-size: 0.9rem;
    }
    .modal-body {
        padding: 1rem;
    }
    .modal-footer {
        padding: 0.75rem 1rem;
    }

    /* Flash messages */
    .flash-success, .flash-error {
        font-size: 0.8rem;
        padding: 0.625rem 0.75rem;
    }

    /* Badge */
    .badge {
        font-size: 0.6rem;
        padding: 0.15rem 0.4rem;
    }

    /* Invoice responsive */
    .inv-header {
        flex-direction: column;
        gap: 1rem;
        padding: 1.25rem 1rem !important;
    }
    .inv-type {
        text-align: left !important;
    }
    .inv-type h2 {
        font-size: 1.5rem !important;
    }
    .inv-body {
        padding: 1rem !important;
    }
    .inv-parties {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }
    .inv-table th,
    .inv-table td {
        padding: 0.5rem !important;
        font-size: 0.75rem !important;
    }
    .inv-totals {
        width: 100% !important;
    }
    .inv-footer {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem !important;
        text-align: center;
    }
    .inv-signature {
        text-align: center !important;
    }
    .inv-signature div {
        margin: 0 auto !important;
    }
    .action-bar {
        bottom: 0.75rem !important;
        right: 0.75rem !important;
        left: 0.75rem !important;
        justify-content: center;
    }
    .meas-grid {
        gap: 0.25rem !important;
    }
    .meas-chip {
        font-size: 0.65rem !important;
        padding: 0.15rem 0.35rem !important;
    }

    /* Login page */
    .login-card {
        padding: 1.5rem 1.25rem !important;
    }
}

/* ── Tablet and Mobile (up to 1023px) ────────────────────────── */
@media (max-width: 1023px) {
    /* Show hamburger when sidebar is hidden */
    #menuBtn {
        display: flex !important;
    }
}

/* ── Tablet and up (640px+) ─────────────────────────────────── */
@media (min-width: 640px) {
    .responsive-grid-2 {
        grid-template-columns: 1fr 1fr;
    }
    .responsive-grid-3 {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ── Tablet landscape (768px+) ──────────────────────────────── */
@media (min-width: 768px) {
    .responsive-sidebar-layout {
        grid-template-columns: 1fr auto;
    }
}

/* ── Desktop sidebar visible (1024px+) ─────────────────────── */
@media (min-width: 1024px) {
    #menuBtn {
        display: none !important;
    }
}

/* ── Print keeps full layout ────────────────────────────────── */
@media print {
    .inv-header {
        flex-direction: row !important;
    }
    .inv-parties {
        grid-template-columns: 1fr 1fr !important;
    }
}

