:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --panel-2: #f3f4f6;
  --text: #111827;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-600: #1d4ed8;
  --danger: #dc2626;
  --danger-600: #b91c1c;
  --ok: #16a34a;
  --border: #e5e7eb;
  --input-bg: #ffffff;
  --badge: #f1f5f9;
  --yellow: #f59e0b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", sans-serif;
}

.container {
  max-width: 1100px;
  margin: 1rem auto;
  padding: 0 0.75rem;
}

@media (min-width: 768px) {
  .container {
    margin: 2rem auto;
    padding: 0 1rem;
  }
}

.card {
  background: linear-gradient(180deg, rgba(255,255,255,0.02), transparent), var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem;
  box-shadow: 0 10px 40px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.04);
}

@media (min-width: 768px) {
  .card {
    padding: 1.25rem;
  }
}

.header {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

@media (min-width: 768px) {
  .header {
    gap: 0.75rem;
    margin-bottom: 1.25rem;
    flex-wrap: nowrap;
  }
}

.header .title {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

@media (min-width: 768px) {
  .header .title {
    gap: 0.75rem;
  }
}

h1, h2, h3 {
  margin: 0;
}

h1 { font-size: 1.25rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }

@media (min-width: 768px) {
  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.25rem; }
  h3 { font-size: 1.1rem; }
}

.badge {
  background: var(--badge);
  color: var(--text);
  padding: 0.15rem 0.4rem;
  font-size: 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  white-space: nowrap;
}

@media (min-width: 768px) {
  .badge {
    padding: 0.15rem 0.5rem;
    font-size: 0.8rem;
  }
}

.muted { color: var(--muted); }

.row {
  display: flex;
  gap: 1rem;
}

.col {
  flex: 1 1 0%;
}

.form
 {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 0.85rem;
    background-color: #0d0032;
    padding: 20px;
    border-radius: 15px;
}

.form .field {
  grid-column: span 12;
}

@media (min-width: 720px) {
  .form .span-6 { grid-column: span 6; }
  .form .span-4 { grid-column: span 4; }
  .form .span-3 { grid-column: span 3; }
  .form .span-2 { grid-column: span 2; }
}

.label {
  display: block;
  font-size: 0.9rem;
  color: #fff;
  margin-bottom: 0.45rem;
}

.input, .select {
  width: 100%;
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.6rem 0.7rem;
  border-radius: 8px;
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.input:focus, .select:focus {
  border-color: #2e3a8c;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.button {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  background: linear-gradient(180deg, rgba(255,255,255,0.08), transparent), var(--primary);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.12);
  border-bottom-color: rgba(0,0,0,0.35);
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.875rem;
  transition: transform 80ms ease, box-shadow 150ms ease, background 150ms ease;
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.22), inset 0 1px 0 rgba(255,255,255,0.18);
  white-space: nowrap;
}

@media (min-width: 768px) {
  .button {
    gap: 0.45rem;
    padding: 0.6rem 0.9rem;
    font-size: 1rem;
  }
}

.button:hover {
  transform: translateY(-1px);
}

.button:active {
  transform: translateY(0);
}

.button.secondary {
  background: linear-gradient(180deg, rgba(255,255,255,0.06), transparent), #2b2f3b;
}

.button.danger {
  background: linear-gradient(180deg, rgba(255,255,255,0.06), transparent), var(--danger);
  box-shadow: 0 10px 24px rgba(220, 38, 38, 0.2), inset 0 1px 0 rgba(255,255,255,0.18);
}

.toolbar {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  flex-wrap: wrap;
}

@media (min-width: 768px) {
  .toolbar {
    gap: 0.5rem;
  }
}

.table-wrapper {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  background: var(--panel-2);
  -webkit-overflow-scrolling: touch;
}

.table {
  width: 100%;
  border-collapse: collapse;
  min-width: 600px;
}

@media (min-width: 768px) {
  .table {
    min-width: 100%;
  }
}

.table th, .table td {
  padding: 8px 0.5rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-size: 0.85rem;
}

@media (min-width: 768px) {
  .table th, .table td {
    padding: 10px 0.85rem;
    font-size: 1rem;
  }
}

.table thead th {
  background: rgba(0,0,0,0.03);
  text-align: left;
  font-weight: 600;
  font-size: 0.8rem;
  white-space: nowrap;
}

@media (min-width: 768px) {
  .table thead th {
    font-size: 0.9rem;
  }
}

.table tbody tr:hover {
  background: rgba(0,0,0,0.02);
}

.table .actions {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
}

@media (min-width: 768px) {
  .table .actions {
    gap: 0.35rem;
  }
}

.sep {
  height: 1px;
  background: var(--border);
  margin: 1rem 0;
}

.center {
  text-align: center;
}

.auth-card {
  max-width: 420px;
  margin: 2rem auto;
  padding: 1rem;
}

@media (min-width: 768px) {
  .auth-card {
    margin: 4rem auto;
    padding: 1.25rem;
  }
}

.alert {
  padding: 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
}

.alert.error {
  border-color: rgba(220, 38, 38, 0.6);
  background: rgba(220, 38, 38, 0.12);
  color: #fecaca;
}

.grid {
  display: grid;
  gap: 0.85rem;
}

.grid-2 {
  grid-template-columns: 1fr;
}

@media (min-width: 640px) {
  .grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

@media (min-width: 768px) {
  .topbar {
    flex-wrap: nowrap;
    margin-bottom: 0;
  }
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 0.95rem;
}

@media (min-width: 768px) {
  .topbar .brand {
    gap: 0.6rem;
    font-size: 1rem;
  }
}

.kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-bottom-color: #d1d5db;
  border-radius: 6px;
  padding: 0.15rem 0.35rem;
}

footer {
  margin-top: 2rem;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

/* Month badge colors (derived from created_at)
   Classes correspond to: .badge.month-jan ... .badge.month-dec 
   See month_css_class() in app/init.php */
.badge.month-jan { background: #2563eb; border-color: rgba(0,0,0,0.25); color: #fff; } /* Blue */
.badge.month-feb { background: #db2777; border-color: rgba(0,0,0,0.25); color: #fff; } /* Rose */
.badge.month-mar { background: #059669; border-color: rgba(0,0,0,0.25); color: #fff; } /* Emerald */
.badge.month-apr { background: #84cc16; border-color: rgba(0,0,0,0.25); color: #111; } /* Lime */
.badge.month-may { background: #f59e0b; border-color: rgba(0,0,0,0.25); color: #111; } /* Amber */
.badge.month-jun { background: #06b6d4; border-color: rgba(0,0,0,0.25); color: #fff; } /* Cyan */
.badge.month-jul { background: #ef4444; border-color: rgba(0,0,0,0.25); color: #fff; } /* Red */
.badge.month-aug { background: #8b5cf6; border-color: rgba(0,0,0,0.25); color: #fff; } /* Violet */
.badge.month-sep { background: #f97316; border-color: rgba(0,0,0,0.25); color: #fff; } /* Orange */
.badge.month-oct { background: #a855f7; border-color: rgba(0,0,0,0.25); color: #fff; } /* Purple */
.badge.month-nov { background: #22c55e; border-color: rgba(0,0,0,0.25); color: #fff; } /* Green */
.badge.month-dec { background: #0ea5e9; border-color: rgba(0,0,0,0.25); color: #fff; } /* Sky */

.badge.month-unknown { background: #374151; border-color: rgba(0,0,0,0.25); color: #fff; }

/* Payment status badges */
.badge.unpaid { background: #f43f5e; border-color: rgba(0,0,0,0.25); color: #fff; } /* Rose-500 */
.badge.paid { background: #16a34a; border-color: rgba(0,0,0,0.25); color: #fff; }   /* Green-600 */

/* Status badges */
.badge.status-have-to-collect { background: #f97316; border-color: rgba(0,0,0,0.25); color: #fff; } /* Orange */
.badge.status-collected { background: #0ea5e9; border-color: rgba(0,0,0,0.25); color: #fff; } /* Sky blue */
.badge.status-on-repair { background: #a855f7; border-color: rgba(0,0,0,0.25); color: #fff; } /* Purple */
.badge.status-repaired { background: #33ff88; border-color: rgba(0,0,0,0.25); color: #111; } /* Custom green */
.badge.status-installed-successfully { background: #16a34a; border-color: rgba(0,0,0,0.25); color: #fff; } /* Green */

/* Payment Status badges */
.badge.payment-pending { background: #ff5722; border-color: rgba(0,0,0,0.25); color: #fff; } /* Red-Orange */
.badge.payment-advanced-paid { background: #f59e0b; border-color: rgba(0,0,0,0.25); color: #fff; } /* Amber/Orange */
.badge.payment-paid { background: #16a34a; border-color: rgba(0,0,0,0.25); color: #fff; } /* Green */

/* Category badges - Different colors for each category */
.badge.category-s1x-gen-3 { background: #3b82f6; border-color: rgba(0,0,0,0.25); color: #fff; } /* Blue */
.badge.category-s1x-gen-2 { background: #8b5cf6; border-color: rgba(0,0,0,0.25); color: #fff; } /* Violet */
.badge.category-s1x-plus-gen-3 { background: #ec4899; border-color: rgba(0,0,0,0.25); color: #fff; } /* Pink */
.badge.category-s1x-plus-gen-2 { background: #f43f5e; border-color: rgba(0,0,0,0.25); color: #fff; } /* Rose */
.badge.category-s1-pro-gen-3 { background: #10b981; border-color: rgba(0,0,0,0.25); color: #fff; } /* Emerald */
.badge.category-s1-pro-gen-2 { background: #14b8a6; border-color: rgba(0,0,0,0.25); color: #fff; } /* Teal */
.badge.category-s1-pro-gen-1 { background: #06b6d4; border-color: rgba(0,0,0,0.25); color: #fff; } /* Cyan */
.badge.category-s1-air-gen-2 { background: #f59e0b; border-color: rgba(0,0,0,0.25); color: #fff; } /* Amber */
.badge.category-s1-air-gen-1 { background: #ef4444; border-color: rgba(0,0,0,0.25); color: #fff; } /* Red */

/* Modal styles */
.hidden { display: none !important; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.modal-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: linear-gradient(180deg, rgba(255,255,255,0.02), transparent), var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 92%;
  max-width: 440px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.04);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
}

.modal-body {
  padding: 1rem;
  color: var(--text);
}

.modal-footer {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: flex-end;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
}

.modal-close {
  appearance: none;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  padding: 0.25rem 0.5rem;
  font-size: 1.25rem;
  line-height: 1;
  border-radius: 6px;
  cursor: pointer;
}

.modal-close:hover {
  border-color: var(--border);
  background: rgba(255,255,255,0.04);
}

/* Emphasize Price (Emp) value in Mark Paid modal */
#priceEmpText {
  color: var(--ok);
  font-size: 1.5rem;
}


#priceEmpText {
    color: green;
    font-size: 3vw;
    text-align: center !important;
}

/* Mobile-specific improvements */
@media (max-width: 767px) {
  /* Improve touch targets */
  .button,
  .input,
  .select {
    min-height: 44px;
  }
  
  /* Better spacing for mobile forms */
  .form {
    gap: 1rem;
  }
  
  /* Stack action buttons vertically on very small screens */
  @media (max-width: 480px) {
    .table .actions {
      flex-direction: column;
      align-items: stretch;
    }
    
    .table .actions .button {
      width: 100%;
    }
    
    .toolbar {
      width: 100%;
    }
    
    .topbar .toolbar {
      justify-content: flex-end;
    }
  }
  
  /* Improve table readability on mobile */
  .table th,
  .table td {
    padding: 10px 0.4rem;
  }
  
  /* Better modal sizing on mobile */
  .modal-panel {
    width: 95%;
    max-height: 90vh;
    overflow-y: auto;
  }
  
  /* Adjust badge sizes for better readability */
  .badge {
    font-size: 0.75rem;
    padding: 0.2rem 0.45rem;
  }
  
  /* Improve header spacing */
  .header {
    gap: 0.75rem;
  }
  
  /* Better form field spacing */
  .field {
    margin-bottom: 0.5rem;
  }
  
  /* Improve alert visibility */
  .alert {
    font-size: 0.9rem;
    padding: 0.85rem;
  }
  
  /* Better pagination on mobile */
  nav.toolbar {
    justify-content: center;
    gap: 0.25rem;
  }
  
  nav.toolbar .button {
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
  }
}

/* Landscape mobile optimization */
@media (max-width: 767px) and (orientation: landscape) {
  .container {
    margin: 0.5rem auto;
  }
  
  .card {
    padding: 0.5rem;
  }
  
  h1 {
    font-size: 1.1rem;
  }
  
  h2 {
    font-size: 1rem;
  }
}

/* Tablet optimization */
@media (min-width: 768px) and (max-width: 1024px) {
  .container {
    max-width: 95%;
  }
  
  .table th,
  .table td {
    padding: 8px 0.6rem;
    font-size: 0.9rem;
  }
}

/* Prevent zoom on input focus for iOS */
@media (max-width: 767px) {
  .input,
  .select,
  textarea {
    font-size: 16px;
  }
}

/* Improve scrollbar appearance on mobile */
.table-wrapper::-webkit-scrollbar {
  height: 8px;
}

.table-wrapper::-webkit-scrollbar-track {
  background: var(--panel-2);
}

.table-wrapper::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.table-wrapper::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

/* Add scroll hint for tables on mobile */
@media (max-width: 767px) {
  .table-wrapper::after {
    content: '← Scroll →';
    display: block;
    text-align: center;
    padding: 0.5rem;
    font-size: 0.75rem;
    color: var(--muted);
    background: var(--panel-2);
    border-top: 1px solid var(--border);
  }
  
  .table-wrapper::-webkit-scrollbar {
    display: none;
  }
}

/* Safe area insets for notched devices */
@supports (padding: max(0px)) {
  .container {
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
  }
  
  @media (min-width: 768px) {
    .container {
      padding-left: max(1rem, env(safe-area-inset-left));
      padding-right: max(1rem, env(safe-area-inset-right));
    }
  }
}

/* QR Scanner Styles */
.scan-button {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  background: linear-gradient(180deg, rgba(255,255,255,0.08), transparent), #059669;
  color: #fff;
  border: 1px solid rgba(255,255,255,0.12);
  border-bottom-color: rgba(0,0,0,0.35);
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.875rem;
  transition: transform 80ms ease, box-shadow 150ms ease, background 150ms ease;
  box-shadow: 0 10px 24px rgba(5, 150, 105, 0.22), inset 0 1px 0 rgba(255,255,255,0.18);
  white-space: nowrap;
  margin-left: 0.5rem;
}

@media (min-width: 768px) {
  .scan-button {
    gap: 0.45rem;
    padding: 0.6rem 0.9rem;
    font-size: 1rem;
  }
}

.scan-button:hover {
  transform: translateY(-1px);
  background: linear-gradient(180deg, rgba(255,255,255,0.1), transparent), #047857;
}

.scan-button:active {
  transform: translateY(0);
}

/* Input group for battery number field with scan button */
.input-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.input-group .input {
  flex: 1;
}

/* QR Reader container styles */
#qr-reader {
  position: relative;
  padding: 0 !important;
  border: 2px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #000;
}

#qr-reader video {
  width: 100% !important;
  height: auto !important;
}

/* Override Html5-QRCode default styles */
#qr-reader__scan_region {
  background: transparent !important;
}

#qr-reader__dashboard {
  display: none !important;
}

/* Mobile optimizations for QR scanner */
@media (max-width: 767px) {
  .scan-button {
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
  }
  
  .input-group {
    flex-direction: column;
    align-items: stretch;
  }
  
  .input-group .scan-button {
    margin-left: 0;
    margin-top: 0.5rem;
    width: 100%;
  }
  
  #qr-scanner-modal .modal-panel {
    width: 95%;
    max-width: none;
  }
}

/* Scan icon (camera emoji or SVG) */
.scan-icon {
  display: inline-block;
  width: 1.2em;
  height: 1.2em;
  vertical-align: middle;
}
