/* ============================================
   FONT: Anek Malayalam (Local)
   ============================================ */
@font-face { font-family: 'Anek Malayalam'; src: url('font/AnekMalayalam-Thin.ttf') format('truetype'); font-weight: 100; font-style: normal; font-display: swap; }
@font-face { font-family: 'Anek Malayalam'; src: url('font/AnekMalayalam-ExtraLight.ttf') format('truetype'); font-weight: 200; font-style: normal; font-display: swap; }
@font-face { font-family: 'Anek Malayalam'; src: url('font/AnekMalayalam-Light.ttf') format('truetype'); font-weight: 300; font-style: normal; font-display: swap; }
@font-face { font-family: 'Anek Malayalam'; src: url('font/AnekMalayalam-Regular.ttf') format('truetype'); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: 'Anek Malayalam'; src: url('font/AnekMalayalam-Medium.ttf') format('truetype'); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: 'Anek Malayalam'; src: url('font/AnekMalayalam-SemiBold.ttf') format('truetype'); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: 'Anek Malayalam'; src: url('font/AnekMalayalam-Bold.ttf') format('truetype'); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: 'Anek Malayalam'; src: url('font/AnekMalayalam-ExtraBold.ttf') format('truetype'); font-weight: 800; font-style: normal; font-display: swap; }

@font-face { font-family: 'Rachana'; src: url('font/Rachana-Regular.ttf') format('truetype'); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: 'Rachana'; src: url('font/Rachana-Bold.ttf') format('truetype'); font-weight: 700; font-style: normal; font-display: swap; }

/* ============================================
   DESIGN TOKENS — LIGHT THEME
   ============================================ */
:root {
    --white: #ffffff;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    --primary-50: #eef2ff;
    --primary-100: #e0e7ff;
    --primary-200: #c7d2fe;
    --primary-500: #6366f1;
    --primary-600: #4f46e5;
    --primary-700: #4338ca;
    --primary-800: #3730a3;
    --accent-green: #16a34a;
    --accent-red: #dc2626;
    --accent-gold: #b45309;
    --accent-blue: #2563eb;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.1);
    --shadow-xl: 0 16px 48px rgba(0,0,0,0.12);
    --transition: all 0.2s ease;
}

/* ============================================
   BASE
   ============================================ */
*, *::before, *::after { box-sizing: border-box; }

body {
    background: var(--gray-100);
    font-family: 'Anek Malayalam', system-ui, sans-serif;
    color: var(--gray-800);
    margin: 0;
    -webkit-font-smoothing: antialiased;
}

/* ============================================
   PRINT FONT (UNTOUCHED — Rachana only)
   ============================================ */
.malayalam-print {
    font-family: 'Rachana', serif;
}

/* ============================================
   CUSTOM UTILITIES
   ============================================ */
.text-8 { font-size: 8px !important; }
.text-10 { font-size: 10px !important; }
.text-14 { font-size: 14px !important; }
.text-15 { font-size: 15px !important; }
.text-16 { font-size: 16px !important; }
.text-17 { font-size: 17px !important; }
.text-18 { font-size: 18px !important; }
.h-40px { height: 40px !important; }
.min-w-140px { min-width: 140px !important; }
.z-100 { z-index: 100 !important; }
.z-60 { z-index: 60 !important; }
.indent-50 { text-indent: 50px !important; }

/* ============================================
   GLOBAL HEADER — LIGHT
   ============================================ */
.g-header {
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    padding: 0 24px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 60;
    box-shadow: var(--shadow-sm);
}
.g-header-brand {
    display: flex;
    align-items: center;
    gap: 14px;
    text-decoration: none;
}
.g-header-brand img {
    height: 36px;
    width: auto;
    border-radius: 6px;
}
.g-header-brand-text h1 {
    font-size: 17px;
    font-weight: 800;
    color: var(--gray-900);
    margin: 0;
    letter-spacing: -0.3px;
}
.g-header-brand-text span {
    font-size: 10px;
    color: var(--primary-600);
    text-transform: uppercase;
    letter-spacing: 2px;
    font-weight: 700;
}
.g-nav {
    display: flex;
    align-items: center;
    gap: 6px;
}
.g-nav-link {
    color: var(--gray-500);
    font-size: 13px;
    font-weight: 700;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    transition: var(--transition);
    border: 1px solid transparent;
}
.g-nav-link:hover {
    color: var(--gray-800);
    background: var(--gray-50);
    border-color: var(--gray-200);
}
.g-nav-link.active {
    color: var(--primary-700);
    background: var(--primary-50);
    border-color: var(--primary-200);
}
.g-nav-divider {
    width: 1px;
    height: 24px;
    background: var(--gray-200);
    margin: 0 8px;
}
.g-nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 700;
    padding: 8px 16px;
    border-radius: 100px;
    border: none;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}
.g-nav-btn-green {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}
.g-nav-btn-green:hover { background: #bbf7d0; }
.g-nav-btn-red {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}
.g-nav-btn-red:hover { background: #fecaca; }
.g-nav-btn-blue {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}
.g-nav-btn-blue:hover { background: #bfdbfe; }
.g-nav-btn-gold {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
}
.g-nav-btn-gold:hover { background: #fde68a; }
.g-nav-btn-logout {
    background: transparent;
    color: var(--gray-400);
    border: 1px solid var(--gray-200);
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-family: inherit;
}
.g-nav-btn-logout:hover {
    color: var(--accent-red);
    border-color: #fecaca;
    background: #fef2f2;
}
.g-nav-btn-logout svg { width: 14px; height: 14px; }

/* Mobile hamburger */
.g-mobile-toggle {
    display: none;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    padding: 8px;
    color: var(--gray-700);
    cursor: pointer;
}
.g-mobile-toggle svg { width: 22px; height: 22px; }

/* Mobile menu overlay */
.g-mobile-menu {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,0.97);
    backdrop-filter: blur(24px);
    z-index: 200;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
}
.g-mobile-menu.open { display: flex; }
.g-mobile-menu a, .g-mobile-menu button {
    font-size: 16px;
    font-weight: 700;
    color: var(--gray-600);
    text-decoration: none;
    padding: 10px 28px;
    border-radius: var(--radius-md);
    transition: var(--transition);
    border: none;
    background: transparent;
    cursor: pointer;
    font-family: inherit;
}
.g-mobile-menu a.active { color: var(--primary-700); }
.g-mobile-menu a:hover, .g-mobile-menu button:hover { color: var(--gray-900); background: var(--gray-100); }
.g-mobile-menu .close-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    background: var(--gray-100);
    border: 1px solid var(--gray-200);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gray-600);
    cursor: pointer;
}
.g-mobile-menu .mobile-logout-btn {
    color: var(--accent-red);
}
.g-mobile-menu hr {
    width: 60px;
    border: none;
    border-top: 1px solid var(--gray-200);
}

@media (max-width: 1023px) {
    .g-nav { display: none; }
    .g-mobile-toggle { display: flex; }
}

/* ============================================
   MALAYALAM TOGGLE (header inline)
   ============================================ */
.ml-toggle-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    padding: 6px 14px;
    border-radius: 100px;
    cursor: pointer;
    user-select: none;
}
.ml-toggle-wrap span {
    font-size: 12px;
    font-weight: 700;
    color: var(--gray-500);
}
.toggle-checkbox { top: 0; left: 0; border-color: var(--gray-300); }
.toggle-checkbox:checked { left: 1.25rem; border-color: var(--primary-600); }
.toggle-checkbox:checked + .toggle-label { background-color: var(--primary-600); }

/* ============================================
   LOGIN PAGE — SPLIT LAYOUT
   ============================================ */
.login-bg {
    min-height: 100vh;
    display: flex;
    background: var(--white);
}
/* Side A: Login form */
.login-side-a {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    background: var(--white);
}
.login-card {
    width: 100%;
    max-width: 380px;
    text-align: center;
}
.login-card img {
    height: 72px;
    width: auto;
    border-radius: 12px;
    margin-bottom: 20px;
}
.login-card h2 {
    font-size: 24px;
    font-weight: 800;
    color: var(--gray-900);
    margin: 0 0 4px;
}
.login-card .subtitle {
    font-size: 11px;
    color: var(--primary-600);
    text-transform: uppercase;
    letter-spacing: 2.5px;
    font-weight: 700;
    margin-bottom: 32px;
}
.login-input {
    width: 100%;
    background: var(--gray-50);
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-md);
    padding: 16px 20px;
    font-size: 16px;
    font-weight: 600;
    color: var(--gray-800);
    text-align: center;
    outline: none;
    transition: var(--transition);
    font-family: inherit;
    margin-bottom: 16px;
}
.login-input::placeholder { color: var(--gray-400); }
.login-input:focus {
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
    background: var(--white);
}
.login-btn {
    width: 100%;
    background: var(--primary-600);
    color: var(--white);
    font-size: 15px;
    font-weight: 800;
    padding: 16px;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}
.login-btn:hover {
    background: var(--primary-700);
    box-shadow: 0 4px 16px rgba(79,70,229,0.25);
}
.login-error {
    color: var(--accent-red);
    font-size: 13px;
    font-weight: 700;
    margin-top: 16px;
}
.login-nav {
    margin-top: 28px;
    display: flex;
    gap: 12px;
    justify-content: center;
}
.login-nav a {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
    transition: var(--transition);
    border: 1px solid var(--gray-200);
    color: var(--gray-600);
    background: var(--white);
}
.login-nav a:hover {
    color: var(--primary-700);
    border-color: var(--primary-200);
    background: var(--primary-50);
}
.login-nav svg { width: 16px; height: 16px; }
.login-logout-wrap {
    margin-top: 24px;
}

/* Side B: Instructions */
.login-side-b {
    flex: 1;
    background: var(--gray-50);
    border-left: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px;
}
.instructions-card {
    max-width: 440px;
    width: 100%;
}
.instructions-card h3 {
    font-size: 20px;
    font-weight: 800;
    color: var(--gray-900);
    margin: 0 0 8px;
}
.instructions-card .inst-subtitle {
    font-size: 13px;
    color: var(--gray-400);
    margin-bottom: 28px;
    font-weight: 500;
}
.inst-step {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
    align-items: flex-start;
}
.inst-step-num {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary-50);
    color: var(--primary-700);
    font-size: 14px;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: 1px solid var(--primary-200);
}
.inst-step-text h4 {
    font-size: 14px;
    font-weight: 700;
    color: var(--gray-800);
    margin: 0 0 4px;
}
.inst-step-text p {
    font-size: 13px;
    color: var(--gray-500);
    margin: 0;
    line-height: 1.6;
    font-weight: 500;
}
.inst-shortcut {
    margin-top: 28px;
    padding: 16px;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
}
.inst-shortcut h4 {
    font-size: 12px;
    font-weight: 700;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0 0 10px;
}
.inst-shortcut-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    color: var(--gray-600);
    font-weight: 600;
    padding: 6px 0;
}
.inst-shortcut-item:not(:last-child) {
    border-bottom: 1px solid var(--gray-100);
}
.inst-kbd {
    background: var(--gray-100);
    border: 1px solid var(--gray-200);
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 700;
    color: var(--gray-700);
    font-family: monospace;
}

@media (max-width: 768px) {
    .login-bg { flex-direction: column; }
    .login-side-b { border-left: none; border-top: 1px solid var(--gray-200); }
    .login-side-a, .login-side-b { padding: 32px 24px; }
}

/* ============================================
   LETTER EDITOR LAYOUT
   ============================================ */
.letter-body {
    background: var(--gray-100);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
.editor-wrap {
    display: flex;
    flex: 1;
    overflow: hidden;
}
.editor-panel {
    width: 40%;
    background: var(--white);
    border-right: 1px solid var(--gray-200);
    padding: 28px;
    overflow-y: auto;
}
.preview-panel {
    width: 60%;
    background: var(--gray-200);
    overflow-y: auto;
}

/* Glass section cards in editor */
.form-section {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 20px;
    transition: var(--transition);
}
.form-section:hover {
    border-color: var(--primary-200);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.05);
}
.form-section-title {
    font-size: 13px;
    font-weight: 800;
    color: var(--primary-700);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0 0 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--gray-200);
}

/* Vertical stack for textarea groups */
.form-stack {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* Form inputs */
.f-label {
    display: block;
    font-size: 12px;
    font-weight: 700;
    color: var(--gray-500);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.f-input, .f-textarea {
    width: 100%;
    background: var(--white);
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-800);
    outline: none;
    transition: var(--transition);
    font-family: 'Anek Malayalam', system-ui, sans-serif;
}
.f-input::placeholder, .f-textarea::placeholder { color: var(--gray-400); }
.f-input:focus, .f-textarea:focus {
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}
.f-textarea {
    resize: vertical;
    min-height: 80px;
}
.f-textarea.tall { min-height: 200px; }
.f-textarea.tall:focus { min-height: 320px; }

/* TinyMCE Editor Container */
.tinymce-wrap {
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-sm);
    overflow: hidden;
    transition: var(--transition);
}
.tinymce-wrap:focus-within {
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}
.tinymce-wrap .tox-tinymce { border: none !important; }
.tinymce-wrap .tox .tox-toolbar__primary { background: var(--gray-50) !important; border-bottom: 1px solid var(--gray-200) !important; }
.tinymce-wrap .tox .tox-toolbar__group { border-right-color: var(--gray-200) !important; }
.tinymce-wrap .tox .tox-statusbar { border-top: 1px solid var(--gray-200) !important; background: var(--gray-50) !important; }
.tinymce-wrap .tox .tox-edit-area__iframe { background: var(--white) !important; }
.f-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

/* File number prefix/suffix */
.f-fileno-wrap {
    display: flex;
    align-items: stretch;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-sm);
    overflow: hidden;
    transition: var(--transition);
    background: var(--white);
}
.f-fileno-wrap:focus-within {
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}
.f-fileno-prefix, .f-fileno-suffix {
    padding: 10px 12px;
    background: var(--gray-100);
    color: var(--gray-500);
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    display: flex;
    align-items: center;
}
.f-fileno-prefix { border-right: 1px solid var(--gray-200); }
.f-fileno-suffix { border-left: 1px solid var(--gray-200); }
.f-fileno-wrap input {
    flex: 1;
    background: transparent;
    border: none;
    padding: 10px 12px;
    color: var(--gray-800);
    font-size: 14px;
    font-weight: 700;
    outline: none;
    font-family: inherit;
}

/* Info banner */
.info-banner {
    background: var(--primary-50);
    border: 1px solid var(--primary-200);
    border-radius: var(--radius-md);
    padding: 14px 18px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 20px;
}
.info-banner svg { width: 20px; height: 20px; color: var(--primary-600); flex-shrink: 0; margin-top: 2px; }
.info-banner p { font-size: 12px; font-weight: 600; color: var(--primary-800); line-height: 1.7; margin: 0; }

/* Designation toggle */
.toggle-card {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.toggle-card label {
    font-size: 13px;
    font-weight: 700;
    color: var(--gray-600);
    cursor: pointer;
}

/* Edit mode banner */
.edit-banner {
    background: #fffbeb;
    border-bottom: 2px solid #f59e0b;
    color: #92400e;
    text-align: center;
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 700;
    position: sticky;
    top: 64px;
    z-index: 55;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}
.edit-banner a { color: var(--accent-red); text-decoration: underline; margin-left: 12px; }
.edit-banner-fileno { color: var(--gray-900); font-weight: 800; }

/* ============================================
   A4 PREVIEW OUTPUT STYLES
   ============================================ */
.a4-preview {
    width: 210mm;
    min-height: 297mm;
    padding: 12mm;
    background: white;
    box-shadow: var(--shadow-xl);
    margin: 0 auto;
    color: black;
    box-sizing: border-box;
    font-size: 12pt;
}

/* Thin header line */
.a4-preview .header-hr {
    border: none;
    border-bottom: 0.5px solid black;
    margin: 0;
    padding: 0;
}

/* Force list styles inside preview (Tailwind preflight strips them) */
.a4-preview ol { list-style-type: decimal !important; padding-left: 20px !important; }
.a4-preview ul { list-style-type: disc !important; padding-left: 20px !important; }
.a4-preview li { display: list-item !important; }
#out-body ol { list-style-type: decimal !important; padding-left: 24px !important; margin: 8px 0 !important; }
#out-body ul { list-style-type: disc !important; padding-left: 24px !important; margin: 8px 0 !important; }
#out-body li { display: list-item !important; margin-bottom: 4px; }

/* Reference list: no extra left margin, aligns with subject text */
#out-ref { list-style-type: decimal !important; padding-left: 20px !important; margin: 0 !important; }

.preview-container {
    padding: 2rem;
}

@media (max-width: 768px) {
    .preview-container { padding: 1rem; display: flex; justify-content: center; overflow-x: hidden; }
    .a4-preview { transform: scale(0.46); transform-origin: top center; margin-bottom: -150%; }
}
@media (min-width: 769px) and (max-width: 1024px) {
    .a4-preview { transform: scale(0.7); transform-origin: top center; margin-bottom: -40%; }
}

/* ============================================
   PRINT STYLES (UNTOUCHED)
   ============================================ */
@media print {
    body * { visibility: hidden; }
    #print-section, #print-section * { visibility: visible; }
    #print-section {
        position: absolute; left: 0; top: 0; width: 210mm; padding: 12mm;
        box-shadow: none; transform: scale(1) !important; margin: 0;
        font-family: 'Rachana', serif !important;
        font-size: 12pt !important;
    }
    .no-print { display: none !important; }
    @page { size: A4; margin: 5mm 0; }
}

/* ============================================
   SUGGESTION BOX (Transliteration)
   ============================================ */
#suggestion-box {
    font-family: 'Anek Malayalam', system-ui, sans-serif;
    box-shadow: var(--shadow-lg);
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    z-index: 100;
    min-width: 140px;
    overflow: hidden;
}
#suggestion-box ul { padding: 4px 0; margin: 0; list-style: none; }
#suggestion-box li {
    padding: 8px 14px;
    font-size: 14px;
    font-weight: 700;
    color: var(--gray-800);
    cursor: pointer;
    transition: background 0.15s;
}
#suggestion-box li:hover, #suggestion-box li:first-child { background: var(--primary-50); color: var(--primary-700); }

/* ============================================
   CUSTOM SCROLLBAR
   ============================================ */
.custom-scroll::-webkit-scrollbar { width: 6px; height: 6px; }
.custom-scroll::-webkit-scrollbar-track { background: transparent; }
.custom-scroll::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 3px; }
.custom-scroll::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* ============================================
   LOADING DOTS ANIMATION
   ============================================ */
.loading-dots::after {
    content: '';
    display: inline-block;
    width: 12px;
    text-align: left;
    animation: dots 1.5s steps(5, end) infinite;
}
@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* ============================================
   DASHBOARD STYLES — LIGHT
   ============================================ */
.dash-body {
    background: var(--gray-100);
    min-height: 100vh;
}
.dash-content {
    max-width: 1300px;
    margin: 0 auto;
    padding: 28px;
}
.dash-title-wrap {
    margin-bottom: 24px;
}
.dash-title {
    font-size: 22px;
    font-weight: 800;
    color: var(--gray-900);
    margin: 0;
}
.dash-subtitle {
    font-size: 13px;
    color: var(--gray-400);
    margin-top: 4px;
    font-weight: 500;
}
.dash-table-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

/* Search & Sort toolbar */
.dash-toolbar {
    padding: 20px 24px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    align-items: center;
    justify-content: space-between;
    background: var(--gray-50);
}
.dash-toolbar-left {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    flex: 1;
}
.dash-toolbar-right {
    display: flex;
    align-items: center;
    gap: 14px;
}
.dash-search-wrap {
    position: relative;
    flex: 1;
    min-width: 200px;
    max-width: 420px;
}
.dash-search-wrap svg {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--gray-400);
    pointer-events: none;
}
.dash-search {
    width: 100%;
    background: var(--white);
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-md);
    padding: 11px 16px 11px 42px;
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-800);
    outline: none;
    transition: var(--transition);
    font-family: inherit;
}
.dash-search::placeholder { color: var(--gray-400); }
.dash-search:focus {
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}
.dash-sort {
    background: var(--white);
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-md);
    padding: 11px 14px;
    font-size: 12px;
    font-weight: 700;
    color: var(--gray-700);
    cursor: pointer;
    outline: none;
    transition: var(--transition);
    font-family: inherit;
}
.dash-sort:focus {
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}
.dash-stats {
    font-size: 12px;
    font-weight: 700;
    color: var(--gray-400);
}
.dash-stats .num { color: var(--primary-600); }
.dash-refresh-btn {
    background: var(--primary-50);
    color: var(--primary-700);
    border: 1px solid var(--primary-200);
    padding: 9px 18px;
    border-radius: 100px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}
.dash-refresh-btn:hover { background: var(--primary-100); }

/* Table overflow wrapper */
.dash-table-scroll {
    overflow-x: auto;
}

/* Table */
.dash-table {
    width: 100%;
    text-align: left;
    border-collapse: collapse;
    table-layout: fixed;
}
/* 7 columns: #, Date, FileNo, Recipient, Subject, LastUpdated, Actions */
.dash-table colgroup .col-index { width: 46px; }
.dash-table colgroup .col-date { width: 100px; }
.dash-table colgroup .col-fileno { width: 105px; }
.dash-table colgroup .col-recipient { width: 20%; }
.dash-table colgroup .col-subject { width: auto; }
.dash-table colgroup .col-updated { width: 110px; }
.dash-table colgroup .col-actions { width: 200px; }

.dash-table thead {
    background: var(--gray-800);
}
.dash-table th {
    padding: 14px 16px;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: rgba(255,255,255,0.7);
    border-bottom: 1px solid var(--gray-700);
}
.dash-table th .sub {
    font-size: 10px;
    font-weight: 500;
    color: rgba(255,255,255,0.35);
    text-transform: none;
    margin-top: 2px;
}
.dash-table th.th-center { text-align: center; }
.dash-table tbody tr {
    transition: background 0.15s;
    border-bottom: 1px solid var(--gray-100);
}
.dash-table tbody tr:hover { background: var(--primary-50); }
.dash-table td {
    padding: 14px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-600);
    word-break: break-word;
    white-space: normal;
    max-width: 250px;
}
.dash-table td.td-index { max-width: 40px; white-space: nowrap; color: var(--gray-400); }
.dash-table td.td-fileno { max-width: 100px; white-space: nowrap; color: var(--primary-700); font-weight: 700; }
.dash-table td.td-subject { font-weight: 700; color: var(--gray-800); }
.dash-table td.td-updated { font-size: 11px; color: var(--gray-400); white-space: nowrap; }
.dash-table td.td-actions { max-width: none; white-space: nowrap; }

/* Action buttons */
.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 700;
    transition: var(--transition);
    border: 1px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    font-family: inherit;
}
.action-btn svg { width: 14px; height: 14px; flex-shrink: 0; }
.btn-view { background: #eff6ff; color: #2563eb; border-color: #bfdbfe; }
.btn-view:hover { background: #dbeafe; border-color: #93c5fd; }
.btn-edit { background: #f0fdf4; color: #16a34a; border-color: #bbf7d0; }
.btn-edit:hover { background: #dcfce7; border-color: #86efac; }
.btn-print { background: #fefce8; color: #ca8a04; border-color: #fde68a; }
.btn-print:hover { background: #fef9c3; border-color: #fcd34d; }
.btn-delete { background: #fef2f2; color: #dc2626; border-color: #fecaca; }
.btn-delete:hover { background: #fee2e2; border-color: #fca5a5; }
.td-actions-wrap {
    display: flex;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
}

@media (max-width: 768px) {
    .action-btn span.btn-label { display: none; }
    .action-btn { padding: 7px; border-radius: 6px; }
    .action-btn svg { width: 16px; height: 16px; }
}

/* View modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: none;
    align-items: flex-start;
    justify-content: center;
    overflow-y: auto;
    padding: 2rem 1rem;
}
.modal-overlay.active { display: flex; }
.modal-content {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 860px;
    animation: modalIn 0.3s ease;
}
@keyframes modalIn {
    from { opacity: 0; transform: translateY(20px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    border-bottom: 1px solid var(--gray-200);
    background: var(--gray-50);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.modal-header h3 { font-size: 16px; font-weight: 800; color: var(--gray-900); margin: 0; }
.modal-header-btns { display: flex; gap: 8px; }
.modal-body { padding: 24px; }
.modal-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--gray-100);
    border: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    color: var(--gray-500);
}
.modal-close:hover { background: #fee2e2; border-color: #fca5a5; color: var(--accent-red); }

/* Letter preview in modal */
.letter-preview {
    font-family: 'Rachana', serif;
    color: black;
    padding: 12mm;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    background: white;
}

/* Print from modal */
@media print {
    .modal-overlay, .modal-overlay * { visibility: visible !important; }
    .modal-overlay {
        position: absolute;
        inset: 0;
        background: white !important;
        backdrop-filter: none !important;
        padding: 0 !important;
    }
    .modal-content {
        box-shadow: none !important;
        border-radius: 0 !important;
        max-width: 100% !important;
        border: none !important;
        background: white !important;
    }
    .modal-header { display: none !important; }
    .modal-body { padding: 0 !important; }
    .letter-preview { border: none !important; padding: 12mm !important; }
}

/* ============================================
   RESPONSIVE EDITOR
   ============================================ */
@media (max-width: 1023px) {
    .editor-wrap { flex-direction: column; }
    .editor-panel { width: 100%; border-right: none; border-bottom: 1px solid var(--gray-200); padding: 20px; }
    .preview-panel { width: 100%; }
    .f-row { grid-template-columns: 1fr; }
    .dash-content { padding: 16px; }
}

/* ============================================
   FOOTER
   ============================================ */
.g-footer {
    background: var(--white);
    border-top: 1px solid var(--gray-200);
    text-align: center;
    padding: 10px;
    font-size: 11px;
    color: var(--gray-400);
    position: fixed;
    bottom: 0;
    width: 100%;
    z-index: 60;
}
.g-footer .accent { color: var(--primary-600); font-weight: 700; }

/* ============================================
   STATUS MESSAGES IN TABLE (used by JS)
   ============================================ */
.td-status-loading {
    padding: 32px;
    text-align: center;
    color: var(--gray-400);
    font-weight: 700;
}
.td-status-error {
    padding: 24px;
    text-align: center;
    color: var(--accent-red);
    font-weight: 700;
}
.td-status-empty {
    padding: 24px;
    text-align: center;
    color: var(--gray-400);
    font-weight: 700;
}

/* ============================================
   LETTER PREVIEW OUTPUT CLASSES (lp-*)
   Used by buildLetterHTML() in modal + popups
   ============================================ */
.letter-preview .lp-header-block { border-bottom: 0.5px solid black; padding-bottom: 16px; margin-bottom: 24px; }
.letter-preview .lp-logo-area { display: flex; flex-direction: column; align-items: center; margin-bottom: 12px; }
.letter-preview .lp-logo { height: 40px; width: auto; margin-bottom: 4px; }
.letter-preview .lp-motto { text-align: center; font-weight: bold; font-size: 14px; }
.letter-preview .lp-header-row { display: flex; justify-content: space-between; align-items: flex-end; }
.letter-preview .lp-file-no { font-weight: bold; font-size: 16px; }
.letter-preview .lp-office-block { text-align: right; }
.letter-preview .lp-office-name { font-weight: bold; font-size: 18px; line-height: 1.3; }
.letter-preview .lp-office-meta { font-size: 15px; font-weight: bold; margin-top: 4px; }
.letter-preview .lp-office-contact { font-size: 14px; font-weight: bold; }
.letter-preview .lp-recipient-block { margin-bottom: 24px; font-size: 12pt; }
.letter-preview .lp-recipient-name { margin-left: 40px; font-weight: bold; white-space: pre-line; font-size: 12pt; }
.letter-preview .lp-salutation { margin-bottom: 16px; font-size: 12pt; }
.letter-preview .lp-subject-block { margin-left: 40px; margin-bottom: 32px; padding-right: 16px; font-size: 12pt; }
.letter-preview .lp-subject-row { display: flex; align-items: flex-start; margin-bottom: 12px; }
.letter-preview .lp-ref-row { display: flex; align-items: flex-start; }
.letter-preview .lp-label { width: 80px; flex-shrink: 0; font-weight: bold; text-decoration: underline; }
.letter-preview .lp-subject-text { flex: 1; font-weight: bold; text-align: justify; font-size: 12pt; }
.letter-preview .lp-ref-list { flex: 1; }
.letter-preview .lp-list { list-style: decimal; padding-left: 20px; margin: 0; }
.letter-preview .lp-body { text-align: justify; margin-bottom: 32px; font-size: 12pt; }
.letter-preview .lp-body p { text-indent: 50px; text-align: justify; margin-bottom: 8px; }
.letter-preview .lp-body-para { text-indent: 50px; text-align: justify; margin-bottom: 12px; }
.letter-preview .lp-body ol { list-style-type: decimal; padding-left: 24px; margin: 8px 0; }
.letter-preview .lp-body ul { list-style-type: disc; padding-left: 24px; margin: 8px 0; }
.letter-preview .lp-body li { display: list-item; margin-bottom: 4px; }
.letter-preview .lp-body table { border-collapse: collapse; width: 100%; margin: 12px 0; }
.letter-preview .lp-body table td, .letter-preview .lp-body table th { border: 1px solid black; padding: 6px 10px; }

/* A4 preview body table + paragraph styles */
#out-body p { text-indent: 50px; text-align: justify; margin-bottom: 8px; }
#out-body table { border-collapse: collapse; width: 100%; margin: 12px 0; }
#out-body table td, #out-body table th { border: 1px solid black; padding: 6px 10px; font-size: 12pt; }
.letter-preview .lp-footer-block { display: flex; justify-content: space-between; align-items: flex-start; margin-top: 32px; padding-top: 16px; font-size: 12pt; }
.letter-preview .lp-footer-left { flex: 1; padding-right: 16px; }
.letter-preview .lp-attach-section { margin-bottom: 16px; }
.letter-preview .lp-section-label { font-weight: bold; text-decoration: underline; }
.letter-preview .lp-sign-block { display: flex; flex-direction: column; align-items: flex-end; margin-right: 24px; flex-shrink: 0; padding-top: 8px; }
.letter-preview .lp-sign-inner { text-align: center; }
.letter-preview .lp-sign-regards { font-size: 12pt; }
.letter-preview .lp-sign-gap { height: 40px; }
.letter-preview .lp-sign-name { font-weight: bold; font-size: 12pt; line-height: 1.3; text-align: right; }

/* ============================================
   DUPLICATE FILE NUMBER WARNING MODAL
   ============================================ */
.dup-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    backdrop-filter: blur(6px);
    z-index: 300;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.dup-modal-overlay.active { display: flex; }
.dup-modal {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 520px;
    animation: modalIn 0.3s ease;
    overflow: hidden;
}
.dup-modal-header {
    background: #fef3c7;
    border-bottom: 2px solid #f59e0b;
    padding: 18px 24px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.dup-modal-header svg {
    width: 28px;
    height: 28px;
    color: #b45309;
    flex-shrink: 0;
}
.dup-modal-header h3 {
    font-size: 16px;
    font-weight: 800;
    color: #92400e;
    margin: 0;
}
.dup-modal-body {
    padding: 24px;
}
.dup-modal-body .dup-info {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-bottom: 20px;
}
.dup-modal-body .dup-info-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--gray-400);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}
.dup-modal-body .dup-info-fileno {
    font-size: 15px;
    font-weight: 800;
    color: var(--primary-700);
    margin-bottom: 10px;
}
.dup-modal-body .dup-info-subject {
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-700);
    line-height: 1.6;
}
.dup-modal-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    padding: 0 24px 24px;
}
.dup-modal-actions button {
    flex: 1;
    min-width: 120px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.dup-btn-edit {
    background: #eff6ff;
    color: #2563eb;
    border-color: #bfdbfe !important;
}
.dup-btn-edit:hover { background: #dbeafe; }
.dup-btn-continue {
    background: #f0fdf4;
    color: #16a34a;
    border-color: #bbf7d0 !important;
}
.dup-btn-continue:hover { background: #dcfce7; }
.dup-btn-cancel {
    background: var(--gray-50);
    color: var(--gray-600);
    border-color: var(--gray-200) !important;
}
.dup-btn-cancel:hover { background: var(--gray-100); }

/* ============================================
   SYNC STATUS BAR
   ============================================ */
.dash-sync-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    margin-bottom: 12px;
    font-size: 11px;
    color: var(--gray-500);
    font-weight: 600;
}
.dash-sync-bar .sync-time {
    color: var(--primary-600);
    font-weight: 700;
}

/* ============================================
   PAGINATION
   ============================================ */
.dash-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 16px;
    border-top: 1px solid var(--gray-200);
}
.pg-btn {
    padding: 8px 18px;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-md);
    background: var(--white);
    color: var(--gray-700);
    font-weight: 700;
    font-size: 12px;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}
.pg-btn:hover:not(:disabled) {
    background: var(--primary-50);
    border-color: var(--primary-300);
    color: var(--primary-700);
}
.pg-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.pg-info {
    font-size: 13px;
    font-weight: 700;
    color: var(--gray-600);
}

/* ============================================
   UTILITY: HIDDEN
   ============================================ */
.hidden { display: none !important; }