* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #f3f4f6;
    color: #111827;
    padding-bottom: 100px;
    overflow-y: scroll;
}

.safe-area-top {
    height: env(safe-area-inset-top, 0px);
    background: transparent;
}

header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 12px 16px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

header h1 {
    font-size: 24px;
    font-weight: bold;
    margin-bottom: 4px;
}

.tab-nav {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    overflow-x: auto;
    padding: 0 8px;
}

.tab-btn {
    padding: 8px 16px;
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    transition: all 0.2s;
}

.tab-btn.active {
    background: white !important;
    color: #667eea !important;
    transform: scale(1.05);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2) !important;
}

.tab-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.tab-btn:active {
    opacity: 0.8;
    transform: scale(0.98);
}

.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 16px;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.stats {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    background: white;
    border-radius: 12px;
    padding: 12px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.stat-card .number {
    font-size: 24px;
    font-weight: bold;
    color: #3b82f6;
}

.stat-card .label {
    font-size: 11px;
    color: #6b7280;
    margin-top: 4px;
    text-transform: uppercase;
}

.search-box {
    margin-bottom: 20px;
}

input[type="search"],
input[type="text"],
input[type="number"],
input[type="date"],
input[type="file"],
select {
    width: 100%;
    padding: 12px;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-size: 16px;
    font-family: inherit;
    margin-bottom: 12px;
}

input:focus,
select:focus {
    outline: none;
    border-color: #3b82f6;
}

.section-title {
    font-size: 14px;
    font-weight: bold;
    color: #6b7280;
    text-transform: uppercase;
    margin-top: 20px;
    margin-bottom: 12px;
    padding-left: 4px;
}

.item-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.item-card {
    background: white;
    border-radius: 10px;
    padding: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    transition: all 0.2s;
}

.item-card:active {
    transform: scale(0.98);
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.item-card.low-stock {
    border-left: 4px solid #ef4444;
}

.item-card.expired {
    border-left: 4px solid #d97706;
    opacity: 0.7;
}

.item-info {
    flex: 1;
}

.item-name {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 4px;
}

.item-meta {
    display: flex;
    gap: 12px;
    font-size: 12px;
    color: #6b7280;
}

.item-qty {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: 12px;
}

.qty-btn {
    width: 32px;
    height: 32px;
    border: 1px solid #d1d5db;
    background: white;
    border-radius: 6px;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qty-btn:active {
    background: #e5e7eb;
}

.qty-display {
    min-width: 40px;
    text-align: center;
    font-weight: bold;
}

.delete-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: #fee2e2;
    color: #dc2626;
    border-radius: 6px;
    cursor: pointer;
    margin-left: 8px;
}

.delete-btn:active {
    background: #fecaca;
}

.category-section {
    margin-bottom: 20px;
}

.category-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border-left: 4px solid #3b82f6;
    border-radius: 8px;
    margin-bottom: 12px;
    font-weight: 700;
    font-size: 16px;
    color: #0c4a6e;
}

.category-count {
    background: #3b82f6;
    color: white;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: bold;
}

.category-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-left: 4px;
}

.add-item-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, #3b82f6 0%, #1e40af 100%);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 28px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99;
}

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

.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: flex-end;
}

.modal.active {
    display: flex;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-content {
    background: white;
    width: 100%;
    border-radius: 20px 20px 0 0;
    padding: 20px;
    padding-bottom: max(20px, env(safe-area-inset-bottom, 0px));
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 16px;
}

.button-group {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

.btn {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}

.btn-primary {
    background: linear-gradient(135deg, #3b82f6 0%, #1e40af 100%);
    color: white;
}

.btn-primary:active {
    opacity: 0.9;
}

.btn-secondary {
    background: #e5e7eb;
    color: #111827;
}

.btn-secondary:active {
    background: #d1d5db;
}

.btn-success {
    background: #10b981;
    color: white;
}

.btn-success:active {
    background: #059669;
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #6b7280;
}

.empty-state .icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.warning-banner {
    background: #fef3c7;
    border: 1px solid #fcd34d;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 16px;
    display: flex;
    gap: 8px;
}

.warning-banner.danger {
    background: #fee2e2;
    border-color: #fecaca;
}

.tabs-inline {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.tab-toggle {
    flex: 1;
    padding: 10px;
    border: 2px solid #e5e7eb;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
}

.tab-toggle.active {
    background: #3b82f6;
    color: white;
    border-color: #3b82f6;
}

.form-section {
    display: none;
}

.form-section.active {
    display: block;
}

.loading {
    text-align: center;
    padding: 20px;
    color: #3b82f6;
}

.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #e5e7eb;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.product-result {
    background: #f0f9ff;
    border: 2px solid #bfdbfe;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
}

.product-result strong {
    display: block;
    margin-bottom: 4px;
}

.product-result small {
    color: #6b7280;
    display: block;
}

.member-card {
    background: white;
    border-radius: 10px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.member-name {
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 8px;
}

.member-info {
    font-size: 13px;
    color: #6b7280;
    line-height: 1.6;
}

#cameraContainer {
    position: fixed;
    inset: 0;
    background: black;
    z-index: 2000;
    display: none;
    flex-direction: column;
}

#cameraContainer.active {
    display: flex;
}

#qr-reader {
    flex: 1;
    width: 100%;
    height: 100%;
    background: black;
    display: none;
    object-fit: cover;
}

#qr-reader.active {
    display: block;
}

#scanStatus {
    position: absolute;
    top: 20px;
    left: 0;
    right: 0;
    text-align: center;
    color: white;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
    z-index: 10;
    padding: 10px;
    font-size: 16px;
}

#scanStatus.success {
    color: #00ff00;
    text-shadow: 0 0 10px #00ff00;
    animation: pulse 0.5s ease-out;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

#cameraControls {
    padding: 16px;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
    align-items: center;
}

#cameraControls button {
    background: #3b82f6;
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    font-size: 14px;
}

#cameraControls button:hover {
    background: #2563eb;
}

#cameraControls button:active {
    background: #1d4ed8;
}

#cameraSelect {
    background: #3b82f6;
    color: white;
    border: none;
    padding: 10px 12px;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    font-size: 14px;
}

#cameraSelect option {
    background: #1f2937;
    color: white;
}

#cameraControls button:active {
    opacity: 0.8;
    transform: scale(0.95);
}

#cameraControls button.close {
    background: #ef4444;
}

.scanner-hint {
    position: absolute;
    bottom: 100px;
    left: 0;
    right: 0;
    text-align: center;
    color: #fff;
    font-size: 14px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
    animation: bounce 1s infinite;
    z-index: 5;
}

#scannerReticle {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 250px;
    height: 100px;
    border: 3px solid #00ff00;
    border-radius: 8px;
    z-index: 8;
    box-shadow: 
        0 0 20px rgba(0, 255, 0, 0.5),
        inset 0 0 20px rgba(0, 255, 0, 0.2);
    pointer-events: none;
}

#scannerReticle::before {
    content: '';
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 10px;
    background: #00ff00;
    border-radius: 0 0 4px 4px;
}

#scannerReticle::after {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 10px;
    background: #00ff00;
    border-radius: 4px 4px 0 0;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* Confetti Animation */
.confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    overflow: hidden;
}

.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    background: #f00;
    animation: confetti-fall 3s linear forwards;
}

@keyframes confetti-fall {
    0% {
        transform: translateY(-100vh) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

.recipe-card {
    background: white;
    border-radius: 10px;
    padding: 8px 10px 10px;
    margin-bottom: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    border-left: 4px solid #fbbf24;
}

.recipe-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 4px;
}

.recipe-card-title {
    font-weight: 600;
    font-size: 15px;
    color: #111827;
    flex: 1;
    line-height: 1.4;
}

.recipe-card-meta {
    font-size: 12px;
    color: #6b7280;
    margin-bottom: 6px;
}

.recipe-card-actions {
    display: flex;
    gap: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
}

.recipe-card-actions button {
    flex: 0 0 auto;
    padding: 12px 12px;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    min-height: 44px;
}

.recipe-btn-open {
    background: #3b82f6;
    color: white;
}

.recipe-btn-view {
    background: #6366f1;
    color: white;
}

.recipe-btn-edit {
    background: #0ea5e9;
    color: white;
}

.recipe-btn-add {
    background: #10b981;
    color: white;
}

.recipe-btn-rename {
    background: #f59e0b;
    color: white;
}

.recipe-btn-delete {
    background: #ef4444;
    color: white;
    flex: 0;
    padding: 12px 12px;
}

.recipe-btn-open:active {
    background: #2563eb;
}

.recipe-btn-view:active {
    background: #4f46e5;
}

.recipe-btn-edit:active {
    background: #0284c7;
}

.recipe-btn-add:active {
    background: #059669;
}

.recipe-btn-rename:active {
    background: #d97706;
}

.recipe-btn-delete:active {
    background: #dc2626;
}
