@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: #eeeeee;
  --gray-250: #e5e7eb;
  --gray-300: #dddddd;
  --gray-400: #cccccc;
  --gray-500: #888888;
  --gray-600: #666666;

  /* Extra neutrals / surfaces */
  --gray-700-soft: #4b5563;
  --gray-800-soft: #333333;
  --gray-900-soft: #111111;
  --surface-alt: #f7f7f9;
  --surface-alt-strong: #f5f7f9;

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

  /* Gradients */
  --gradient-body: linear-gradient(to bottom, #ffffff, #f3f3f3);
  --gradient-press-start: #e5e5e5;
  --gradient-press-end: #d4d4d4;

  /* 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;
  --size-nav-toggle:44px;
  --size-avatar:40px;

  /* 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);
  --border-soft: 1px solid var(--gray-300);
  --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);
  --shadow-soft-elevated: 0 2px 6px rgba(0, 0, 0, 0.08);
  --shadow-header: 0 1px 5px 0 rgba(21, 24, 26, 0.1);
  --shadow-sticky: 0 -4px 16px rgba(0,0,0,.06);

  /* 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;

  /* Semantic text colors */
  --text-strong: var(--gray-900-soft);
  --text-default: var(--gray-800-soft);
  --text-subtle-strong: var(--gray-700-soft);

  /* Status surfaces */
  --error-strong: #ff0000;
  --error-bg-soft: #ffe5e5;
  --error-bg: #ffe0e0;
  --error-text: #a00000;
  --error-border: #d00000;

  --success-bg: #e0ffe0;
  --success-text: #007000;
  --success-border: #00a000;

  --warning-bg: #fff4e0;
  --warning-text: #a06000;
  --warning-border: #d08000;

  /* Table / hover */
  --row-hover-bg: rgba(0, 119, 255, 0.06);

  /* Tooltips / overlays */
  --surface-hover-soft: rgba(0, 0, 0, 0.03);
  --tooltip-bg: #333333;
  --overlay-backdrop-strong: rgba(0,0,0,0.45);
  --overlay-backdrop-medium: rgba(0,0,0,0.4);
  --overlay-backdrop-light: rgba(0,0,0,0.6);

  /* Chat */
  --chat-me-bg: #e8f2ff;
  --chat-me-border: #d6e9ff;

  /* Bulkbar / sticky bar */
  --bulkbar-bg: var(--surface-alt);
  --bulkbar-border: var(--gray-300);

  /* Progress */
  --progress-bg: var(--surface-alt-strong);
  --progress-fill: var(--state-sale-color);

  /* Icons / SVG */
  --svg-stroke-default: var(--gray-600);
  --select-arrow-icon: 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");
}

:root[data-theme="dark"] {
  /* Brand / links */
  --color-primary: #cbd5f5;
  --color-secondary: #1f2937;
  --color-primary-hover: #e5e7ff;

  /* Neutrals tuned for dark */
  --white: #0b1120;
  --black: #f9fafb;
  --gray-50: #020617;
  --gray-75: #020617;
  --gray-100: #111827;
  --gray-150: #1f2937;
  --gray-200: #1f2937;
  --gray-250: #273549;
  --gray-300: #334155;
  --gray-400: #475569;
  --gray-500: #9ca3af;
  --gray-600: #e5e7eb;

  /* Surfaces / backgrounds (phone-like navy card) */
  --color-background-body: #111827;
  --color-background-login: #111827;
  --header-color: #111827;

  --surface-alt: #111827;
  --surface-alt-strong: #1f2937;

  /* Typography */
  --text-strong: #f9fafb;
  --text-default: #e5e7eb;
  --text-subtle-strong: #9ca3af;

  /* Accent & states */
  --accent: #60a5fa;

  /* Gradients */
  --gradient-body: linear-gradient(to bottom, #111827, #020617);
  --gradient-press-start: #1f2937;
  --gradient-press-end: #111827;

  /* Status backgrounds (soft on dark) */
  --error-bg: rgba(248, 113, 113, 0.12);
  --error-bg-soft: rgba(248, 113, 113, 0.08);
  --success-bg: rgba(34, 197, 94, 0.12);
  --warning-bg: rgba(234, 179, 8, 0.12);

  /* Chat bubble "me" */
  --chat-me-bg: rgba(96, 165, 250, 0.12);
  --chat-me-border: rgba(96, 165, 250, 0.4);

  /* Table / hover */
  --row-hover-bg: rgba(148, 163, 184, 0.24);

  /* Tooltip / overlays */
  --tooltip-bg: #020617;
  --overlay-backdrop-strong: rgba(15, 23, 42, 0.75);
  --overlay-backdrop-medium: rgba(15, 23, 42, 0.7);
  --overlay-backdrop-light: rgba(15, 23, 42, 0.6);

  /* Bulk bar */
  --bulkbar-bg: #020617;
  --bulkbar-border: #273549;

  /* Progress */
  --progress-bg: #020617;
  --progress-fill: #60a5fa;
}


/* =========================================
   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: transparent;
  max-width: 100%;
  overflow-x: hidden;
  color: var(--text-default);
}

h1, h2, h3, h4, h5, h6 {
  color: var(--text-strong);
}

/* 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: var(--shadow-header);
  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: var(--size-nav-toggle);
    block-size: var(--size-nav-toggle);
    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: var(--shadow-header);
    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: 250px; height: auto; max-width: 50%; }

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

.align-right {float: right;}

/* =========================================
   Forms & Controls
   ========================================= */
form {
  margin: var(--space-xl) 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; }

label[for][required]::after {
  content: " *";
  color: var(--error-strong);
  font-weight: bold;
}

/* 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: var(--shadow-soft-elevated);
  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: var(--text-default);
}

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: var(--shadow-soft-elevated), var(--focus-ring);
}

/* Select specifics */
select:not([multiple]):not([size]) {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: var(--select-arrow-icon);
  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: var(--shadow-m);
}
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: var(--shadow-soft-elevated);
  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: var(--shadow-soft-elevated), var(--focus-ring);
}
table thead th {
  color: var(--text-strong);
  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;
  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: var(--row-hover-bg); }

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); }

/* === Generic responsive table (stack on mobile) === */
.table--stack { width: 100%; }

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

  .table--stack tr {
    display: block;
    border: var(--border-subtle);
    border-radius: var(--radius-l);
    padding: 10px 12px;
    margin: 12px 0;
    background: var(--white);
    box-shadow: var(--shadow-xs);
  }

  .table--stack td {
    display: grid;
    grid-template-columns: 40% 1fr; /* label : value */
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    border: 0;
  }

  .table--stack td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--gray-700-soft);
    align-self: center;
  }

  .table--stack td.is-control,
  .table--stack td.is-actions {
    grid-template-columns: 1fr max-content; /* label left, button(s) right */
    align-items: center;
  }

  .table--stack input[type="checkbox"] {
    inline-size: 22px;
    block-size: 22px;
    margin: 0;
    line-height: 1;
    -webkit-appearance: checkbox; /* avoid unexpected scaling on iOS */
    appearance: checkbox;
  }
}


/* =========================================
   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 {
  background-color: var(--error-bg);
  color: var(--error-text);
  border: 1px solid var(--error-border);
}

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

.warning-box {
  background-color: var(--warning-bg);
  color: var(--warning-text);
  border: 1px solid var(--warning-border);
}

.error {
  border: 2px solid var(--error-strong);
  background-color: var(--error-bg-soft);
}

.error-message {
  color: var(--error-strong);
  font-size: 0.9em;
  margin-top: 4px;
}

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

.launch-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  padding: 16px;
}

button.launch {
  width: 100%;
  aspect-ratio: 3 / 1;

  border: none;
  border-radius: var(--radius-l);
  padding: 10px;

  /* Make text centered nicely */
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;

  /* Smooth hover animation */
  transition:
    transform 0.12s ease-out,
    box-shadow 0.12s ease-out,
    background 0.12s ease-out;
}

button.launch:hover {
  transform: translateY(-2px) scale(1.02);
}

/* Active / click effect */
button.launch:active {
  transform: translateY(0) scale(0.98);
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  background: linear-gradient(
    135deg,
    var(--gradient-press-start),
    var(--gradient-press-end)
  );
}

/* Optional: keyboard focus outline */
button.launch:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

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

.confirm-backdrop {
  position: fixed; inset: 0; background: var(--overlay-backdrop-strong);
  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: var(--text-default); }

.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: var(--shadow-soft-elevated);
  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: var(--shadow-soft-elevated), 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: var(--tooltip-bg);
  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%;}

.thumbnail {
  max-width:80px;
  max-height:80px;
  object-fit:cover;
}

img.zoomable {
  cursor: pointer;
}

dialog.imgDialog {
  border: none;
  padding: 0;
  background: transparent;
}

.large-img {
  max-width: 90vw;
  max-height: 90vh;
}

dialog.imgDialog::backdrop {
  background: var(--overlay-backdrop-light);
}

#closeBtn {
  position: absolute;
  top: 10px;
  right: 20px;
  padding: 5px 10px;
}

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, var(--black) 12px,  var(--black) 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: var(--surface-hover-soft);
  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: var(--text-subtle-strong);
  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: var(--text-subtle-strong);
}

.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 {
  max-width: 800px;
  border-collapse: collapse;
}

.assets thead th {
    cursor: pointer;
}

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

.assets th.select-col, .assets td.select-col { width: 2.5rem; text-align: center; }
.assets td.select-col 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: var(--bulkbar-bg);
  border: 1px solid var(--bulkbar-border);
  border-radius: .5rem;
  padding: .5rem .75rem;
  margin-top: .75rem;
  box-shadow: var(--shadow-sticky);
}
.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;
}

@media (max-width: 768px) {
  .asset-filters {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: .5rem;
  }

  .assets.table--stack td.select-col {
    /* no label column for the checkbox cell */
    grid-template-columns: max-content;  /* just the checkbox */
    align-items: center;
  }
  .assets.table--stack td.select-col::before {
    content: none !important;            /* hide "Valitse" label */
  }
  .assets.table--stack td.select-col input[type="checkbox"] {
    width: 22px;
    height: 22px;
    margin: 0;
    justify-self: start;
  }

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

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

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

  .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: var(--row-hover-bg);
  max-width: 100%;
  overflow: hidden;
  min-width: 0;
  display: grid;
  grid-template-columns: 40px minmax(0 1fr);
}

.conversation-item__avatar {
  inline-size: var(--size-avatar);
  block-size: var(--size-avatar);
  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: var(--text-strong); }

.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: var(--text-default);
}

.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: var(--chat-me-bg);
  border-color: var(--chat-me-border);
}

.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: var(--shadow-soft-elevated);
  background: var(--white);
  font: inherit;
  outline: none;
}
.chat-reply__input:focus {
  border-color: var(--accent);
  box-shadow: var(--shadow-soft-elevated), 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: var(--overlay-backdrop-medium);
  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: var(--font-family-base);
  max-width: 560px;
  margin: var(--space-l) 0;
}
.uploader__dropzone {
  background: var(--white);
  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: var(--shadow-soft-elevated), var(--focus-ring);
  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: var(--white);
  color: var(--color-primary);
  border: var(--border-soft);
  box-shadow: var(--shadow-soft-elevated);
}
.btn--ghost:hover {
  background: var(--white);
  color: var(--color-primary-hover);
  box-shadow: var(--shadow-m);
}

.uploader__preview,
.uploader__fields {
  margin-top: var(--space-base);
  display: grid;
  gap: var(--space-base);
  background: var(--white);
  border: var(--border-soft);
  border-radius: var(--radius-m);
  padding: var(--space-base);
  box-shadow: var(--shadow-m);
}
.uploader__preview img {
  width: 100%;
  height: auto;
  border-radius: var(--radius-m);
  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: var(--gray-600);
}

.uploader__field { display: grid; gap: 6px; }
.uploader__label { font-size: var(--font-size-xs); color: var(--gray-600); }
.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: var(--progress-bg);
  border: 1px solid var(--gray-300);
  border-radius:999px;
  overflow:hidden;
}
.uploader__bar {
  height: 100%;
  background: var(--progress-fill);
  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;
  }
}