:root {
  --bg-start: #fff5ea;
  --bg-end: #f3ede4;
  --surface: #ffffff;
  --surface-soft: #faf5ee;
  --surface-tint: #f6ede2;
  --ink: #241d17;
  --ink-muted: #6e6054;
  --border: #e7dacb;
  --border-strong: #d4c0aa;
  --accent: #b86b35;
  --accent-dark: #935124;
  --accent-soft: #f9eadc;
  --success: #2a7a4f;
  --success-soft: #e6f5ec;
  --warning: #b06c13;
  --warning-soft: #fdf2df;
  --danger: #b4392e;
  --danger-soft: #fceae8;
  --info: #2d5f8b;
  --info-soft: #e8f1f8;
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --shadow-sm: 0 2px 8px rgba(48, 30, 14, 0.05);
  --shadow-md: 0 10px 30px rgba(48, 30, 14, 0.09);
  --font-serif: Georgia, 'Times New Roman', serif;
  --font-sans: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: var(--font-sans);
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg-start) 0%, var(--bg-end) 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.serif-heading {
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--ink);
}

.num, .money {
  font-variant-numeric: tabular-nums;
}

.muted-text {
  color: var(--ink-muted);
  font-size: 0.9rem;
  margin: 0;
}

/* Brand Mark */
.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: linear-gradient(135deg, #c97a42, var(--accent-dark));
  color: #fff5ea;
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 700;
  font-size: 1.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(184, 107, 53, 0.28);
}

.brand-mark-sm {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  font-size: 1rem;
}

/* Login Screen */
.login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  box-shadow: var(--shadow-md);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.login-brand h1 {
  font-size: 1.75rem;
  line-height: 1.1;
}

.login-hint {
  margin: 18px 0 0;
  font-size: 0.8rem;
  color: var(--ink-muted);
  text-align: center;
}

/* App Shell & Sticky Topbar */
.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: rgba(255, 245, 234, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

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

.topbar-brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar-title {
  font-size: 1.2rem;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mode-pill {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--accent-dark);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.desktop-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}

.desktop-nav::-webkit-scrollbar {
  display: none;
}

.nav-btn {
  border: none;
  background: transparent;
  color: var(--ink-muted);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-btn:hover {
  background: var(--surface-tint);
  color: var(--ink);
}

.nav-btn.active {
  background: var(--accent);
  color: #ffffff;
}

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

.user-chip {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 11px;
  white-space: nowrap;
}

/* Main Content */
.main-content {
  width: 100%;
  max-width: 1220px;
  margin: 0 auto;
  padding: 22px 20px 44px;
  flex: 1;
}

/* Mobile Bottom Nav (<= 860px) */
.mobile-bottom-nav {
  display: none;
}

@media (max-width: 860px) {
  .desktop-nav {
    display: none;
  }

  .main-content {
    padding: 16px 14px 92px;
  }

  .mobile-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 45;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .mobile-bottom-nav::-webkit-scrollbar {
    display: none;
  }

  .mobile-nav-btn {
    border: 1px solid transparent;
    background: transparent;
    color: var(--ink-muted);
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 600;
    padding: 8px 12px;
    border-radius: 999px;
    white-space: nowrap;
    cursor: pointer;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 5px;
  }

  .mobile-nav-btn.active {
    background: var(--accent);
    color: #ffffff;
  }
}

/* Page Header & Toolbars */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.page-header h1 {
  font-size: 1.7rem;
  line-height: 1.15;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.toolbar-grow {
  flex: 1;
  min-width: 180px;
}

/* Cards & Grids */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}

.card-compact {
  padding: 14px 16px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.kpi-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
}

.kpi-value {
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.kpi-value.accent { color: var(--accent-dark); }
.kpi-value.success { color: var(--success); }
.kpi-value.danger { color: var(--danger); }

.kpi-sub {
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 14px;
}

.two-col-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

@media (max-width: 860px) {
  .two-col-grid {
    grid-template-columns: 1fr;
  }
}

/* Single-column card grids & aligned stacked toolbars on <= 640px */
@media (max-width: 640px) {
  .topbar {
    padding: 10px 12px;
  }

  .user-chip {
    display: none;
  }

  .page-header {
    flex-direction: column;
    align-items: stretch;
  }

  .page-header .btn-row {
    width: 100%;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .toolbar > *,
  .toolbar-grow {
    width: 100%;
    min-width: 0;
  }

  .card-grid,
  .kpi-grid {
    grid-template-columns: 1fr;
  }
}

/* Form Inputs & Custom Select Chevrons */
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-muted);
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="month"],
input[type="tel"],
input[type="search"],
textarea,
select {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background-color: var(--surface);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 0.94rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(184, 107, 53, 0.16);
}

textarea {
  min-height: 82px;
  resize: vertical;
}

select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236e6054' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  background-size: 16px 16px;
  cursor: pointer;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-grid .span-2 {
  grid-column: 1 / -1;
}

@media (max-width: 640px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}

.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.stack-md { display: flex; flex-direction: column; gap: 14px; }
.stack-lg { display: flex; flex-direction: column; gap: 20px; }

.btn-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn-sm {
  min-height: 32px;
  padding: 5px 10px;
  font-size: 0.8rem;
}

.btn-full {
  width: 100%;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--accent-dark);
}

.btn-secondary {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--border-strong);
}

.btn-secondary:hover {
  background: var(--surface-soft);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-muted);
  border-color: var(--border);
}

.btn-ghost:hover {
  background: var(--surface-tint);
  color: var(--ink);
}

.btn-whatsapp {
  background: #1f8a4c;
  color: #ffffff;
}

.btn-whatsapp:hover {
  background: #186f3c;
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: #efc5c1;
}

.btn-danger:hover {
  background: #f7d9d6;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--ink);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Tabs / Segmented Controls */
.tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 14px;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-muted);
  font-family: var(--font-sans);
  font-size: 0.84rem;
  font-weight: 600;
  padding: 7px 13px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}

.tab-btn.active {
  background: var(--ink);
  color: #ffffff;
  border-color: var(--ink);
}

/* Badges & Status Pills */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-neutral { background: var(--surface-tint); color: var(--ink-muted); }

/* Entity Cards */
.entity-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.entity-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.entity-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0;
}

.entity-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  font-size: 0.84rem;
  color: var(--ink-muted);
}

.entity-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--surface-tint);
  flex-wrap: wrap;
}

/* Tables */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th, td {
  padding: 11px 12px;
  text-align: left;
  border-bottom: 1px solid var(--surface-tint);
  vertical-align: middle;
}

th {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
  background: var(--surface-soft);
  white-space: nowrap;
}

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

/* Alerts & Empty States */
.alert-banner {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  font-weight: 500;
}

.alert-danger { background: var(--danger-soft); color: var(--danger); border: 1px solid #f0c4bf; }
.alert-warning { background: var(--warning-soft); color: var(--warning); border: 1px solid #edd4a6; }
.alert-info { background: var(--info-soft); color: var(--info); border: 1px solid #c5dcef; }

.empty-state {
  text-align: center;
  padding: 36px 18px;
  color: var(--ink-muted);
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
}

/* Calculator Summary Box */
.calc-summary {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.calc-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
}

.calc-row.total {
  padding-top: 8px;
  margin-top: 4px;
  border-top: 1px solid var(--border-strong);
  font-weight: 700;
  font-size: 1.02rem;
}

/* Bottom-Sheet / Centered Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(36, 29, 23, 0.48);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-dialog {
  width: 100%;
  max-width: 680px;
  max-height: 90dvh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.lightbox-dialog {
  width: 100%;
  max-width: 820px;
  max-height: 92dvh;
  background: var(--surface);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.lightbox-content {
  padding: 16px;
  overflow: auto;
  text-align: center;
}

.lightbox-content img {
  max-width: 100%;
  max-height: 72dvh;
  border-radius: var(--radius-sm);
}

.lightbox-content iframe {
  width: 100%;
  height: 72dvh;
  border: none;
  border-radius: var(--radius-sm);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-soft);
}

.modal-title {
  font-size: 1.25rem;
}

.modal-subtitle {
  font-size: 0.82rem;
  margin-top: 2px;
}

.modal-body {
  padding: 18px 20px 24px;
  overflow-y: auto;
}

@media (max-width: 640px) {
  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }

  .modal-dialog {
    max-width: 100%;
    max-height: 92dvh;
    border-radius: 22px 22px 0 0;
    animation: slideUpSheet 0.2s ease-out;
  }
}

@keyframes slideUpSheet {
  from { transform: translateY(36px); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}

/* Highlight Pulse Animation when closing a printed receipt */
.highlight-pulse {
  animation: highlightPulse 1.8s ease-out;
}

@keyframes highlightPulse {
  0% { box-shadow: 0 0 0 0 rgba(184, 107, 53, 0.55); background-color: #fdf0e1; }
  50% { box-shadow: 0 0 0 10px rgba(184, 107, 53, 0); background-color: #fbf3ea; }
  100% { box-shadow: 0 0 0 0 rgba(184, 107, 53, 0); background-color: var(--surface); }
}

/* Toast */
.toast-container {
  position: fixed;
  top: 72px;
  right: 16px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 340px;
}

.toast {
  background: var(--ink);
  color: #fff5ea;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  box-shadow: var(--shadow-md);
}

.toast.toast-error {
  background: var(--danger);
}

/* Handover Condition Cycle Button */
.condition-pill {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font-sans);
}

.condition-good { background: var(--success-soft); color: var(--success); border-color: #b7dfc7; }
.condition-repair { background: var(--warning-soft); color: var(--warning); border-color: #edd09a; }
.condition-missing { background: var(--danger-soft); color: var(--danger); border-color: #ebb7b2; }

/* Printable Receipt Styling */
.print-only {
  display: none;
}

.receipt-sheet {
  background: #ffffff;
  color: #1f1914;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 24px;
}

.receipt-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding-bottom: 14px;
  border-bottom: 2px solid var(--accent);
  margin-bottom: 16px;
}

.receipt-table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
}

.receipt-table th,
.receipt-table td {
  padding: 9px 10px;
  border-bottom: 1px solid #e7dacb;
}

.receipt-table td:last-child,
.receipt-table th:last-child {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

@media print {
  body > *:not(#print-receipt-area) {
    display: none !important;
  }

  #print-receipt-area {
    display: block !important;
    position: static !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
  }

  .receipt-sheet {
    border: none !important;
    box-shadow: none !important;
    padding: 12px !important;
  }
}
