/* ==========================================================================
   OSF Tax Invoicing App - Main Stylesheet
   ========================================================================== */

:root {
  --primary-color: #1e3a8a;
  --primary-dark: #0f172a;
  --primary-light: #3b82f6;
  --accent-color: #f59e0b;
  --danger-color: #ef4444;
  --success-color: #10b981;
  --bg-app: #f1f5f9;
  --bg-card: #ffffff;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border-color: #cbd5e1;
  --border-focus: #2563eb;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "Roboto Mono", monospace;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header & Top Bar - Modernized Enterprise Grade */
.top-header {
  background: linear-gradient(135deg, #0b1329 0%, #172554 45%, #1e3a8a 100%);
  color: white;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 4px 20px rgba(11, 19, 41, 0.4), inset 0 -1px 0 rgba(255, 255, 255, 0.1);
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 16px;
  flex-wrap: wrap;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo-container {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.95);
  padding: 4px 8px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25), inset 0 0 0 1px rgba(255, 255, 255, 0.6);
  transition: transform 0.2s ease;
}

.brand-logo-container:hover {
  transform: translateY(-1px);
}

.brand-logo-img {
  height: 38px;
  width: auto;
  display: block;
  object-fit: contain;
}

.brand-text h1 {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #ffffff;
  line-height: 1.2;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.brand-text p {
  font-size: 0.72rem;
  color: #93c5fd;
  font-weight: 500;
  margin-top: 2px;
  letter-spacing: 0.01em;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(15, 23, 42, 0.45);
  padding: 4px 6px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.2);
}

.nav-btn {
  background: transparent;
  color: #cbd5e1;
  border: none;
  padding: 6px 13px;
  border-radius: 7px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

.nav-btn.active {
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  color: #ffffff;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.header-cache-btn {
  background: rgba(255, 255, 255, 0.08);
  color: #f1f5f9;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 7px;
  padding: 6px 11px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.header-cache-btn:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

.header-status-badge {
  margin-left: 4px;
  font-size: 0.74rem;
  font-weight: 700;
  background: rgba(6, 78, 59, 0.6);
  color: #34d399;
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid rgba(16, 185, 129, 0.4);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.15);
}

.status-dot-pulse {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #34d399;
  box-shadow: 0 0 6px #34d399;
  display: inline-block;
  animation: headerPulse 2s infinite ease-in-out;
}

@keyframes headerPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

/* Main Container */
.app-container {
  max-width: 1380px;
  margin: 0 auto;
  padding: 24px 20px;
  width: 100%;
  flex: 1;
}

.view-section {
  display: none;
}

.view-section.active {
  display: block;
}

/* Cards & Layout */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid #f1f5f9;
}

.card-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--primary-dark);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Grid Layouts */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

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

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

@media (max-width: 900px) {
  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr;
  }
}

/* Form Controls */
.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.form-control {
  width: 100%;
  padding: 9px 12px;
  font-size: 0.9rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background-color: #fff;
  color: var(--text-main);
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-control:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

textarea.form-control {
  resize: vertical;
  min-height: 70px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
}

.btn-primary {
  background-color: var(--primary-light);
  color: white;
}
.btn-primary:hover {
  background-color: #1d4ed8;
}

.btn-success {
  background-color: var(--success-color);
  color: white;
}
.btn-success:hover {
  background-color: #059669;
}

.btn-danger {
  background-color: #fee2e2;
  color: var(--danger-color);
  border-color: #fca5a5;
}
.btn-danger:hover {
  background-color: var(--danger-color);
  color: white;
}

.btn-outline {
  background: white;
  border-color: var(--border-color);
  color: var(--text-main);
}
.btn-outline:hover {
  background-color: #f8fafc;
  border-color: #94a3b8;
}

.btn-lg {
  padding: 12px 24px;
  font-size: 1rem;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.775rem;
}

/* Items Table in Builder */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
}

.items-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.875rem;
}

.items-table th {
  background-color: #f8fafc;
  padding: 10px 12px;
  font-weight: 600;
  color: var(--primary-dark);
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

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

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

.items-table tr:hover td {
  background-color: #fbfcfe;
}

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

/* Summary Box */
.summary-box {
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 16px;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: 0.9rem;
}

.summary-row.total-row {
  border-top: 2px solid var(--border-color);
  margin-top: 8px;
  padding-top: 10px;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary-dark);
}

.in-words-box {
  background: #eff6ff;
  border: 1px dashed #93c5fd;
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-top: 14px;
  font-size: 0.85rem;
}

.in-words-title {
  font-weight: 700;
  color: #1e40af;
  margin-bottom: 4px;
}

.in-words-text {
  font-family: var(--font-mono);
  color: #1e3a8a;
  font-weight: 600;
}

/* History / List Table */
.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.data-table th {
  background: #f8fafc;
  padding: 12px 14px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
  font-size: 0.8rem;
  text-transform: uppercase;
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.9rem;
}

.data-table tr:hover td {
  background-color: #f8fafc;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-green { background: #dcfce7; color: #15803d; }
.badge-amber { background: #fef3c7; color: #b45309; }

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  background: white;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 650px;
  max-height: 90vh;
  overflow-y: auto;
}

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

.modal-body {
  padding: 20px;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: #f8fafc;
}

/* Toast Notifications */
#toastContainer {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: var(--primary-dark);
  color: white;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideIn 0.25s ease-out;
}

.toast.success { background: #065f46; border-left: 4px solid #10b981; }
.toast.error { background: #991b1b; border-left: 4px solid #ef4444; }

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

/* Print Preview Container */
#printPreviewContainer {
  background: #525659;
  padding: 30px 10px;
  min-height: 100vh;
  display: none;
}

#printPreviewContainer.active {
  display: block;
}

.preview-controls {
  max-width: 210mm;
  margin: 0 auto 16px auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #1e293b;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  color: white;
}
