@import url('https://fonts.googleapis.com/css?family=Open+Sans:400,600');

/* =========================================
   Design Tokens
   ========================================= */
:root {
  /* Brand */
  --color-primary: #989ea2;
  --color-secondary: #b8bec2;
  --color-primary-hover: #8a8e92;

  /* States */
  --state-ok-color: #22c55e;
  --state-sale-color: #0077ff;
  --state-stolen-color: #e11d48;
  --state-broken-color: #f59e0b;
  --state-repair-color: #8b5cf6;
  --state-lost-color: #6b7280;

  /* Neutrals */
  --white: #ffffff;
  --black: #000000;
  --gray-50: #fafafa;
  --gray-75: #f9f9f9;
  --gray-100: #f8f9fb;
  --gray-150: #f5f5f5;
  --gray-200: #eee;
  --gray-250: #e5e7eb;
  --gray-300: #ddd;
  --gray-400: #ccc;
  --gray-500: #888;
  --gray-600: #666;

  /* Backgrounds */
  --color-background-body: #f3f6f8;
  --color-background-login: #b8bec2; /* kept from original */
  --header-color: #ffffff;

  /* Gradients */
  --gradient-body: linear-gradient(to bottom, #ffffff, #f3f3f3);

  /* Typography */
  --font-family-base: "Open Sans", sans-serif;
  --font-size-display:36px;
  --font-size-h1:32px;
  --font-size-h2:28px;
  --font-size-h3:26px;
  --font-size-h4:22px;
  --font-size-h5:20px;
  --font-size-h6:18px;
  --font-size-base:20px;
  --font-size-l:20px;
  --font-size-m:16px;
  --font-size-s:14px;
  --font-size-xs:12px;
  --font-size-label:11px;
  --line-height-base: 1.5;

  /* Spacing */
  --space-none:0;
  --space-xs:4px;
  --space-s:8px;
  --space-base:16px;
  --space-m:24px;
  --space-l:32px;
  --space-xl:40px;
  --space-xxl:48px;

  /* Layout sizes */
  --header-size:56px;
  --header-size-content:48px;
  --side-menu-size:300px;
  --bottom-bar-size:56px;
  --footer-height:0px;
  --content-max: 1280px;

  /* Radii */
  --radius-s: 8px;
  --radius-m: 12px;
  --radius-l: 16px;
  --radius-pill: 999px;

  /* Borders & Outlines */
  --border: 1px solid var(--gray-300);
  --border-subtle: 1px solid var(--gray-250);
  --border-strong: 1px solid var(--gray-400);
  --focus-ring: 0 0 0 3px rgba(0, 119, 255, 0.2);
  --delete-red: #dc2626;

  /* Shadows */
  --shadow-xs: 0 1px 3px rgba(0,0,0,.12);
  --shadow-s: 0 2px 5px rgba(0, 0, 0, 0.15);
  --shadow-m: 0 4px 6px rgba(0, 0, 0, 0.1);
  --shadow-l: 0 4px 12px rgba(0,0,0,0.05);

  /* Elevation */
  --layer-header:1000;

  /* Animation / Transitions */
  --easing: ease;
  --duration-fast: .18s;
  --duration-base: .2s;
  --transition-base: all var(--duration-base) linear;

  /* Breakpoints */
  --bp-sm: 640px;
  --bp-md: 768px;
  --bp-lg: 900px;

  /* Accents */
  --accent: #0077ff;
}

/* =========================================
   Utilities & Global
   ========================================= */
.state--ok        { color: var(--state-ok-color) }
.state--for-sale  { color: var(--state-sale-color) }
.state--stolen    { color: var(--state-stolen-color) }
.state--broken    { color: var(--state-broken-color) }
.state--repairing { color: var(--state-repair-color) }
.state--lost      { color: var(--state-lost-color) }

.state-icon { display: inline-flex; align-items: center; gap: .4em; }
.state-icon svg { vertical-align: middle; }

*, *::before, *::after { box-sizing: border-box; }

html { overflow-x: hidden; }

body {
  background-color: var(--color-background-body);
  background: var(--gradient-body);
  direction: ltr;
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);
  font-family: var(--font-family-base);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  max-width: 100%;
  overflow-x: hidden;
}

/* Links */
a, a:visited {
  color: var(--color-primary);
  transition: var(--transition-base);
  text-decoration: none;
}
a:hover, a:focus {
  color: var(--color-primary-hover);
  text-decoration: underline;
}

/* Headers & page chrome */
header {
  background-color: var(--header-color);
  box-shadow: 0 1px 5px 0 rgba(21, 24, 26, 0.1); /* kept look */
  left: 0;
  position: sticky;
  right: 0;
  top: 0;
  width: 100%;
  z-index: var(--layer-header);
}

header, main, footer {
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  box-sizing: border-box;
}

.header-content {
  max-width: var(--content-max);
  width: 100%;
  margin: 0 auto;
  padding-inline: var(--space-xl);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-s);
  min-height: var(--header-size);
  text-align: left;
}

nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-s);
}
nav > * { display: inline-flex; align-items: center; margin: 0; }

.menu-logo {
  height: clamp(28px, 6vw, 40px);
  width: auto;
}

.nav-links,
.nav-actions {
  display: flex;
  align-items: center;
  gap: var(--space-base);
  flex-wrap: wrap;
}

header select { max-width: 18ch; }

/* --- Mobile collapse --- */
.nav-toggle {
  border: var(--border-subtle);
  background: var(--white);
  border-radius: var(--radius-l);
  padding: var(--space-s);
  line-height: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: box-shadow var(--duration-base) var(--easing), background var(--duration-base) var(--easing);
}

@media (max-width: 768px) {
  .nav-toggle {
    inline-size: 44px;
    block-size: 44px;
    padding: 10px;
    flex: 0 0 auto;
  }

  .nav-toggle,
  .nav-toggle:hover,
  .nav-toggle:focus,
  .nav-toggle:active {
    background: var(--white);
    box-shadow: none;
  }

  .nav-toggle svg {
    display: block;
    width: 100%;
    height: 100%;
    pointer-events: none;
  }
  .nav-toggle svg path { stroke: var(--color-primary); }
  .nav-toggle:hover svg path,
  .nav-toggle:focus svg path { stroke: var(--color-primary-hover); }

  .brand { min-width: 0; }
  .menu-logo { height: clamp(24px, 7vw, 34px); }

  .nav {
    display: none;
    position: fixed;
    top: var(--header-size);
    left: 0;
    right: 0;
    background: var(--header-color);
    box-shadow: 0 1px 5px 0 rgba(21,24,26,.1);
    border-bottom: var(--border-subtle);
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    padding-block: var(--space-s);
    flex-direction: column;
    gap: var(--space-s);
    box-sizing: border-box;
    inset-inline: 0;
    z-index: calc(var(--layer-header) + 10);
    width: 100%;
    max-width: none;
    overflow-x: hidden;
  }
  .nav.is-open { display: flex; }

  .nav-links,
  .nav-actions {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-s);
  }

  .nav a, .nav select { padding: var(--space-s) 0; }

  header { padding-left: 0; padding-right: 0; }

  .site-header {
    overflow-x: hidden;
    isolation: isolate;
  }

  .header-content {
    position: relative;
    max-width: 100vw;
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(18px, env(safe-area-inset-right));
  }

  #serialInput {
    max-width: 25ch;
  }
}

/* --- Desktop layout --- */
@media (min-width: 769px) {
  .nav-toggle { display: none; }
  .nav {
    position: static;
    display: flex !important;
    flex-direction: row;
    align-items: center;
    gap: var(--space-base);
    min-width: 0;
    flex-wrap: nowrap;
  }
  .nav-links {
    flex: 1 1 auto;
    min-width: 0;
    flex-wrap: nowrap;
  }
  .nav-links a { white-space: nowrap; }
  .nav-actions {
    flex: 0 0 auto;
    min-width: 0;
    flex-wrap: nowrap;
    white-space: nowrap;
    gap: var(--space-base);
  }

  .nav-actions select {
    width: auto;
    max-width: 18ch;
  }

  .nav-actions > * {
    flex: 0 0 auto;
  }
}

/* Wrapping safeguards */
.header-content, .nav, .nav-links, .nav-actions { min-width: 0; }
header a { white-space: nowrap; }
@media (max-width: 900px) { header a { white-space: normal; } }

/* Main */
.main-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

#main-logo { width: 300px; height: 300px; max-width: 100%; }

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

/* =========================================
   Forms & Controls
   ========================================= */
form {
  margin: var(--space-xxl) auto var(--space-xl);
  padding: var(--space-m);
  border: var(--border);
  border-radius: var(--radius-m);
  background-color: var(--gray-75);
  box-shadow: var(--shadow-l);
  display: flex;
  flex-direction: column;
  gap: var(--space-base);
  box-sizing: border-box;
  width: 100%;
  max-width: 800px;
  font: inherit; /* inherit family/size from body */
}

form label {
  color: var(--gray-500);
  font-size: var(--font-size-s);
}

form div.group { display: flex; flex-direction: column; gap: 0; }

/* Shared field chrome */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="tel"],
input[type="url"],
select {
  padding: 0.6em 1em;
  border: 1px solid var(--gray-400);
  border-radius: var(--radius-m);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  font-size: 1rem;
  box-sizing: border-box;
  outline: none;
  transition: border var(--duration-base) var(--easing), box-shadow var(--duration-base) var(--easing);
  width: 100%;
  max-width: 50ch;
  min-width: 5ch;
  background-color: var(--white);
  color: inherit;
}

textarea {
  width: 100%;
  min-height: calc(1.5em * 3);  /* 3 text rows */
  max-height: calc(1.5em * 10); /* 10 text rows */
  line-height: 1.5;
  overflow-y: auto;
  box-sizing: border-box;
  resize: vertical;
}

/* Focus style (shared) */
input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input[type="search"]:focus,
input[type="tel"]:focus,
input[type="url"]:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08), var(--focus-ring);
}

/* Select specifics */
select:not([multiple]):not([size]) {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75em center;
  background-size: 1em;
  padding-right: 2.5em;
}
select:disabled {
  background-color: var(--gray-150);
  color: var(--gray-500);
  cursor: not-allowed;
}

/* Buttons */
button {
  padding: 0.6em 1.2em;
  font-size: var(--font-size-base);
  border: none;
  border-radius: var(--radius-pill);
  background-color: var(--color-primary);
  color: var(--white);
  cursor: pointer;
  box-shadow: var(--shadow-s);
  transition: background-color var(--duration-base) var(--easing), box-shadow var(--duration-base) var(--easing);
  margin: 5px;
}
button:hover {
  background-color: var(--color-primary-hover);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}
button:active {
  background-color: var(--color-primary-hover);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* =========================================
   Tables
   ========================================= */
table {
  margin-top: 50px;
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  border: var(--border);
  border-radius: var(--radius-m);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  font-size: 1rem;
  background: var(--white);
  transition: border var(--duration-base) var(--easing), box-shadow var(--duration-base) var(--easing);
  word-break: break-word;
  overflow-wrap: anywhere;
}
table:focus-within {
  border-color: var(--accent);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08), var(--focus-ring);
}
table thead th {
  background: var(--gray-100);
  text-align: left;
  font-weight: 600;
  padding: 0.75em 1em;
  border-bottom: var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
  cursor: pointer;
  user-select: none;
  word-break: break-word;
  overflow-wrap: anywhere;
}
table thead th.sorted { color: var(--accent); }
table thead th.sorted::after {
  content: "";
  display: inline-block;
  margin-left: 0.4em;
  width: 0; height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
}
table thead th.sort-asc::after  { border-bottom: 6px solid currentColor; transform: translateY(-1px); }
table thead th.sort-desc::after { border-top: 6px solid currentColor; transform: translateY(1px); }

table td {
  padding: 0.75em 1em;
  border-bottom: 1px solid var(--gray-200);
  vertical-align: middle;
  word-break: break-word;
  overflow-wrap: anywhere;
}

table tbody tr:nth-child(odd) { background: var(--gray-50); }
table tbody tr:hover { background: rgba(0, 119, 255, 0.06); }

table thead th:first-child { border-top-left-radius: var(--radius-m); }
table thead th:last-child  { border-top-right-radius: var(--radius-m); }
table tbody tr:last-child td:first-child { border-bottom-left-radius: var(--radius-m); }
table tbody tr:last-child td:last-child  { border-bottom-right-radius: var(--radius-m); }

table--compact thead th,
table--compact td { padding: 0.5em 0.75em; }

/* =========================================
   Messages / Alerts
   ========================================= */
.error-box,
.success-box,
.warning-box {
  padding: 12px 16px;
  margin: 20px 0;
  border-radius: var(--radius-s);
  box-shadow: var(--shadow-m);
  display: none;
}

.error-box {
  --err-bg: #ffe0e0;
  --err-text: #a00000;
  --err-border: #d00000;
  background-color: var(--err-bg);
  color: var(--err-text);
  border: 1px solid var(--err-border);
}

.success-box {
  --ok-bg: #e0ffe0;
  --ok-text: #007000;
  --ok-border: #00a000;
  background-color: var(--ok-bg);
  color: var(--ok-text);
  border: 1px solid var(--ok-border);
  transition: opacity 0.5s ease;
}

.warning-box {
  --warn-bg: #fff4e0;
  --warn-text: #a06000;
  --warn-border: #d08000;
  background-color: var(--warn-bg);
  color: var(--warn-text);
  border: 1px solid var(--warn-border);
}

.icon-delete {
  width: 24px;
  height: 24px;
  color: var(--delete-red);
  stroke: currentColor;
  fill: none;
  transition: fill 0.2s ease, stroke 0.2s ease;
}

button:hover .icon-delete {
  fill: currentColor;
  stroke: white;
}

.confirm-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  backdrop-filter: blur(2px); z-index: 1000;
}
.confirm-modal {
  position: fixed; inset: 0; display: grid; place-items: center; z-index: 1001;
}
.confirm-modal[hidden], .confirm-backdrop[hidden] { display: none !important; }

.confirm-card {
  width: min(520px, 92vw);
  background: var(--white);
  color: var(--gray-600);
  border: var(--border);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-l);
  padding: var(--space-m);
  font: inherit;
}
.confirm-title {
  margin: 0 0 var(--space-s);
  font-size: var(--font-size-h5);
  color: var(--black);
}
.confirm-message { margin: 0 0 var(--space-base); color: #333; }

.confirm-label {
  display: grid; gap: var(--space-xs);
  margin: var(--space-s) 0 var(--space-base);
  font-size: var(--font-size-s);
  color: var(--gray-500);
}
.confirm-input {
  padding: .6em 1em; border: 1px solid var(--gray-400);
  border-radius: var(--radius-m);
  box-shadow: 0 2px 6px rgba(0,0,0,.08);
  font-size: 1rem; width: 5ch; text-align: center;
  background: var(--white); color: inherit; outline: none;
  transition: border var(--duration-base) var(--easing),
              box-shadow var(--duration-base) var(--easing);
}
.confirm-input:focus {
  border-color: var(--accent);
  box-shadow: 0 2px 6px rgba(0,0,0,.08), var(--focus-ring);
}

.confirm-actions { display: flex; gap: var(--space-s); justify-content: flex-end; }
.btn.btn--ghost { background: var(--gray-100); color: var(--gray-600); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }


/* =========================================
   Misc layout helpers & components
   ========================================= */
.asset-row { display: flex; flex-wrap: wrap; align-items: flex-start; gap: var(--space-base); }
.assetImg { max-width: 400px; max-height: 400px; }

.help-container { position: relative; display: inline-block; }

.help-button {
  background: var(--accent);
  color: var(--white);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  cursor: pointer;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
}

.tooltip {
  visibility: hidden;
  background-color: #333;
  color: var(--white);
  text-align: left;
  padding: 10px;
  border-radius: 6px;
  position: absolute;
  top: 40px;
  left: 0;
  width: 250px;
  z-index: 1;
  opacity: 0;
  transition: opacity var(--duration-base) var(--easing);
}
.help-container:hover .tooltip { visibility: visible; opacity: 1; }

img.map, img.qr {max-width: 600px; width: 100%;}

div.qr { max-width: 600px;}
div.qr > svg {
  display: block;
  width: 100% !important;
  height: auto !important;
  max-width: 100%;
}

/* ===== Tabs component (scoped) ===== */
.tabs {
  max-width: 100vw;
  width: 100%;
  overflow-x: hidden;
  margin: var(--space-l) auto;
  background: var(--white);
  border: var(--border);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-m);
  overflow: hidden;
  font: inherit;
}
.tabs .tablist {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  width: 100%;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scroll-snap-type: x mandatory;
  scroll-snap-align: start;
  contain: content;
  gap: var(--space-xs);
  padding: var(--space-xs);
  background: var(--gray-100);
  border-bottom: var(--border);
  mask-image: linear-gradient(to right, transparent 0, #000 12px, #000 calc(100% - 12px), transparent 100%);
}

.tabs .tab {
  flex: 0 0 auto;
  white-space: nowrap;
  min-width: 0;
  appearance: none;
  border: 0;
  background: transparent;
  padding: calc(var(--space-s) * 0.75) var(--space-base);
  border-radius: var(--radius-pill);
  font-weight: 600;
  font-size: var(--font-size-l);
  color: var(--color-primary);
  cursor: pointer;
  outline: none;
  transition: background-color var(--duration-fast) var(--easing), color var(--duration-fast) var(--easing), box-shadow var(--duration-fast) var(--easing);
}
.tabs .tab:hover {
  background: rgba(0, 0, 0, 0.03);
  color: var(--color-primary-hover);
}
.tabs .tab[aria-selected="true"] {
  background: var(--color-secondary);
  color: var(--white);
  box-shadow: var(--shadow-xs);
}
.tabs .tab:focus-visible { box-shadow: var(--focus-ring); }

.tabs .tabpanel {
  padding: var(--space-base) var(--space-l) var(--space-l);
  display: none;
  animation: tabs-fade var(--duration-fast) var(--easing);
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);
  background: var(--white);
  max-width: 100%;
  overflow-x: hidden;
}

.tabs .tabpanel[data-active] { display: block; }

@keyframes tabs-fade { from { opacity: 0 } to { opacity: 1 } }

/* No-JS fallback */
.no-js .tabs .tabpanel { display: block; }

/* === Asset table === */
.asset-filters {
  display:flex;
  gap:.5rem;
  align-items:center;
  flex-wrap:wrap;
  margin-bottom:.5rem;
  border: var(--border-subtle);
  border-radius: var(--radius-m);
  padding:.5rem .75rem .75rem;
  min-inline-size: min(100%, 820px);
}
.asset-filters__legend {
  font-weight: 600;
  color: #4b5563; /* could be promoted to token if needed */
  font-size: var(--font-size-s);
  padding: 0 .35em;
}
.asset-filters input, .asset-filters select { padding:.4rem .6rem; }
.asset-filters button { padding:.4rem .6rem; }

.mobile-sort { display: none; align-items: center; gap: .5rem; }
.mobile-sort-label {
  font-weight: 600;
  color: #4b5563; /* same note as above */
}

.asset-totals {
  display:grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap:.5rem;
  margin-top:.5rem;
  padding:.5rem;
  border-top: var(--border);
}

.sr-only{
  position:absolute;
  width:1px;
  height:1px;
  padding:0;
  margin:-1px;
  overflow:hidden;
  clip:rect(0,0,0,0);
  white-space:nowrap;
  border:0;
}

.assets {
  width: 100%;
  max-width: 800px;
  border-collapse: collapse;
}
.assets th, .assets td {
  padding: 12px;
  border-bottom: var(--border-subtle);
  text-align: left;
}
.assets th { font-weight: 600; }

.assets th:first-child, .assets td:first-child { width: 2.5rem; text-align: center; }
.assets td:first-child input[type="checkbox"] { transform: translateY(1px); }
/* Ensure header sort styles ignore the first column */
.assets thead th.select-col { cursor: default !important; }

.asset-bulkbar {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: none;
  gap: .75rem;
  align-items: center;
  justify-content: space-between;
  background: #f7f7f9;
  border: 1px solid #ddd;
  border-radius: .5rem;
  padding: .5rem .75rem;
  margin-top: .75rem;
  box-shadow: 0 -4px 16px rgba(0,0,0,.06);
}
.asset-bulkbar--visible { display: flex; }
.asset-bulkbar__left { display: flex; gap: .5rem; align-items: center; }
.asset-bulkbar__right { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.asset-bulkbar button, .asset-bulkbar select {
  font: inherit;
}

/* Mobile “cards” */
@media (max-width: 640px) {
  .assets thead { display: none; }

  .asset-filters {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: .5rem;
  }

  .mobile-sort { display:flex; margin:0.5rem 0; }

  .assets tr {
    display: block;
    border: var(--border-subtle);
    border-radius: var(--radius-l);
    padding: 10px 12px;
    margin: 12px 0;
    background: var(--white);
  }
  .assets td {
    display: grid;
    grid-template-columns: 40% 1fr; /* label : value */
    gap: 8px;
    padding: 8px 0;
    border: 0;
  }

  .assets td:first-child {
    display: flex;             /* instead of grid */
    align-items: center;
    justify-content: flex-start;
    padding: 8px 0;            /* keep it compact */
    border: 0;
  }
  .assets td:first-child::before {
    content: none !important;  /* hide "Valitse" label */
  }

  /* Make the touch target comfy on mobile */
  .assets td:first-child input[type="checkbox"] {
    width: 22px;
    height: 22px;
    transform: none;
  }

  .assets td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #4b5563;
  }
  .asset-bulkbar { position: fixed; left: .75rem; right: .75rem; bottom: .75rem; }

  .asset-totals { grid-template-columns: 1fr; }

  /* Optional: hide least-important columns on tiny screens
     .assets td:nth-child(2) { display: none; }
  */
}

/* Ensure [hidden] truly hides */
.assets tr[hidden], [hidden] { display: none !important; }


/* char styles */ 

/* ===== Messages module (leans on your tokens) ===== */
.messages.module.card {
  background: var(--white);
  border: var(--border);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-m);
  margin: var(--space-l) auto;
  max-width: 100%;
  overflow-x: hidden;
}

.messages__layout {
  display: grid;
  grid-template-columns: minmax(240px, 320px) 1fr;
  gap: 0;
  min-height: 560px;
  max-width: 100%;
  overflow: hidden;
}

.messages__sidebar {
  border-right: var(--border-subtle);
  background: var(--gray-75);
  display: flex;
  flex-direction: column;
}
.messages__sidebar-header { padding: var(--space-base) var(--space-base) var(--space-s); }
.messages__title { margin: 0; font-size: var(--font-size-h5); color: var(--gray-600); }

.conversation-list {
  list-style: none; margin: 0; padding: 0;
  overflow: auto; height: 100%;
}
.conversation-item { border-bottom: var(--border-subtle); }
.conversation-item__btn {
  appearance: none; border: 0; background: transparent; text-align: left;
  width: 100%; padding: var(--space-base); display: grid; grid-template-columns: 40px 1fr; gap: var(--space-base);
  cursor: pointer; font: inherit;
}
.conversation-item__btn:hover { background: var(--gray-100); }
.conversation-item__btn[aria-current="true"] {
  background: rgba(0,119,255,.06);
  max-width: 100%;
  overflow: hidden;
  min-width: 0;
  display: grid;
  grid-template-columns: 40px minmax(0 1fr);
}

.conversation-item__avatar {
  inline-size: 40px; block-size: 40px; border-radius: 50%;
  display: grid; place-items: center; background: var(--gray-200); color: var(--gray-600);
  font-weight: 700;
}
.conversation-item__meta {
  display: grid;
  gap: var(--space-xs);
  align-content: center;
  min-width: 0;
}
.conversation-item__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-s);
  min-width: 0;
  flex-wrap: nowrap;
}

.conversation-item__name { font-weight: 600; color: #111; }

.conversation-item__time {
  flex: 0 0 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--font-size-xs);
  color: var(--gray-600);
}

.conversation-item__snippet {
  display: block;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  word-break: break-word;
  font-size: var(--font-size-s);
  color: #333;
}

.badge.badge--unread {
  flex: 0 0 auto;
  background: var(--state-sale-color);
  color: var(--white);
  border-radius: var(--radius-pill);
  padding: 0 .5em;
  font-size: var(--font-size-xs);
  line-height: 1.6;
  margin-left: var(--space-s);
}

/* Main chat area */
.messages__main {
  position: relative;
  background: var(--white);
  max-width: 100%;
  overflow-x: hidden;
  max-inline-size: 100%;
  min-inline-size: 0;
}

.chat-panel {
  display: none;
  height: 100%;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
  max-inline-size: 100%;
  min-inline-size: 0;
}

.chat-panel[data-active] {
  display: flex;
  flex-direction: column;
  min-height: 60vh;
}

.chat-panel__header {
  padding: var(--space-base) var(--space-l) var(--space-s);
  border-bottom: var(--border-subtle);
  z-index: calc(var(--layer-header)-10);
}
.chat-panel__title { margin: 0; font-size: var(--font-size-h5); }

.chat-timeline {
  list-style: none;
  margin: 0;
  padding: var(--space-base) var(--space-l);
  overflow: auto; background: var(--gray-50);
  flex: 1 1 auto;
  overflow-y: auto;
  max-width: 100%;
  overflow-x: hidden;
  max-inline-size: 100%;
  min-inline-size: 0;
}
.chat-msg {
  display: flex;
  margin: var(--space-s) 0;
  max-inline-size: 100%;
  min-inline-size: 0;
}
.chat-msg--me { justify-content: flex-end; }
.chat-msg__bubble {
  max-width: 70%;
  background: var(--white);
  border: var(--border);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-xs);
  padding: var(--space-base);
  max-inline-size: 100%;
  min-inline-size: 0;
}
.chat-msg--me .chat-msg__bubble {
  background: #e8f2ff; /* subtle “me” tint; still neutral with your palette */
  border-color: #d6e9ff;
}

.chat-msg__text {
  margin: 0 0 var(--space-xs);
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  word-break: break-word;
  max-inline-size: 100%;
  min-inline-size: 0;
}

.chat-msg__meta {
  font-size: var(--font-size-xs);
  color: var(--gray-600);
  display: flex;
  gap: var(--space-s);
  justify-content: flex-end;
}

/* Reply box (compact form variant) */
.form--compact {
  margin: 0;
  border: var(--border-subtle);
  border-radius: 0;
  background: var(--gray-100);
  box-shadow: none;
  padding: var(--space-s) var(--space-l);
}
.chat-reply {
  border-top: var(--border-subtle);
  position: sticky;
  bottom: 0;
  background: var(--white);
  padding: var(--space-s);
  border-top: var(--border-subtle);
  z-index: 1;
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
}

.chat-reply__send {
  flex: 0 0 auto;
  max-width: 45%;
  white-space: nowrap;
}

.chat-reply__row {
  display: flex;
  grid-template-columns: 1fr auto;
  gap: var(--space-s);
  align-items: flex-end;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  min-width: 0;
  max-width: 100%;
  flex-wrap: nowrap;
}
.chat-reply__input {
  flex: 1 1 0%;
  width: 100%;
  resize: vertical;
  max-height: 40vh;
  min-height: 44px;
  min-width: 0;
  min-inline-size: 0;
  max-inline-size: 100%;
  overflow-x: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  padding: .6em 1em;
  border: 1px solid var(--gray-400);
  border-radius: var(--radius-m);
  box-sizing: border-box;
  box-shadow: 0 2px 6px rgba(0,0,0,.08);
  background: var(--white);
  font: inherit;
  outline: none;
}
.chat-reply__input:focus { border-color: var(--accent); box-shadow: 0 2px 6px rgba(0,0,0,.08), var(--focus-ring); }

/* Empty */
.messages__empty { padding: var(--space-l); color: var(--gray-600); }

.message-dialog {
  border: none;
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-l);
  padding: 0;
  width: min(400px, 90vw);
}

.message-dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(2px);
}

.message-dialog__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-s) var(--space-base);
  border-bottom: var(--border-subtle);
}

.message-dialog__body {
  padding: var(--space-base);
}

.message-dialog__inner textarea {
  width: 100%;
  resize: vertical;
  border: var(--border);
  border-radius: var(--radius-m);
  padding: .6em 1em;
  font: inherit;
  min-height: 80px;
  box-sizing: border-box;
}

.message-dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-s);
  margin-top: var(--space-s);
}

.message-dialog__close {
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}





/* Uploader */

.uploader {
  --radius: 12px;
  --pad: var(--space-l);
  --pad-s: var(--space-base);
  --accent: var(--state-sale-color);
  font-family: "Open Sans", sans-serif;
  max-width: 560px;
  margin: var(--space-l) 0;
}
.uploader__dropzone {
  background: #fff;
  border: 2px dashed var(--color-secondary);
  border-radius: var(--radius);
  padding: var(--pad);
  box-shadow: var(--shadow-m);
  color: var(--color-primary);
  display: grid; gap: var(--space-base); justify-items: center; text-align: center;
  transition: border-color .2s, box-shadow .2s, color .2s;
  outline: none;
}
.uploader__dropzone:hover,
.uploader__dropzone:focus,
.uploader__dropzone.is-dragover {
  border-color: var(--accent);
  box-shadow: 0 2px 6px rgba(0,0,0,.08), 0 0 0 3px rgba(0,119,255,.2);
  color: var(--color-primary-hover);
}
.uploader__icon { color: var(--color-secondary); }
.uploader__title { font-size: var(--font-size-h5); font-weight: 600; }
.uploader__subtitle { font-size: var(--font-size-s); opacity: .8; }
.uploader__hint {
  font-size: var(--font-size-xs);
  color: var(--color-secondary);
  margin-top: var(--space-base);
}
.uploader__actions { display: inline-flex; gap: var(--space-base); }

.btn--ghost {
  background: #fff; color: var(--color-primary);
  border: 1px solid #ccc; box-shadow: 0 2px 6px rgba(0,0,0,.08);
}
.btn--ghost:hover {
  background: #fff; color: var(--color-primary-hover);
  box-shadow: 0 4px 10px rgba(0,0,0,.2);
}

.uploader__preview {
  margin-top: var(--space-base);
  display: grid; gap: var(--space-base);
  background: #fff; border: 1px solid #ddd; border-radius: var(--radius);
  padding: var(--pad-s); box-shadow: var(--shadow-m);
}
.uploader__preview img {
  width: 100%;
  height: auto;
  border-radius: 10px;
  display:block;
}
.uploader__preview iframe {
  width:100%;
  height:auto;
  border:0;
}
.uploader__meta { display:flex; justify-content:space-between; font-size: var(--font-size-xs); color:#666; }

.uploader__fields {
  margin-top: var(--space-base);
  display: grid; gap: var(--space-base);
  background: #fff; border: 1px solid #ddd; border-radius: var(--radius);
  padding: var(--pad-s); box-shadow: var(--shadow-m);
}
.uploader__field { display: grid; gap: 6px; }
.uploader__label { font-size: var(--font-size-xs); color:#666; }
.uploader__submit { display:flex; gap: var(--space-base); }

.uploader__progress-wrap {
  display:grid; grid-template-columns: 1fr auto; align-items:center; gap: var(--space-base);
  margin-top: var(--space-base);
}

.uploader__progress-wrap.is-indeterminate .uploader__bar {
  transition: width 0.15s linear; /* the JS timer advances width */
}

.uploader__progress {
  height: 10px; background: #f5f7f9; border:1px solid #ddd; border-radius:999px; overflow:hidden;
}
.uploader__bar { height: 100%; background: var(--accent); width:0%; transition: width .15s linear; }
.uploader__percent { min-width:3ch; font-variant-numeric: tabular-nums; color: var(--color-primary); font-size: var(--font-size-s); }
.uploader__progress-actions { grid-column: 1 / -1; display:flex; gap: var(--space-base); }

@media (max-width: 480px) {
  .uploader { margin: var(--space-base); }
  .uploader__actions, .uploader__submit { flex-direction: column; }
  .uploader__actions > *, .uploader__submit > * { width: 100%; }
}
.uploader [hidden] { display: none !important; }





/* Responsive */
@media (max-width: 768px) {
  .conversation-item__row { flex-wrap: wrap; }
  .conversation-item__snippet {
    white-space: normal;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    line-clamp: 2;
    -webkit-line-clamp: 2;
    overflow: hidden;
    word-break: break-word;
    overflow-wrap: anywhere;
  }
  .messages__layout { grid-template-columns: 1fr; }
  .messages__sidebar { order: 2; }
  .messages__main { order: 1; }
  .chat-msg__bubble { max-width: 88%; }
}



@media print {
  /* Hide everything by default (keeps layout for the shown element) */
  body * { visibility: hidden !important; }

  /* Show the target and its descendants */
  .print-target, .print-target * { visibility: visible !important; }

  /* Lift it to the page origin so it uses the paper cleanly */
  .print-target {
    position: absolute;
    left: 0; top: 0;
    right: 0; /* allow full width */
    margin: 0;
    width: 100%;
    height: auto;
    display: block;
  }
}