/* =========================================================
   AIS Invoice Pro — style.css
   Modern, responsive invoice generator styles
   ========================================================= */

/* ── CSS Variables ───────────────────────────────────────── */
:root {
  --primary:        #4f46e5;
  --primary-dark:   #3730a3;
  --primary-light:  #ede9fe;
  --success:        #059669;
  --success-dark:   #047857;
  --danger:         #dc2626;
  --danger-light:   #fee2e2;
  --gray-50:        #f9fafb;
  --gray-100:       #f3f4f6;
  --gray-200:       #e5e7eb;
  --gray-300:       #d1d5db;
  --gray-400:       #9ca3af;
  --gray-500:       #6b7280;
  --gray-700:       #374151;
  --gray-800:       #1f2937;
  --gray-900:       #111827;
  --white:          #ffffff;
  --border-radius:  0.5rem;
  --shadow-sm:      0 1px 2px 0 rgb(0 0 0 / .05);
  --shadow:         0 1px 3px 0 rgb(0 0 0 / .1), 0 1px 2px -1px rgb(0 0 0 / .1);
  --shadow-md:      0 4px 6px -1px rgb(0 0 0 / .1), 0 2px 4px -2px rgb(0 0 0 / .1);
  --shadow-lg:      0 10px 15px -3px rgb(0 0 0 / .1), 0 4px 6px -4px rgb(0 0 0 / .1);
  --shadow-xl:      0 20px 25px -5px rgb(0 0 0 / .1), 0 8px 10px -6px rgb(0 0 0 / .1);
  --font:           'Inter', system-ui, -apple-system, sans-serif;
  --transition:     0.15s ease;
}

/* ── Reset & Base ────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--gray-800);
  background: var(--gray-100);
  min-height: 100vh;
}

/* ── Utility ─────────────────────────────────────────────── */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

.hidden { display: none !important; }

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

.mt-4 { margin-top: 1rem; }

/* ── App Header ──────────────────────────────────────────── */
.app-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: var(--white);
  padding: 1.25rem 0;
  box-shadow: var(--shadow-md);
}

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

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.brand-icon {
  width: 2.25rem;
  height: 2.25rem;
  flex-shrink: 0;
}

.brand-name {
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header-tagline {
  font-size: 0.8125rem;
  opacity: 0.8;
}

/* ── Main Content ────────────────────────────────────────── */
.main-content {
  padding-top: 2rem;
  padding-bottom: 4rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ── Card ────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  padding: 1.75rem;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.0625rem;
  font-weight: 600;
  color: var(--gray-800);
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--gray-200);
}

.card-title svg {
  width: 1.125rem;
  height: 1.125rem;
  color: var(--primary);
  flex-shrink: 0;
}

/* ── Form Grid ───────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem 1.25rem;
}

.form-group { display: flex; flex-direction: column; gap: 0.25rem; }
.form-col-2 { grid-column: span 2; }
.form-col-full { grid-column: span 4; }

label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--gray-700);
}

.required { color: var(--danger); }

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="url"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--gray-300);
  border-radius: 0.375rem;
  font-family: var(--font);
  font-size: 0.9rem;
  color: var(--gray-800);
  background: var(--white);
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
}

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

input::placeholder, textarea::placeholder { color: var(--gray-400); }

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%236b7280'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.625rem center;
  background-size: 1rem;
  padding-right: 2.25rem;
  cursor: pointer;
}

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

.input-sm {
  max-width: 10rem;
}

/* ── Logo Upload ─────────────────────────────────────────── */
.logo-upload-area {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
  padding: 1rem;
  background: var(--gray-50);
  border: 1px dashed var(--gray-300);
  border-radius: var(--border-radius);
}

.logo-preview-wrap {
  width: 5rem;
  height: 5rem;
  border-radius: 0.375rem;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--white);
  border: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-preview {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.logo-placeholder {
  color: var(--gray-300);
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-placeholder svg {
  width: 2.5rem;
  height: 2.5rem;
}

.logo-upload-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5625rem 1.25rem;
  border: 1.5px solid transparent;
  border-radius: 0.375rem;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
}

.btn svg { width: 1rem; height: 1rem; flex-shrink: 0; }

.btn-primary {
  background: var(--primary);
  color: var(--white);
  border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.btn-success {
  background: var(--success);
  color: var(--white);
  border-color: var(--success);
}
.btn-success:hover { background: var(--success-dark); border-color: var(--success-dark); }

.btn-outline {
  background: transparent;
  color: var(--primary);
  border-color: var(--primary);
}
.btn-outline:hover { background: var(--primary-light); }

.btn-ghost {
  background: transparent;
  color: var(--gray-700);
  border-color: var(--gray-300);
}
.btn-ghost:hover { background: var(--gray-100); border-color: var(--gray-400); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: none;
  padding: 0.25rem 0.5rem;
}
.btn-danger:hover { background: var(--danger-light); border-radius: 0.25rem; }

.btn-sm {
  padding: 0.375rem 0.875rem;
  font-size: 0.8125rem;
}

/* ── Action Bar ──────────────────────────────────────────── */
.action-bar {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
}

/* ── Line Items Table ────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

.items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.items-table th {
  padding: 0.625rem 0.75rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-500);
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
}

.items-table td {
  padding: 0.5rem 0.5rem;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}

.items-table tr:hover td { background: var(--gray-50); }

.col-desc   { width: 45%; }
.col-qty    { width: 12%; }
.col-price  { width: 18%; }
.col-amount { width: 18%; }
.col-action { width: 7%; text-align: right; }

.amount-cell {
  font-weight: 500;
  color: var(--gray-800);
  text-align: right;
  padding-right: 0.75rem;
}

/* ── Totals ──────────────────────────────────────────────── */
.totals-area {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--gray-200);
}

.totals-inputs {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.totals-summary {
  min-width: 240px;
  flex-shrink: 0;
}

.totals-row {
  display: flex;
  justify-content: space-between;
  padding: 0.375rem 0;
  font-size: 0.9rem;
  color: var(--gray-700);
  border-bottom: 1px solid var(--gray-100);
}

.totals-grand {
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--gray-900);
  border-top: 2px solid var(--gray-300);
  border-bottom: none;
  padding-top: 0.5rem;
  margin-top: 0.25rem;
}

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17,24,39,0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 1000;
  overflow-y: auto;
  padding: 1.5rem;
}

.modal-dialog {
  background: var(--white);
  border-radius: 0.75rem;
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 820px;
  margin: auto;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

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

.modal-header h2 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--gray-800);
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
}

/* ── Invoice Print Layout ────────────────────────────────── */
.invoice-print {
  background: var(--white);
  padding: 2rem 2.5rem;
  font-family: var(--font);
  color: var(--gray-800);
  max-width: 760px;
  margin: 0 auto;
  box-shadow: var(--shadow-md);
  border-radius: 0.5rem;
}

/* Header row */
.inv-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 2rem;
  margin-bottom: 2rem;
}

.inv-from { flex: 1; }

.inv-logo {
  max-width: 9rem;
  max-height: 5rem;
  object-fit: contain;
  margin-bottom: 0.75rem;
}

.inv-company-name {
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 0.25rem;
}

.inv-address {
  font-style: normal;
  font-size: 0.85rem;
  color: var(--gray-600, var(--gray-500));
  line-height: 1.6;
  white-space: pre-line;
}

.inv-meta { text-align: right; }

.inv-title {
  font-size: 2rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
}

.inv-meta-table {
  border-collapse: collapse;
  margin-left: auto;
  font-size: 0.85rem;
}

.inv-meta-table td {
  padding: 0.2rem 0.4rem;
}

.inv-meta-table td:first-child {
  color: var(--gray-500);
  text-align: right;
  padding-right: 0.75rem;
}

.inv-meta-table td:last-child {
  font-weight: 500;
  color: var(--gray-800);
}

/* Bill To */
.inv-bill-section {
  display: flex;
  gap: 2rem;
  margin-bottom: 1.5rem;
}

.inv-bill-to {
  background: var(--gray-50);
  border-left: 3px solid var(--primary);
  padding: 0.875rem 1rem;
  border-radius: 0 0.375rem 0.375rem 0;
  min-width: 200px;
  max-width: 320px;
}

.inv-bill-to h3 {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--primary);
  margin-bottom: 0.4rem;
}

.inv-bill-to div {
  font-size: 0.875rem;
  color: var(--gray-700);
  line-height: 1.55;
  white-space: pre-line;
}

/* Items table */
.inv-items-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

.inv-items-table thead tr {
  background: var(--primary);
  color: var(--white);
}

.inv-items-table th {
  padding: 0.625rem 0.75rem;
  font-weight: 600;
  text-align: left;
  font-size: 0.8125rem;
  letter-spacing: 0.04em;
}

.inv-col-desc   { width: 48%; }
.inv-col-qty    { width: 12%; text-align: center; }
.inv-col-price  { width: 20%; text-align: right; }
.inv-col-amount { width: 20%; text-align: right; }

.inv-items-table th.inv-col-qty,
.inv-items-table th.inv-col-price,
.inv-items-table th.inv-col-amount { text-align: right; }

.inv-items-table td {
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid var(--gray-200);
  color: var(--gray-700);
}

.inv-items-table tr:last-child td { border-bottom: none; }
.inv-items-table tr:nth-child(even) td { background: var(--gray-50); }

.inv-td-qty    { text-align: center; }
.inv-td-price  { text-align: right; }
.inv-td-amount { text-align: right; font-weight: 500; }

/* Totals */
.inv-totals {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 1.5rem;
}

.inv-totals-inner {
  min-width: 260px;
  border: 1px solid var(--gray-200);
  border-radius: 0.375rem;
  overflow: hidden;
}

.inv-totals-row {
  display: flex;
  justify-content: space-between;
  padding: 0.45rem 0.875rem;
  font-size: 0.875rem;
  color: var(--gray-700);
  border-bottom: 1px solid var(--gray-100);
}

.inv-totals-row:last-child { border-bottom: none; }

.inv-grand-total {
  background: var(--primary);
  color: var(--white);
  font-weight: 700;
  font-size: 0.9375rem;
}

/* Footer (notes/terms) */
.inv-footer {
  border-top: 1px solid var(--gray-200);
  padding-top: 1.25rem;
  display: flex;
  gap: 2rem;
  flex-wrap: wrap;
}

.inv-notes, .inv-terms { flex: 1; min-width: 180px; }

.inv-notes h4, .inv-terms h4 {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--gray-500);
  margin-bottom: 0.35rem;
}

.inv-notes p, .inv-terms p {
  font-size: 0.8125rem;
  color: var(--gray-600, var(--gray-500));
  line-height: 1.55;
  white-space: pre-line;
}

/* ── App Footer ──────────────────────────────────────────── */
.app-footer {
  text-align: center;
  padding: 1.25rem;
  font-size: 0.8125rem;
  color: var(--gray-500);
  background: var(--white);
  border-top: 1px solid var(--gray-200);
}

.app-footer a {
  color: var(--primary);
  text-decoration: none;
}

.app-footer a:hover { text-decoration: underline; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 700px) {
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-col-2, .form-col-full { grid-column: span 2; }

  .totals-area { flex-direction: column; }
  .totals-summary { width: 100%; }

  .action-bar { flex-direction: column; }
  .action-bar .btn { justify-content: center; }

  .inv-header { flex-direction: column; gap: 1rem; }
  .inv-meta { text-align: left; }
  .inv-meta-table { margin-left: 0; }
  .inv-title { font-size: 1.5rem; }

  .modal-overlay { padding: 0.5rem; }
  .invoice-print { padding: 1.25rem; }
}

@media (max-width: 480px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-col-2, .form-col-full { grid-column: span 1; }
  .card { padding: 1.25rem; }
}

/* ── Print / PDF ─────────────────────────────────────────── */
@media print {
  /* Hide everything except the invoice */
  body {
    background: white !important;
    color: black;
    font-family: var(--font);
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  .app-header,
  .app-footer,
  .main-content,
  .modal-overlay .modal-header,
  #closeModal,
  #printBtn {
    display: none !important;
  }

  .modal-overlay {
    position: static !important;
    background: none !important;
    backdrop-filter: none !important;
    padding: 0 !important;
    overflow: visible !important;
    display: block !important;
  }

  .modal-dialog {
    box-shadow: none !important;
    border-radius: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 !important;
  }

  .modal-body {
    padding: 0 !important;
    overflow: visible !important;
  }

  .invoice-print {
    padding: 0 !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    max-width: 100% !important;
    page-break-inside: avoid;
  }

  .inv-items-table thead tr {
    background: var(--primary) !important;
    color: white !important;
  }

  .inv-grand-total {
    background: var(--primary) !important;
    color: white !important;
  }

  .hidden { display: none !important; }

  @page {
    margin: 1.5cm;
    size: A4 portrait;
  }
}
