/*
 * JONET Scan - datorvyn.
 *
 * Avsiktligt sparsam: vit yta, tunna linjer, en mörk accent. Färg används
 * bara där den betyder något - differenser och fel.
 */

.desk {
    --d-bg: #f5f6f8;
    --d-surface: #ffffff;
    --d-line: #e4e7ec;
    --d-line-strong: #d0d5dd;
    --d-text: #101828;
    --d-sub: #475467;
    --d-muted: #667085;
    --d-faint: #98a2b3;
    --d-accent: #1d2939;
    --d-accent-hover: #101828;
    --d-hover: #f9fafb;
    --d-select: #f2f4f7;
    --d-up: #067647;
    --d-down: #b42318;
    --d-warn-bg: #fffaeb;
    --d-warn-line: #fedf89;
    --d-warn-text: #93370d;
    --d-radius: 8px;
}

body.desk-mode {
    background: #f5f6f8;
    padding: 0;
    min-height: 100vh;
    -webkit-user-select: text;
    user-select: text;
    -webkit-touch-callout: default;
}

body.desk-mode .main-container { display: none; }

.desk {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    color: var(--d-text);
    font-size: 14px;
    line-height: 1.45;
}

.desk button { cursor: pointer; }

/* ---------- Toppfält ---------- */

.desk-top {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    height: 52px;
    padding: 0 24px;
    background: var(--d-surface);
    border-bottom: 1px solid var(--d-line);
}

.desk-top-left,
.desk-top-right {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.desk-brand {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-weight: 600;
    white-space: nowrap;
}

.desk-brand .icon { width: 16px; height: 16px; }

.desk-sep {
    width: 1px;
    height: 18px;
    background: var(--d-line-strong);
}

.desk-org {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.desk-store,
.desk-user {
    color: var(--d-muted);
    white-space: nowrap;
}

.desk-link {
    border: none;
    background: none;
    padding: 6px 8px;
    border-radius: 6px;
    color: var(--d-sub);
    font-size: 13px;
    font-weight: 500;
}

.desk-link:hover { background: var(--d-select); color: var(--d-text); }

/* ---------- Ram ---------- */

.desk-body {
    flex: 1;
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    min-height: 0;
}

.desk-side {
    background: var(--d-surface);
    border-right: 1px solid var(--d-line);
    padding: 20px 12px;
    position: sticky;
    top: 52px;
    height: calc(100vh - 52px);
    overflow-y: auto;
}

.desk-side-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 8px 12px;
}

.desk-side-head h2 {
    font-size: 13px;
    font-weight: 600;
    color: var(--d-sub);
}

.desk-side-sub {
    margin: 20px 8px 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--d-faint);
}

.desk-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.desk-nav-item {
    display: block;
    width: 100%;
    padding: 8px 10px;
    border: none;
    border-radius: 6px;
    background: none;
    text-align: left;
    color: var(--d-text);
}

.desk-nav-item:hover { background: var(--d-hover); }
.desk-nav-item.active { background: var(--d-select); }

.desk-nav-name {
    display: block;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.desk-nav-meta {
    display: block;
    margin-top: 1px;
    font-size: 12px;
    color: var(--d-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.desk-nav-empty {
    padding: 6px 10px;
    font-size: 13px;
    color: var(--d-faint);
}

.desk-main {
    padding: 28px 32px 48px;
    min-width: 0;
}

.desk-empty {
    padding: 80px 0;
    text-align: center;
    color: var(--d-muted);
}

/* ---------- Rubrik ---------- */

.desk-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 20px;
}

.desk-head-main { min-width: 0; }

.desk-head h1 {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.015em;
    overflow-wrap: anywhere;
}

.desk-meta {
    margin-top: 4px;
    color: var(--d-muted);
}

.desk-head-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

/* Statusmärke - grått, inte färgat */
.desk-status {
    display: inline-block;
    padding: 1px 8px;
    border: 1px solid var(--d-line-strong);
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    color: var(--d-sub);
    vertical-align: 1px;
}

.desk-notice {
    margin-bottom: 20px;
    padding: 10px 14px;
    border: 1px solid var(--d-warn-line);
    border-radius: var(--d-radius);
    background: var(--d-warn-bg);
    color: var(--d-warn-text);
}

.desk-notice .d-btn { margin-left: 10px; }

/* ---------- Nyckeltal ---------- */

.desk-stats {
    display: flex;
    margin-bottom: 20px;
    background: var(--d-surface);
    border: 1px solid var(--d-line);
    border-radius: var(--d-radius);
}

.desk-stats > div {
    flex: 1;
    padding: 14px 18px;
}

.desk-stats > div + div { border-left: 1px solid var(--d-line); }

.desk-stats dt {
    font-size: 12px;
    color: var(--d-muted);
}

.desk-stats dd {
    margin-top: 2px;
    font-size: 20px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* Lagervärde: döljs när kassan inte kan lämna inpris (äldre JONET Sync) */
.desk-table.no-values .col-value { display: none; }
.desk-table .col-value.pending { color: var(--d-muted); }

/* ---------- Knappar och fält ---------- */

.d-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 36px;
    padding: 0 14px;
    border: 1px solid var(--d-line-strong);
    border-radius: var(--d-radius);
    background: var(--d-surface);
    color: var(--d-text);
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
}

.d-btn:hover:not(:disabled) { background: var(--d-hover); }
.d-btn:disabled { opacity: 0.5; cursor: default; }

.d-btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }

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

.d-btn-primary:hover:not(:disabled) { background: var(--d-accent-hover); }

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

.d-btn-danger:hover:not(:disabled) { background: #912018; }

.d-input {
    height: 36px;
    padding: 0 12px;
    border: 1px solid var(--d-line-strong);
    border-radius: var(--d-radius);
    background: var(--d-surface);
    font-size: 14px;
    color: var(--d-text);
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
}

.d-input:focus {
    outline: none;
    border-color: var(--d-accent) !important;
    box-shadow: 0 0 0 3px rgba(29, 41, 57, 0.12);
}

/* mobilens sökfältsregler ska inte slå igenom här */
.desk input[type="search"].d-input {
    padding: 0 12px;
    border: 1px solid var(--d-line-strong);
    border-radius: var(--d-radius);
    font-size: 14px;
}

.desk input[type="search"].d-input::placeholder { font-size: 14px; }

/* ---------- Verktygsrad ---------- */

.desk-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 12px;
}

.desk-filter { width: 380px; max-width: 100%; }

.desk-add {
    display: flex;
    gap: 8px;
}

.desk-add #deskAddCode { width: 220px; }
.desk-add-qty { width: 76px; text-align: right; }

/* ---------- Tabell ---------- */

/* Ingen overflow: hidden här - då blir rutan rullningsbehållare och
   rubrikraden fastnar 52 px ner i tabellen i stället för under toppfältet. */
.desk-table-wrap {
    background: var(--d-surface);
    border: 1px solid var(--d-line);
    border-radius: var(--d-radius);
}

.desk-table thead th:first-child { border-top-left-radius: var(--d-radius); }
.desk-table thead th:last-child { border-top-right-radius: var(--d-radius); }

.desk-table {
    width: 100%;
    border-collapse: collapse;
}

.desk-table th {
    position: sticky;
    top: 52px;
    z-index: 1;
    padding: 10px 16px;
    background: #f9fafb;
    border-bottom: 1px solid var(--d-line);
    text-align: left;
    font-size: 12px;
    font-weight: 500;
    color: var(--d-muted);
    white-space: nowrap;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
}

.desk-table th:hover { color: var(--d-text); }

.desk-table th.sorted { color: var(--d-text); }
.desk-table th.sorted::after { content: " ↓"; }
.desk-table th.sorted.asc::after { content: " ↑"; }

.desk-table td {
    padding: 0 16px;
    height: 44px;
    border-bottom: 1px solid var(--d-line);
    vertical-align: middle;
}

.desk-table tbody tr:last-child td { border-bottom: none; }
.desk-table tbody tr:hover td { background: var(--d-hover); }

.desk-table .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.desk-table .mono {
    font-variant-numeric: tabular-nums;
    color: var(--d-sub);
    white-space: nowrap;
}

.desk-table .desc {
    font-weight: 500;
    overflow-wrap: anywhere;
}

.desk-table .when { color: var(--d-muted); }

.desk-table .diff-up { color: var(--d-up); font-weight: 500; }
.desk-table .diff-down { color: var(--d-down); font-weight: 500; }
.desk-table .diff-none { color: var(--d-faint); }

.desk-table tr.is-zero .desc,
.desk-table tr.is-zero .mono { color: var(--d-faint); }

/* Räknat-fältet: ser ut som text tills man pekar eller klickar */
.desk-qty {
    width: 84px;
    height: 30px;
    padding: 0 8px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    text-align: right;
    font-size: 14px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--d-text);
    -moz-appearance: textfield;
}

.desk-qty::-webkit-outer-spin-button,
.desk-qty::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.desk-table tr:hover .desk-qty { border-color: var(--d-line-strong); background: var(--d-surface); }

.desk-qty:focus {
    outline: none;
    border-color: var(--d-accent);
    background: var(--d-surface);
    box-shadow: 0 0 0 3px rgba(29, 41, 57, 0.12);
}

.desk-qty.saving { opacity: 0.5; }

.desk-table-empty {
    padding: 40px 16px;
    text-align: center;
    color: var(--d-muted);
}

.desk-more {
    padding: 12px 16px;
    border-top: 1px solid var(--d-line);
    text-align: center;
    color: var(--d-muted);
    font-size: 13px;
}

/* ---------- Dialog ---------- */

.desk-dialog {
    width: 520px;
    max-width: calc(100vw - 32px);
    margin: auto;
    padding: 0;
    border: none;
    border-radius: 12px;
    color: var(--d-text);
    box-shadow: 0 20px 40px rgba(16, 24, 40, 0.18);
}

.desk-dialog::backdrop { background: rgba(16, 24, 40, 0.35); }

.desk-dialog form,
.desk-dialog .dd-body { padding: 24px; }

.desk-dialog h3 {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 4px;
}

.dd-sub {
    color: var(--d-muted);
    margin-bottom: 18px;
}

.dd-field {
    display: block;
    margin-bottom: 14px;
}

.dd-field > span {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--d-sub);
}

.dd-field .d-input { width: 100%; }

.dd-check {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 14px;
}

.dd-check input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--d-accent); }

.dd-warn {
    margin-bottom: 14px;
    padding: 10px 12px;
    border: 1px solid var(--d-warn-line);
    border-radius: var(--d-radius);
    background: var(--d-warn-bg);
    color: var(--d-warn-text);
}

.dd-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
}

.dd-error {
    margin-top: 10px;
    color: var(--d-down);
    font-weight: 500;
}

/* Lista att bocka i (leverantörer/varugrupper) */
.dd-pick {
    height: 240px;
    overflow-y: auto;
    border: 1px solid var(--d-line-strong);
    border-radius: var(--d-radius);
}

.dd-pick label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 12px;
    border-bottom: 1px solid var(--d-line);
    cursor: pointer;
}

.dd-pick label:last-child { border-bottom: none; }
.dd-pick label:hover { background: var(--d-hover); }
.dd-pick input { width: 15px; height: 15px; accent-color: var(--d-accent); }

.dd-pick-search { margin-bottom: 8px; }

.dd-picked {
    margin-top: 6px;
    font-size: 13px;
    color: var(--d-muted);
}

/* Förlopp */
.dd-progress {
    height: 6px;
    margin: 18px 0 8px;
    border-radius: 999px;
    background: var(--d-select);
    overflow: hidden;
}

.dd-progress-fill {
    height: 100%;
    width: 0;
    background: var(--d-accent);
    transition: width 0.4s;
}

.dd-progress-fill.is-working { animation: ddPulse 1.4s ease-in-out infinite; }

@keyframes ddPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

.dd-progress-text {
    color: var(--d-sub);
    font-variant-numeric: tabular-nums;
}

.dd-result p + p { margin-top: 4px; }

/* Länk-knapp i mobilens inställningar */
.link-btn {
    border: none;
    background: none;
    padding: 0;
    color: var(--secondary-color);
    font-size: 13px;
    text-decoration: underline;
    cursor: pointer;
}

/* Toasts ovanpå dialogen */
body.desk-mode .toast-container { z-index: 1000; }
