:root {
  --blue: #2563eb;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #f59e0b;
  --bg: #f5f6f8;
  --card-bg: #ffffff;
  --border: #e2e5ea;
  --text: #1f2430;
  --muted: #6b7280;
}

* { box-sizing: border-box; }

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  flex-wrap: wrap;
  gap: 10px;
}

.brand { font-weight: 700; font-size: 1.2rem; }

.topbar nav a {
  margin-left: 18px;
  text-decoration: none;
  color: var(--muted);
  font-weight: 500;
  padding-bottom: 4px;
}

.topbar nav a.active,
.topbar nav a:hover {
  color: var(--blue);
  border-bottom: 2px solid var(--blue);
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  margin-left: auto;
}

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  cursor: pointer;
  padding: 0;
}

.nav-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
}

.btn-link {
  background: none;
  border: none;
  color: var(--blue);
  cursor: pointer;
  padding: 0;
  font-size: 0.9rem;
  text-decoration: underline;
}

.content {
  max-width: 1000px;
  margin: 0 auto;
  padding: 24px;
}

.auth-content {
  max-width: 420px;
  margin: 60px auto;
}

h1 { margin-top: 0; }
h2 { margin-top: 32px; }
.muted { color: var(--muted); }

.flashes { margin-bottom: 16px; }
.flash {
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 8px;
  font-size: 0.95rem;
}
.flash-success { background: #dcfce7; color: #166534; }
.flash-error { background: #fee2e2; color: #991b1b; }

.cards {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin: 16px 0;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 20px;
  min-width: 160px;
  flex: 1;
}

.card-warn { border-color: var(--amber); background: #fffbeb; }

.card-label { font-size: 0.85rem; color: var(--muted); }
.card-value { font-size: 1.6rem; font-weight: 700; margin-top: 4px; }
.card-sub { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.table th, .table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.95rem;
}

.table th { background: #fafbfc; font-weight: 600; }
.row-warn { background: #fff7ed; }

.grid-table {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.grid-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding: 8px 14px;
  gap: 8px;
}

.grid-row:last-child { border-bottom: none; }
.grid-head { background: #fafbfc; font-weight: 600; font-size: 0.9rem; }
.grid-row-form { display: contents; }
.grid-row .actions { display: contents; }
.grid-row form.actions { display: contents; }

.sell .grid-row, form .grid-row { grid-template-columns: repeat(4, 1fr); }

.small-input { width: 100%; padding: 6px; border: 1px solid var(--border); border-radius: 4px; }

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  background: var(--card-bg);
  border: 1px solid var(--border);
  padding: 14px;
  border-radius: 8px;
}

.inline-form input, .inline-form select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.inline { display: inline; }

.role-form { display: flex; align-items: center; gap: 6px; }
.role-form select { padding: 6px 8px; width: auto; max-width: none; }
.role-form button { padding: 6px 10px; font-size: 0.85rem; }

input, select, button {
  font-family: inherit;
  font-size: 0.95rem;
}

button {
  padding: 8px 14px;
  border: none;
  border-radius: 6px;
  background: var(--blue);
  color: white;
  cursor: pointer;
}

button:hover { opacity: 0.9; }

.btn-danger { background: var(--red); }
.btn-primary { background: var(--green); font-size: 1.05rem; padding: 10px 20px; }

.pay-options { display: flex; gap: 20px; margin: 10px 0; flex-wrap: wrap; }

.field-label { display: block; margin-top: 12px; margin-bottom: 6px; font-weight: 600; }

select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 100%;
  max-width: 400px;
}

.pill {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
}

.pill-active { background: var(--blue); color: white; border-color: var(--blue); }

/* ------------------------------------------------------------------------
   Phone screens: stack grid/table rows into single-column labeled cards,
   and make everything easier to tap with a finger.
   ------------------------------------------------------------------------ */
@media (max-width: 640px) {
  .content { padding: 14px; }

  .topbar { padding: 10px 14px; }

  /* Nav collapses behind a hamburger button instead of wrapping into a
     crowded row of links - tap the button to open a full-width dropdown. */
  .nav-toggle { display: flex; margin-left: auto; }

  .topbar nav {
    display: none;
    width: 100%;
    flex-direction: column;
    gap: 0;
    margin-top: 10px;
    border-top: 1px solid var(--border);
  }
  .topbar.nav-open nav { display: flex; }

  .topbar nav a {
    margin-left: 0;
    font-size: 1rem;
    padding: 13px 4px;
    border-bottom: 1px solid var(--border);
  }
  .topbar nav a:last-child { border-bottom: none; }
  .topbar nav a.active, .topbar nav a:hover {
    border-bottom: 1px solid var(--border);
    background: #eef2ff;
    padding-left: 10px;
  }

  .user-badge { order: 2; }

  h1 { font-size: 1.4rem; }
  h2 { font-size: 1.1rem; margin-top: 24px; }

  .cards { flex-direction: column; }
  .card { min-width: 0; }

  /* Plain tables (customers, reports, customer detail, dashboard) become
     stacked cards: one row per item, each cell labeled by its column name. */
  .table, .table thead, .table tbody, .table th, .table td, .table tr {
    display: block;
  }
  .table thead { display: none; }
  .table tr {
    border-bottom: 1px solid var(--border);
    padding: 10px 14px;
  }
  .table tr:last-child { border-bottom: none; }
  .table td {
    border-bottom: none;
    padding: 4px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    text-align: right;
  }
  .table td[data-label]::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--muted);
    text-align: left;
  }

  /* Grid-based editable tables (inventory, sell) become the same style of
     stacked, labeled rows instead of a multi-column grid. */
  .grid-head { display: none; }
  .grid-row {
    display: block;
    grid-template-columns: none !important;
    padding: 12px 14px;
  }
  .grid-row > div,
  .grid-row-form > div,
  .grid-row form.actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 5px 0;
  }
  .grid-row [data-label]::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--muted);
    flex-shrink: 0;
  }
  .grid-row .small-input { max-width: 55%; text-align: right; }
  .grid-row .actions { justify-content: flex-end; }

  .inline-form { flex-direction: column; align-items: stretch; }
  .inline-form input, .inline-form select, .inline-form button { width: 100%; }

  select { max-width: none; }

  button { padding: 10px 16px; min-height: 40px; }
  input, select { min-height: 40px; }
}
