@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
@import url('templates.css');

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --bg-page: #f8fafc;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --destructive: #ef4444;
  --radius: 8px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Header */
header {
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 40;
  transition: all 0.2s ease;
}

@media (max-width: 880px) {
  header {
    flex-direction: column;
    align-items: stretch;
    padding: 12px 14px;
    gap: 12px;
  }

  .brand-title {
    justify-content: space-between;
    width: 100%;
  }

  .nav-tabs {
    width: 100%;
  }

  .nav-tab {
    flex: 1;
    justify-content: center;
    padding: 8px 10px;
    font-size: 0.8rem;
  }

  .header-actions {
    width: 100%;
    display: grid;
    grid-template-columns: auto auto 1fr;
    gap: 8px;
  }

  .header-actions .btn-primary,
  .header-actions .btn-secondary {
    justify-content: center;
    padding: 9px 12px;
    font-size: 0.82rem;
  }
}

@media (max-width: 440px) {
  .brand-title h1 {
    font-size: 1.05rem;
  }
  .brand-title div {
    display: none;
  }
}

.brand-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-title h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: #0f172a;
}

.brand-badge {
  background: #eff6ff;
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 9999px;
  border: 1px solid #bfdbfe;
}

/* Navigation Tabs */
.nav-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #f1f5f9;
  padding: 4px;
  border-radius: 8px;
}

.nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #64748b;
  text-decoration: none;
  border-radius: 6px;
  transition: all 0.15s ease;
}

.nav-tab:hover {
  color: #0f172a;
  background: rgba(255, 255, 255, 0.6);
}

.nav-tab.active {
  color: var(--primary);
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Quick Preset Chips */
.quick-preset-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

@media (max-width: 640px) {
  .quick-preset-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
    margin-bottom: 10px;
  }
  .chip-btn {
    flex-shrink: 0;
    padding: 6px 12px;
    font-size: 0.8rem;
  }
}

.chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 500;
  color: #334155;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chip-btn:hover {
  background: #eff6ff;
  border-color: #93c5fd;
  color: #1d4ed8;
}

.header-actions {
  display: flex;
  gap: 12px;
}

/* Main Layout */
.container {
  max-width: 1540px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  grid-template-columns: 1fr 500px;
  gap: 32px;
}

@media (max-width: 1180px) {
  .container {
    grid-template-columns: 1fr;
    gap: 24px;
    padding: 16px;
  }
}

@media (max-width: 640px) {
  .container {
    padding: 10px 8px;
    gap: 16px;
  }
}

/* Mobile Segmented View Tabs (Shown on screens <= 1024px) */
.mobile-view-tabs {
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  background: #e2e8f0;
  padding: 4px;
  border-radius: 10px;
  margin-bottom: 16px;
}

@media (max-width: 1024px) {
  .mobile-view-tabs {
    display: grid;
  }
  
  /* When preview is active on mobile, hide form */
  .container.preview-active .form-panel {
    display: none !important;
  }
  .container.preview-active .preview-panel {
    display: flex !important;
    width: 100%;
  }

  /* When form is active on mobile, hide preview */
  .container.form-active .preview-panel {
    display: none !important;
  }
  .container.form-active .form-panel {
    display: block !important;
    width: 100%;
  }
}

.mobile-view-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  color: #64748b;
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.mobile-view-tab.active {
  background: #ffffff;
  color: var(--primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Mobile Floating Action Bar */
.mobile-floating-bar {
  display: none;
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  background: #0f172a;
  padding: 6px 10px;
  border-radius: 9999px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.4), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
  align-items: center;
  gap: 8px;
  max-width: calc(100vw - 24px);
}

@media (max-width: 1024px) {
  .mobile-floating-bar {
    display: flex;
  }
}

.btn-floating-view {
  background: #1e293b;
  color: #f8fafc;
  border: 1px solid #334155;
  padding: 8px 14px;
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  white-space: nowrap;
}

.btn-floating-pdf {
  background: var(--primary);
  color: #ffffff;
  border: none;
  padding: 8px 16px;
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  white-space: nowrap;
}

.mobile-table-hint {
  display: none;
  font-size: 0.75rem;
  color: #64748b;
  margin-bottom: 6px;
  font-style: italic;
}

@media (max-width: 768px) {
  .mobile-table-hint {
    display: block;
  }
}

/* Form Styles */
.form-panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05);
}

@media (max-width: 640px) {
  .form-panel {
    padding: 16px 12px;
    border-radius: 8px;
  }
  .section-divider {
    margin: 18px 0;
  }
  .section-title {
    font-size: 1rem;
    margin-bottom: 12px;
  }
  /* 16px font-size prevents mobile auto-zoom */
  input[type="text"],
  input[type="number"],
  input[type="date"],
  input[type="time"],
  select,
  textarea {
    font-size: 16px;
    padding: 9px 10px;
  }
}

.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 16px;
  color: #1e293b;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-divider {
  height: 1px;
  background: var(--border);
  margin: 28px 0;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}

.col-span-2 {
  grid-column: span 2;
}

.col-span-3 {
  grid-column: span 3;
}

@media (max-width: 640px) {
  .grid-2, .grid-3 {
    grid-template-columns: 1fr;
  }
  .col-span-2, .col-span-3 {
    grid-column: span 1;
  }
}

.form-group {
  margin-bottom: 14px;
}

label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 6px;
  color: #334155;
}

label .required {
  color: var(--destructive);
  margin-left: 3px;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="time"],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.875rem;
  color: #0f172a;
  background: #ffffff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  font-family: inherit;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

textarea {
  resize: vertical;
}

/* Template Selector Cards */
.template-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

@media (max-width: 768px) {
  .template-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px;
  }
}

@media (max-width: 440px) {
  .template-card {
    padding: 8px 4px;
  }
  .template-card-title {
    font-size: 0.78rem;
  }
  .template-card-desc {
    font-size: 0.68rem;
  }
}

.template-card {
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  text-align: center;
  cursor: pointer;
  background: #ffffff;
  transition: all 0.2s ease;
}

.template-card:hover {
  border-color: #93c5fd;
  transform: translateY(-1px);
}

.template-card.active {
  border-color: var(--primary);
  background: #eff6ff;
}

.template-card-icon {
  font-size: 1.5rem;
  margin-bottom: 6px;
}

.template-card-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: #0f172a;
}

.template-card-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Radio Group */
.radio-group {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-top: 4px;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.875rem;
  font-weight: normal;
  cursor: pointer;
  color: #1e293b;
}

/* Items Table */
.items-table-wrap {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 12px;
  width: 100%;
}

table.items-table {
  width: 100%;
  border-collapse: collapse;
}

table.items-table th {
  background: #f1f5f9;
  padding: 10px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  color: #475569;
  border-bottom: 1px solid var(--border);
}

table.items-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

table.items-table td input,
table.items-table td textarea {
  padding: 6px 8px;
  font-size: 0.85rem;
}

.btn-icon {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-icon:hover {
  background: #f8fafc;
}

.btn-icon.destructive {
  color: var(--destructive);
  border-color: #fca5a5;
}

.btn-icon.destructive:hover {
  background: #fef2f2;
}

.btn-add-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #334155;
  cursor: pointer;
}

.btn-add-item:hover {
  background: #e2e8f0;
}

/* Primary Buttons */
.btn-primary {
  background: var(--primary);
  color: #ffffff;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s ease;
}

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

.btn-secondary {
  background: #ffffff;
  color: #334155;
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.15s ease;
}

.btn-secondary:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
}

/* Preview Column Sticky */
.preview-panel {
  position: sticky;
  top: 90px;
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

@media (max-width: 1024px) {
  .preview-panel {
    position: static;
    top: 0;
    width: 100%;
  }
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.preview-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #334155;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.preview-stage {
  background: #334155;
  border-radius: 10px;
  padding: 24px 16px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 520px;
  max-height: calc(100vh - 170px);
  overflow-y: auto;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: inset 0 2px 4px 0 rgba(0, 0, 0, 0.2);
}

@media (max-width: 1024px) {
  .preview-stage {
    min-height: auto;
    max-height: none;
    padding: 16px 8px;
  }
}

@media (max-width: 520px) {
  .preview-stage {
    padding: 14px 6px;
    justify-content: flex-start;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  #receipt-preview {
    margin: 0 auto;
    max-width: none;
  }
}

.receipt-shadow {
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.4), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s ease;
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #0f172a;
  color: #ffffff;
  padding: 14px 20px;
  border-radius: 8px;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 100;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Print Overrides */
@media print {
  body * {
    visibility: hidden;
  }
  #print-target, #print-target * {
    visibility: visible;
  }
  #print-target {
    position: absolute;
    left: 0;
    top: 0;
    margin: 0 !important;
    padding: 0 !important;
  }
}
