/* ──────────────────────────────────────────────────────────────────────────
   JuiceTrack app stylesheet
   All pages link this file and use the component classes below instead of
   re-declaring buttons/inputs/cards inline.
   ────────────────────────────────────────────────────────────────────────── */

:root {
  --bg:         #0D1117;
  --bg-card:    #1F2533;
  --bg-hover:   #252D3D;
  --bg-input:   #252D3D;
  --border:     #374151;
  --border-2:   #4B5563;
  --text:       #F3F4F6;
  --text-mute:  #9CA3AF;
  --text-dim:   #6B7280;
  --brand:      #08FA6B;
  --brand-dark: #06d45c;
  --brand-ink:  #1F2533;
  --danger:     #EF4444;
  --warn:       #FCD34D;
  --success:    #86EFAC;
  --info:       #A5B4FC;

  --radius:     8px;
  --radius-lg:  16px;
  --nav-h:      56px;
}

* { box-sizing: border-box; }

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

a { color: inherit; }

/* ── Layout containers ────────────────────────────────────────────────── */

.page        { padding: 24px 16px 48px; }
.page-wrap   { max-width: 72rem; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }
.page-auth   { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }

@media (min-width: 640px) {
  .page { padding: 32px 24px 64px; }
}

/* ── Cards ────────────────────────────────────────────────────────────── */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.card-pad    { padding: 20px; }
.card-pad-sm { padding: 12px 16px; }
@media (min-width: 640px) {
  .card-pad    { padding: 24px; }
}

/* ── Buttons ──────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  min-height: 40px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
  white-space: nowrap;
  font-family: inherit;
}
.btn:disabled { background: var(--border) !important; color: var(--text-dim) !important; cursor: not-allowed; border-color: transparent !important; }

.btn-primary   { background: var(--brand);    color: var(--brand-ink); }
.btn-primary:hover:not(:disabled)   { background: var(--brand-dark); }

.btn-secondary { background: var(--bg-card);  color: var(--text-mute); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); color: var(--text); }

.btn-danger    { background: rgba(239,68,68,.15); color: var(--danger); }
.btn-danger:hover:not(:disabled)    { background: rgba(239,68,68,.25); }

.btn-ghost     { background: transparent; color: var(--text-mute); border-color: transparent; }
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--bg-hover); }

.btn-sm        { padding: 6px 12px; min-height: 32px; font-size: 0.8rem; }
.btn-xs        { padding: 4px 8px;  min-height: 26px; font-size: 0.75rem; }

/* ── Inputs ───────────────────────────────────────────────────────────── */

.input, .select, .textarea,
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]),
select, textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  line-height: 1.5;
  font-family: inherit;
  transition: border-color .12s, box-shadow .12s;
}
.input:focus, .select:focus, .textarea:focus,
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]):focus,
select:focus, textarea:focus {
  outline: none;
  border: 1px solid var(--brand);
  box-shadow: 0 0 0 2px rgba(8,250,107,.15);
}
input:disabled, select:disabled, textarea:disabled { opacity: .7; cursor: not-allowed; }
input::placeholder, textarea::placeholder { color: var(--text-dim); }
option { background: var(--bg-card); color: var(--text); }

/* Replace the browser's default dropdown arrow with a chevron that sits a few
   pixels in from the right edge, giving selects a little breathing room. */
.select, select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none' stroke='%239CA3AF' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><polyline points='1 1 6 6 11 1'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
.select[multiple], select[multiple] {
  background-image: none;
  padding-right: 12px;
}

/* ── Lookup (search-as-you-type picker) ──────────────────────────────── */
.lookup { position: relative; }
.lookup-input { padding-right: 36px; }
.lookup-clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 24px; height: 24px; border: 0; background: transparent;
  color: var(--text-mute); cursor: pointer; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
}
.lookup-clear:hover { color: var(--text); background: var(--bg-hover); }
.lookup-menu {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px);
  max-height: 240px; overflow-y: auto;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 4px 12px rgba(0,0,0,.4);
  z-index: 50;
}
.lookup-row {
  padding: 8px 12px; cursor: pointer; font-size: 0.9rem;
  border-bottom: 1px solid var(--border);
}
.lookup-row:last-child { border-bottom: 0; }
.lookup-row:hover { background: var(--bg-hover); }
.lookup-empty {
  padding: 10px 12px; color: var(--text-mute); font-size: 0.85rem; font-style: italic;
}

.label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-mute);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
  font-weight: 600;
}
.label-req::after { content: " *"; color: var(--brand); }

.field { margin-bottom: 14px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
@media (max-width: 640px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; gap: 10px; }
}

/* ── Tables ───────────────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; border-radius: inherit; }
.table {
  width: 100%;
  border-collapse: collapse;
  min-width: 100%;
}
.table th, .table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table th {
  color: var(--text-mute);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.table tbody tr:hover td { background: var(--bg-hover); }
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--text); }
.table tr.row-clickable { cursor: pointer; }

/* ── Quantity stepper (inline +/- wrapper around a number input) ────── */
.qty-stepper { display: inline-flex; align-items: stretch; border-radius: var(--radius); transition: box-shadow .12s; }
/* When the inner input is focused, ring the whole group instead of just the input. */
.qty-stepper:focus-within { box-shadow: 0 0 0 2px rgba(8,250,107,.15); }
.qty-stepper:focus-within button { border-color: var(--brand); }
.qty-stepper:focus-within input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]) { border-color: var(--brand) !important; }
/* Suppress input's own glow in all states — the parent .qty-stepper owns the ring. */
.qty-stepper input,
.qty-stepper input:focus { box-shadow: none !important; outline: none; }
.qty-stepper button {
  width: 28px; min-height: 32px; padding: 0;
  background: var(--bg-input); border: 1px solid var(--border); color: var(--text);
  cursor: pointer; font-weight: 600; line-height: 1;
  transition: border-color .12s, background .12s;
}
.qty-stepper button:first-child { border-radius: var(--radius) 0 0 var(--radius); border-right: 0; }
.qty-stepper button:last-child  { border-radius: 0 var(--radius) var(--radius) 0; border-left: 0; }
.qty-stepper button:hover:not(:disabled) { background: var(--bg-hover); }
.qty-stepper input {
  /* !important to override the global `input { width: 100% }` rule, which has
     higher specificity via its long :not() chain. */
  width: 56px !important; min-width: 56px; text-align: center;
  border-radius: 0 !important; padding: 4px 6px;
  -moz-appearance: textfield; appearance: textfield;
}
.qty-stepper input::-webkit-outer-spin-button,
.qty-stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.table tbody tr:last-child td { border-bottom: 0; }
.table a.row-link { color: var(--text); text-decoration: none; }
.table a.row-link:hover { color: var(--brand); }
.table td.wrap, .table th.wrap { white-space: normal; }
/* Subheading row used to group a table by a parent entity (e.g. assets grouped by site). */
.table tr.site-group-row td {
  background: var(--bg);
  color: var(--text-mute);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 8px 14px;
}
.table tbody tr.site-group-row:hover td { background: var(--bg); }
.only-mobile { display: none; }
@media (max-width: 640px) {
  .hide-mobile { display: none !important; }
  .only-mobile { display: inline; }
  /* Group-subhead rows collapse their own padding/border in stacked mode so they
     don't end up looking like regular cards. */
  .table-stack tr.site-group-row { padding: 0; border: 0; }

  /* Responsive "stacking" tables: on narrow screens the table collapses into
     per-row cards. Each <td> renders as a block with its column label read
     from data-label (blank data-label = no prefix, for the prominent cell). */
  .table-stack { min-width: 0; }
  .table-stack thead { display: none; }
  .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
  .table-stack tr {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
  }
  .table-stack tbody tr:last-child { border-bottom: 0; }
  .table-stack tbody tr:hover td { background: transparent; }
  .table-stack td {
    padding: 3px 0;
    white-space: normal;
    border: 0;
  }
  .table-stack td[data-label]:not([data-label=""])::before {
    content: attr(data-label) ":";
    display: inline-block;
    min-width: 72px;
    color: var(--text-mute);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-right: 8px;
    vertical-align: middle;
  }
  .table-stack td.row-title {
    padding: 0 0 4px;
    font-size: 1rem;
    font-weight: 600;
  }
  .table-stack td.row-title::before { display: none; }
}

/* ── Badges ───────────────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-green  { background: rgba(34,197,94,.12);  color: var(--success); }
.badge-brand  { background: rgba(8,250,107,.12);  color: var(--brand); }
.badge-yellow { background: rgba(245,158,11,.12); color: var(--warn); }
.badge-red    { background: rgba(239,68,68,.12);  color: var(--danger); }
.badge-blue   { background: rgba(99,102,241,.12); color: var(--info); }
.badge-grey   { background: rgba(107,114,128,.15);color: var(--text-mute); }
.table .badge { font-size: 0.85rem; }

/* Mapped status classes used by status-to-badge helpers */
.badge-Open              { background: rgba(99,102,241,.12); color: var(--info); }
.badge-In-Progress       { background: rgba(8,250,107,.12);  color: var(--brand); }
.badge-CS-Review         { background: rgba(245,158,11,.12); color: var(--warn); }
.badge-Awaiting-Approval { background: rgba(245,158,11,.12); color: var(--warn); }
.badge-Approved          { background: rgba(34,197,94,.12);  color: var(--success); }
.badge-Scheduled         { background: rgba(34,197,94,.12);  color: var(--success); }
.badge-Completed         { background: rgba(107,114,128,.15);color: var(--text-mute); }
.badge-Rejected          { background: rgba(239,68,68,.12);  color: var(--danger); }
.badge-Closed            { background: rgba(107,114,128,.15);color: var(--text-mute); }

.badge-Low      { background: rgba(107,114,128,.15); color: var(--text-mute); }
.badge-Medium   { background: rgba(99,102,241,.12);  color: var(--info); }
.badge-High     { background: rgba(245,158,11,.12);  color: var(--warn); }
.badge-Critical { background: rgba(239,68,68,.12);   color: var(--danger); }

.badge-battery  { background: rgba(8,250,107,.12);  color: var(--brand); }
.badge-charger  { background: rgba(245,158,11,.12); color: var(--warn); }
.badge-In-Service     { background: rgba(34,197,94,.12);  color: var(--success); }
.badge-Out-Of-Service { background: rgba(239,68,68,.12);  color: var(--danger); }
.badge-In-Repair      { background: rgba(245,158,11,.12); color: var(--warn); }
.badge-Removed        { background: rgba(107,114,128,.15);color: var(--text-mute); }

/* ── Status phrases ───────────────────────────────────────────────────── */

.muted { color: var(--text-mute); }
.dim   { color: var(--text-dim); }
.mono  { font-family: ui-monospace, "SF Mono", Consolas, monospace; }

.empty, .loading {
  text-align: center;
  padding: 36px 16px;
  color: var(--text-dim);
  font-size: 0.95rem;
}
.loading::after {
  content: "";
  display: inline-block;
  width: 1em;
  animation: dots 1.2s steps(4,end) infinite;
}
@keyframes dots { 0%{content:""} 25%{content:"."} 50%{content:".."} 75%{content:"..."} }

.status-line { font-size: 0.85rem; min-height: 1.2em; }
.status-ok   { color: var(--success); }
.status-err  { color: var(--danger); }
.status-warn { color: var(--warn); }

/* ── Navigation ───────────────────────────────────────────────────────── */

.app-nav {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}
.nav-inner {
  max-width: 72rem;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
}
.brand {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -.03em;
  color: var(--brand);
  text-decoration: none;
  padding: 4px 6px;
}
.nav-links {
  display: flex;
  gap: 2px;
  flex: 1;
  flex-wrap: wrap;
  margin-left: 12px;
}
.nav-link {
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--text-mute);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.9rem;
}
.nav-link:hover { background: var(--bg-hover); color: var(--text); }
.nav-link.is-active {
  color: var(--brand);
  background: rgba(8,250,107,.08);
}
.nav-user { display: flex; gap: 10px; align-items: center; }
.nav-user-name { font-size: 0.82rem; color: var(--text-mute); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-signout {
  font-size: 0.82rem;
  color: var(--text-mute);
  text-decoration: none;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.nav-signout:hover { background: var(--bg-hover); color: var(--text); }
.nav-toggle {
  display: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 6px;
  min-height: 36px;
}

/* Sign-out + user label inside the burger menu — mobile only. */
.nav-mobile-user, .nav-mobile-signout { display: none; }

@media (max-width: 720px) {
  .nav-toggle { display: inline-flex; align-items: center; order: 2; margin-left: auto; }
  /* Desktop user+signout hidden on mobile; those move inside the burger menu. */
  .nav-user { display: none; }
  .nav-mobile-user {
    display: block;
    padding: 8px 12px;
    font-size: 0.8rem;
    color: var(--text-mute);
    border-bottom: 1px solid var(--border);
    margin-bottom: 6px;
  }
  .nav-mobile-signout {
    display: block;
    border-top: 1px solid var(--border);
    margin-top: 6px;
    padding-top: 12px;
    color: var(--text-mute);
  }
  /* Open menu floats below the header as an absolutely-positioned panel rather
     than expanding the sticky header. Anchored to .app-nav (sticky == positioned). */
  .nav-links {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    gap: 2px;
    margin: 0;
    padding: 8px;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 10px 24px rgba(0,0,0,0.5);
    max-height: calc(100vh - 60px);
    overflow-y: auto;
  }
  .app-nav.nav-open .nav-links { display: flex; }
  .nav-link { padding: 10px 12px; }
}

/* ── Impersonation banner ─────────────────────────────────────────────── */

.imp-banner {
  background: rgba(245,158,11,.14);
  border-bottom: 1px solid rgba(245,158,11,.5);
  color: var(--warn);
  font-size: 0.85rem;
  text-align: center;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}
.imp-banner strong { color: var(--text); }
.imp-banner .btn { padding: 4px 10px; min-height: 26px; font-size: 0.75rem; }

/* ── Toast ────────────────────────────────────────────────────────────── */

.toast-stack {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 60;
  max-width: 92vw;
  pointer-events: none;
}
.toast {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: 0 12px 36px rgba(0,0,0,0.5);
  pointer-events: auto;
  animation: toast-in .18s ease-out;
}
.toast-success { border-color: rgba(34,197,94,.4); color: var(--success); }
.toast-error   { border-color: rgba(239,68,68,.4); color: var(--danger); }
.toast-info    { border-color: var(--border); color: var(--text); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── Tabs ─────────────────────────────────────────────────────────────── */

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab {
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  color: var(--text-mute);
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  background: transparent;
  border-left: none; border-right: none; border-top: none;
  font-family: inherit;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Misc ─────────────────────────────────────────────────────────────── */

hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

.sticky-bar {
  position: sticky;
  bottom: 16px;
  z-index: 20;
}

/* Scrollbar */
::-webkit-scrollbar       { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-2); }

/* Utility tweaks */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; } .gap-6 { gap: 24px; }
.mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; } .mb-4 { margin-bottom: 16px; }
.text-sm { font-size: 0.875rem; } .text-xs { font-size: 0.75rem; } .text-lg { font-size: 1.1rem; }
.text-2xl { font-size: 1.5rem; line-height: 1.2; } .text-3xl { font-size: 1.875rem; line-height: 1.2; }
.font-bold { font-weight: 700; } .font-semibold { font-weight: 600; }
.text-right { text-align: right; } .text-center { text-align: center; }
.hidden { display: none !important; }
.w-full { width: 100%; }
