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

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

  /* 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) + 1);
    max-width: 100vw;
  }
  .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; }

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


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

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

.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);
  display: none;
}

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

.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);
  display: none;
}

/* =========================================
   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%; }

/* ===== Tabs component (scoped) ===== */
.tabs {
  max-width: 960px;
  width: 100%;
  margin: var(--space-l) auto;
  background: var(--white);
  border: var(--border);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-m);
  overflow: clip;
  font: inherit;
}
.tabs .tablist {
  display: flex;
  gap: var(--space-xs);
  padding: var(--space-xs);
  background: var(--gray-100);
  border-bottom: var(--border);
}
.tabs .tab {
  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);
}
.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; }

/* 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::before {
    content: attr(data-label);
    font-weight: 600;
    color: #4b5563;
  }

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