/* ==========================================================================
   Design system and variables (dark mode with pill navigation and toggle switch)
   ========================================================================== */

:root {
  color-scheme: dark;

  /* Backgrounds and surfaces */
  --page-bg: #0b0f19;
  --surface: #161f30;
  --surface-hover: #1e293b;
  --surface-dark: #0d1424;
  --border-color: #2a364f;

  /* Text colors */
  --text: #f1f5f9;
  --muted: #94a3b8;

  /* Header and brand colors */
  --header-bg: #0d1320;
  --brand-text: #ffffff;
  --purple: #6366f1;
  --purple-glow: rgba(99, 102, 241, 0.25);

  /* Status colors and transparencies */
  --green: #10b981;
  --green-bg: rgba(16, 185, 129, 0.12);
  --blue: #3b82f6;
  --blue-bg: rgba(59, 130, 246, 0.12);
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.12);

  /* Navigation and switch colors (from reference images) */
  --nav-bg: #121926;
  --nav-active-bg: #1e293d;
  --nav-active-text: #818cf8;
  --nav-inactive-text: #94a3b8;
  --switch-track: #2a364f;
  --switch-track-active: #3b82f6;
  --switch-thumb: #ffffff;

  /* Shadows and overlays */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.15);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.3);
  --toast-bg: #0f172a;
}

/* Light mode fallback values for the switch and navigation */
html[data-theme="light"] {
  color-scheme: light;

  --page-bg: #f8fafc;
  --surface: #ffffff;
  --surface-hover: #f1f5f9;
  --surface-dark: #e2e8f0;
  --border-color: #cbd5e1;

  --text: #0f172a;
  --muted: #64748b;

  --header-bg: #1e293b;
  --brand-text: #ffffff;

  --nav-bg: #0f172a;
  --nav-active-bg: #334155;
  --nav-active-text: #a5b4fc;
  --nav-inactive-text: #cbd5e1;
  --switch-track: #cbd5e1;
  --switch-track-active: #2563eb;

  --green: #059669;
  --green-bg: rgba(5, 150, 105, 0.1);
  --blue: #2563eb;
  --blue-bg: rgba(37, 99, 235, 0.1);
  --red: #dc2626;
  --red-bg: rgba(220, 38, 38, 0.1);

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
  --toast-bg: #1e293b;
}

/* ==========================================================================
   Base layout
   ========================================================================== */

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  padding-bottom: 82px;
  background-color: var(--page-bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  transition: background-color 0.25s ease, color 0.25s ease;
}

button, input {
  font: inherit;
}

/* ==========================================================================
   Header and pill navigation (image 1)
   ========================================================================== */

.app-header {
  min-height: 72px;
  padding: 12px clamp(16px, 3vw, 36px);
  display: flex;
  align-items: center;
  gap: 24px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
}

.brand {
  color: var(--brand-text);
  text-decoration: none;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  transition: opacity 0.2s ease;
}

.brand:hover {
  opacity: 0.9;
}

/* Navigation container (rounded pill shape as in image 1) */
.top-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--nav-bg);
  padding: 5px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

/* Individual navigation buttons */
.nav-link {
  color: var(--nav-inactive-text);
  text-decoration: none;
  padding: 8px 20px;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 500;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.nav-link:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

/* Active segment */
.nav-link.active {
  background: var(--nav-active-bg);
  color: var(--nav-active-text);
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 1.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.icon-button:hover {
  background: var(--surface-hover);
  border-color: var(--purple);
  transform: translateY(-1px);
}

.icon-button svg {
  display: block;
}

/* ==========================================================================
   Main content
   ========================================================================== */

.main-content {
  width: min(1100px, 100%);
  margin: 0 auto;
  padding: 28px clamp(14px, 2.5vw, 28px) 36px;
}

.page-heading h1 {
  margin: 0 0 22px;
  font-size: clamp(1.6rem, 3.5vw, 2.1rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* Search and filters */
.search-area {
  display: grid;
  grid-template-columns: minmax(220px, 1.5fr) minmax(250px, 1fr);
  gap: 18px;
  align-items: center;
  margin-bottom: 24px;
}

.single-field-search {
  grid-template-columns: minmax(0, 1fr);
}

.search-box {
  min-height: 50px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.search-box:focus-within {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px var(--purple-glow);
}

.search-icon {
  font-size: 1.4rem;
  color: var(--muted);
}

.search-box input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 0.98rem;
}

.search-box input::placeholder {
  color: var(--muted);
  opacity: 0.8;
}

.clear-search {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.4rem;
  padding: 0 4px;
}

.clear-search:hover {
  color: var(--text);
}

/* ==========================================================================
   Toggle Switch Styling (Bild 2)
   ========================================================================== */

.switch-container {
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  user-select: none;
}

.switch-text {
  color: var(--muted);
  font-size: 1.05rem;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 28px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--switch-track);
  transition: 0.25s ease;
  border-radius: 34px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 22px;
  width: 22px;
  left: 3px;
  bottom: 3px;
  background-color: var(--switch-thumb);
  transition: 0.25s ease;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.switch input:checked + .slider {
  background-color: var(--switch-track-active);
}

.switch input:checked + .slider:before {
  transform: translateX(24px);
}

/* ==========================================================================
   Artikelliste & Legende
   ========================================================================== */

.list-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin: 0 2px 14px;
  color: var(--muted);
  font-size: 0.9rem;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 0.85rem;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.legend-dot.stock { background: var(--green); box-shadow: 0 0 8px var(--green); }
.legend-dot.order { background: var(--blue); box-shadow: 0 0 8px var(--blue); }
.legend-dot.discontinued { background: var(--red); box-shadow: 0 0 8px var(--red); }
.legend-dot.crm { background: var(--green); box-shadow: 0 0 8px var(--green); }
.legend-dot.cleaning { background: var(--blue); box-shadow: 0 0 8px var(--blue); }
.legend-dot.self { background: var(--red); box-shadow: 0 0 8px var(--red); }

.article-list {
  display: grid;
  gap: 14px;
}

/* Article cards */
.article-card {
  width: 100%;
  padding: 16px 20px;
  border: 1px solid var(--border-color);
  border-left: 5px solid var(--border-color);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: transform 0.2s ease, background-color 0.25s ease, box-shadow 0.2s ease;
  box-shadow: var(--shadow-sm);
}

.article-card:hover {
  background: var(--surface-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

/* Status bars on cards */
.article-card.stock { border-left-color: var(--green); }
.article-card.order { border-left-color: var(--blue); }
.article-card.discontinued {
  border-left-color: var(--red);
  opacity: 0.75;
}

.article-card.overdue {
  border-left-color: var(--red);
}

.article-card.order-card {
  cursor: default;
}

.article-card.order-card:hover {
  background: var(--surface);
  transform: none;
  box-shadow: var(--shadow-sm);
}

.article-card.order-card.crm { border-left-color: var(--green); }
.article-card.order-card.cleaning { border-left-color: var(--blue); }
.article-card.order-card.self { border-left-color: var(--red); }

.article-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.article-tag {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 2px 12px;
  border: 1px solid var(--border-color);
  border-radius: 20px;
  background: var(--surface-dark);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
  white-space: nowrap;
}

.article-card.stock .article-tag {
  background: var(--green-bg);
  color: var(--green);
  border-color: rgba(16, 185, 129, 0.3);
}

.article-card.order .article-tag {
  background: var(--blue-bg);
  color: var(--blue);
  border-color: rgba(59, 130, 246, 0.3);
}

.article-card.discontinued .article-tag {
  background: var(--red-bg);
  color: var(--red);
  border-color: rgba(239, 68, 68, 0.3);
}

.article-card.overdue .article-tag {
  background: var(--red-bg);
  color: var(--red);
  border-color: rgba(239, 68, 68, 0.3);
}

.article-card.order-card.crm .article-tag {
  background: var(--green-bg);
  color: var(--green);
  border-color: rgba(16, 185, 129, 0.3);
}

.article-card.order-card.cleaning .article-tag {
  background: var(--blue-bg);
  color: var(--blue);
  border-color: rgba(59, 130, 246, 0.3);
}

.article-card.order-card.self .article-tag {
  background: var(--red-bg);
  color: var(--red);
  border-color: rgba(239, 68, 68, 0.3);
}

.order-items {
  margin: 0;
  padding: 0;
  list-style: none;
}

.order-item-line {
  padding: 10px 0;
  border-top: 1px solid var(--border-color);
  color: var(--text);
  overflow-wrap: anywhere;
}

.article-name {
  display: block;
  margin-bottom: 4px;
  font-size: clamp(1.05rem, 2vw, 1.3rem);
  font-weight: 600;
  line-height: 1.35;
  color: var(--text);
  overflow-wrap: anywhere;
}

.article-subtitle {
  display: block;
  color: var(--muted);
  font-size: clamp(0.9rem, 1.8vw, 1.05rem);
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.84rem;
}

/* Helper text and status */
.empty-state, .loading-indicator, .list-end {
  padding: 28px 12px;
  color: var(--muted);
  text-align: center;
  font-size: 0.95rem;
}

/* ==========================================================================
   Mobile Navigation & Toast
   ========================================================================== */

.bottom-nav {
  display: none;
  position: fixed;
  z-index: 10;
  left: 0;
  right: 0;
  bottom: 0;
  min-height: 64px;
  padding: 6px 4px max(6px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border-color);
  justify-content: space-around;
  box-shadow: var(--shadow-lg);
}

.bottom-nav-link {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.75rem;
  font-weight: 500;
}

.bottom-nav-link.active {
  color: var(--purple);
}

.bottom-nav-icon {
  font-size: 1.35rem;
  line-height: 1;
}

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 18px;
  border-radius: 10px;
  background: var(--toast-bg);
  border: 1px solid var(--border-color);
  color: #ffffff;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  font-size: 0.9rem;
}

.toast.visible {
  opacity: 1;
}

button.scan-button {
  display: none;
}

html.android-chrome button.scan-button {
  display: inline-flex;
}

@media (max-width: 760px) {
  .icon-button.scan-button,
  .icon-button#add-button,
  .icon-button#inventory-button,
  .icon-button#export-button {
    width: 48px;
    height: 48px;
  }
}

/* Responsive adjustments */
@media (max-width: 760px) {
  body { padding-bottom: 76px; }
  .app-header { min-height: 64px; gap: 12px; padding: 8px 14px; }
  .brand { font-size: 1.2rem; }
  .top-nav { display: none; }
  .header-actions { margin-left: auto; gap: 4px; }
  .icon-button { width: 36px; height: 36px; font-size: 1.15rem; }
  .main-content { padding-top: 18px; }
  .search-area { grid-template-columns: 1fr; gap: 14px; }
  .search-box { min-height: 46px; }
  .bottom-nav { display: flex; }
}

@media (max-width: 390px) {
  .brand { font-size: 1.05rem; }
  .icon-button { width: 34px; height: 34px; }
  .article-card { padding: 12px 14px; border-radius: 10px; }
}

/* ==========================================================================
   Article detail view
   ========================================================================== */

.article-detail-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
}

.article-detail-heading h1 {
    margin-bottom: 4px;
}

#article-number-heading,
#device-number-heading,
#maintenance-subtitle {
    margin: 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.detail-actions,
.edit-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.action-button {
    min-height: 42px;
    padding: 9px 18px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s ease;
}

.action-button:hover {
    transform: translateY(-1px);
    filter: brightness(1.15);
}

.action-button.primary {
    background: var(--purple);
    border-color: var(--purple);
    color: white;
}

.action-button.danger {
    background: var(--red-bg);
    border-color: var(--red);
    color: var(--red);
}

.action-button.secondary {
    background: var(--surface);
    color: var(--text);
}

.detail-card {
    padding: 24px;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.detail-card h2 {
    margin: 0 0 22px;
    font-size: 1.15rem;
}

.detail-card dl {
    display: grid;
    gap: 0;
    margin: 0;
}

.detail-row {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) 2fr;
    gap: 16px;
    padding: 13px 0;
    border-bottom: 1px solid var(--border-color);
}

.detail-row:last-child {
    border-bottom: 0;
}

.detail-row dt {
    color: var(--muted);
}

.detail-row dd {
    margin: 0;
    font-weight: 500;
    overflow-wrap: anywhere;
}

/* Edit form */

.detail-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.detail-field {
    display: flex;
    flex-direction: column;
    gap: 7px;
    color: var(--muted);
    font-size: 0.9rem;
}

.detail-field input:not([type="checkbox"]),
.detail-field textarea,
.detail-field select {
    width: 100%;
    min-height: 44px;
    padding: 9px 12px;
    border: 1px solid var(--border-color);
    border-radius: 9px;
    background: var(--surface-dark);
    color: var(--text);
    font: inherit;
    outline: none;
}

.detail-field textarea {
    min-height: 110px;
    resize: vertical;
}

.detail-field input:focus,
.detail-field textarea:focus,
.detail-field select:focus {
    border-color: var(--purple);
    box-shadow: 0 0 0 3px var(--purple-glow);
}

.detail-field input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--purple);
    cursor: pointer;
}

.barcode-input-group {
    display: flex;
    align-items: stretch;
    gap: 8px;
}

.barcode-input-group input {
    min-width: 0;
    flex: 1;
}

.barcode-input-group .action-button {
    flex: 0 0 auto;
}

.scanner-dialog {
    width: min(520px, calc(100% - 28px));
    max-height: calc(100% - 28px);
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-lg);
}

.scanner-dialog::backdrop {
    background: rgba(0, 0, 0, 0.72);
}

.scanner-dialog-content {
    display: grid;
    gap: 14px;
    padding: 18px;
}

.scanner-dialog-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.scanner-dialog-heading h2 {
    margin: 0;
    font-size: 1.15rem;
}

.scanner-status {
    min-height: 1.5em;
    margin: 0;
    color: var(--muted);
}

.scanner-video {
    width: 100%;
    max-height: min(62vh, 500px);
    aspect-ratio: 4 / 3;
    border-radius: 12px;
    background: #000;
    object-fit: cover;
}

.scanner-retry {
    justify-self: start;
}

.edit-actions {
    margin-top: 20px;
}

[hidden] {
    display: none !important;
}

/* Mobile */

@media (max-width: 600px) {
    .article-detail-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .detail-actions {
        width: 100%;
    }

    .detail-actions .action-button {
        flex: 1;
    }

    .detail-card {
        padding: 16px;
    }

    .detail-row {
        grid-template-columns: 1fr;
        gap: 3px;
        padding: 12px 0;
    }

    .detail-form {
        grid-template-columns: 1fr;
    }

    .edit-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }
}
