/* ASB-FUE – Arbeiter-Samariter-Bund Österreich */
/* Light: Weiß + ASB Rot/Gelb | Dark: Dunkel + gleiche Akzente */

:root {
  /* ASB Österreich: Rot + Gelb */
  --asb-red: #c41e3a;
  --asb-red-dark: #9e1830;
  --asb-yellow: #f4c430;
  --asb-yellow-dark: #d4a82a;

  --bg: #ffffff;
  --bg-alt: #f5f5f5;
  --text: #1a1a1a;
  --text-muted: #555;
  --border: #ddd;
  --input-bg: #fff;
  --card-bg: #fff;
  --expired: #c41e3a;
  --warning: #b8860b;
  --ok: #2d6a2d;
}

[data-theme="dark"] {
  --bg: #1a1a1a;
  --bg-alt: #252525;
  --text: #f0f0f0;
  --text-muted: #aaa;
  --border: #444;
  --input-bg: #2d2d2d;
  --card-bg: #252525;
  --expired: #e85c78;
  --warning: #e6b800;
  --ok: #4ade4a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ----- Login ----- */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.login-card {
  width: 100%;
  max-width: 360px;
  padding: 2rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.login-header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.login-header h1 {
  margin: 0;
  font-size: 1.25rem;
  color: var(--asb-red);
}

.login-header .subtitle {
  margin: 0.25rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.pin-form label {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.9rem;
}

.pin-form input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text);
  margin-bottom: 1rem;
}

.pin-form input:focus {
  outline: none;
  border-color: var(--asb-red);
  box-shadow: 0 0 0 2px rgba(196, 30, 58, 0.2);
}

.error-msg {
  color: var(--expired);
  font-size: 0.9rem;
  margin: 0 0 0.5rem;
}

.hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 1rem 0 0;
}

/* ----- Buttons ----- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  font-size: 0.95rem;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  text-decoration: none;
  background: transparent;
  color: var(--text);
  transition: background 0.15s, color 0.15s;
}

.btn-primary {
  background: var(--asb-red);
  color: #fff;
}

.btn-primary:hover {
  background: var(--asb-red-dark);
}

.btn-secondary {
  background: var(--asb-yellow);
  color: #1a1a1a;
}

[data-theme="dark"] .btn-secondary {
  background: var(--asb-yellow-dark);
  color: #1a1a1a;
}

.btn-secondary:hover {
  filter: brightness(1.1);
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--bg-alt);
}

.btn-icon {
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-alt);
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='5'/%3E%3Cpath d='M12 1v2M12 21v2M4.22 4.22l1.42 1.42M18.36 18.36l1.42 1.42M1 12h2M21 12h2M4.22 19.78l1.42-1.42M18.36 5.64l1.42-1.42'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
}

[data-theme="dark"] .btn-icon {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23aaa' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='5'/%3E%3Cpath d='M12 1v2M12 21v2M4.22 4.22l1.42 1.42M18.36 18.36l1.42 1.42M1 12h2M21 12h2M4.22 19.78l1.42-1.42M18.36 5.64l1.42-1.42'/%3E%3C/svg%3E");
}

/* ----- App layout ----- */
.app-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.app-header h1 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--asb-red);
}

.app-main {
  flex: 1;
  padding: 1rem;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

.panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.panel h2 {
  margin: 0 0 1rem;
  font-size: 1.1rem;
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.panel-head h2 {
  margin: 0;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.pruefer-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.9rem;
}

.pruefer-input {
  width: 120px;
  padding: 0.35rem 0.5rem;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text);
}

/* Logs section */
.logs-section {
  margin-top: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--card-bg);
}

.logs-section-toggle {
  width: 100%;
  padding: 0.6rem 0.75rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.9rem;
  border: none;
  background: var(--bg-alt);
  color: var(--text);
  cursor: pointer;
  min-height: 44px;
}

.logs-section-toggle:hover {
  background: var(--border);
}

.logs-content {
  padding: 0.75rem;
  max-height: 40vh;
  overflow-y: auto;
}

.logs-content.hidden {
  display: none;
}

.logs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.logs-table th,
.logs-table td {
  padding: 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.logs-table th {
  font-weight: 600;
  color: var(--text-muted);
}

@media (max-width: 640px) {
  .logs-table {
    font-size: 0.8rem;
  }

  .logs-table th,
  .logs-table td {
    padding: 0.35rem;
  }
}

.last-check {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.hidden {
  display: none !important;
}

/* ----- Vehicle list ----- */
.vehicle-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.vehicle-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 0.5rem;
  background: var(--bg-alt);
}

.vehicle-list .vehicle-info {
  font-weight: 500;
}

.vehicle-list .vehicle-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.vehicle-list .vehicle-actions {
  display: flex;
  gap: 0.35rem;
}

.vehicle-list .btn {
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
}

.vehicle-has-expired {
  border-color: var(--warning);
  background: rgba(184, 134, 11, 0.08);
}

[data-theme="dark"] .vehicle-has-expired {
  background: rgba(230, 184, 0, 0.12);
}

.vehicle-expired-badge {
  color: var(--expired);
  font-weight: bold;
  margin-left: 0.25rem;
}

.tree-item-details-row.piece-expired {
  background: rgba(196, 30, 58, 0.15);
  border: 1px solid var(--expired);
  border-radius: 4px;
}

[data-theme="dark"] .tree-item-details-row.piece-expired {
  background: rgba(232, 92, 120, 0.2);
}

.tree-item-details-row.piece-warning {
  background: rgba(184, 134, 11, 0.12);
  border: 1px solid var(--warning);
  border-radius: 4px;
}

[data-theme="dark"] .tree-item-details-row.piece-warning {
  background: rgba(230, 184, 0, 0.15);
}

/* ----- Schnellprüfung (freie Eingabe) ----- */
.quick-check-ui {
  margin-bottom: 1rem;
}

.quick-check-ui h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.quick-check-hint {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin: 0 0 1rem;
}

.quick-check-entries {
  margin-bottom: 1rem;
}

.quick-check-entry {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 0.5rem;
}

.quick-check-entry-name {
  flex: 1;
  font-weight: 500;
}

.quick-check-entry-ok {
  display: flex;
  gap: 0.25rem;
}

.quick-check-entry-ok .btn {
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
}

.quick-check-entry-ok .btn.active-ok {
  background: var(--ok);
  color: #fff;
  border-color: var(--ok);
}

.quick-check-entry-ok .btn.active-nok {
  background: var(--expired);
  color: #fff;
  border-color: var(--expired);
}

.quick-check-add {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.quick-check-add select {
  min-width: 180px;
  flex: 1;
}

.quick-check-or {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.quick-check-add input[type="text"] {
  flex: 1;
  min-width: 120px;
}

@media (max-width: 640px) {
  .quick-check-add {
    flex-direction: column;
    align-items: stretch;
  }

  .quick-check-add .quick-check-or {
    text-align: center;
  }
}

/* ----- Check type ----- */
.check-type-choice {
  margin-bottom: 1rem;
}

.check-type-choice p {
  margin: 0 0 0.5rem;
}

.check-type-choice .btn {
  margin-right: 0.5rem;
}

.check-type-choice .btn + .btn {
  margin-top: 0.25rem;
}

/* Geführte Komplettkontrolle */
.guided-check {
  margin: 1rem 0;
}

.guided-progress {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.guided-card {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
}

.guided-path {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.guided-item-name {
  margin: 0 0 0.75rem;
  font-size: 1.15rem;
}

.guided-meta {
  margin-bottom: 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
}

.guided-check-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
}

.guided-qty {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.guided-pieces-title {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
}

.guided-pieces .tree-item-details-row {
  margin-bottom: 0.5rem;
}

.guided-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.25rem;
  flex-wrap: wrap;
}

.guided-block-text {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
}

.guided-block-image {
  max-width: 100%;
  max-height: 200px;
  border-radius: 6px;
  margin: 0.5rem 0;
  border: 1px solid var(--border);
}

/* Block editor in tree item details */
.guided-blocks-editor {
  margin-top: 1rem;
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.guided-blocks-list {
  margin-bottom: 0.75rem;
}

.guided-block-item {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  margin-bottom: 0.5rem;
}

.guided-block-controls {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.guided-block-controls .btn {
  padding: 0.25rem 0.4rem;
  font-size: 0.8rem;
}

.guided-block-text-input {
  flex: 1;
  min-width: 0;
  padding: 0.5rem;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text);
}

.guided-block-preview {
  max-width: 150px;
  max-height: 100px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.guided-blocks-add {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ----- Inventory layout + Ablauf-Sidebar ----- */
.inventory-layout {
  display: flex;
  gap: 1rem;
  margin-top: 0.5rem;
  align-items: flex-start;
}

.inventory-main {
  flex: 1;
  min-width: 0;
}

.expiry-sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.expiry-sidebar-toggle {
  width: 100%;
  padding: 0.5rem 0.75rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.9rem;
  border: none;
  background: var(--card-bg);
  color: var(--text);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.expiry-sidebar-toggle:hover {
  background: var(--bg-alt);
}

.expiry-sidebar-content {
  padding: 0.75rem;
  max-height: 70vh;
  overflow-y: auto;
}

.expiry-sidebar-content.hidden {
  display: none;
}

.expiry-section {
  margin-bottom: 1rem;
}

.expiry-section:last-child {
  margin-bottom: 0;
}

.expiry-section h4 {
  margin: 0 0 0.35rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.expiry-expired h4 {
  color: var(--expired);
}

.expiry-warning h4 {
  color: var(--warning);
}

.expiry-section ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.expiry-entry {
  display: flex;
  align-items: flex-start;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}

.expiry-entry-label {
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

.expiry-entry .btn-goto-item {
  flex-shrink: 0;
  padding: 0.2rem 0.4rem;
  font-size: 0.8rem;
}

.tree-item-row.highlight-item {
  animation: highlight-pulse 2s ease-out;
}

@keyframes highlight-pulse {
  0% { background: rgba(196, 30, 58, 0.35); }
  100% { background: transparent; }
}

[data-theme="dark"] .tree-item-row.highlight-item {
  animation: highlight-pulse-dark 2s ease-out;
}

@keyframes highlight-pulse-dark {
  0% { background: rgba(232, 92, 120, 0.4); }
  100% { background: transparent; }
}

/* ----- Inventory tree ----- */
.inventory-tree {
  margin: 0.5rem 0 1rem;
}

.tree-node {
  margin-bottom: 0.25rem;
}

.tree-node-header {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.5rem;
  background: var(--bg-alt);
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  border: 1px solid transparent;
}

.tree-node-header:hover {
  border-color: var(--border);
}

.tree-node-label {
  flex: 1;
}

.cat-expired {
  color: var(--expired);
  font-weight: bold;
  margin-left: 0.25rem;
}

.tree-node-header .toggle {
  width: 1.25rem;
  text-align: center;
  font-size: 0.8rem;
  transition: transform 0.15s;
}

.tree-node.expanded .tree-node-header .toggle {
  transform: rotate(90deg);
}

.tree-node:not(.expanded) .tree-node-children {
  display: none;
}

.tree-node-children {
  margin-left: 1.25rem;
  padding-left: 0.5rem;
  border-left: 2px solid var(--border);
}

.tree-item-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.5rem;
  background: var(--bg-alt);
  border-radius: 6px;
  margin-bottom: 0.35rem;
  flex-wrap: wrap;
}

.tree-item-row input[type="checkbox"] {
  flex-shrink: 0;
}

.tree-item-row .item-name {
  flex: 1;
  min-width: 120px;
}

.tree-item-row .item-qty {
  width: 4rem;
  padding: 0.25rem 0.4rem;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--input-bg);
  color: var(--text);
}

.tree-item-details {
  margin-top: 0.5rem;
  margin-left: 1.5rem;
  padding: 0.5rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 100%;
}

.tree-item-details-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
  align-items: center;
}

.tree-item-details-row input {
  padding: 0.25rem 0.4rem;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--input-bg);
  color: var(--text);
}

.item-expiry {
  font-size: 0.85rem;
}

.item-expiry.expired {
  color: var(--expired);
  font-weight: 600;
}

.item-expiry.warning {
  color: var(--warning);
  font-weight: 500;
}

.inventory-actions {
  margin-top: 1rem;
}

.save-feedback {
  margin-left: 0.75rem;
  font-size: 0.9rem;
}

.save-feedback-ok {
  color: var(--ok);
}

.save-feedback-error {
  color: var(--expired);
}

/* ----- Add node form ----- */
#add-node-form label {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.9rem;
}

#add-node-form input,
#add-node-form select {
  width: 100%;
  max-width: 320px;
  padding: 0.5rem 0.6rem;
  margin-bottom: 0.75rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text);
}

.form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* ----- Modals / overlay ----- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  max-width: 400px;
  width: 100%;
}

.modal h3 {
  margin: 0 0 1rem;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* ----- Responsive & Touch ----- */
/* Safe-area for notch devices */
body {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
}

.app-header {
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
}

/* Global touch targets */
.btn {
  min-height: 44px;
  padding: 0.6rem 1rem;
}

.btn-icon {
  min-width: 44px;
  min-height: 44px;
}

/* Main form inputs - prevents iOS zoom on focus */
.pin-form input,
#add-node-form input,
#add-node-form select {
  font-size: 16px;
  min-height: 44px;
}

.pin-form .btn,
#add-node-form .btn {
  min-height: 44px;
}

/* Tablet: 640px - 900px */
@media (max-width: 900px) {
  .app-main {
    padding: 0.875rem;
  }

  .inventory-layout {
    flex-direction: column;
  }

  .expiry-sidebar {
    width: 100%;
    max-width: 100%;
  }

  .expiry-sidebar-toggle {
    min-height: 44px;
    padding: 0.6rem 0.75rem;
  }

  .tree-item-details-row {
    grid-template-columns: 1fr 1fr auto;
  }
}

/* Handy: < 640px */
@media (max-width: 640px) {
  .app-main {
    padding: 0.75rem;
  }

  .app-header h1 {
    font-size: 1rem;
  }

  .panel-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .panel-actions {
    width: 100%;
    gap: 0.5rem;
  }

  .panel-actions .btn {
    min-height: 44px;
  }

  .inventory-layout {
    flex-direction: column;
  }

  .expiry-sidebar {
    width: 100%;
  }

  .expiry-sidebar-content {
    max-height: 50vh;
  }

  .expiry-sidebar-toggle {
    min-height: 44px;
    padding: 0.6rem 0.75rem;
  }

  .tree-node-children {
    margin-left: 0.75rem;
  }

  .tree-item-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .tree-item-row .item-name {
    min-width: 0;
    width: 100%;
  }

  .tree-item-row .item-qty {
    width: 100%;
    max-width: 6rem;
  }

  .tree-item-details-row {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .guided-meta {
    flex-direction: column;
    align-items: flex-start;
  }

  .guided-actions {
    flex-direction: column;
  }

  .guided-actions .btn {
    width: 100%;
  }

  .vehicle-list li {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.75rem;
  }

  .vehicle-list .vehicle-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .vehicle-list .btn {
    min-height: 44px;
    padding: 0.5rem 0.75rem;
  }
}

/* Very small screens < 480px */
@media (max-width: 480px) {
  .login-card {
    max-width: 100%;
    padding: 1.5rem;
  }

  .login-page {
    padding: 0.75rem;
  }

  .pin-form input {
    min-height: 44px;
  }

  .pin-form .btn {
    min-height: 44px;
  }

  .tree-node-header {
    min-height: 44px;
    padding: 0.5rem 0.6rem;
  }

  .check-type-choice .btn {
    display: block;
    width: 100%;
    margin-right: 0;
    margin-bottom: 0.5rem;
    min-height: 44px;
  }
}
