/* ==========================================================================
   Daily Report Management System - Modern UI Stylesheet
   ========================================================================== */

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-border: #bfdbfe;
  
  --success: #10b981;
  --success-hover: #059669;
  --success-light: #ecfdf5;
  
  --whatsapp: #25d366;
  --whatsapp-hover: #1ebd5b;
  --whatsapp-light: #e8f9ee;

  --warning: #f59e0b;
  --danger: #ef4444;
  --danger-light: #fef2f2;

  --bg-app: #f8fafc;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --bg-hover: #f1f5f9;
  --bg-terminal: #0f172a;
  
  --border-color: #e2e8f0;
  --border-focus: #3b82f6;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-code: #38bdf8;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', Consolas, monospace;
}

[data-theme="dark"] {
  --bg-app: #0b0f19;
  --bg-card: #131b2e;
  --bg-input: #1a233b;
  --bg-hover: #1e293b;
  --bg-terminal: #050811;

  --border-color: #27354f;
  --border-focus: #60a5fa;

  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;
  --text-code: #7dd3fc;

  --primary-light: #172554;
  --primary-border: #1e3a8a;
  --success-light: #064e3b;
  --danger-light: #450a0a;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.4);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.5);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.6);
}

/* Base Resets */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  padding: 1.5rem;
}

.app-container {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.875rem;
}

.logo-icon {
  background: linear-gradient(135deg, var(--primary), #6366f1);
  color: #ffffff;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3);
}

.app-header h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--bg-hover);
  border: 1px solid var(--border-color);
}

.status-badge.online {
  background: var(--success-light);
  color: var(--success);
  border-color: rgba(16, 185, 129, 0.3);
}

.status-badge.offline {
  background: #fef3c7;
  color: #b45309;
  border-color: #fde68a;
}

[data-theme="dark"] .status-badge.offline {
  background: #451a03;
  color: #fde68a;
  border-color: #78350f;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: currentColor;
}

.status-badge.online .status-dot {
  box-shadow: 0 0 6px var(--success);
}

.icon-button {
  background: var(--bg-hover);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 1rem;
}

.icon-button:hover {
  background: var(--primary-light);
  border-color: var(--primary-border);
}

/* Main Layout */
.main-layout {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 1.5rem;
}

@media (max-width: 992px) {
  .main-layout {
    grid-template-columns: 1fr;
  }
}

/* Card Containers */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.card-title {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.card-title h2 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.step-num {
  background-color: var(--primary);
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 700;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.live-pill {
  font-size: 0.75rem;
  font-weight: 600;
  color: #0284c7;
  background: #e0f2fe;
  padding: 0.25rem 0.65rem;
  border-radius: 9999px;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

[data-theme="dark"] .live-pill {
  background: #082f49;
  color: #38bdf8;
}

.live-pill::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

/* Form Styles */
.form-section-title {
  display: flex;
  align-items: center;
  margin-top: 0.5rem;
  margin-bottom: -0.25rem;
}

.form-section-title span {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: var(--bg-card);
  padding-right: 0.5rem;
}

.form-section-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background-color: var(--border-color);
}

.grid-2-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 576px) {
  .grid-2-col {
    grid-template-columns: 1fr;
  }
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.required-indicator {
  color: var(--danger);
}

.label-hint {
  font-size: 0.75rem;
  color: var(--primary);
  font-weight: 500;
}

.form-control {
  width: 100%;
  padding: 0.65rem 0.85rem;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text-primary);
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  outline: none;
  transition: all 0.2s ease;
}

.form-control:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.date-input-container {
  display: flex;
  gap: 0.5rem;
}

.input-with-affix {
  position: relative;
  display: flex;
  align-items: center;
}

.input-prefix {
  position: absolute;
  left: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.95rem;
  pointer-events: none;
}

.input-with-affix .form-control {
  padding-left: 1.85rem;
}

.input-annotation {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.number-readable {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary);
  min-height: 1.1rem;
  transition: color 0.2s;
}

/* Highlight boxes */
.highlight-box {
  background: var(--bg-hover);
  padding: 0.85rem;
  border-radius: var(--radius-md);
  border: 1px dashed var(--border-color);
}

.total-profit-box {
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.05), rgba(16, 185, 129, 0.08));
  border: 1.5px solid rgba(16, 185, 129, 0.3);
  padding: 1rem;
  border-radius: var(--radius-md);
}

.auto-calc-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--success);
  background: var(--success-light);
  padding: 0.15rem 0.5rem;
  border-radius: 9999px;
  text-transform: uppercase;
}

.total-profit-input {
  font-weight: 700;
  font-size: 1.15rem;
  color: #059669;
}

[data-theme="dark"] .total-profit-input {
  color: #34d399;
}

.profit-calc-formula {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
}

/* Action Buttons */
.form-actions-row {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
  font-family: inherit;
  text-decoration: none;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background-color: var(--primary);
  color: #ffffff;
  box-shadow: 0 2px 4px rgba(37, 99, 235, 0.25);
}

.btn-primary:hover {
  background-color: var(--primary-hover);
  box-shadow: 0 4px 8px rgba(37, 99, 235, 0.35);
}

.btn-large {
  flex: 1;
  padding: 0.85rem 1.5rem;
  font-size: 1rem;
}

.btn-secondary {
  background-color: var(--bg-hover);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background-color: var(--border-color);
}

.btn-outline-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.78rem;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
}

.btn-outline-sm:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-secondary-sm {
  padding: 0.4rem 0.85rem;
  font-size: 0.85rem;
  background-color: var(--bg-hover);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.btn-secondary-sm:hover {
  background-color: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary-border);
}

.btn-whatsapp {
  background-color: var(--whatsapp);
  color: #ffffff;
}

.btn-whatsapp:hover {
  background-color: var(--whatsapp-hover);
  box-shadow: 0 4px 8px rgba(37, 211, 102, 0.35);
}

/* Summary Tiles */
.summary-tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}

.tile {
  background: var(--bg-hover);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.tile.highlight {
  background: var(--primary-light);
  border-color: var(--primary-border);
}

.tile-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
}

.tile.highlight .tile-label {
  color: var(--primary);
}

.tile-value {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text-primary);
  word-break: break-all;
}

.tile.highlight .tile-value {
  color: var(--primary);
}

/* Preview Box (Terminal Style) */
.preview-box-container {
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  border: 1px solid #1e293b;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.preview-box-header {
  background: #1e293b;
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.window-dots {
  display: flex;
  gap: 6px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.dot-red { background-color: #ef4444; }
.dot-yellow { background-color: #f59e0b; }
.dot-green { background-color: #10b981; }

.window-title {
  color: #94a3b8;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  font-weight: 600;
}

.copy-badge {
  display: none;
  font-size: 0.7rem;
  background: var(--success);
  color: #ffffff;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-weight: 600;
}

.report-preview-text {
  background-color: var(--bg-terminal);
  color: #f8fafc;
  padding: 1.25rem;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  line-height: 1.7;
  white-space: pre-wrap;
  margin: 0;
  min-height: 220px;
  max-height: 280px;
  overflow-y: auto;
  user-select: all;
}

.preview-actions {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  gap: 0.75rem;
}

@media (max-width: 576px) {
  .preview-actions {
    grid-template-columns: 1fr;
  }
}

/* History Card & Table */
.history-card {
  margin-top: 0.5rem;
}

.counter-badge {
  background: var(--bg-hover);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  border: 1px solid var(--border-color);
}

.history-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.search-input {
  max-width: 240px;
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
}

.table-container {
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.875rem;
}

.report-table th {
  background-color: var(--bg-hover);
  color: var(--text-secondary);
  font-weight: 700;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.report-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
  white-space: nowrap;
}

.report-table tbody tr:hover {
  background-color: var(--bg-hover);
}

.report-table .text-right {
  text-align: right;
}

.empty-row td {
  text-align: center;
  color: var(--text-muted);
  padding: 2.5rem 1rem;
  font-style: italic;
}

.action-btn-group {
  display: inline-flex;
  gap: 0.35rem;
}

.table-btn {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.15s;
}

.table-btn:hover {
  background: var(--primary-light);
  border-color: var(--primary-border);
  color: var(--primary);
}

.table-btn.btn-delete:hover {
  background: var(--danger-light);
  border-color: #fca5a5;
  color: var(--danger);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: #0f172a;
  color: #ffffff;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-left: 4px solid var(--success);
}

.toast.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 1rem;
}

.modal-content {
  background: var(--bg-card);
  width: 100%;
  max-width: 520px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  padding: 1rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  font-size: 1.1rem;
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
}

.modal-body {
  padding: 1.25rem;
}

.modal-pre {
  background: var(--bg-terminal);
  color: #f8fafc;
  padding: 1rem;
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: 0.95rem;
  white-space: pre-wrap;
  margin: 0;
}

.modal-footer {
  padding: 0.85rem 1.25rem;
  background: var(--bg-hover);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  border-top: 1px solid var(--border-color);
}

/* Print Styles */
@media print {
  body {
    background: #fff;
    color: #000;
    padding: 0;
    overflow: visible !important;
  }
  .app-header, .main-content, .history-toolbar, .range-selector,
  .custom-range, .search-input, .drawer-backdrop, .drawer-header, .btn {
    display: none !important;
  }
  /* Print the Recent Bills drawer contents as a normal page */
  .drawer {
    position: static !important;
    transform: none !important;
    width: 100% !important;
    max-width: 100% !important;
    box-shadow: none;
    border: none;
  }
  .bill-item {
    border: 1px solid #ddd;
    page-break-inside: avoid;
    color: #000;
  }
  .bill-profit { color: #000; }
}

/* ===== Main content (report form only) ===== */
.main-content {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  min-width: 0;
}

/* ===== Recent Bills drawer (hamburger) ===== */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.55);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease;
  z-index: 60;
}
.drawer-backdrop.show {
  opacity: 1;
  visibility: visible;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: 380px;
  max-width: 88vw;
  background: var(--bg-card);
  border-left: 1px solid var(--border-color);
  box-shadow: -8px 0 28px rgba(2, 6, 23, 0.25);
  transform: translateX(100%);
  transition: transform 0.28s ease;
  z-index: 70;
  display: flex;
  flex-direction: column;
}
.drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}
.drawer-header h2 {
  font-size: 1.1rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.drawer-body {
  padding: 1.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  flex: 1;
}

/* Prevent the page behind the drawer from scrolling while it's open */
body.drawer-locked {
  overflow: hidden;
}

/* ===== Range selector ===== */
.range-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.range-btn {
  flex: 1 1 auto;
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary, var(--text-muted));
  background: var(--bg-hover);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.range-btn:hover {
  border-color: var(--border-focus);
}

.range-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.custom-range {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.custom-range .form-control {
  flex: 1;
  min-width: 0;
}

.custom-range-sep {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ===== Range totals ===== */
.range-totals {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.range-caption {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  text-align: center;
  margin-top: -0.25rem;
}

/* ===== Bills list ===== */
.bills-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.bills-empty {
  padding: 1.5rem 0.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.bill-item {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.75rem;
  background: var(--bg-hover);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.bill-row1 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.bill-date {
  font-weight: 700;
  color: var(--text-primary);
}

.bill-profit {
  font-weight: 800;
  color: var(--success);
}

.bill-row2 {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.bill-actions {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.15rem;
}

.bill-actions .table-btn {
  flex: 1;
}

/* ===== Mobile view ===== */
@media (max-width: 640px) {
  body { padding: 0.75rem; }
  .app-container { gap: 1rem; }

  .app-header { padding: 0.75rem 0.9rem; }
  .brand h1 { font-size: 1.15rem; }
  .subtitle { display: none; }
  .logo-icon { width: 38px; height: 38px; }

  /* Keep the header compact: connection status moves out of the way */
  #connectionStatus { display: none; }
  .header-right { gap: 0.4rem; }

  .card { padding: 1.1rem; }

  /* Stack the submit buttons full-width so they're easy to tap */
  .form-actions-row { flex-wrap: wrap; }
  .form-actions-row .btn { flex: 1 1 100%; }

  .drawer { width: 100%; max-width: 100%; }
}
