/* --- 1. CSS VARIABLES & IMPORTS --- */
@import url("https://fonts.googleapis.com/css2?family=Noto+Sans+Devanagari:wght@400;500;600;700;800&display=swap");

:root {
  --primary-color: #1a2b56;
  --secondary-color: #00a651;
  --success-color: #10b981; /* Emerald Green for PNG Button */
  --success-hover: #059669;
  --text-dark: #0f172a;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --bg-body: #94a3b8;
  --bg-panel: #ffffff;
  --bg-input: #f8fafc;
  --border-color: #cbd5e1;
  --border-light: #e2e8f0;
  --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.12);
  --shadow-down: 0 10px 40px rgba(0, 0, 0, 0.15);
  --font-family: "Noto Sans Devanagari", system-ui, -apple-system, sans-serif;
  --transition: all 0.35s cubic-bezier(0.32, 0.72, 0, 1);
}

/* --- 2. CSS RESET & BASE --- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #64748b;
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: #475569;
}

/* --- 3. ADVANCED UPSIDE DRAWER (TOP PANEL) --- */
.top-drawer {
  position: relative;
  width: 100%;
  background: var(--bg-panel);
  border-radius: 0 0 24px 24px;
  box-shadow: var(--shadow-down);
  z-index: 100;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 32px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-light);
  z-index: 102;
}

.header-title-group {
  display: flex;
  align-items: center;
  gap: 14px;
}
.header-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--primary-color);
  display: flex;
  align-items: center;
  justify-content: center;
}
.header-title-group h2 {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-dark);
  margin-bottom: 2px;
}
.header-title-group p {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.action-panel {
  display: flex;
  gap: 12px;
  align-items: center;
}
#logo0 {
  height: 30px;
  margin: 0 25px 0 0;
}
#logo {
  height: 70px;
}
.btn-icon {
  width: 44px;
  height: 44px;
  background: #ffffff;
  border: 1px solid var(--border-color);
  color: var(--text-dark);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
}
.btn-icon:hover {
  background: #f8fafc;
  border-color: #94a3b8;
  transform: translateY(-1px);
}

/* Updated PNG Export Button */
.btn-export {
  background: var(--success-color);
  color: white;
  border: none;
  padding: 0 24px;
  height: 44px;
  border-radius: 12px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.25);
}
.btn-export:hover {
  background: var(--success-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(16, 185, 129, 0.35);
}
/* Loading State for PNG Generation */
.btn-export.loading {
  animation: pulse 1.5s infinite;
  background: var(--success-hover);
  pointer-events: none;
}
@keyframes pulse {
  0% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
  100% {
    opacity: 1;
  }
}

.drawer-body {
  max-height: 55vh;
  overflow-y: auto;
  padding: 24px 32px 16px;
  background: white;
  transition: var(--transition);
  opacity: 1;
}

.top-drawer.collapsed .drawer-body {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  opacity: 0;
  overflow: hidden;
}

.swipe-handle {
  height: 28px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  background: #fafafa;
  border-top: 1px solid var(--border-light);
  border-radius: 0 0 24px 24px;
}
.swipe-handle:active {
  cursor: grabbing;
}
.pill {
  width: 44px;
  height: 5px;
  border-radius: 5px;
  background: #cbd5e1;
  transition: background 0.2s;
}
.swipe-handle:hover .pill {
  background: #94a3b8;
}

/* Professional FinTech Vertical Form Grid */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
}
.form-group {
  position: relative;
  width: 100%;
}
.input-icon {
  position: absolute;
  top: 17px;
  left: 16px;
  color: #94a3b8;
  pointer-events: none;
  transition: var(--transition);
}
.form-group input {
  width: 100%;
  padding: 24px 16px 8px 46px;
  border: 1.5px solid transparent;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  background: var(--bg-input);
  color: var(--text-dark);
  transition: var(--transition);
  outline: none;
}
.form-group label {
  position: absolute;
  top: 20px;
  left: 46px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  transition: var(--transition);
  pointer-events: none;
}
.form-group input:hover {
  background: #f1f5f9;
}
.form-group input:focus {
  border-color: var(--primary-color);
  background: white;
  box-shadow: 0 4px 12px rgba(26, 43, 86, 0.05);
}
.form-group input:focus ~ label,
.form-group input:not(:placeholder-shown) ~ label {
  top: 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--primary-color);
}
.form-group input:focus ~ .input-icon {
  color: var(--primary-color);
}

/* --- 4. LAYOUT: DOCUMENT PREVIEW --- */
.preview-canvas {
  flex: 1;
  background: transparent;
  padding: 40px 20px 100px 20px;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  position: relative;
}

.zoom-wrapper {
  position: relative;
  transition:
    width 0.25s,
    height 0.25s;
}

.document-page {
  position: absolute;
  top: 0;
  left: 0;
  width: 920px;
  min-height: 1123px;
  background: white;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  text-rendering: optimizeLegibility;
  transform-origin: top left;
  transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Floating Zoom Controls Widget */
.zoom-controls {
  position: fixed;
  bottom: 25px;
  right: 25px;
  background: white;
  border: 1px solid var(--border-color);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
  border-radius: 50px;
  display: flex;
  align-items: center;
  padding: 6px;
  gap: 8px;
  z-index: 90;
}

.zoom-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: #f1f5f9;
  color: var(--text-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}
.zoom-btn:hover {
  background: #e2e8f0;
}
.zoom-btn:active {
  transform: scale(0.95);
}
.zoom-level {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary-color);
  min-width: 48px;
  text-align: center;
  user-select: none;
}

/* Document Internal Blocks */
.doc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 6px solid var(--primary-color);
  padding: 10px 45px;
}
.brand-left .logo-main {
  font-size: 38px;
  font-weight: 900;
  color: var(--primary-color);
  font-style: italic;
  letter-spacing: -1px;
}
.brand-left .logo-main span {
  color: var(--secondary-color);
  font-style: normal;
  font-weight: 700;
  margin-left: 2px;
}
.brand-sub {
  margin-top: 2px;
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
}
.badge-right {
  background: var(--primary-color);
  color: white;
  border-radius: 50px 0 0 50px;
  padding: 15px 20px 15px 15px;
  display: flex;
  align-items: center;
  min-width: 320px;
  box-shadow: var(--shadow-sm);
  gap: 15px;
  position: relative;
  left: 45px;
}
.badge-icon-circle {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.badge-text h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.5px;
  line-height: 1.1;
}
.badge-text p {
  margin-top: 2px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 3px;
  color: var(--text-light);
  text-transform: uppercase;
}

.doc-content {
  padding: 40px 50px;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
}
.meta-row {
  display: flex;
  justify-content: space-between;
  align-items: start;
  margin-bottom: 30px;
}
.recipient-info {
  font-size: 16px;
  line-height: 1.8;
  color: var(--text-dark);
}
.recipient-info .label {
  font-weight: 600;
  display: inline-block;
  color: var(--text-dark);
}
.date-block {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-dark);
  padding-top: 5px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: 12px 8px;
  margin-bottom: 30px;
  background: #fafafa;
}
.grid-column {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 16px;
  border-right: 1px solid var(--border-light);
  transition: var(--transition);
}
.grid-column:last-child {
  border-right: none;
}
.icon-square {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  flex-shrink: 0;
}
.col-data p {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.col-data h4 {
  margin-top: 4px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-dark);
}

.salutation {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-dark);
  margin-bottom: 16px;
}
.letter-body {
  text-align: justify;
  font-size: 15.5px;
  line-height: 1.8;
  color: #334155;
  margin-bottom: 30px;
}
.letter-body p {
  margin-bottom: 16px;
}

.requirements-box {
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: #fff;
  margin-bottom: 30px;
  position: relative;
  display: flex;
  box-shadow: var(--shadow-sm);
}
.req-badge {
  position: absolute;
  top: -14px;
  left: 24px;
  background: var(--primary-color);
  color: white;
  padding: 4px 24px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 4px;
}
.req-badge::after {
  content: "";
  position: absolute;
  right: -10px;
  top: 0;
  border-width: 13px 0 13px 10px;
  border-style: solid;
  border-color: transparent transparent transparent var(--primary-color);
}
.req-left {
  width: 60%;
  padding: 35px 24px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.req-item {
  display: flex;
  align-items: center;
  gap: 14px;
}
.req-icon-circle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-color);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.req-text {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text-dark);
}
.divider-line {
  border-top: 1px dashed var(--border-color);
  margin-left: 46px;
}
.vertical-split {
  width: 1px;
  border-left: 1px dashed var(--border-color);
  margin: 24px 0;
}
.req-right {
  width: 40%;
  padding: 35px 24px 24px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.alert-icon svg {
  width: 55px;
  height: 55px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--secondary-color);
  font-size: 32px;
  font-weight: 700;
  flex-shrink: 0;
}
.alert-text {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-main);
  font-weight: 500;
}

.warning-banner {
  background: #fdf0f0;
  border: 1px solid #f7bbbb;
  border-radius: 10px;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 35px;
}
.shield-box {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  flex-shrink: 0;
}
.warning-message {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-dark);
}

.signatories-row {
  display: flex;
  justify-content: space-between;
  align-items: end;
  margin-top: auto;
  padding-bottom: 10px;
}
.officer-block {
  display: flex;
  align-items: center;
  gap: 18px;
}
.avatar-circle {
  width: 56px;
  height: 56px;
  background: var(--primary-color);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  flex-shrink: 0;
}
.officer-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--secondary-color);
  margin-bottom: 6px;
}
.officer-details p {
  margin-top: 2px;
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 500;
}
.officer-details .name-bold {
  font-size: 19px;
  font-weight: 700;
  color: var(--text-dark);
  margin-bottom: 4px;
}
.signature-block {
  text-align: right;
  width: 280px;
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
}
.signature-block .salute {
  margin-bottom: 12px;
  font-weight: 600;
}
.signature-img-text {
  font-family: "Courier New", cursive, sans-serif;
  font-size: 0px;
  font-weight: 700;
  color: #1e3a8a;
  font-style: italic;
  margin-bottom: 0px;
  display: inline-block;
  letter-spacing: -0.5px;
}
.signature-img-text img {
  height: 50px;
}
.signature-block .name {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-dark);
  margin-top: 2px;
}
.signature-block .dept {
  font-size: 13.5px;
  margin-top: 2px;
}
.signature-block .firm {
  font-size: 15px;
  font-weight: 800;
  color: var(--primary-color);
  margin-top: 4px;
}

.doc-footer {
  border-top: 2px solid var(--primary-color);
  padding: 20px 45px 20px;
  text-align: center;
}
.footer-firm-title {
  font-size: 15px;
  font-weight: 800;
  color: var(--primary-color);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.footer-meta-items {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 16px;
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 600;
}
.meta-item {
  display: flex;
  align-items: center;
  gap: 6px;
  text-align: center;
}
.meta-item svg {
  color: var(--primary-color);
  fill: var(--primary-color);
}
.meta-item .stroke-svg svg {
  fill: transparent;
}

/* --- 5. RESPONSIVE DESIGN FOR UI ONLY --- */
@media only screen and (max-width: 600px) {
  .drawer-header {
    padding: 16px 20px;
  }
  .header-icon {
    display: none;
  }
  .action-panel {
    width: 100%;
    justify-content: space-between;
  }
  .header-title-group h2 {
    font-size: 16px;
  }
  .btn-export {
    flex: 1;
    padding: 0;
  }
  .drawer-body {
    padding: 20px 20px 24px;
    max-height: 60vh;
  }
  .form-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .preview-canvas {
    padding-top: 40px;
    padding-bottom: 100px;
  }
  .zoom-controls {
    bottom: 20px;
    right: 20px;
  }
}

/* --- DESKTOP RESPONSIVE LAYOUT (LEFT SIDE MENU) --- */
@media only screen and (min-width: 1024px) {
  /* Change the entire app layout from top-to-bottom to left-to-right */
  body {
    flex-direction: row;
  }

  /* Canvas expands to fill the remaining space on the right */
  .preview-canvas {
    height: 100vh;
    flex: 1;
  }

  /* Convert Drawer to a fixed Left Side Panel */
  .top-drawer {
    width: 380px;
    height: 100vh;
    border-radius: 0;
    border-right: 1px solid var(--border-light);
    box-shadow: 10px 0 40px rgba(0, 0, 0, 0.08);
    /* Transition margin-left instead of margin-right */
    transition: margin-left 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  }

  /* When closed, slide it off the left edge of the screen */
  .top-drawer.collapsed {
    margin-left: -380px;
  }

  /* Disable the mobile 'squish' effect so the panel contents stay intact while sliding */
  .top-drawer.collapsed .drawer-body {
    max-height: none;
    opacity: 1;
    padding: 24px 32px 16px;
  }

  .drawer-body {
    max-height: none;
    flex: 1;
    overflow-y: auto;
  }

  /* Reformat Header & Buttons for vertical sidebar */
  .drawer-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 20px;
  }

  .action-panel {
    width: 100%;
    justify-content: space-between;
  }

  .btn-export {
    flex: 1;
  }

  .form-grid {
    grid-template-columns: 1fr; /* Stack inputs vertically */
  }

  /* Transform the handle into a vertical right pull-tab */
  .swipe-handle {
    position: absolute;
    top: 50%;
    right: -28px; /* Sticks out to the right of the side panel */
    width: 28px;
    height: 80px;
    border-radius: 0 12px 12px 0;
    border-top: 1px solid var(--border-light);
    border-right: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
    border-left: none;
    transform: translateY(-50%);
    box-shadow: 4px 0 10px rgba(0, 0, 0, 0.05);
    cursor: pointer;
  }

  /* Make the inner pill visual vertical */
  .pill {
    width: 4px;
    height: 40px;
  }
}
