/* ===== Base ===== */
* {
  box-sizing: border-box;
}

body {
  font-family: system-ui, Arial, sans-serif;
  margin: 0;
  background: #0c0c0c;
  color: #dfdfdf;
}

h1, h2, h3 {
  margin-bottom: 8px;
}

/* ===== Layout ===== */
.page-wrap {
  max-width: 1920px;
  margin: 0 auto;
  padding: 24px 20px;
}

.card {
  background: #1e1e1e;
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 18px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: end;
}

/* stays flex even at mobile breakpoint */
.flex-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

/* responsive quantity grid: 3-col on desktop, stacked on mobile */
.qty-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr 1fr auto;
  align-items: end;
}

/* ===== Dashboard ===== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

.stat-card {
  text-align: center;
  padding: 20px 16px;
}

.stat-label {
  font-size: 12px;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
}

.stat-danger { color: #f87171; }
.stat-warn   { color: #fcd34d; }

.alerts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 18px;
}

.dash-part-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid #2a2a2a;
}
.dash-part-row:last-child { border-bottom: none; }

.freq-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
}

.freq-card {
  padding: 10px;
  text-align: center;
}

/* button-styled anchor */
.btn-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: 8px;
  background: #3b82f6;
  color: #fff;
  font-weight: 600;
  text-decoration: none;
  font-size: 14px;
  cursor: pointer;
}
.btn-link.secondary {
  background: #2a2a2a;
  color: #dfdfdf;
}
.btn-link img.btn-icon {
  width: 18px;
  height: 18px;
}
.btn-link.secondary img.btn-icon { filter: brightness(0) invert(1); }

.link {
  text-decoration: none;
  color: #d3d3d3;
  font-weight: 600;
}

/* ===== App Navigation Topbar ===== */
.app-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 16px;
  height: 52px;
  background: #141414;
  border-bottom: 1px solid #2a2a2a;
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 12px;
}

.app-topbar-left {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.app-topbar-nav {
  display: flex;
  align-items: center;
  gap: 2px;
}

.app-brand {
  font-weight: 800;
  font-size: 16px;
  color: #f66711;
  margin-right: 6px;
  letter-spacing: -0.5px;
  white-space: nowrap;
}

.nav-link {
  text-decoration: none;
  color: #aab0bd;
  font-weight: 500;
  font-size: 14px;
  padding: 6px 10px;
  border-radius: 6px;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.nav-link:hover {
  background: #2a2a2a;
  color: #dfdfdf;
}

.nav-link.active {
  background: #2a2a2a;
  color: #f66711;
}

.app-topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.app-username {
  color: #aab0bd;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.view-as-select {
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid #3a3a3a;
  background: #242424;
  color: #dfdfdf;
  font-size: 13px;
  cursor: pointer;
  max-height: none;
  min-width: 0;
}

.app-logout {
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  background: transparent;
  border: 1px solid #3a3a3a;
  color: #aab0bd;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}

.app-logout:hover {
  background: #2a2a2a;
  color: #dfdfdf;
}

/* ===== Hamburger button ===== */
.app-hamburger {
  display: none;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: #dfdfdf;
  padding: 6px;
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
}

.app-hamburger:hover {
  background: #2a2a2a;
}

/* ===== Side Drawer ===== */
.app-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 260px;
  background: #141414;
  border-right: 1px solid #2a2a2a;
  z-index: 200;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
}

.app-drawer.open {
  transform: translateX(0);
}

.app-drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 16px;
  height: 52px;
  border-bottom: 1px solid #2a2a2a;
  flex-shrink: 0;
}

.app-drawer-close {
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: #aab0bd;
  padding: 6px;
  border-radius: 6px;
  cursor: pointer;
}

.app-drawer-close:hover {
  background: #2a2a2a;
  color: #dfdfdf;
}

.app-drawer-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 10px 8px;
  gap: 2px;
  overflow-y: auto;
}

.app-drawer-nav .nav-link {
  display: flex;
  padding: 10px 12px;
  font-size: 15px;
  border-radius: 8px;
}

.app-drawer-footer {
  padding: 16px;
  border-top: 1px solid #2a2a2a;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.app-drawer-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #555;
}

.app-drawer-user {
  font-size: 13px;
  color: #aab0bd;
  font-weight: 500;
}

.app-drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 199;
  display: none;
  backdrop-filter: blur(2px);
}

.app-drawer-overlay.open {
  display: block;
}

/* ===== Inputs ===== */
input, select:not(.view-as-select) {
  padding: 10px 12px;
  min-width: 200px;
  border-radius: 8px;
  border: 1px solid #d0d5dd;
  background: #fff;
  color: black;
  max-height: 37px;
}

input:focus, select:not(.view-as-select):focus {
  outline: none;
  border-color: #4c7dff;
}

/* ===== Buttons ===== */
button {
  padding: 10px 14px;
  border-radius: 8px;
  border: none;
  background: #f66711;
  color: white;
  cursor: pointer;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

button img.btn-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

button.secondary {
  background: #e5e7eb;
  color: #222;
}

button.secondary img.btn-icon {
  filter: brightness(0);
}

button.secondary:hover {
  background: #d6d9df;
}

/* ===== Square icon-only buttons ===== */
.btn-sq {
  width: 38px;
  height: 38px;
  padding: 0;
  flex-shrink: 0;
}

/* ===== Search row + wrapped input ===== */
.search-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.search-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  background: #fff;
  border: 1px solid #d0d5dd;
  border-radius: 8px;
  overflow: hidden;
}

.search-wrap:focus-within {
  border-color: #4c7dff;
}

.search-wrap input {
  border: none;
  border-radius: 0;
  min-width: 0;
  flex: 1;
  padding: 10px 12px 10px 0;
  background: transparent;
  max-height: none;
}

.search-wrap input:focus {
  outline: none;
}

.search-icon-btn {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0 10px;
  height: 37px;
  width: auto;
  cursor: pointer;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.search-icon-btn img {
  width: 16px;
  height: 16px;
  filter: brightness(0) opacity(0.4);
}

.search-icon-btn:hover img {
  filter: brightness(0) opacity(0.75);
}

/* ===== Table ===== */
table {
  width: 100%;
  border-collapse: collapse;
  background: #1e1e1e;
  border-radius: 10px;
  overflow: hidden;
  border-color: #272727;
}

tr:nth-of-type(even) {
  background: #272727;
}

th {
  background: #313131;
  text-align: left;
  font-size: 14px;
}

th, td {
  padding: 12px;
  border-bottom: 1px solid #303030;
}

tr:last-child td {
  border-bottom: none;
}

/* ===== Images ===== */
.part-img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
  background: #eee;
}

/* ===== Status ===== */
.muted {
  color: #848995;
  font-size: 13px;
}

.ok {
  color: #0a7a3e;
  font-weight: 500;
}

.err {
  color: #b42318;
  font-weight: 500;
}

/* ===== Forms ===== */
.form {
  display: grid;
  gap: 10px;
}

.form input {
  width: 100%;
  min-width: 0;
}

.form button {
  width: 100%;
}

.form .hint {
  font-size: 12px;
  color: #848995;
}

/* ===== Login ===== */
.page-center {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: #1e1e1e;
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.10);
}

.login-title {
  margin: 0 0 6px 0;
}

.login-subtitle {
  margin: 0 0 14px 0;
}

/* ===== Parts (mobile cards) ===== */
.mobile-list {
  display: none;
}

.part-card {
  background: #2f2f2f;
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.08);
  display: grid;
  gap: 10px;
}

.part-card-top {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 12px;
  align-items: center;
}

.part-card-title {
  display: grid;
  gap: 2px;
}

.part-card-title .name {
  font-weight: 700;
  font-size: 16px;
}

.part-card-title .number {
  font-size: 13px;
  color: #aab0bd;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #434343;
  padding: 8px 10px;
  border-radius: 10px;
  font-weight: 600;
  width: fit-content;
}

.part-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.part-actions input {
  width: 100%;
}

.part-actions button {
  white-space: nowrap;
}

/* ===== Autocomplete ===== */
.autocomplete {
  position: relative;
  width: 100%;
}

.autocomplete-list {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  background: #fff;
  border: 1px solid #d0d5dd;
  border-radius: 10px;
  margin-top: 4px;
  max-height: 240px;
  overflow-y: auto;
  z-index: 50;
  box-shadow: 0 10px 24px rgba(0,0,0,0.12);
  color: black;
}

.autocomplete-item {
  padding: 10px 12px;
  cursor: pointer;
  display: grid;
  gap: 2px;
}

.autocomplete-item:hover {
  background: #f1f3f7;
}

.autocomplete-item .main {
  font-weight: 600;
}

.autocomplete-item .sub {
  font-size: 12px;
  color: #667085;
}

/* ===== Loading ===== */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: grid;
  place-items: center;
  z-index: 9999;
  pointer-events: auto;
}

.loading-card {
  background: #464646;
  border-radius: 14px;
  padding: 16px 18px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  display: grid;
  gap: 10px;
  width: min(320px, calc(100vw - 40px));
  justify-items: center;
}

.loading-text {
  font-weight: 600;
  text-align: center;
}

.spinner {
  width: 38px;
  height: 38px;
  border: 4px solid rgba(0,0,0,0.12);
  border-top-color: rgba(0,0,0,0.65);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 9998;
  display: grid;
  place-items: center;
  padding: 16px;
  pointer-events: auto;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.45);
  pointer-events: auto;
}

.modal-panel {
  position: relative;
  background: #1a1a1a;
  border-radius: 16px;
  box-shadow: 0 20px 70px rgba(0,0,0,0.25);
  width: min(900px, 100%);
  height: min(80vh, 720px);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: modalIn .18s ease-out;
  transform-origin: center;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(.98); }
  to   { opacity: 1; transform: scale(1); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
  flex: 0 0 auto;
}

.modal-controls {
  flex: 0 0 auto;
}

.modal-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  padding-right: 4px;
}

.modal-footer {
  flex: 0 0 auto;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ===== Misc ===== */
.parts-list {
  display: grid;
  gap: 12px;
}

.repairheader {
  padding-bottom: 12px;
}

/* ===== Toasts ===== */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 99999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  max-width: 360px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  pointer-events: auto;
  transition: opacity 0.3s ease, transform 0.3s ease;
  animation: toastIn 0.2s ease-out;
}

.toast.toast-hide {
  opacity: 0;
  transform: translateX(20px);
}

.toast-ok {
  background: #1a3d2b;
  color: #6ee7b7;
  border: 1px solid #2d6a4f;
}

.toast-err {
  background: #3d1a1a;
  color: #fca5a5;
  border: 1px solid #7f1d1d;
}

.toast-info {
  background: #2a2a2a;
  color: #dfdfdf;
  border: 1px solid #3a3a3a;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ===== Danger button ===== */
button.danger {
  background: #7f1d1d;
  color: #fca5a5;
}

button.danger:hover {
  background: #991b1b;
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
  .login-card { padding: 16px; border-radius: 12px; }
  input, button { padding: 14px; }
}

@media (max-width: 720px) {
  .page-wrap { padding: 16px 14px; }

  .row {
    display: grid;
    gap: 10px;
    align-items: stretch;
  }

  input, button {
    width: 100%;
    min-width: 0;
  }

  .btn-sq { width: 38px; }
  .search-icon-btn { width: auto; }
  .search-wrap input { width: auto; }
  .dash-part-row button { width: auto; }
  .search-row { flex-wrap: nowrap; }

  .qty-grid {
    grid-template-columns: 1fr;
  }
  .qty-grid button { width: 100%; }

  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-value { font-size: 1.6rem; }
  .btn-link { width: 100%; justify-content: center; }
  .alerts-grid { grid-template-columns: 1fr; }

  table { display: none; }
  .mobile-list { display: grid; gap: 12px; }

  /* Topbar: show hamburger, hide desktop-only items */
  .app-hamburger { display: flex; }
  .app-topbar-nav { display: none; }
  .app-topbar-right { display: none; }
}
