/* ==========================================================================
   LEGAL PROPOSAL & QUOTATION SYSTEM - STYLES
   Designed for High-End Law Firms & Legal Advisory Agencies
   ========================================================================== */

:root {
  /* Default Theme: Royal Navy & Gold */
  --primary: #0b192c;
  --primary-light: #1e3e62;
  --accent-gold: #c59b27;
  --gold-glow: rgba(197, 155, 39, 0.25);
  --bg-gradient: linear-gradient(135deg, #09121d 0%, #152336 100%);
  --paper-bg: #ffffff;
  --paper-text: #1e293b;
  --border-color: #cbd5e1;
  --card-bg: #f8fafc;

  /* UI Tokens */
  --font-main: 'Tajawal', 'Cairo', sans-serif;
  --font-serif: 'Amiri', serif;
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.25), 0 10px 10px -5px rgba(0, 0, 0, 0.15);
  --shadow-paper: 0 25px 50px -12px rgba(0, 0, 0, 0.35);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Theme 2: Emerald & Gold */
[data-active-theme="emerald-gold"] {
  --primary: #064e3b;
  --primary-light: #047857;
  --accent-gold: #d97706;
  --gold-glow: rgba(217, 119, 6, 0.25);
  --bg-gradient: linear-gradient(135deg, #022c22 0%, #064e3b 100%);
}

/* Theme 3: Charcoal & Amber */
[data-active-theme="charcoal-amber"] {
  --primary: #18181b;
  --primary-light: #27272a;
  --accent-gold: #b45309;
  --gold-glow: rgba(180, 83, 9, 0.25);
  --bg-gradient: linear-gradient(135deg, #09090b 0%, #18181b 100%);
}

/* Theme 4: Minimalist Monochrome */
[data-active-theme="minimal-black"] {
  --primary: #000000;
  --primary-light: #333333;
  --accent-gold: #475569;
  --gold-glow: rgba(71, 85, 105, 0.25);
  --bg-gradient: linear-gradient(135deg, #18181b 0%, #27272a 100%);
}

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

body {
  font-family: var(--font-main);
  background: var(--bg-gradient);
  color: #f1f5f9;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Header Bar */
.app-header {
  background: rgba(11, 25, 44, 0.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(197, 155, 39, 0.3);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  position: sticky;
  top: 0;
  z-index: 100;
}

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

.logo-icon {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--accent-gold), #9a7617);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: #0b192c;
  box-shadow: 0 4px 12px var(--gold-glow);
}

.brand-text h1 {
  font-size: 18px;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: -0.3px;
}

.brand-text .subtext {
  font-size: 12px;
  color: #94a3b8;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.template-selector, .theme-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #cbd5e1;
}

.template-selector select {
  background: #1e293b;
  color: #fff;
  border: 1px solid #334155;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}

.theme-dots {
  display: flex;
  gap: 6px;
}

.theme-btn {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: var(--transition);
}

.theme-btn[data-theme="royal-navy"] { background: #0b192c; border-color: #c59b27; }
.theme-btn[data-theme="emerald-gold"] { background: #064e3b; border-color: #d97706; }
.theme-btn[data-theme="charcoal-amber"] { background: #18181b; border-color: #b45309; }
.theme-btn[data-theme="minimal-black"] { background: #000000; border-color: #94a3b8; }

.theme-btn.active, .theme-btn:hover {
  transform: scale(1.15);
  box-shadow: 0 0 8px #fff;
}

.action-buttons {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Button Styles */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: var(--transition);
}

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

.btn-secondary {
  background: #1e293b;
  color: #e2e8f0;
  border: 1px solid #334155;
}

.btn-secondary:hover {
  background: #334155;
  color: #fff;
}

.btn-danger-outline {
  background: transparent;
  color: #f87171;
  border: 1px solid #f87171;
}

.btn-danger-outline:hover {
  background: rgba(248, 113, 113, 0.15);
}

.btn-primary-outline {
  background: transparent;
  color: #38bdf8;
  border: 1px solid #38bdf8;
}

.btn-primary-outline:hover {
  background: rgba(56, 189, 248, 0.15);
}

.btn-gold {
  background: linear-gradient(135deg, #d4af37, #9a7617);
  color: #0b192c;
  box-shadow: 0 4px 14px var(--gold-glow);
}

.btn-gold:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px var(--gold-glow);
}

.btn-group-row {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

/* Main Container Layout */
.main-container {
  display: flex;
  flex: 1;
  overflow: hidden;
  height: calc(100vh - 70px);
}

/* Sidebar Editor Panel */
.sidebar-editor {
  width: 380px;
  background: rgba(15, 23, 42, 0.9);
  border-left: 1px solid #1e293b;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sidebar-header h2 {
  font-size: 16px;
  color: #f8fafc;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-header p {
  font-size: 12px;
  color: #94a3b8;
  margin-top: 4px;
}

.editor-sections {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.editor-group {
  background: #1e293b;
  border-radius: var(--radius-md);
  border: 1px solid #334155;
  overflow: hidden;
}

.editor-group.highlight-group {
  border-color: var(--accent-gold);
  box-shadow: 0 0 10px var(--gold-glow);
}

.editor-group summary {
  padding: 12px 16px;
  font-weight: 700;
  font-size: 14px;
  color: #e2e8f0;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.02);
  transition: var(--transition);
}

.editor-group summary:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--accent-gold);
}

.group-content {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-top: 1px solid #334155;
  background: #0f172a;
}

.form-control {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-control label {
  font-size: 12px;
  color: #cbd5e1;
  font-weight: 500;
}

.file-input-custom {
  background: #1e293b;
  color: #e2e8f0;
  padding: 6px;
  border: 1px dashed var(--accent-gold);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.form-control input,
.form-control select,
.form-control textarea {
  background: #1e293b;
  border: 1px solid #334155;
  color: #ffffff;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  transition: var(--transition);
}

.form-control input:focus,
.form-control select:focus,
.form-control textarea:focus {
  outline: none;
  border-color: var(--accent-gold);
  box-shadow: 0 0 0 2px var(--gold-glow);
}

.form-row {
  display: flex;
  gap: 10px;
}

.form-row .form-control {
  flex: 1;
}

/* Document Live Preview Stage */
.preview-stage {
  flex: 1;
  background: #090e17;
  overflow-y: auto;
  padding: 40px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

/* A4 Document Box */
.a4-document {
  width: 210mm;
  min-height: 297mm;
  background: var(--paper-bg);
  color: var(--paper-text);
  padding: 16mm 18mm;
  box-shadow: var(--shadow-paper);
  border-radius: 4px;
  position: relative;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  transition: var(--transition);
}

/* Editable text glow effect */
.editable {
  outline: none;
  border-radius: 3px;
  transition: background 0.2s, box-shadow 0.2s;
  padding: 1px 4px;
}

.editable:hover {
  background: rgba(197, 155, 39, 0.1);
  box-shadow: 0 0 0 1px var(--accent-gold);
  cursor: text;
}

.editable:focus {
  background: rgba(197, 155, 39, 0.15);
  box-shadow: 0 0 0 2px var(--accent-gold);
}

/* Watermark Background */
.legal-watermark {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 260px;
  color: rgba(11, 25, 44, 0.03);
  pointer-events: none;
  z-index: 0;
}

/* Header Section inside Document */
.doc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  position: relative;
  z-index: 1;
}

.firm-brand {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.firm-logo-badge {
  width: 68px;
  height: 68px;
  background: var(--primary);
  border: 2px solid var(--accent-gold);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  color: var(--accent-gold);
  box-shadow: 0 4px 10px rgba(0,0,0,0.1);
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.2s;
}

.firm-logo-badge:hover {
  transform: scale(1.05);
}

.firm-name {
  font-size: 18px;
  font-weight: 900;
  color: var(--primary);
  line-height: 1.25;
  text-align: right;
}

.firm-slogan {
  font-size: 12px;
  color: #64748b;
  font-weight: 600;
  margin-top: 2px;
  text-align: right;
}

.firm-meta {
  font-size: 11px;
  color: #475569;
  margin-top: 4px;
  text-align: right;
}

/* Single Line Title Badge */
.doc-title-badge.single-line-badge {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  background: var(--primary);
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  border-right: 4px solid var(--accent-gold);
}

.badge-title {
  font-size: 14px;
  font-weight: 800;
  color: var(--accent-gold);
}

.badge-separator {
  color: var(--accent-gold);
  font-weight: 300;
  opacity: 0.7;
}

.badge-subtitle {
  font-size: 10px;
  letter-spacing: 0.5px;
  color: #cbd5e1;
  font-weight: 600;
}

/* Gold Divider */
.gold-divider {
  display: flex;
  align-items: center;
  text-align: center;
  margin: 14px 0;
  position: relative;
  z-index: 1;
}

.gold-divider::before, .gold-divider::after {
  content: '';
  flex: 1;
  border-bottom: 2px dashed var(--accent-gold);
  opacity: 0.5;
}

.gold-divider span {
  padding: 0 12px;
  color: var(--accent-gold);
  font-size: 14px;
}

/* Meta Card Grid */
.doc-meta-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
  position: relative;
  z-index: 1;
}

.meta-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px 14px;
  text-align: right;
}

.meta-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
  text-align: right;
}

.client-name {
  font-size: 15px;
  font-weight: 800;
  color: var(--primary);
  text-align: right;
}

.client-rep {
  font-size: 12px;
  color: #475569;
  margin-top: 2px;
  text-align: right;
}

.meta-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  padding: 2px 0;
  border-bottom: 1px dotted #e2e8f0;
}

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

.meta-label {
  color: #64748b;
  font-weight: 600;
}

.meta-val {
  font-weight: 800;
  color: var(--primary);
}

/* Section Headings - Strict Right Alignment */
.text-align-right {
  text-align: right !important;
  direction: rtl !important;
}

.section-heading, .text-right-heading {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  font-size: 13px;
  font-weight: 800;
  color: var(--primary);
  background: #f1f5f9;
  padding: 6px 12px;
  border-radius: 6px;
  border-right: 4px solid var(--accent-gold);
  margin-bottom: 10px;
  text-align: right;
  direction: rtl;
  gap: 8px;
}

.section-heading i {
  color: var(--accent-gold);
}

.section-heading span {
  flex: 1;
  text-align: right;
}

.scope-text, .text-right-content {
  font-size: 12.5px;
  line-height: 1.7;
  color: #334155;
  margin-bottom: 16px;
  text-align: right !important;
  direction: rtl !important;
}

/* Legal Fees Table */
.fees-table-section {
  margin-bottom: 16px;
  position: relative;
  z-index: 1;
  text-align: right;
}

.btn-add-item {
  background: var(--primary);
  color: #fff;
  border: none;
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  transition: var(--transition);
  margin-right: auto;
}

.btn-add-item:hover {
  background: var(--accent-gold);
  color: var(--primary);
}

.legal-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 6px;
  font-size: 12px;
  text-align: right;
}

.legal-table th {
  background: var(--primary);
  color: #ffffff;
  padding: 8px 10px;
  font-weight: 700;
  text-align: right;
  border: 1px solid var(--primary);
}

.legal-table td {
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  color: #1e293b;
  vertical-align: top;
  text-align: right;
}

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

.btn-del-row {
  color: #ef4444;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 13px;
  transition: transform 0.2s;
}

.btn-del-row:hover {
  transform: scale(1.2);
}

/* Financial Summary & Tafqeet */
.financial-summary-wrapper {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
  position: relative;
  z-index: 1;
  text-align: right;
}

.tafqeet-box {
  background: #fdfbf7;
  border: 1px solid var(--accent-gold);
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  text-align: right;
}

.tafqeet-label {
  font-size: 11px;
  color: #78350f;
  font-weight: 700;
  text-align: right;
}

.tafqeet-text {
  font-size: 13px;
  font-weight: 800;
  color: #92400e;
  margin: 6px 0;
  font-family: var(--font-serif);
  text-align: right;
}

.bank-info-box {
  border-top: 1px dashed #fde68a;
  padding-top: 6px;
  font-size: 11px;
  color: #475569;
  text-align: right;
}

.bank-title {
  font-weight: 700;
  color: var(--primary);
  display: block;
  text-align: right;
}

.totals-table {
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.total-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
}

.total-label {
  color: #64748b;
}

.total-value {
  font-weight: 800;
  color: var(--primary);
}

.grand-total {
  border-top: 2px solid var(--accent-gold);
  padding-top: 6px;
  margin-top: 2px;
  font-size: 14px;
}

.grand-total .total-label {
  font-weight: 800;
  color: var(--primary);
}

.grand-total .total-value {
  font-size: 16px;
  color: var(--accent-gold);
}

/* Terms List - Right Aligned */
.legal-terms-section {
  margin-bottom: 16px;
  position: relative;
  z-index: 1;
  text-align: right !important;
}

.terms-list {
  padding-right: 20px;
  padding-left: 0;
  font-size: 11.5px;
  color: #475569;
  line-height: 1.6;
  text-align: right !important;
  direction: rtl !important;
}

.terms-list li {
  margin-bottom: 4px;
  text-align: right !important;
}

/* Signatures & Seal Section */
.signatures-wrapper {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 30px;
  margin-top: 10px;
  margin-bottom: 10px;
  position: relative;
  z-index: 1;
  text-align: right;
}

.sig-column {
  border: 1px dashed var(--border-color);
  border-radius: 8px;
  padding: 12px;
  background: rgba(248, 250, 252, 0.5);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  text-align: right;
}

.sig-title {
  font-size: 12px;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 6px;
  text-align: right;
}

.partner-name {
  font-size: 13px;
  font-weight: 800;
  color: var(--primary);
  text-align: right;
}

.partner-title {
  font-size: 11px;
  color: #64748b;
  text-align: right;
}

.stamp-seal-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
}

/* Seal Stamp Graphic */
.official-seal {
  width: 80px;
  height: 80px;
  border: 3px double var(--accent-gold);
  border-radius: 50%;
  padding: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: rotate(-12deg);
  opacity: 0.85;
}

.seal-inner {
  width: 100%;
  height: 100%;
  border: 1px dashed var(--accent-gold);
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 7.5px;
  color: var(--accent-gold);
  font-weight: 700;
  line-height: 1.1;
  background: rgba(197, 155, 39, 0.05);
}

.seal-inner i {
  font-size: 14px;
  margin-bottom: 2px;
}

.digital-signature-line .sig-script {
  font-family: 'Amiri', cursive;
  font-size: 20px;
  color: var(--primary);
  font-weight: bold;
  transform: rotate(-6deg);
  display: block;
}

.sig-line-placeholder {
  font-size: 11px;
  color: #64748b;
  margin-top: 6px;
  text-align: right;
}

.sig-box-space {
  height: 40px;
  border: 1px dotted #cbd5e1;
  margin: 6px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: #94a3b8;
  border-radius: 4px;
}

/* Footer Section */
.doc-footer {
  border-top: 2px double var(--accent-gold);
  padding-top: 8px;
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: #64748b;
  position: relative;
  z-index: 1;
}

/* Toast Notifications */
.toast {
  position: fixed;
  bottom: 24px;
  left: 24px;
  background: var(--primary);
  color: #fff;
  border-right: 4px solid var(--accent-gold);
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
  z-index: 999;
}

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

/* Print Optimization */
@media print {
  .no-print {
    display: none !important;
  }
  
  body {
    background: #ffffff !important;
    color: #000000 !important;
    padding: 0 !important;
  }

  .main-container {
    height: auto !important;
    overflow: visible !important;
  }

  .preview-stage {
    padding: 0 !important;
    background: none !important;
    overflow: visible !important;
  }

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

  .editable:hover, .editable:focus {
    background: none !important;
    box-shadow: none !important;
  }

  @page {
    size: A4 portrait;
    margin: 12mm 15mm;
  }
}
