:root {
  --bg-dark: #090d16;
  --bg-card-glass: rgba(17, 24, 39, 0.85);
  --bg-input: #1f293d;
  --border-color: rgba(255, 255, 255, 0.1);
  --border-focus: #3b82f6;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #2563eb;
  --accent: #10b981;
  --danger: #ef4444;
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
  --radius-lg: 16px;
  --radius-md: 10px;
  --font-main: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --card-ar-font: 'Noto Naskh Arabic', Tahoma, serif;
  --card-en-font: Tahoma, Arial, sans-serif;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  background: radial-gradient(circle at top left, #1e1b4b, #090d16 50%, #030712);
  color: var(--text-main);
  font-family: var(--font-main);
  min-height: 100vh;
  padding-bottom: 40px;
}

.app-container {
  max-width: 1540px;
  margin: 0 auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Responsive Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 22px;
  background: var(--bg-card-glass);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  flex-wrap: wrap;
  gap: 12px;
}

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

.brand-icon {
  font-size: 30px;
  background: rgba(59, 130, 246, 0.15);
  padding: 6px 10px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
}

.app-header h1 {
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, #ffffff, #93c5fd);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1.2;
}

.subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

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

.status-badge {
  font-size: 11px;
  font-weight: 600;
  color: #34d399;
  background: rgba(52, 211, 153, 0.12);
  border: 1px solid rgba(52, 211, 153, 0.3);
  padding: 4px 10px;
  border-radius: 20px;
}

/* Main Grid Layout - Desktop 2 Column / Mobile 1 Column */
.main-content {
  display: grid;
  grid-template-columns: 480px 1fr;
  gap: 20px;
  align-items: start;
}

/* Panels */
.editor-panel, .preview-panel {
  background: var(--bg-card-glass);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel-header, .preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}

.panel-header h2, .preview-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.sample-preset-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.font-control-select {
  background: #1e293b;
  color: #f8fafc;
  border: 1px solid #3b82f6;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  cursor: pointer;
  width: 100%;
}

/* Font Selector Section */
.font-selector-section {
  background: linear-gradient(135deg, rgba(30, 58, 138, 0.3), rgba(15, 23, 42, 0.6));
  border: 1px solid rgba(59, 130, 246, 0.3);
}

/* Form Styles */
.editor-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-section {
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section-title {
  font-size: 12px;
  font-weight: 700;
  color: #93c5fd;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

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

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

.form-group label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
}

.form-input, .form-select {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  width: 100%;
}

.font-bold {
  font-weight: 700;
}

.form-input:focus, .form-select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
  background: #1e293b;
}

.rtl-text {
  font-family: var(--card-ar-font);
  direction: rtl;
  text-align: right;
  font-weight: 700;
}

.input-with-preset, .input-with-btn {
  display: flex;
  gap: 6px;
}

.input-with-preset input, .input-with-btn input {
  flex: 1;
  min-width: 0;
}

.preset-select {
  width: 100px;
  font-size: 11px;
  padding: 6px;
  cursor: pointer;
}

.btn-action-icon {
  background: #1e293b;
  border: 1px solid #3b82f6;
  color: #93c5fd;
  font-size: 11px;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-action-icon:hover {
  background: #2563eb;
  color: #ffffff;
}

.file-upload-wrapper {
  display: flex;
  gap: 6px;
}

.file-input {
  display: none;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  font-family: inherit;
  transition: all 0.2s ease;
}

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

.btn-secondary:hover {
  background: #475569;
}

.btn-accent {
  background: linear-gradient(135deg, #059669, #10b981);
  color: white;
}

.btn-accent:hover {
  background: linear-gradient(135deg, #10b981, #34d399);
}

.btn-download-main {
  width: 100%;
  padding: 14px 20px;
  font-size: 15px;
  font-weight: 700;
  border-radius: 10px;
  box-shadow: 0 10px 20px -5px rgba(16, 185, 129, 0.4);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  flex: 1;
}

.btn-icon {
  background: #334155;
  color: #94a3b8;
  padding: 6px 10px;
}

/* ==========================================================================
   DRIVING LICENSE CARD - 100% PROPORTIONAL CONTAINER QUERY RESPONSIVE ENGINE
   ========================================================================== */
.card-display-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 14px;
  background: radial-gradient(circle, rgba(30, 41, 59, 0.8) 0%, rgba(15, 23, 42, 0.95) 100%);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  width: 100%;
  container-type: inline-size;
  container-name: cardbox;
}

.driving-license-card {
  width: 100%;
  max-width: 820px;
  aspect-ratio: 1024 / 682;
  background-image: url('card_background.png');
  background-size: 100% 100%;
  background-repeat: no-repeat;
  position: relative;
  overflow: hidden;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.8);
  user-select: none;
}

/* Dynamic Font Classes */
.font-ar-dyn {
  font-family: var(--card-ar-font) !important;
  font-weight: 700 !important;
}

.font-en-dyn {
  font-family: var(--card-en-font) !important;
  font-weight: 700 !important;
}

/* Header Text Layer - Responsive Proportional */
.card-header-layer {
  position: absolute;
  top: 8.5%;
  left: 20.8%;
  right: 17.5%;
  height: 21%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.header-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.line-1 {
  /* Line 1: Black title */
}

.line-2 {
  padding-left: clamp(20px, 11.2cqw, 92px);
  padding-right: clamp(28px, 14.6cqw, 120px);
}

.hdr-en {
  font-size: clamp(8px, 2.45cqw, 20px);
  color: #000000;
  white-space: nowrap;
}

.hdr-ar {
  font-size: clamp(9px, 2.65cqw, 22px);
  color: #000000;
  direction: rtl;
  white-space: nowrap;
}

.hdr-red-en {
  font-size: clamp(8px, 2.45cqw, 20px);
  color: #dc2626;
  white-space: nowrap;
}

.hdr-red-ar {
  font-size: clamp(9px, 2.65cqw, 22px);
  color: #dc2626;
  direction: rtl;
  white-space: nowrap;
}

/* Left Photo Box */
.card-photo-wrapper {
  position: absolute;
  top: 34.3%;
  left: 1.5%;
  width: 23.5%;
  height: 42.4%;
  background: #ffffff;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.photo-img-element {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Left Authority Box */
.card-authority-layer {
  position: absolute;
  top: 78.5%;
  left: 2.3%;
  width: 21.0%;
  height: 18.0%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-around;
  text-align: center;
}

.auth-text-ar {
  font-size: clamp(6.5px, 1.9cqw, 15px);
  color: #000000;
  line-height: 1;
}

.auth-text-code {
  font-size: clamp(7.5px, 2.35cqw, 19px);
  color: #000000;
  letter-spacing: 0.5px;
  line-height: 1;
}

.auth-text-en {
  font-size: clamp(5.5px, 1.55cqw, 12.5px);
  color: #000000;
  line-height: 1;
}

/* Right Table Grid Text Layer - Proportional Responsive Anchors */
.card-table-layer {
  position: absolute;
  top: 34.2%;
  left: 26.0%;
  width: 72.5%;
  height: 60.8%;
  display: grid;
  grid-template-rows: repeat(8, 1fr);
}

.table-row {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
}

.lbl-en {
  position: absolute;
  left: clamp(4px, 2.0cqw, 16px);
  font-size: clamp(7px, 2.05cqw, 17px);
  color: #000000;
  white-space: nowrap;
}

.lbl-ar {
  position: absolute;
  right: clamp(4px, 2.0cqw, 16px);
  font-size: clamp(8px, 2.3cqw, 19px);
  color: #000000;
  direction: rtl;
  white-space: nowrap;
}

/* Column Values */
.val-mid {
  position: absolute;
  left: 37.5%;
  font-size: clamp(7.5px, 2.2cqw, 18px);
  color: #000000;
  white-space: nowrap;
}

.val-name-en {
  position: absolute;
  left: 21.0%;
  font-size: clamp(7px, 2.1cqw, 17px);
  color: #000000;
  white-space: nowrap;
}

.val-nat-en {
  position: absolute;
  left: 27.5%;
  font-size: clamp(7px, 2.1cqw, 17px);
  color: #000000;
  white-space: nowrap;
}

/* Export Actions */
.export-actions {
  display: flex;
  width: 100%;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #10b981;
  color: white;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px);
  transition: all 0.3s ease;
  z-index: 1000;
}

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

/* ==========================================================================
   MOBILE & TABLET RESPONSIVE MEDIA QUERIES
   ========================================================================== */
@media (max-width: 1100px) {
  .main-content {
    grid-template-columns: 1fr;
  }
  
  /* On Mobile/Tablet, show the Card Preview on Top so user sees immediate results */
  .preview-panel {
    order: -1;
  }
}

@media (max-width: 600px) {
  .app-container {
    padding: 12px 10px;
    gap: 14px;
  }

  .app-header {
    padding: 12px 14px;
  }

  .app-header h1 {
    font-size: 17px;
  }

  .brand-icon {
    font-size: 24px;
    padding: 4px 8px;
  }

  .editor-panel, .preview-panel {
    padding: 14px;
    border-radius: 12px;
  }

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

  .form-section {
    padding: 12px 10px;
  }

  .card-display-wrapper {
    padding: 8px;
  }

  .btn-download-main {
    padding: 12px 16px;
    font-size: 14px;
  }

  .toast {
    left: 12px;
    right: 12px;
    bottom: 12px;
    text-align: center;
  }
}
