/* Shared CRM design system — Sälj + Inköp + Admin. See ARCHITECTURE.md.
   Sidebar shell + blue accent, ported from the design mockups (2026-07). */
:root {
  --bg: #f5f6f8;
  --sidebar: #1e2533;
  --sidebar-text: #a0a8b8;
  --sidebar-active: #4a90d9;
  --card: #ffffff;
  --card-shadow: 0 1px 3px rgba(0,0,0,0.08);
  --text: #1a1d23;
  --text2: #5a6270;
  --muted: #8a919d;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-light: #eff6ff;
  --border: #e5e7eb;
  --ok: #22c55e; --ok-text: #16a34a; --ok-bg: #f0fdf4;
  --warn: #f59e0b; --warn-text: #d97706; --warn-bg: #fffbeb;
  --radius: 10px; --radius-sm: 6px; --radius-pill: 20px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.5;
}

/* ---- LAYOUT ---- */
.layout { display: flex; min-height: 100vh; }

/* ---- SIDEBAR ---- */
.sidebar {
  width: 220px; background: var(--sidebar); padding: 24px 0;
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 10;
}
.sidebar-logo { padding: 0 20px 24px; color: #ffffff; font-size: 18px; font-weight: 500; }
.sidebar nav { flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 20px;
  color: var(--sidebar-text); text-decoration: none; font-size: 14px;
  cursor: pointer; border-left: 3px solid transparent; transition: all .15s; user-select: none;
}
.nav-item:hover { color: #fff; background: rgba(255,255,255,0.05); }
.nav-item.active { color: #fff; background: rgba(74,144,217,0.15); border-left-color: var(--sidebar-active); }
.nav-item .ic { width: 18px; text-align: center; }
.nav-sep { margin: 14px 20px 6px; font-size: 10px; text-transform: uppercase; letter-spacing: .6px; color: #6b7280; }

/* Profilmeny (nås via profil-raden längst ner) — portalbyte + utloggning
   göms här, så utlogg inte råkar klickas. Öppnas uppåt. */
.profile-menu { position: absolute; left: 12px; right: 12px; bottom: calc(100% + 6px); background: #2a3342; border: 1px solid rgba(255,255,255,.1); border-radius: 10px; padding: 6px; box-shadow: 0 -10px 34px rgba(0,0,0,.45); display: none; z-index: 70; }
.profile-menu.open { display: block; }
.profile-menu .pm-cap { font-size: 10px; text-transform: uppercase; letter-spacing: .6px; color: #6b7280; padding: 8px 10px 4px; }
.pm-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 6px; color: var(--sidebar-text); text-decoration: none; font-size: 13px; }
.pm-item .ic { width: 16px; text-align: center; }
.pm-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.pm-item.active { color: #fff; }
.pm-item.active::after { content: '✓'; margin-left: auto; color: var(--accent); font-size: 12px; }
.pm-div { height: 1px; background: rgba(255,255,255,.1); margin: 6px 4px; }
.pm-item.logout { color: #fca5a5; }
.pm-item.logout:hover { background: rgba(239,68,68,.12); color: #fecaca; }
.sidebar-user {
  position: relative; cursor: pointer; user-select: none;
  padding: 16px 20px; border-top: 1px solid rgba(255,255,255,0.1);
  display: flex; align-items: center; gap: 10px;
}
.sidebar-user:hover { background: rgba(255,255,255,0.04); }
.sidebar-user .su-meta { min-width: 0; }
.sidebar-user .avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; flex: none;
}
.sidebar-user .su-name { color: #fff; font-size: 13px; line-height: 1.2; }
.sidebar-user .su-role { color: var(--sidebar-text); font-size: 11px; text-transform: capitalize; }
.sidebar-user .caret { margin-left: auto; color: var(--sidebar-text); font-size: 11px; transition: transform .15s; }
.sidebar-user.open .caret { transform: rotate(180deg); }

/* ---- MAIN ---- */
.main { margin-left: 220px; flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* ---- TOPBAR ---- */
.topbar {
  padding: 14px 28px; background: var(--card); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px; position: sticky; top: 0; z-index: 5;
}
.topbar-title { font-size: 16px; font-weight: 600; display: flex; align-items: baseline; gap: 8px; }
.topbar-title .build { font-size: 11px; color: var(--muted); font-weight: 400; }

/* ---- DATAKÄLLA-IKON (ersätter öppen filruta för vanliga roller) ---- */
.util { position: relative; margin-left: auto; }
.ds-btn {
  position: relative; width: 36px; height: 36px; border-radius: 8px;
  border: 1px solid var(--border); background: #fff; color: var(--text2);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.ds-btn:hover { background: var(--bg); color: var(--text); }
.ds-btn .hd { position: absolute; top: 5px; right: 5px; width: 8px; height: 8px; border-radius: 50%; background: #9ca3af; border: 2px solid #fff; }
.ds-pop {
  position: absolute; right: 0; top: 44px; width: 290px; background: #fff;
  border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 34px rgba(0,0,0,0.14);
  padding: 14px 16px; z-index: 60; display: none;
}
.ds-pop.open { display: block; }
.ds-pop h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin-bottom: 8px; }
.ds-pop .ds-sub { font-size: 12px; color: var(--text2); margin-bottom: 6px; display: flex; align-items: center; gap: 6px; }
.ds-pop .ds-sub .d { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.ds-row { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; font-size: 12.5px; border-top: 1px solid var(--border); }
.ds-row .n { color: var(--text); font-weight: 500; }
.ds-row .m { color: var(--muted); text-align: right; }
.ds-foot { margin-top: 10px; font-size: 12px; color: var(--muted); }
.ds-foot a { color: var(--accent); text-decoration: none; }

/* ---- CONTENT ---- */
.content { padding: 24px 28px; overflow-y: auto; }
.section-title { font-size: 20px; font-weight: 700; margin-bottom: 4px; }

/* ---- SEARCH ---- */
.search-box {
  width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 14px; margin-bottom: 16px; background: #fff; outline: none; font-family: inherit;
}
.search-box:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,0.1); }
.count { color: var(--text2); font-size: 13px; margin-bottom: 14px; }

/* ---- TABLE ---- */
.table-scroll { overflow-x: auto; background: var(--card); border-radius: var(--radius); box-shadow: var(--card-shadow); }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; padding: 10px 16px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .5px; color: var(--muted); background: #fafbfc; border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: 12px 16px; font-size: 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody tr:last-child td, tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }

.pri-a { color: var(--text); font-weight: 700; }
.pri-b { color: var(--text2); }
.pri-c { color: var(--muted); }
.supplier { color: #374151; font-weight: 500; }

/* ---- PAGINATION ---- */
.pager, .pagination { display: flex; gap: 6px; align-items: center; justify-content: center; margin-top: 16px; color: var(--text2); font-size: 13px; flex-wrap: wrap; }
.pager button, .pagination button, .pagination a, .pager span {
  padding: 6px 11px; border: 1px solid var(--border); background: #fff; border-radius: var(--radius-sm);
  cursor: pointer; color: var(--text2); font-size: 13px; text-decoration: none;
}
.pager button:hover, .pagination button:hover { background: var(--bg); }
.pager .active, .pagination .active, .pager b { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }

/* ---- STATES ---- */
.loading { text-align: center; padding: 4rem; color: var(--text2); }
.error { background: #fef2f2; color: #991b1b; padding: 1rem; border-radius: var(--radius-sm); border: 1px solid #fecaca; }

/* ---- AUTH (login / logout) — samma tokens som portalerna ---- */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 24px; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0,0,0,0.08); padding: 40px 36px; text-align: center;
}
.auth-logo { font-size: 22px; font-weight: 700; letter-spacing: -.02em; color: var(--text); }
.auth-title { font-size: 18px; font-weight: 600; margin-top: 22px; }
.auth-sub { font-size: 14px; color: var(--text2); margin-top: 6px; line-height: 1.55; }
.auth-actions { margin-top: 28px; }
.btn-accent {
  display: inline-flex; align-items: center; justify-content: center; width: 100%;
  padding: 11px 16px; background: var(--accent); color: #fff; border: none; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; font-family: inherit; cursor: pointer; text-decoration: none;
  transition: background .15s;
}
.btn-accent:hover { background: var(--accent-hover); }
.auth-foot { margin-top: 22px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---- RESPONSIVE ---- */
@media (max-width: 768px) {
  .sidebar {
    width: 100%; height: auto; position: static; flex-direction: row; align-items: center;
    padding: 10px 14px; overflow-x: auto;
  }
  .sidebar-logo { padding: 0 14px 0 6px; }
  .sidebar nav { display: flex; gap: 2px; }
  .nav-item { padding: 8px 12px; border-left: none; border-bottom: 3px solid transparent; white-space: nowrap; }
  .nav-item.active { border-left: none; border-bottom-color: var(--sidebar-active); }
  .nav-sep { display: none; }
  .sidebar-user { border-top: none; border-left: 1px solid rgba(255,255,255,0.1); margin-left: auto; padding: 6px 14px; }
  .main { margin-left: 0; }
  .topbar { padding: 12px 16px; }
  .content { padding: 16px; }
  .profile-menu { left: auto; right: 8px; bottom: auto; top: calc(100% + 6px); width: 220px; }
}
