/* style.css */
:root {
    --bg-color: #0f172a;
    /* Mörkblå/svart */
    --surface-color: #1e293b;
    --primary-color: #3b82f6;
    /* Blå */
    --primary-hover: #2563eb;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border-color: #334155;
    --success-color: #10b981;
    --danger-color: #ef4444;

    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    user-select: none;
    /* Förhindra markering på touch */
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

/* === LOGIN PAGE === */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
}

.login-card {
    background: var(--surface-color);
    padding: 2.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    border: 1px solid var(--border-color);
}

.login-card h2 {
    text-align: center;
    font-size: 1.8rem;
    font-weight: 600;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.input-group label {
    font-size: 0.9rem;
    color: var(--text-muted);
}

input,
textarea {
    width: 100%;
    padding: 1rem;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-main);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
    user-select: auto;
}

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

.btn {
    padding: 1rem;
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
}

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

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

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

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

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

/* === MAIN POS LAYOUT === */
#pos-layout {
    display: flex;
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#pos-layout.visible {
    opacity: 1;
}

/* Vänster kolumn (Kategorier Sidebar) */
.categories-sidebar {
    width: 280px;
    background: var(--surface-color);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100%;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    font-weight: 700;
    font-size: 1.2rem;
    text-align: center;
}

.categories-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    gap: 0.5rem;
}

.category-item {
    padding: 1rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.category-item:hover {
    background: rgba(59, 130, 246, 0.1);
}

.category-item.active {
    background: var(--primary-color);
    color: white;
}

/* Mitten kolumn (Produkter) */
.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    gap: 1.5rem;
    overflow-y: auto;
}

/* Header (Top bar) */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

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

.logout-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    padding: 0.5rem 1rem;
}

.logout-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

/* Breadcrumbs (Kategorier -> Produkter) */
.breadcrumbs {
    display: flex;
    gap: 0.5rem;
    font-size: 1.1rem;
    align-items: center;
    cursor: pointer;
}

.breadcrumbs span {
    color: var(--primary-color);
}

/* Grid Layouts */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
}

/* Kort (Kategori / Produkt) */
.card {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    cursor: pointer;
    min-height: 140px;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.card:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
}

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

.card-title {
    font-weight: 600;
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.card-price {
    color: var(--success-color);
    font-weight: 700;
    font-size: 1.2rem;
}

.product-img {
    width: 60px;
    height: 60px;
    object-fit: contain;
    margin-bottom: 1rem;
    border-radius: 8px;
    background: white;
}


/* Höger kolumn (Varukorg) */
.cart-sidebar {
    width: 380px;
    background: var(--surface-color);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.cart-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    font-size: 1.2rem;
    text-align: center;
}

.cart-items {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* Cart Item */
.cart-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-color);
    padding: 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.cart-item-info {
    flex: 1;
}

.cart-item-title {
    font-weight: 600;
    font-size: 1rem;
}

.cart-item-price {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 0.2rem;
}

.cart-actions {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.qty-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    color: white;
    font-size: 1.2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

.qty-btn:active {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

/* Cart Footer */
.cart-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    background: var(--surface-color);
}

.total-row {
    display: flex;
    justify-content: space-between;
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
}

/* === MODAL (Kassa) === */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

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

.modal-content {
    background: var(--surface-color);
    padding: 2rem;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 500px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    max-height: 90vh;
    overflow-y: auto;
}

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

.modal-header h2 {
    font-size: 1.5rem;
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 2.5rem;
    cursor: pointer;
    line-height: 1;
    padding: 0.5rem;
}

.checkout-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Feedback messages (Loading, Error) */
.message {
    padding: 1rem;
    border-radius: var(--radius-md);
    text-align: center;
    margin-bottom: 1rem;
    display: none;
}

.message.error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger-color);
    border: 1px solid rgba(239, 68, 68, 0.2);
    display: block;
}

.message.success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success-color);
    border: 1px solid rgba(16, 185, 129, 0.2);
    display: block;
}

.spinner {
    height: 60px;
    width: 60px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 2rem auto;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Variation Select (Touch Friendly) */
#product-variation-select {
    width: 100%;
    padding: 1rem;
    font-size: 1.1rem;
    background: var(--surface-color);
    border: 2px solid var(--border-color);
    color: var(--text-main);
    border-radius: var(--radius-md);
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-slash;
    background-position: right 1rem center;
    background-size: 1.5em;
    cursor: pointer;
}

#product-variation-select:focus {
    border-color: var(--primary-color);
    outline: none;
}

#product-variation-select option {
    padding: 1rem;
    /* Bättre touch area i de flesta mobila OS */
    font-size: 1.1rem;
}

/* === PRODUCT MANAGER UI === */
.product-row {
    display: grid;
    grid-template-columns: 50px 2fr 1fr 1fr auto;
    gap: 1rem;
    padding: 1rem 0.5rem;
    border-bottom: 1px solid var(--border-color);
    align-items: center;
}

.product-row:hover {
    background: rgba(255, 255, 255, 0.02);
}

.product-manager-img {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: 4px;
    background: white;
}

.variation-card {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.variation-card .btn-danger {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
}

/* === RECEIPT DESIGNER UI === */
.designer-controls select {
    width: 100%;
    padding: 0.6rem;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    border-radius: var(--radius-md);
    margin-top: 0.3rem;
    font-size: 0.9rem;
}

.toggle-control {
    background: var(--bg-color);
    padding: 0.8rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    transition: background 0.2s;
}

.toggle-control:hover {
    background: rgba(255, 255, 255, 0.05);
}

.toggle-control input[type="checkbox"] {
    width: 1.2rem;
    height: 1.2rem;
    accent-color: var(--primary-color);
    cursor: pointer;
}

/* Utils */
.hidden {
    display: none !important;
}

/* === UTSKRIFT (Kvitto) === */
@media print {

    /* Dölj hela POS-gränssnittet */
    body>*:not(#receipt-container) {
        display: none !important;
    }

    body {
        background: white;
        color: black;
        width: 100%;
        height: auto;
        margin: 0;
        padding: 0;
        overflow: visible;
        display: block;
    }

    #receipt-container {
        display: block !important;
        width: 80mm;
        /* Standardbredd för kvittoskrivare */
        margin: 0 auto;
        padding: 0;
        font-family: 'Courier New', Courier, monospace;
        /* Tydligare för kvitto */
        font-size: 12px;
        line-height: 1.5;
    }

    #receipt-container.receipt-57mm {
        width: 57mm;
        font-size: 11px;
        /* Något mindre font för att få plats */
    }

    /* Kvitto inre styling - dessa kommer renderas via JS in i #receipt-container */
    .receipt-header {
        text-align: center;
        margin-bottom: 10px;
    }

    .receipt-header h2 {
        font-size: 16px;
        margin: 0 0 5px 0;
    }

    .receipt-meta {
        font-size: 11px;
        margin-bottom: 15px;
        border-bottom: 1px dashed #000;
        padding-bottom: 10px;
    }

    .receipt-items {
        width: 100%;
        margin-bottom: 15px;
        border-bottom: 1px dashed #000;
        padding-bottom: 10px;
    }

    .receipt-item {
        display: flex;
        justify-content: space-between;
        margin-bottom: 5px;
    }

    .receipt-item-name {
        flex: 1;
        padding-right: 10px;
        word-break: break-word;
        /* Hantera långa namn */
    }

    .receipt-item-total {
        text-align: right;
        min-width: 60px;
    }

    .receipt-total {
        display: flex;
        justify-content: space-between;
        font-weight: bold;
        font-size: 14px;
        margin-bottom: 20px;
    }

    .receipt-footer {
        text-align: center;
        font-size: 11px;
        margin-top: 20px;
    }
}