:root {
    --primary-color: #0f172a;
    --primary-light: #334155;
    --secondary-color: #2563eb;
    --secondary-hover: #1d4ed8;
    --accent-color: #10b981;
    --danger-color: #ef4444;
    --background-color: #f1f5f9;
    --card-bg: rgba(255, 255, 255, 0.85);
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border-color: rgba(226, 232, 240, 0.8);
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.05);
    --shadow-md: 0 10px 15px -3px rgba(0,0,0,0.05), 0 4px 6px -2px rgba(0,0,0,0.025);
    --shadow-lg: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-full: 9999px;
    --nav-height: 70px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Rubik', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--background-color);
    background-image: radial-gradient(circle at top right, #e0e7ff 0%, transparent 40%),
                      radial-gradient(circle at bottom left, #dcfce7 0%, transparent 40%);
    background-attachment: fixed;
    color: var(--text-main);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Typography & Utilities */
h1, h2, h3 { color: var(--primary-color); margin-bottom: 1rem; font-weight: 600; }
.hidden { display: none !important; }
.text-center { text-align: center; }

/* Header */
.app-header {
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: white;
    padding: 1rem 2rem;
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 50;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.app-header h1 {
    color: white;
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

nav {
    display: flex;
    gap: 0.5rem;
}

.nav-btn { flex-direction: column; gap: 0.2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.7);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-full);
    cursor: pointer;
    font-weight: 500;
    font-size: 0.95rem;
    transition: all 0.3s ease;
}

.nav-btn:hover {
    color: white;
    background: rgba(255,255,255,0.1);
}

.nav-btn.active {
    color: white;
    background: var(--secondary-color);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.nav-btn .material-symbols-outlined {
    font-size: 1.25rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 600;
    font-size: 1rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-align: center;
}

.btn-primary {
    background: linear-gradient(135deg, var(--secondary-color), var(--secondary-hover));
    color: white;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.3);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary:disabled {
    background: var(--text-muted);
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background-color: white;
    border: 1px solid var(--border-color);
    color: var(--text-main);
    box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
    border-color: #cbd5e1;
    background-color: #f8fafc;
}

.btn-outline {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
}

.btn-outline:hover {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.5);
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.btn-large {
    width: 100%;
    padding: 1rem;
    font-size: 1.125rem;
    border-radius: var(--radius-lg);
}

/* Layout */
#app-container {
    flex: 1;
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 1rem;
    width: 100%;
}

.card {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.5);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem;
    margin-bottom: 2rem;
    animation: fadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Auth Cards */
.auth-card {
    max-width: 500px;
    margin: 4rem auto;
}

/* Tabs */
.tabs, .admin-tabs {
    display: flex;
    margin-bottom: 2rem;
    background: rgba(241, 245, 249, 0.8);
    padding: 0.5rem;
    border-radius: var(--radius-md);
    gap: 0.5rem;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: calc(var(--radius-md) - 4px);
    transition: all 0.2s ease;
}

.tab-btn:hover { 
    color: var(--primary-color); 
    background: rgba(255,255,255,0.5);
}

.tab-btn.active {
    color: var(--secondary-color);
    background: white;
    box-shadow: var(--shadow-sm);
}

/* Forms */
.input-group {
    margin-bottom: 1.5rem;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--primary-light);
    font-size: 0.9rem;
}

.input-group input, .input-group select {
    width: 100%;
    padding: 1rem;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
    transition: all 0.2s ease;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.02);
}

.input-group input:focus, .input-group select:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 4px rgba(37, 130, 246, 0.1);
}

/* Action Toggle */
.action-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    margin-bottom: 2.5rem;
    padding: 1.5rem;
    background: linear-gradient(to right, rgba(241,245,249,0.8), rgba(255,255,255,0.8));
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 64px;
    height: 36px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--accent-color);
    transition: .4s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 36px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

.slider:before {
    position: absolute;
    content: "";
    height: 28px;
    width: 28px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

input:checked + .slider { background-color: var(--secondary-color); }
input:checked + .slider:before { transform: translateX(28px); }

.action-label {
    font-size: 1.25rem;
    font-weight: 700;
    transition: color 0.3s;
}
.action-label.take { color: var(--accent-color); }
.action-label.return { color: var(--secondary-color); }

/* Equipment Grid */
.equipment-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}

.equipment-item {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem 1rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: white;
    position: relative;
    overflow: hidden;
}

.equipment-item::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    border: 2px solid transparent;
    border-radius: var(--radius-lg);
    transition: border-color 0.3s;
    pointer-events: none;
}

.equipment-item:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
}

.equipment-item.selected {
    background-color: #eff6ff;
}

.equipment-item.selected::after {
    border-color: var(--secondary-color);
}

.equipment-item img {
    width: 80px;
    height: 80px;
    object-fit: contain;
    margin-bottom: 1rem;
    border-radius: var(--radius-md);
    transition: transform 0.3s;
}

.equipment-item:hover img {
    transform: scale(1.05);
}

.item-quantity-control {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 1rem;
    background: var(--background-color);
    border-radius: var(--radius-full);
    padding: 0.25rem;
}

.qty-btn {
    background: white;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-weight: bold;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qty-btn:hover { background: var(--secondary-color); color: white; }
.item-qty { font-weight: bold; width: 40px; text-align: center; }

/* Serial Input */
.serial-input-container {
    margin-top: 0.75rem;
}
.serial-input-container input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    text-align: center;
}

/* Signature */
.signature-section {
    margin-bottom: 2.5rem;
    background: rgba(248, 250, 252, 0.5);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
}

.canvas-container {
    border: 2px dashed #cbd5e1;
    border-radius: var(--radius-md);
    background: #fff;
    margin-bottom: 1rem;
    overflow: hidden;
    position: relative;
    transition: border-color 0.3s;
}

.canvas-container:hover {
    border-color: var(--secondary-color);
}

#signature-pad, canvas[id$="-pad"] {
    width: 100%;
    height: 250px;
    touch-action: none;
}

/* Tables (Responsive without extra wrapper) */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.data-table th, .data-table td {
    padding: 1rem;
    text-align: right;
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    background-color: #f8fafc;
    font-weight: 600;
    color: var(--primary-light);
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tbody tr {
    transition: background-color 0.2s;
}

.data-table tbody tr:hover {
    background-color: #f8fafc;
}

.data-table img {
    width: 50px;
    height: 50px;
    object-fit: contain;
    border-radius: var(--radius-md);
    background: #f1f5f9;
    padding: 4px;
}

.sig-image-small {
    width: 80px;
    height: 40px;
    object-fit: contain;
    border: 1px dashed var(--border-color);
    border-radius: 4px;
    padding: 2px;
}

/* Modals */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 900;
    animation: modalFadeIn 0.3s ease-out;
    padding: 1rem;
}

@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--card-bg);
    padding: 2.5rem;
    border-radius: var(--radius-lg);
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
    width: 100%;
    max-width: 550px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    animation: modalSlideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalSlideUp {
    from { opacity: 0; transform: translateY(30px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: var(--background-color);
}
::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Loading & Notifications */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255,255,255,0.85);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 4px solid var(--border-color);
    border-top-color: var(--secondary-color);
    border-radius: 50%;
    animation: spin 1s cubic-bezier(0.55, 0.15, 0.45, 0.85) infinite;
    margin-bottom: 1.5rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.notification {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary-color);
    color: white;
    padding: 1rem 2rem;
    border-radius: var(--radius-full);
    box-shadow: 0 10px 25px -5px rgba(0,0,0,0.2);
    z-index: 1001;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    animation: notifSlideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.notification.success { background: var(--accent-color); }
.notification.error { background: var(--danger-color); }

@keyframes notifSlideUp {
    from { opacity: 0; transform: translate(-50%, 40px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

/* Mobile Adjustments */
@media (max-width: 768px) {
    .app-header {
        padding: 0.5rem 1rem;
    }
    
    .header-content {
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 0.2rem;
    }

    #app-container {
        padding-bottom: calc(var(--nav-height) + 2rem);
    }

    /* Move nav to bottom for mobile */
    nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        border-top: 1px solid var(--border-color);
        padding: 0.5rem;
        display: flex;
        justify-content: space-around;
        box-shadow: 0 -4px 15px rgba(0,0,0,0.05);
        z-index: 90;
        padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
        height: var(--nav-height);
    }

    .nav-btn { flex-direction: column; gap: 0.2rem;
        flex-direction: column;
        color: var(--text-muted);
        font-size: 0.75rem;
        padding: 0.5rem;
        gap: 0.25rem;
        border-radius: var(--radius-md);
        flex: 1;
    }
    
    .nav-btn .material-symbols-outlined {
        font-size: 1.5rem;
    }

    .nav-btn:hover {
        background: transparent;
        color: var(--secondary-color);
    }

    .nav-btn.active {
        background: transparent;
        color: var(--secondary-color);
        box-shadow: none;
    }
    
    .nav-btn.btn-outline {
        border: none;
    }

    .card { 
        padding: 1.5rem; 
        margin-bottom: 1.5rem;
    }
    
    .equipment-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }

    /* Table horizontal scrolling for mobile */
    .data-table {
        display: block;
        width: 100%;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }
    
    .modal-content {
        padding: 1.5rem;
    }
    
    .action-toggle {
        flex-direction: column;
        gap: 1rem;
    }
}

/* For very small phones */
@media (max-width: 380px) {
    .equipment-grid {
        grid-template-columns: 1fr;
    }
    .nav-btn .nav-text {
        display: none;
    }
}

/* Print Styles */
@media print {
    body * { visibility: hidden !important; }
    #print-view-container, #print-view-container * { visibility: visible !important; }
    #print-view-container {
        display: block !important;
        position: absolute; left: 0; top: 0; width: 100%;
        padding: 20px; background: white;
    }
    .print-header { text-align: center; margin-bottom: 2rem; border-bottom: 2px solid #000; padding-bottom: 1rem; }
    .print-table { width: 100%; border-collapse: collapse; margin-bottom: 2rem; }
    .print-table th, .print-table td { border: 1px solid #ccc; padding: 8px; text-align: right; }
    .print-table th { background-color: #f1f5f9 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .print-signature-img { max-height: 50px; max-width: 150px; }
    .page-break { page-break-before: always; }
}
/* Desktop: hide nav-label, show nav-text */
.nav-label { display: none; }
.nav-text { display: inline; }

/* Mobile (<=768px): show nav-label, hide nav-text */
@media (max-width: 768px) {
    .nav-label { display: block; font-size: 0.75rem; font-weight: 500; font-family: 'Rubik', sans-serif; }
    .nav-text { display: none !important; }
}
