/* ===== Google Fonts ===== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ===== CSS Variables ===== */
:root {
  --horus-orange: #E8611A;
  --horus-orange-light: #F28C5A;
  --horus-orange-dark: #C44E12;
  --horus-orange-glow: rgba(232, 97, 26, 0.15);
  --bg-dark: #0F1117;
  --bg-card: #1A1D27;
  --bg-card-hover: #22252F;
  --bg-input: #14161E;
  --bg-form: rgba(26, 29, 39, 0.85);
  --text-primary: #F0F0F5;
  --text-secondary: #9096A8;
  --text-muted: #5C6278;
  --border-color: rgba(144, 150, 168, 0.15);
  --border-focus: rgba(232, 97, 26, 0.5);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.15);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.35);
  --shadow-glow: 0 0 20px rgba(232, 97, 26, 0.2);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
}

/* ===== App Layout ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(15, 17, 23, 0.8);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-color);
  padding: 16px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

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

.header-title {
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--horus-orange-light), var(--horus-orange));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 400;
}

.header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--horus-orange), var(--horus-orange-dark));
  color: white;
  box-shadow: 0 4px 12px rgba(232, 97, 26, 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(232, 97, 26, 0.4);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--horus-orange);
  transform: translateY(-1px);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 8px 12px;
}

.btn-ghost:hover {
  color: var(--horus-orange);
  background: var(--horus-orange-glow);
}

.btn-danger {
  background: rgba(220, 53, 69, 0.15);
  color: #ff6b7a;
  border: 1px solid rgba(220, 53, 69, 0.25);
  padding: 6px 10px;
  font-size: 12px;
}

.btn-danger:hover {
  background: rgba(220, 53, 69, 0.25);
}

.btn-add {
  background: rgba(232, 97, 26, 0.1);
  color: var(--horus-orange);
  border: 1px dashed rgba(232, 97, 26, 0.3);
  width: 100%;
  justify-content: center;
  padding: 12px;
  border-radius: var(--radius-md);
  font-size: 13px;
}

.btn-add:hover {
  background: rgba(232, 97, 26, 0.2);
  border-color: var(--horus-orange);
}

.btn-icon {
  font-size: 16px;
  line-height: 1;
}

/* ===== Main Content ===== */
.main-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  height: calc(100vh - 65px);
}

/* ===== Form Panel ===== */
.form-panel {
  overflow-y: auto;
  padding: 28px;
  border-right: 1px solid var(--border-color);
  background: linear-gradient(180deg, rgba(26, 29, 39, 0.4) 0%, transparent 100%);
}

.form-panel::-webkit-scrollbar {
  width: 6px;
}

.form-panel::-webkit-scrollbar-track {
  background: transparent;
}

.form-panel::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

.form-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 20px;
  transition: var(--transition);
}

.form-section:hover {
  border-color: rgba(232, 97, 26, 0.2);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.section-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-color);
}

.section-number {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--horus-orange), var(--horus-orange-dark));
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: white;
  flex-shrink: 0;
}

.section-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

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

.form-group:last-child {
  margin-bottom: 0;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input,
.form-textarea,
.form-select {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  transition: var(--transition);
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  outline: none;
  border-color: var(--horus-orange);
  box-shadow: 0 0 0 3px var(--horus-orange-glow);
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--text-muted);
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
  line-height: 1.6;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

/* ===== Dynamic Items ===== */
.dynamic-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dynamic-item {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  transition: var(--transition);
  position: relative;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.dynamic-item:hover {
  border-color: rgba(232, 97, 26, 0.2);
}

.dynamic-item .item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.dynamic-item .item-inputs {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dynamic-item .form-input,
.dynamic-item .form-textarea {
  background: rgba(15, 17, 23, 0.6);
}

/* ===== Table Effort ===== */
.effort-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin-top: 10px;
}

.effort-table th {
  background: rgba(232, 97, 26, 0.1);
  color: var(--horus-orange);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.effort-table th:first-child {
  border-radius: var(--radius-sm) 0 0 0;
}

.effort-table th:last-child {
  border-radius: 0 var(--radius-sm) 0 0;
  width: 120px;
}

.effort-table th:nth-child(3) {
  width: 50px;
}

.effort-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border-color);
}

.effort-table td .form-input {
  padding: 8px 10px;
  font-size: 13px;
}

.effort-table .total-row td {
  background: rgba(232, 97, 26, 0.06);
  font-weight: 700;
  padding: 12px 14px;
  color: var(--horus-orange);
  font-size: 14px;
}

/* ===== Preview Panel ===== */
.preview-panel {
  overflow-y: auto;
  background: #E8E8E8;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 30px;
}

.preview-panel::-webkit-scrollbar {
  width: 8px;
}

.preview-panel::-webkit-scrollbar-track {
  background: #ddd;
}

.preview-panel::-webkit-scrollbar-thumb {
  background: #bbb;
  border-radius: 4px;
}

/* ===== Document Preview ===== */
.document {
  width: 210mm;
  min-height: 297mm;
  background: white;
  padding: 30mm 25mm;
  box-shadow: var(--shadow-lg);
  color: #1a1a1a;
  font-family: 'Inter', sans-serif;
  font-size: 11pt;
  line-height: 1.7;
  flex-shrink: 0;
  height: auto;
}

.doc-header {
  text-align: center;
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 3px solid var(--horus-orange);
}

.doc-logo-img {
  height: 45px;
  width: auto;
  margin-bottom: 12px;
}

.doc-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--horus-orange);
  margin-top: 10px;
}

.doc-meta {
  display: flex;
  justify-content: space-between;
  margin: 15px 0 25px;
  padding: 12px 18px;
  background: #f8f8f8;
  border-radius: 6px;
  border-left: 4px solid var(--horus-orange);
}

.doc-meta-item {
  font-size: 10pt;
}

.doc-meta-label {
  font-weight: 600;
  color: #555;
  text-decoration: underline;
}

.doc-meta-value {
  color: #333;
}

.doc-section {
  margin-bottom: 24px;
}

.doc-section-title {
  font-size: 13pt;
  font-weight: 700;
  color: var(--horus-orange);
  margin-bottom: 10px;
  padding-bottom: 4px;
}

.doc-section-content {
  font-size: 10.5pt;
  color: #333;
  line-height: 1.7;
}

.doc-section-content strong {
  font-weight: 700;
}

.doc-list {
  list-style: disc;
  padding-left: 24px;
  margin: 8px 0;
}

.doc-list li {
  margin-bottom: 6px;
}

.doc-obs {
  margin-top: 12px;
  padding: 10px 14px;
  background: #fff5f0;
  border-left: 3px solid var(--horus-orange);
  font-size: 10pt;
  color: #c44e12;
}

.doc-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
  font-size: 10pt;
}

.doc-table th {
  background: var(--horus-orange);
  color: white;
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
}

.doc-table td {
  padding: 9px 14px;
  border-bottom: 1px solid #e0e0e0;
}

.doc-table tr:nth-child(even) td {
  background: #f8f8f8;
}

.doc-table .doc-total-row td {
  background: #fff5f0;
  font-weight: 700;
  color: var(--horus-orange);
  border-top: 2px solid var(--horus-orange);
}

.doc-subsection-title {
  font-size: 11.5pt;
  font-weight: 700;
  color: var(--horus-orange);
  margin: 16px 0 8px;
}

.doc-activity-list {
  list-style: none;
  padding: 0;
}

.doc-activity-list li {
  padding: 3px 0;
  font-size: 10.5pt;
}

.doc-activity-list li::before {
  content: "- ";
  color: var(--horus-orange);
  font-weight: 700;
}

/* ===== Empty State ===== */
.empty-placeholder {
  color: #999;
  font-style: italic;
  font-size: 10pt;
}

/* ===== Responsive ===== */
@media (max-width: 1200px) {
  .main-content {
    grid-template-columns: 1fr;
    height: auto;
  }

  .form-panel {
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }

  .preview-panel {
    min-height: 100vh;
  }

  .document {
    width: 100%;
    max-width: 210mm;
    padding: 20mm 15mm;
  }
}

/* ===== Print Styles ===== */
@media print {
  @page {
    size: A4 portrait;
    margin: 20mm; 
  }

  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body {
    background: white;
  }

  .app-header,
  .form-panel,
  .save-toast {
    display: none !important;
  }

  .main-content {
    display: block;
    height: auto;
  }

  .preview-panel {
    background: white;
    padding: 0;
    overflow: visible;
    min-height: auto;
  }

  .document {
    width: 100%;
    padding: 0;
    margin: 0;
    box-shadow: none;
    min-height: auto;
    height: auto;
  }

  .doc-header {
    break-after: avoid;
    page-break-after: avoid;
  }

  .doc-section-title,
  .doc-subsection-title {
    break-after: avoid;
    page-break-after: avoid;
  }

  .doc-section {
    /* Allow sections to break across pages so we don't end up with huge blank spaces */
    break-after: auto;
  }

  .doc-table {
    page-break-inside: auto;
  }

  tr, td, th {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .doc-list li {
    break-inside: avoid;
    page-break-inside: avoid;
  }
}

/* ===== Animations ===== */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.form-section {
  animation: fadeIn 0.4s ease;
}

/* ===== Tooltip ===== */
.tooltip {
  position: relative;
}

.tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 11px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  box-shadow: var(--shadow-md);
}

.tooltip:hover::after {
  opacity: 1;
}

/* Save notification */
.save-toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--bg-card);
  color: #4caf50;
  border: 1px solid rgba(76, 175, 80, 0.3);
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  z-index: 1000;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s ease;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.save-toast.show {
  opacity: 1;
  transform: translateY(0);
}
