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

:root {
    --primary: #0071e3;
    --primary-hover: #0077ed;
    --bg: #f5f5f7;
    --card-bg: rgba(255, 255, 255, 0.8);
    --text: #1d1d1f;
    --text-secondary: #86868b;
    --border: #d2d2d7;
    --success: #28cd41;
    --warning: #ff9f0a;
    --danger: #ff3b30;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --glass: none;
    --card-bg-solid: rgba(255, 255, 255, 1);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--card-bg-solid);
    padding: 1.5rem;
    border-radius: 20px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 600;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
}

.photo-previews {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
}

.photo-preview {
    width: 80px;
    height: 80px;
    border-radius: 12px;
    object-fit: cover;
    border: 2px solid var(--border);
    box-shadow: var(--shadow);
}

/* Photo Gallery in View Modal */
.photo-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.photo-item {
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
    border-radius: 12px;
    border: 1px solid var(--border);
    cursor: pointer;
    background: #000;
}

.photo-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.photo-item:hover img {
    transform: scale(1.05);
}

.zoom-icon {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    opacity: 0.8;
}

@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
        /* Keep 3 columns on mobile */
        gap: 0.5rem;
        /* Reduce gap on mobile */
    }

    /* Modern List Layout for Mobile Repairs */
    .table-responsive {
        overflow: visible;
        /* Allow cards to show shadows */
        width: 100%;
        margin: 0;
        padding: 0;
    }

    .stat-card {
        padding: 0.8rem 0.5rem;
        /* Smaller padding */
        border-radius: 12px;
        align-items: center;
        /* Center content for better look */
        text-align: center;
    }

    .stat-label {
        font-size: 0.65rem;
        /* Smaller font for labels */
    }

    .stat-value {
        font-size: 0.9rem;
        /* Smaller font for values to fit numbers */
    }
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

body.modal-open {
    overflow: hidden !important;
    height: 100vh;
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 3000;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal-content {
    background-color: #ffffff;
    margin: 2rem auto;
    padding: 2.5rem;
    border-radius: 32px;
    width: 92%;
    max-width: 650px;
    position: relative;
    box-shadow: 0 30px 60px -12px rgba(0, 0, 0, 0.25);
    box-sizing: border-box;
    overflow-x: hidden;
    border: 1px solid rgba(0, 0, 0, 0.05);
    opacity: 0;
    will-change: transform, opacity;
    animation: modalAppear 0.3s cubic-bezier(0.165, 0.84, 0.44, 1) forwards;
}

@keyframes modalAppear {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-content h2 {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -0.022em;
    margin-bottom: 2rem;
    color: #1d1d1f;
}

.modal-content h3 {
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.015em;
    margin-top: 1.5rem;
    margin-bottom: 1rem;
    color: #1d1d1f;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem;
    gap: 1rem;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-logo img {
    border-radius: 12px;
}

h1 {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.btn {
    padding: 0.75rem 1.5rem;
    border-radius: 980px;
    border: none;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: scale(1.02);
}

.btn-secondary {
    background: var(--card-bg);
    color: var(--text);
    border: 1px solid var(--border);
}

.card {
    background: var(--card-bg-solid);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}

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

.card-header input {
    max-width: 300px;
}

/* Table Styles */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
}

th {
    text-align: left;
    padding: 1rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
}

td {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

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

.status-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 100px;
    font-size: 0.8rem;
    font-weight: 600;
}

/* Statuses */
.status-pending {
    background: #e3f2fd;
    color: #1976d2;
}

.status-work {
    background: #fff3e0;
    color: #ef6c00;
}

.status-parts {
    background: #f3e5f5;
    color: #7b1fa2;
}

.status-ready {
    background: #e8f5e9;
    color: #2e7d32;
}

.status-issued {
    background: #eee;
    color: #666;
}

/* Form Styles */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

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

label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    font-weight: 500;
}

input,
textarea,
select {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.5);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--primary);
}



.signature-container {
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    background: #fff;
    margin-bottom: 0.5rem;
}

#signature-pad {
    width: 100%;
    height: 200px;
    display: block;
    cursor: crosshair;
    touch-action: none;
}

.signature-buttons {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.form-actions {
    margin-top: 2rem;
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

/* Responsive Info Grid in View Modal */
.repair-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

@media (max-width: 600px) {
    .repair-info-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
}

/* Status Picker (Mobile Optimized) */
.status-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0.8rem 0;
}

.status-chip {
    padding: 0.8rem 1rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: #f5f5f7;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    flex: 1 1 calc(50% - 0.5rem);
    text-align: center;
}

.status-chip.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(0, 113, 227, 0.25);
}

.status-chip:active {
    transform: scale(0.96);
}

.rules-box {
    background: #f8f8f8;
    padding: 1rem;
    border-radius: 12px;
    font-size: 0.85rem;
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border);
}

.rules-box h3 {
    margin-bottom: 0.5rem;
}

.rules-box p {
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    header {
        flex-direction: row;
        align-items: center;
    }

    .header-logo h1 {
        font-size: 1.5rem;
    }

    .header-logo p {
        font-size: 0.8rem;
    }

    .header-logo img {
        height: 40px !important;
    }

    .card-header {
        flex-direction: column;
        align-items: stretch;
    }

    .card-header input {
        max-width: 100%;
    }

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

    /* Modern List Layout for Mobile Repairs */
    #repairs-table {
        display: block;
        min-width: 0;
        /* Override global table min-width to prevent scrolling */
        width: 100%;
    }

    #repairs-table thead,
    #repairs-table tbody,
    #repairs-table th,
    #repairs-table td,
    #repairs-table tr {
        display: block;
    }

    #repairs-table thead {
        display: none;
    }

    /* Hide headers on mobile */

    /* Compact Mobile Card Design */
    #repairs-table tr {
        background: #fff;
        border-radius: 18px;
        margin-bottom: 1rem;
        padding: 1rem;
        border: 1px solid var(--border);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02);
        display: flex;
        flex-direction: column;
        gap: 0.25rem;
        height: auto;
        min-height: 0;
    }

    #repairs-table td {
        padding: 0;
        border: none;
        display: block;
        width: 100%;
        height: auto;
        min-height: 0;
    }

    /* Row 1: ID and Status */
    #repairs-table td[data-label="№"] {
        order: 1;
        font-size: 0.8rem;
        color: var(--text-secondary);
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 0.25rem;
    }

    #repairs-table td[data-label="№"]:after {
        content: attr(data-status);
        /* We will need to add this attribute in JS if possible, or move status here via flex absolute? easier to just reorder */
    }

    /* Let's use Flexbox ordering to rearrange visual layout efficiently */

    /* Top Row: Date (Left) and Status (Right) */
    #repairs-table td[data-label="Дата"] {
        order: 1;
        font-size: 0.75rem;
        color: var(--text-secondary);
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 0.5rem;
    }

    /* Inject Status badge into the Date row visual line using absolute positioning or just standard flow? 
       Actually, let's keep it simple. Stack key info.
    */

    /* Device Model - Big and Bold */
    #repairs-table td[data-label="Модель"] {
        order: 2;
        font-size: 1.1rem;
        font-weight: 700;
        color: #1d1d1f;
        margin-bottom: 0.2rem;
    }

    /* Client Name */
    #repairs-table td[data-label="Клієнт"] {
        order: 3;
        font-size: 0.95rem;
        color: #1d1d1f;
        margin-bottom: 0.8rem;
    }

    /* Status and ID Row */
    #repairs-table td[data-label="Статус"] {
        order: 4;
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 0.8rem;
    }

    #repairs-table td[data-label="Статус"]:after {
        content: "";
        display: none;
    }

    /* Actually reusing standard cells is better */
    #repairs-table td[data-label="Статус"] {
        order: 4;
        margin-bottom: 1rem;
    }

    #repairs-table td[data-label="Дії"] {
        order: 5;
        border-top: 1px solid #f5f5f7;
        padding-top: 0.8rem;
    }

    #repairs-table td[data-label="Дії"] .btn {
        width: 100%;
        justify-content: center;
        background: #f5f5f7;
        color: #0071e3;
        border: none;
        font-weight: 600;
    }

    /* Hide redundant cells if needed, or style them minimal */
    #repairs-table td[data-label="№"] {
        display: none;
    }

    /* Show ID nicely elsewhere if needed, or keep it */

    /* Let's try a very clean layout:
       [Model Name            StatusBadge]
       [Client Name                      ]
       [Date                  Reference #]
       [View Button                      ]
    */

    .modal {
        padding: 0;
    }

    .modal-content {
        padding: 2rem;
        border-radius: 32px !important;
        margin: 1.5rem auto;
        min-height: auto;
    }

    .form-actions {
        flex-direction: column;
    }

    .form-actions .btn {
        width: 100%;
        justify-content: center;
    }
}