/* ==========================================================================
   Wavesure Rentals — design system
   Brand: deep teal #33646d + dark gray #404040 (sampled from logo)
   Mobile-first. Bottom tab bar < 768px, top nav >= 768px.
   ========================================================================== */

:root {
  /* Color — brand */
  --teal-900: #1d3f45;
  --teal-800: #27525a;
  --teal-700: #33646d;   /* logo teal */
  --teal-600: #3f7a85;
  --teal-500: #4f93a0;
  --teal-100: #dcebee;
  --teal-50:  #eff6f7;

  /* Color — neutrals */
  --gray-900: #26282b;
  --gray-800: #404040;   /* logo gray */
  --gray-700: #55585c;
  --gray-600: #6b6f74;
  --gray-500: #8a8f95;
  --gray-400: #b3b8bd;
  --gray-300: #d3d7da;
  --gray-200: #e5e8ea;
  --gray-100: #f1f3f4;
  --gray-50:  #f8f9fa;
  --white: #ffffff;

  /* Color — status */
  --ok-600: #2e7d4f;   --ok-100: #ddf0e4;
  --warn-700: #a05a12; --warn-100: #fbeeda;
  --info-700: #2b5f9e; --info-100: #dfeafa;
  --danger-600: #b3372f; --danger-100: #f9e2e0;
  --muted-600: var(--gray-600); --muted-100: var(--gray-200);

  /* Semantic */
  --bg: var(--gray-100);
  --surface: var(--white);
  --text: var(--gray-900);
  --text-muted: var(--gray-600);
  --border: var(--gray-300);
  --accent: var(--teal-700);
  --accent-hover: var(--teal-800);
  --focus-ring: 0 0 0 3px rgba(63, 122, 133, .35);

  /* Type scale */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --fs-xs: .75rem;
  --fs-sm: .8125rem;
  --fs-base: .9375rem;
  --fs-md: 1.0625rem;
  --fs-lg: 1.25rem;
  --fs-xl: 1.5rem;
  --fs-2xl: 1.875rem;

  /* Spacing scale */
  --sp-1: .25rem;
  --sp-2: .5rem;
  --sp-3: .75rem;
  --sp-4: 1rem;
  --sp-5: 1.5rem;
  --sp-6: 2rem;
  --sp-7: 3rem;

  /* Radii & shadow */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --shadow-1: 0 1px 3px rgba(30, 41, 45, .10);
  --shadow-2: 0 6px 24px rgba(30, 41, 45, .16);

  --tabbar-h: calc(3.6rem + env(safe-area-inset-bottom, 0px));
  --header-h: 3.4rem;
}

/* ---------- Reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  padding-bottom: var(--tabbar-h);
}
h1, h2, h3 { margin: 0 0 var(--sp-3); line-height: 1.2; color: var(--gray-900); }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs-md); }
p { margin: 0 0 var(--sp-3); }
a { color: var(--accent); text-decoration: none; }
img { max-width: 100%; display: block; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--r-sm); }

/* ---------- App header ---------- */
.app-header {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: var(--sp-5);
  height: var(--header-h);
  padding: 0 var(--sp-4);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; height: 100%; }
.brand-logo { height: 2rem; width: auto; }
.top-nav { display: none; }

/* ---------- Bottom tab bar (mobile) ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex;
  height: var(--tabbar-h);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.tabbar a {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  font-size: var(--fs-xs);
  color: var(--gray-600);
}
.tabbar a svg {
  width: 22px; height: 22px;
  fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
}
.tabbar a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabbar a.active { color: var(--accent); font-weight: 600; }

/* ---------- Desktop nav ---------- */
@media (min-width: 768px) {
  body { padding-bottom: 0; }
  .tabbar { display: none; }
  .top-nav { display: flex; gap: var(--sp-2); }
  .top-nav a {
    padding: var(--sp-2) var(--sp-3);
    border-radius: var(--r-sm);
    color: var(--gray-700);
    font-weight: 500;
    font-size: var(--fs-sm);
  }
  .top-nav a:hover { background: var(--teal-50); color: var(--accent); }
  .top-nav a.active { background: var(--teal-100); color: var(--teal-800); }
}

/* ---------- Layout ---------- */
.view {
  max-width: 60rem;
  margin: 0 auto;
  padding: var(--sp-4);
}
@media (min-width: 768px) { .view { padding: var(--sp-5); } }

.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-3); margin-bottom: var(--sp-4); flex-wrap: wrap;
}
.page-head h1 { margin: 0; }
.page-head .actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }

.grid-2 { display: grid; gap: var(--sp-4); grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-4);
  box-shadow: var(--shadow-1);
  margin-bottom: var(--sp-4);
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: .55rem .95rem;
  min-height: 2.5rem;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  font: inherit; font-size: var(--fs-sm); font-weight: 600;
  cursor: pointer;
  background: var(--accent); color: var(--white);
  transition: background .15s, border-color .15s, color .15s;
  text-decoration: none;
}
.btn:hover { background: var(--accent-hover); color: var(--white); }
.btn-secondary { background: var(--surface); color: var(--teal-800); border-color: var(--teal-600); }
.btn-secondary:hover { background: var(--teal-50); color: var(--teal-900); }
.btn-ghost { background: transparent; color: var(--gray-700); border-color: var(--border); }
.btn-ghost:hover { background: var(--gray-100); color: var(--gray-900); }
.btn-danger { background: var(--danger-600); }
.btn-danger:hover { background: #93291f; }
.btn-danger-ghost { color: var(--danger-600); border-color: var(--danger-100); }
.btn-danger-ghost:hover { background: var(--danger-100); color: var(--danger-600); border-color: var(--danger-600); }
.btn-sm { padding: .3rem .6rem; min-height: 2rem; font-size: var(--fs-xs); }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center;
  padding: .15rem .55rem;
  border-radius: 999px;
  font-size: var(--fs-xs); font-weight: 600;
  white-space: nowrap;
}
.badge-available { background: var(--ok-100); color: var(--ok-600); }
.badge-rented { background: var(--info-100); color: var(--info-700); }
.badge-inservice { background: var(--warn-100); color: var(--warn-700); }
.badge-retired { background: var(--muted-100); color: var(--muted-600); }
.badge-overdue { background: var(--danger-100); color: var(--danger-600); }
.badge-draft { background: var(--muted-100); color: var(--muted-600); }
.badge-shipped { background: var(--info-100); color: var(--info-700); }
.badge-returned { background: var(--ok-100); color: var(--ok-600); }
.badge-sold { background: #ece7f9; color: #5b48a2; }
.badge-tier { background: var(--teal-100); color: var(--teal-800); }
.badge-demo { background: #f3e8fb; color: #7a3ea8; }

/* Status badges that are tappable (quick status change) */
button.badge-btn { border: 0; cursor: pointer; font-family: inherit; line-height: 1.4; }
button.badge-btn:hover { filter: brightness(.94); }

/* ---------- KPI tiles (dashboard) ---------- */
.kpi-grid {
  display: grid; gap: var(--sp-3);
  grid-template-columns: repeat(2, 1fr);
  margin-bottom: var(--sp-4);
}
@media (min-width: 640px) { .kpi-grid { grid-template-columns: repeat(4, 1fr); } }
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4);
  box-shadow: var(--shadow-1);
  display: block; color: inherit;
}
.kpi:hover { border-color: var(--teal-600); }
.kpi .kpi-value { font-size: var(--fs-2xl); font-weight: 700; color: var(--teal-800); line-height: 1.1; }
.kpi .kpi-label { font-size: var(--fs-xs); color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi.kpi-danger .kpi-value { color: var(--danger-600); }

/* ---------- Search + filters ---------- */
.toolbar { display: flex; flex-direction: column; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.searchbar {
  width: 100%;
  padding: .6rem .9rem;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font: inherit; font-size: var(--fs-base);
  background: var(--surface);
}
.searchbar:focus { outline: none; border-color: var(--teal-600); box-shadow: var(--focus-ring); }
.chip-row { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.chip {
  padding: .3rem .8rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font: inherit; font-size: var(--fs-xs); font-weight: 600;
  color: var(--gray-700);
  cursor: pointer;
}
.chip.active { background: var(--teal-700); border-color: var(--teal-700); color: var(--white); }

/* ---------- List rows ---------- */
.list { display: flex; flex-direction: column; gap: var(--sp-2); }
.list-row {
  display: flex; align-items: center; gap: var(--sp-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4);
  color: inherit;
  box-shadow: var(--shadow-1);
}
.list-row:hover { border-color: var(--teal-600); }
.list-row .row-main { flex: 1; min-width: 0; }
.list-row .row-title { font-weight: 600; color: var(--gray-900); }
.list-row .row-sub {
  font-size: var(--fs-sm); color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.list-row .row-side { display: flex; flex-direction: column; align-items: flex-end; gap: var(--sp-1); }
.row-count { font-size: var(--fs-sm); color: var(--text-muted); margin: var(--sp-2) 0; }

/* ---------- Definition/spec tables ---------- */
.spec-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.spec-table th, .spec-table td { text-align: left; padding: .45rem var(--sp-2); border-bottom: 1px solid var(--gray-200); vertical-align: top; }
.spec-table th { color: var(--text-muted); font-weight: 600; width: 42%; }
.spec-table tr:last-child th, .spec-table tr:last-child td { border-bottom: none; }

.data-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.data-table th, .data-table td { text-align: left; padding: .5rem var(--sp-2); border-bottom: 1px solid var(--gray-200); }
.data-table th { color: var(--text-muted); font-weight: 600; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .03em; }
.data-table td.num, .data-table th.num { text-align: right; }
.data-table input { max-width: 7rem; }

/* ---------- Forms ---------- */
.field { margin-bottom: var(--sp-4); }
.field > label { display: block; font-size: var(--fs-sm); font-weight: 600; color: var(--gray-800); margin-bottom: var(--sp-1); }
.field .hint { font-size: var(--fs-xs); color: var(--text-muted); margin-top: var(--sp-1); }
.req { color: var(--danger-600); }
input[type="text"], input[type="number"], input[type="date"], input[type="email"], input[type="tel"],
select, textarea {
  width: 100%;
  padding: .55rem .7rem;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font: inherit; font-size: var(--fs-base);
  background: var(--surface);
  color: var(--text);
}
select { appearance: auto; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--teal-600); box-shadow: var(--focus-ring); }
textarea { min-height: 5rem; resize: vertical; }
.field-row { display: grid; gap: var(--sp-3); grid-template-columns: 1fr 1fr; }
.checkbox-field { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); font-weight: 600; color: var(--gray-800); }
.checkbox-field input { width: 1.1rem; height: 1.1rem; accent-color: var(--teal-700); }
.form-actions { display: flex; gap: var(--sp-2); margin-top: var(--sp-5); flex-wrap: wrap; }

.tier-preview {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-3);
  background: var(--teal-50);
  border: 1px dashed var(--teal-600);
  border-radius: var(--r-md);
  margin-bottom: var(--sp-4);
  font-size: var(--fs-sm);
}
.tier-preview strong { font-size: var(--fs-md); color: var(--teal-800); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(30, 41, 45, .5);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
}
.modal {
  background: var(--surface);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  width: 100%; max-width: 34rem;
  max-height: 88vh; overflow-y: auto;
  padding: var(--sp-5) var(--sp-4) calc(var(--sp-5) + env(safe-area-inset-bottom, 0px));
  box-shadow: var(--shadow-2);
}
@media (min-width: 640px) {
  .modal-overlay { align-items: center; padding: var(--sp-5); }
  .modal { border-radius: var(--r-lg); padding: var(--sp-5); }
}
.modal h2 { margin-top: 0; }

/* ---------- Toast ---------- */
#toast-root {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--sp-3));
  z-index: 80;
  display: flex; flex-direction: column; gap: var(--sp-2);
  width: min(92vw, 24rem);
}
@media (min-width: 768px) { #toast-root { bottom: var(--sp-5); } }
.toast {
  background: var(--gray-900); color: var(--white);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  box-shadow: var(--shadow-2);
  animation: toast-in .2s ease-out;
}
.toast-error { background: var(--danger-600); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Wizard (new rental) ---------- */
.wizard-steps {
  display: flex; gap: var(--sp-2); margin-bottom: var(--sp-4);
  font-size: var(--fs-xs); font-weight: 600;
}
.wizard-steps .step {
  flex: 1; text-align: center;
  padding: var(--sp-2);
  border-bottom: 3px solid var(--gray-300);
  color: var(--text-muted);
}
.wizard-steps .step.active { border-color: var(--teal-700); color: var(--teal-800); }
.wizard-steps .step.done { border-color: var(--ok-600); color: var(--ok-600); }

.system-line {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-3);
  margin-bottom: var(--sp-3);
  background: var(--gray-50);
}
.system-line .line-head { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-2); }
.line-price { font-weight: 700; color: var(--teal-800); }

.total-bar {
  position: sticky; bottom: calc(var(--tabbar-h) + var(--sp-2));
  display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3);
  background: var(--gray-900); color: var(--white);
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4);
  box-shadow: var(--shadow-2);
  margin-top: var(--sp-4);
}
@media (min-width: 768px) { .total-bar { bottom: var(--sp-3); } }
.total-bar .total-amount { font-size: var(--fs-lg); font-weight: 700; }
.total-bar .total-label { font-size: var(--fs-xs); opacity: .75; }

/* ---------- Misc ---------- */
.empty-state {
  text-align: center; color: var(--text-muted);
  padding: var(--sp-6) var(--sp-4);
  border: 1px dashed var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
}
.back-link { display: inline-flex; align-items: center; gap: var(--sp-1); font-size: var(--fs-sm); font-weight: 600; margin-bottom: var(--sp-3); }
.muted { color: var(--text-muted); }
.small { font-size: var(--fs-sm); }
.mb-0 { margin-bottom: 0; }
.mt-2 { margin-top: var(--sp-2); }
.divider { border: none; border-top: 1px solid var(--gray-200); margin: var(--sp-4) 0; }
.notice {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  margin-bottom: var(--sp-4);
}
.notice-warn { background: var(--warn-100); color: var(--warn-700); }
.notice-info { background: var(--teal-50); color: var(--teal-800); }

/* ---------- Form field grid (long spec sheets) ---------- */
.field-grid { display: grid; gap: 0 var(--sp-3); grid-template-columns: 1fr; }
@media (min-width: 640px) { .field-grid { grid-template-columns: 1fr 1fr; } }
.field-row-3 { display: grid; gap: var(--sp-3); grid-template-columns: 1fr 1fr; }
@media (min-width: 640px) { .field-row-3 { grid-template-columns: 1fr 1fr 1fr; } }

/* ---------- Filter selects ---------- */
.filter-grid {
  display: grid; gap: var(--sp-2);
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
}
.filter-cell label {
  display: block;
  font-size: var(--fs-xs); font-weight: 600; color: var(--text-muted);
  margin-bottom: 2px;
}
.filter-cell select { padding: .4rem .5rem; font-size: var(--fs-sm); }

/* ---------- Attachments ---------- */
.attach-grid { display: flex; flex-wrap: wrap; gap: var(--sp-3); }
.attach-item {
  position: relative;
  width: 8.5rem;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--gray-50);
  padding: var(--sp-2);
  cursor: pointer;
}
.attach-item:hover { border-color: var(--teal-600); }
.attach-thumb {
  height: 6rem;
  display: flex; align-items: center; justify-content: center;
  background: var(--white);
  border-radius: var(--r-sm);
  overflow: hidden;
  margin-bottom: var(--sp-2);
}
.attach-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.file-badge {
  font-size: var(--fs-sm); font-weight: 700;
  color: var(--teal-700);
  border: 2px solid var(--teal-600);
  border-radius: var(--r-sm);
  padding: .35rem .6rem;
  letter-spacing: .05em;
}
.attach-name {
  font-size: var(--fs-xs); font-weight: 600; color: var(--gray-800);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.attach-size { font-size: var(--fs-xs); }
.attach-del {
  position: absolute; top: -0.5rem; right: -0.5rem;
  width: 1.5rem; height: 1.5rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--white);
  color: var(--gray-700);
  font-size: 1rem; line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow-1);
}
.attach-del:hover { background: var(--danger-100); color: var(--danger-600); border-color: var(--danger-600); }
.attach-count { display: inline-flex; align-items: center; gap: 3px; font-size: var(--fs-xs); color: var(--text-muted); }
.clip-icon { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.attach-mini {
  width: 30px; height: 30px;
  object-fit: cover;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--white);
}

/* Status picker modal */
.status-pick { display: flex; flex-direction: column; gap: var(--sp-2); }

/* ---------- Login screen ---------- */
.login-screen {
  position: fixed; inset: 0; z-index: 100;
  background: var(--gray-100);
  display: flex; align-items: center; justify-content: center;
  padding: var(--sp-4);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
  padding: var(--sp-6) var(--sp-5);
  width: 100%; max-width: 22rem;
}
.login-logo { height: 2.6rem; width: auto; margin-bottom: var(--sp-4); }
.login-error {
  background: var(--danger-100); color: var(--danger-600);
  border-radius: var(--r-sm);
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-sm); font-weight: 600;
  margin-bottom: var(--sp-3);
}
