* { box-sizing: border-box; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  margin: 0;
  background: #f4f5f7;
  color: #1f2430;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #1f2430;
  color: #fff;
  padding: 0.75rem 1.5rem;
}

.topbar .brand {
  color: #fff;
  font-weight: 600;
  font-size: 1.1rem;
  text-decoration: none;
}

.topnav {
  display: flex;
  gap: 0.25rem;
  background: #2a3040;
  padding: 0 1.5rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.topnav a {
  color: #cfd3dc;
  text-decoration: none;
  padding: 0.65rem 0.9rem;
  font-size: 0.9rem;
  border-bottom: 3px solid transparent;
}

.topnav a:hover { color: #fff; }
.topnav a.active { color: #fff; border-bottom-color: #2f6fed; }
.topnav a { flex: 0 0 auto; }

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

h1 { margin-top: 0; }

section {
  background: #fff;
  border: 1px solid #e0e2e8;
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
}

.section-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  row-gap: 0.5rem;
}

.section-header h1, .section-header h2 { margin: 0; }

.button, button {
  display: inline-block;
  background: #2f6fed;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.5rem 0.9rem;
  text-decoration: none;
  cursor: pointer;
  font-size: 0.95rem;
}

.button:hover, button:hover { background: #2559c7; }

.back-link {
  display: inline-block;
  margin-bottom: 1rem;
  color: #2f6fed;
  text-decoration: none;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.5rem;
}

.data-table th, .data-table td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid #e8e9ee;
}

.data-table tbody tr[onclick] { cursor: pointer; }
.data-table tbody tr[onclick]:hover { background: #f0f3ff; }

.kv-table th {
  text-align: left;
  padding: 0.3rem 0.6rem 0.3rem 0;
  color: #555;
  width: 160px;
  vertical-align: top;
}
.kv-table td { padding: 0.3rem 0; }

.tag {
  background: #e4f7e9;
  color: #1a7a3a;
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  font-size: 0.75rem;
}

.tag-przyjete { background: #e4f0fb; color: #1a4d8f; }
.tag-w_trakcie { background: #ffe8d1; color: #a85d00; }
.tag-gotowe { background: #fff4d9; color: #8a6400; }
.tag-zamkniete { background: #eee; color: #555; }

.inline-action { display: inline-block; margin-left: 0.5rem; }
.inline-action button { background: #555; }
.inline-action button:hover { background: #333; }

.form label {
  display: block;
  margin-bottom: 0.9rem;
  font-weight: 500;
}

.form input, .form select, .form textarea, .inline-form input {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.5rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 1rem;
  font-family: inherit;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
  align-items: center;
}

.inline-form input { width: auto; flex: 1 1 140px; margin-top: 0; }
.inline-form input[name="quantity"] { flex: 0 1 70px; }
.inline-form button { white-space: nowrap; flex: 0 0 auto; }

.add-form {
  display: flex;
  flex-wrap: nowrap;
  align-items: flex-end;
  gap: 0.5rem;
  margin-top: 0.75rem;
  overflow-x: auto;
  padding-bottom: 2px;
}

.add-form label {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-width: 90px;
  font-size: 0.75rem;
  color: #555;
  font-weight: 500;
  white-space: nowrap;
}

.add-form label.add-form-qty { flex: 0 0 60px; }

.add-form input {
  margin-top: 0.3rem;
  padding: 0.45rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  min-width: 0;
}

.add-form button { flex: 0 0 auto; white-space: nowrap; }

.search-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.search-form input { flex: 1; padding: 0.5rem; border: 1px solid #ccc; border-radius: 6px; }

.empty { color: #777; }

.flash {
  padding: 0.6rem 0.9rem;
  border-radius: 6px;
  margin-bottom: 1rem;
}
.flash-success { background: #e4f7e9; color: #1a7a3a; }
.flash-error { background: #fbe4e4; color: #a12b2b; }

.list { padding-left: 1.2rem; }

@media (max-width: 640px) {
  .container { padding: 1rem; }

  .topbar { padding: 0.65rem 1rem; flex-wrap: wrap; row-gap: 0.4rem; }
  .topnav { padding: 0 1rem; }

  /* Scroll tables sideways instead of squeezing columns unreadably. */
  .data-table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  /* VIN is a permanent identifier, not the first thing you need at a glance -
     it's still one tap away in the vehicle detail page. */
  .hide-mobile { display: none; }

  /* Stack label/value pairs instead of a cramped two-column table. */
  .kv-table, .kv-table tbody, .kv-table tr, .kv-table th, .kv-table td {
    display: block;
    width: auto;
  }
  .kv-table th {
    padding: 0.6rem 0 0;
    color: #888;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
  }
  .kv-table td { padding: 0.1rem 0 0.5rem; }

  /* Data-entry forms should wrap onto multiple rows on a phone rather
     than requiring sideways scrolling to reach the submit button. */
  .add-form {
    flex-wrap: wrap;
    overflow-x: visible;
  }
  .add-form label { flex: 1 1 45%; white-space: normal; }
  .add-form label.add-form-qty { flex: 1 1 45%; }
  .add-form button { flex: 1 1 100%; }

  .inline-form button { flex: 1 1 100%; }

  /* Avoid iOS Safari zooming in when a sub-16px input gets focus. */
  .add-form input, .inline-form input, .form input, .form select,
  .form textarea, .search-form input {
    font-size: 16px;
  }
}
