* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, "Helvetica Neue", Arial, sans-serif;
  margin: 0;
  padding: 0;
  background: #fafafa;
  color: #222;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

a[href^="tel"], a[href^="sms"] { color: inherit; text-decoration: none; }

/* ============================ Header ============================ */
header {
  background: #1f2937;
  color: #fff;
  padding: 0.75rem 1rem;
  padding-top: calc(0.75rem + env(safe-area-inset-top, 0));
  box-shadow: 0 2px 4px rgba(0,0,0,0.08);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
header h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.header-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.5rem;
}
.lang-btn {
  background: rgba(255,255,255,0.1);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 6px;
  padding: 0.35rem 0.7rem;
  min-height: 32px;
  font-size: 0.85rem;
  cursor: pointer;
  margin-inline-start: auto;
}
.lang-btn:hover { background: rgba(255,255,255,0.2); }

/* Hamburger — only visible on mobile */
.menu-toggle {
  display: none;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255,255,255,0.4);
  background: rgba(255,255,255,0.18);
  border-radius: 8px;
  padding: 0;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}
.menu-toggle:active { background: rgba(255,255,255,0.28); }
.menu-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  background: #fff;
  border-radius: 1px;
  transition: transform 0.2s, opacity 0.2s;
}
.menu-toggle.open span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.menu-toggle.open span:nth-child(2) { opacity: 0; }
.menu-toggle.open span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

nav {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
}
nav button {
  background: transparent;
  color: rgba(255,255,255,0.75);
  border: none;
  padding: 0.5rem 0.85rem;
  cursor: pointer;
  font: inherit;
  font-size: 0.9rem;
  border-bottom: 2px solid transparent;
  border-radius: 4px 4px 0 0;
  min-height: 0;
}
nav button:hover { color: #fff; background: rgba(255,255,255,0.05); }
nav button.active { color: #fff; border-bottom-color: #38bdf8; }

main {
  padding: 1rem;
  max-width: 1200px;
  margin: 0 auto;
}
.tab { display: none; }
.tab.active { display: block; }
.actions {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.actions input[type="search"] {
  flex: 1;
  min-width: 200px;
  padding: 0.55rem 0.8rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  font: inherit;
  font-size: 16px; /* iOS won't auto-zoom on focus when font-size >= 16px */
}

button {
  padding: 0.55rem 1rem;
  min-height: 40px;
  border: 1px solid #ccc;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  font-size: 0.92rem;
  touch-action: manipulation;
}
button:hover { background: #f3f4f6; }
button:active { background: #e5e7eb; }
button.primary { background: #2563eb; color: #fff; border-color: #2563eb; }
button.primary:hover { background: #1d4ed8; }
button.danger { color: #b91c1c; border-color: #b91c1c; background: #fff; }
button.danger:hover { background: #fee2e2; }
button:disabled { opacity: 0.5; cursor: default; }

/* ============================ Revoke form ============================ */
.revoke-form {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 1rem 1.2rem;
  margin-bottom: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-width: 720px;
}
.revoke-form h2 { margin: 0 0 0.2rem; font-size: 1rem; }
.revoke-form textarea,
.revoke-form input {
  font: inherit;
  font-size: 14px;
  padding: 0.55rem 0.8rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  resize: vertical;
}
.revoke-form textarea {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  direction: ltr;
  text-align: left;
}
.revoke-form button { align-self: flex-start; }

/* ============================ Tables ============================ */
table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 0 #e5e7eb;
}
th, td {
  padding: 0.55rem 0.75rem;
  text-align: start;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: middle;
}
th {
  background: #f3f4f6;
  font-weight: 600;
  font-size: 0.85rem;
  color: #374151;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
td.machine, td.serial {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  word-break: break-all;
  direction: ltr;
  text-align: left;
  max-width: 340px;
}

/* Filter + badges */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: rgba(255,255,255,0.85);
  font-size: 0.9rem;
  flex-shrink: 0;
}
.filter-bar select {
  background: rgba(255,255,255,0.1);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.25);
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  font: inherit;
  font-size: 16px;
  min-height: 36px;
}
.filter-bar select option { background: #1f2937; color: #fff; }

.product-badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  background: #dbeafe;
  color: #1e40af;
}
.hidden { display: none !important; }

#toast {
  position: fixed;
  bottom: calc(1rem + env(safe-area-inset-bottom, 0));
  right: 1rem;
  left: 1rem;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
  padding: 0.75rem 1.1rem;
  background: #1f2937;
  color: #fff;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
  font-size: 0.9rem;
}
#toast.error { background: #b91c1c; }

.action-buttons {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.empty { color: #6b7280; padding: 1rem 0.25rem; }

/* ============================ Mobile (≤720px) — card layout ============================ */
@media (max-width: 720px) {
  body { font-size: 14.5px; background: #f3f4f6; }

  .menu-toggle { display: inline-flex; }
  .header-controls {
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    margin-top: 0.75rem;
  }
  .header-controls.open { display: flex; }
  header h1 { font-size: 1rem; }
  .lang-btn { margin-inline-start: 0; }

  .filter-bar {
    color: #fff;
    background: rgba(255,255,255,0.05);
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    flex-wrap: wrap;
  }
  .filter-bar select { flex: 1; min-width: 0; }

  nav {
    background: rgba(255,255,255,0.05);
    padding: 0.25rem;
    border-radius: 6px;
  }
  nav button {
    flex: 1;
    text-align: center;
    border-radius: 4px;
    border-bottom: none;
  }
  nav button.active { background: rgba(56,189,248,0.18); border-bottom: none; }

  main { padding: 0.75rem; }

  /* Convert each table to a stack of cards. */
  table, tbody, tr, td { display: block; width: 100%; }
  table { background: transparent; box-shadow: none; border-radius: 0; }
  thead { display: none; }
  tr {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    margin-bottom: 0.7rem;
    padding: 0.85rem 1rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  }
  td {
    border: none;
    padding: 0.35rem 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    min-height: 28px;
    font-size: 0.92rem;
  }
  td:not(:last-child) {
    border-bottom: 1px solid #f3f4f6;
    padding-bottom: 0.5rem;
    margin-bottom: 0.25rem;
  }
  td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #6b7280;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    flex-shrink: 0;
    min-width: 80px;
  }
  td:not([data-label])::before { display: none; }
  td[data-label=""] { justify-content: flex-end; }
  td[data-label=""]::before { display: none; }
  td.action-cell {
    flex-direction: column;
    align-items: stretch;
    gap: 0.4rem;
  }
  td.action-cell::before { align-self: flex-start; }
  .action-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.35rem;
    width: 100%;
  }
  .action-buttons button {
    padding: 0.55rem 0.4rem;
    font-size: 0.85rem;
  }
  td.machine, td.serial {
    font-size: 11.5px;
    word-break: break-all;
    max-width: none;
  }
}

/* ============================ Very small (≤380px) ============================ */
@media (max-width: 380px) {
  main { padding: 0.5rem; }
  tr { padding: 0.7rem 0.85rem; }
  td::before { min-width: 70px; font-size: 0.65rem; }
  .action-buttons { grid-template-columns: 1fr; }
  .action-buttons button { padding: 0.65rem 0.5rem; }
}

/* ============================ Dark mode ============================ */
@media (prefers-color-scheme: dark) {
  body { background: #0b0d11; color: #e5e7eb; }
  table { background: #161a22; }
  tr { background: #161a22; border-color: #262a33; }
  th { background: #1f242e; color: #cbd5e1; border-bottom-color: #262a33; }
  td { border-bottom-color: #1d212a; }
  @media (max-width: 720px) {
    body { background: #0b0d11; }
    tr { background: #161a22; border-color: #262a33; }
    td:not(:last-child) { border-bottom-color: #1d212a; }
    td::before { color: #9ca3af; }
  }
  button {
    background: #1f242e;
    color: #e5e7eb;
    border-color: #303744;
  }
  button:hover { background: #262c38; }
  button.primary { background: #2563eb; border-color: #2563eb; color: #fff; }
  button.danger { color: #fca5a5; border-color: #ef4444; background: #1f242e; }
  input[type="search"], .revoke-form textarea, .revoke-form input {
    background: #1f242e;
    border-color: #303744;
    color: #e5e7eb;
  }
  input[type="search"]::placeholder,
  .revoke-form textarea::placeholder,
  .revoke-form input::placeholder { color: #6b7280; }
  .revoke-form { background: #161a22; border-color: #262a33; }
  .product-badge { background: #1e3a8a; color: #bfdbfe; }
}
