/* CMX Scan - Solliden */

:root {
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --secondary-dark: #2980b9;
    --success-color: #27ae60;
    --success-dark: #229954;
    --danger-color: #e74c3c;
    --danger-dark: #c0392b;
    --warning-color: #f39c12;
    --light-bg: #ecf0f1;
    --border-color: #bdc3c7;
    --text-color: #2c3e50;
    --muted: #666;
    --page-bg: #60ACB5;
    --card-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

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

html {
    -webkit-text-size-adjust: 100%;
    touch-action: manipulation; /* inget dubbeltryck-zoom */
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--page-bg);
    color: var(--text-color);
    min-height: 100vh;
    padding: 15px;
    padding-bottom: calc(15px + env(safe-area-inset-bottom, 0px));
}

.icon {
    width: 1em;
    height: 1em;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
    vertical-align: -0.125em;
}

.main-container {
    max-width: 800px;
    margin: 0 auto;
}

/* ---------- Header ---------- */

.header {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: var(--card-shadow);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header h1 {
    color: var(--primary-color);
    font-size: 28px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.status-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--border-color);
}

.status-indicator.ok {
    background: var(--success-color);
    animation: pulse 2s infinite;
}

.status-indicator.error {
    background: var(--danger-color);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ---------- Sök ---------- */

.search-container {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: var(--card-shadow);
    margin-bottom: 20px;
}

.search-wrapper {
    display: flex;
    gap: 10px;
}

input,
select,
button {
    font: inherit;
    color: inherit;
}

/* Sökfält med egen töm-knapp (X) - ser likadan ut i alla webbläsare */
.search-field {
    position: relative;
    flex: 1;
    min-width: 0;
    display: flex;
}

input[type="search"] {
    -webkit-appearance: none;
    appearance: none;
    flex: 1;
    min-width: 0;
    padding: 12px 44px 12px 15px; /* plats för X till höger */
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 16px; /* under 16px zoomar iPhone in när fältet får fokus */
    transition: border-color 0.3s;
}

/* Dölj webbläsarens inbyggda X (vi har en egen) */
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-decoration {
    -webkit-appearance: none;
    appearance: none;
    display: none;
}

.clear-search {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 50%;
    background: var(--light-bg);
    color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.clear-search .icon {
    width: 16px;
    height: 16px;
    stroke-width: 2.6;
}

.clear-search:active {
    background: var(--border-color);
}

@media (hover: hover) {
    .clear-search:hover {
        background: #dfe6e9;
        color: var(--text-color);
    }
}

input[type="search"]::placeholder {
    font-size: 14px;
    color: #95a5a6;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--secondary-color) !important;
}

/* ---------- Knappar ---------- */

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: white;
    -webkit-tap-highlight-color: transparent;
}

.btn:disabled {
    opacity: 0.65;
    cursor: default;
}

.btn-primary { background: var(--secondary-color); }
.btn-success { background: var(--success-color); }
.btn-danger { background: var(--danger-color); }
.btn-plain { background: var(--light-bg); color: var(--text-color); }

@media (hover: hover) {
    .btn-primary:hover:not(:disabled) {
        background: var(--secondary-dark);
        transform: translateY(-2px);
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    }
    .btn-success:hover:not(:disabled) { background: var(--success-dark); }
    .btn-danger:hover:not(:disabled) { background: var(--danger-dark); }
    .btn-plain:hover:not(:disabled) { background: #dfe6e9; }
}

/* ---------- Kamera ---------- */

#barcode-viewport {
    position: relative;
    width: 100%;
    height: 200px;
    border-radius: 8px;
    overflow: hidden;
    margin-top: 15px;
    background: #1b2631;
}

#barcode-viewport video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#barcode-viewport .scan-window {
    position: absolute;
    border: 2px solid rgba(255, 255, 255, 0.85);
    border-radius: 6px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.35);
    pointer-events: none;
}

#barcode-viewport .scan-line {
    position: absolute;
    left: 4%;
    right: 4%;
    top: 50%;
    height: 2px;
    background: var(--danger-color);
    box-shadow: 0 0 6px var(--danger-color);
}

#barcode-viewport .scan-window.hit {
    animation: scanHit 0.5s ease-out;
}

@keyframes scanHit {
    0% { border-color: var(--success-color); box-shadow: 0 0 0 9999px rgba(39, 174, 96, 0.35); }
    100% { border-color: rgba(255, 255, 255, 0.85); box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.35); }
}

#barcode-viewport .scan-status {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    text-align: center;
    color: white;
    font-size: 15px;
    background: rgba(27, 38, 49, 0.85);
}

/* ---------- Resultat ---------- */

.results-container {
    margin-top: 20px;
}

.product-card,
.message-card {
    background: white;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--card-shadow);
    animation: slideIn 0.3s ease-out;
}

.message-card {
    text-align: center;
}

.message-card.error {
    color: var(--danger-color);
}

.message-card .message-title {
    font-weight: 600;
}

.message-card .detail {
    margin-top: 10px;
    padding: 10px;
    background: #f7f7f7;
    color: #333;
    font-family: Consolas, Menlo, monospace;
    font-size: 12px;
    text-align: left;
    white-space: pre-wrap;
    word-break: break-all;
    border-radius: 6px;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.product-header {
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--light-bg);
}

.product-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--primary-color);
    overflow-wrap: anywhere;
}

.product-field {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 10px;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--light-bg);
}

.product-field:last-of-type {
    border-bottom: none;
}

.field-label {
    font-weight: 600;
}

.field-value {
    color: #555;
    overflow-wrap: anywhere;
}

.field-value input,
.field-value select {
    width: 100%;
    padding: 8px 12px;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    font-size: 16px; /* 16px förhindrar zoom i iOS */
    background: white;
}

.field-value input.invalid {
    border-color: var(--danger-color);
}

.action-buttons {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

.action-buttons .btn {
    flex: 1;
}

/* ---------- Lager ---------- */

.stock-management {
    background: var(--light-bg);
    padding: 15px;
    border-radius: 8px;
    margin: 15px 0 0;
}

.stock-header h4 {
    margin: 0 0 5px;
    font-size: 16px;
}

.stock-header .stock-current {
    font-size: 14px;
    color: var(--muted);
}

.stock-controls {
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center;
    margin-top: 10px;
}

.stock-controls-buttons {
    display: flex;
    gap: 15px;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.stock-input {
    -webkit-appearance: none;
    appearance: none;
    width: 80px;
    text-align: center;
    font-size: 18px;
    font-weight: 600;
    padding: 10px;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    background: white;
}

.stock-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    color: white;
    transition: transform 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.stock-btn-minus { background: var(--danger-color); }
.stock-btn-plus { background: var(--success-color); }

.stock-btn:active:not(:disabled) { transform: scale(0.95); }
.stock-btn:disabled { opacity: 0.65; cursor: default; }

@media (hover: hover) {
    .stock-btn:hover:not(:disabled) { transform: scale(1.1); }
}

.btn-quick-delivery {
    width: 100%;
    max-width: 300px;
}

/* Negativt antal = lagret minskas -> röd knapp så det syns tydligt */
.btn-quick-delivery.decrease {
    background: var(--danger-color);
}

.stock-input.decrease {
    color: var(--danger-color);
    border-color: var(--danger-color);
}

.reason-toggle {
    margin-top: 10px;
    text-align: center;
}

.toggle-reason-link {
    background: none;
    border: none;
    color: var(--secondary-color);
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
}

@media (hover: hover) {
    .toggle-reason-link:hover {
        background: rgba(52, 152, 219, 0.1);
        color: var(--secondary-dark);
    }
}

.delivery-info {
    margin-top: 10px;
    padding: 10px;
    background: white;
    border-radius: 6px;
    font-size: 14px;
}

.delivery-info input {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    margin-top: 5px;
    font-size: 16px;
}

/* ---------- Tillfälliga priser ---------- */

.temp-prices {
    margin-top: 15px;
    padding: 12px;
    background: #fef5e7;
    border-left: 4px solid var(--warning-color);
    border-radius: 6px;
}

.temp-prices-title {
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}

.temp-price {
    margin: 8px 0 0;
    padding: 8px;
    background: white;
    border-radius: 4px;
    font-size: 14px;
}

/* ---------- Laddning ---------- */

.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s linear infinite;
}

.loading.dark {
    border-color: rgba(44, 62, 80, 0.2);
    border-top-color: var(--primary-color);
}

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

/* ---------- Notiser ---------- */

.toast-container {
    position: fixed;
    right: 20px;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    left: 20px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    z-index: 1000;
    pointer-events: none;
}

.toast {
    max-width: 100%;
    padding: 15px 20px;
    background: var(--success-color);
    color: white;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    gap: 10px;
    animation: toastIn 0.3s ease-out;
    transition: opacity 0.3s, transform 0.3s;
}

.toast.error { background: var(--danger-color); }
.toast.hide { opacity: 0; transform: translateX(40px); }

@keyframes toastIn {
    from { transform: translateX(400px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ---------- Bekräftelseruta ---------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 2000;
    animation: fadeIn 0.15s ease-out;
}

.modal {
    background: white;
    border-radius: 12px;
    padding: 22px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    animation: slideIn 0.2s ease-out;
}

.modal-text {
    font-size: 18px;
    font-weight: 600;
    text-align: center;
    overflow-wrap: anywhere;
}

.modal-detail {
    margin-top: 8px;
    color: var(--muted);
    text-align: center;
    overflow-wrap: anywhere;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.modal-buttons .btn {
    flex: 1;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ---------- Mobil ---------- */

@media screen and (max-width: 600px) {
    body { padding: 10px; }
    .header { padding: 16px 18px; }
    .header h1 { font-size: 22px; }
    .product-field { grid-template-columns: 1fr; gap: 4px; }
    .action-buttons { flex-direction: column; }
    .toast-container { align-items: stretch; }
}

.hidden {
    display: none !important;
}

.search-wrapper .btn .icon {
    width: 20px;
    height: 20px;
}

/* ---------- Session i sidhuvudet ---------- */

.header-main {
    min-width: 0;
}

.header-side {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-shrink: 0;
}

.session-info {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
    margin-top: 6px;
    font-size: 14px;
    color: var(--muted);
}

.session-store {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-weight: 600;
    color: var(--text-color);
}

.btn-logout {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: var(--light-bg);
    color: var(--text-color);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) {
    .btn-logout:hover { background: #dfe6e9; }
}

/* ---------- Inloggning ---------- */

.login-card {
    background: white;
    border-radius: 10px;
    padding: 24px 20px;
    box-shadow: var(--card-shadow);
    max-width: 420px;
    margin: 0 auto;
    animation: slideIn 0.3s ease-out;
}

.login-card h2 {
    font-size: 22px;
    margin-bottom: 4px;
}

.login-hint {
    color: var(--muted);
    margin-bottom: 18px;
}

.login-card label {
    display: block;
    font-weight: 600;
    margin-bottom: 14px;
}

.login-card input {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 12px 14px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 16px;
    font-weight: normal;
}

.login-error {
    color: var(--danger-color);
    margin: 4px 0 12px;
    font-weight: 600;
}

.login-button {
    width: 100%;
    margin-top: 4px;
}

/* Ikonsprite: måste finnas i DOM men inte synas */
.icon-sprite {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}
