/* ============================================================
   Letter Management System — Enterprise Design System
   "Blueprint Precision" · Corporate Modern / Minimalist
   Inspired by Linear + Notion · Inter typeface
   ============================================================ */

:root {
    /* Brand / Primary */
    --brand: #2563eb;
    --brand-strong: #1d4ed8;
    --brand-deep: #004ac6;
    --brand-ink: #00174b;
    --brand-soft: #eef4ff;
    --brand-soft-2: #e5eeff;
    --brand-ring: rgba(37, 99, 235, 0.18);

    /* Canvas / Surfaces (tonal layering) */
    --canvas: #f5f7fb;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --surface-2: #f1f5f9;

    /* Lines */
    --border: #e2e8f0;
    --border-soft: #eef2f7;
    --border-strong: #cbd5e1;

    /* Text */
    --ink: #0b1c30;
    --ink-2: #334155;
    --muted: #64748b;
    --muted-2: #94a3b8;

    /* Semantic */
    --success: #15803d;
    --success-soft: #dcfce7;
    --warning: #b45309;
    --warning-soft: #fef3c7;
    --danger: #b91c1c;
    --danger-soft: #fee2e2;
    --info: #0369a1;
    --info-soft: #e0f2fe;

    /* Elevation */
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow: 0 4px 14px rgba(15, 23, 42, 0.05);
    --shadow-lg: 0 14px 38px rgba(15, 23, 42, 0.10);

    /* Radius */
    --r-sm: 6px;
    --r: 10px;
    --r-md: 12px;
    --r-lg: 16px;
    --r-pill: 999px;

    /* Layout */
    --sidebar-w: 264px;
    --topbar-h: 64px;
    --content-max: 1480px;

    --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

* {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

html {
    min-height: 100%;
}

body {
    min-height: 100vh;
    margin: 0;
    background: var(--canvas);
    color: var(--ink);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    letter-spacing: -0.005em;
}

a {
    color: var(--brand);
    text-decoration: none;
    transition: color 0.15s ease;
}

a:hover {
    color: var(--brand-strong);
}

::selection {
    background: var(--brand-soft-2);
    color: var(--brand-deep);
}

/* ============================================================
   APP SHELL
   ============================================================ */
.app-shell {
    display: flex;
    min-height: 100vh;
}

/* ---- Sidebar ---- */
.app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1040;
    display: flex;
    flex-direction: column;
    width: var(--sidebar-w);
    height: 100vh;
    padding: 18px 16px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 8px 14px;
    color: var(--ink);
}

.sidebar-brand:hover {
    color: var(--ink);
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    border-radius: var(--r-md);
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-deep) 100%);
    color: #fff;
    font-size: 1.15rem;
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.30);
}

.brand-title {
    display: block;
    font-size: 1.02rem;
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: -0.02em;
}

.brand-subtitle {
    display: block;
    margin-top: 2px;
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.sidebar-cta {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    margin: 4px 0 18px;
    padding: 11px 14px;
    border: 0;
    border-radius: var(--r);
    background: var(--brand);
    color: #fff;
    font-size: 0.9rem;
    font-weight: 600;
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.28);
    transition: background 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.sidebar-cta:hover {
    background: var(--brand-strong);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 10px 22px rgba(37, 99, 235, 0.34);
}

.sidebar-section {
    margin: 10px 8px 6px;
    color: var(--muted-2);
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--r);
    color: var(--ink-2);
    font-size: 0.9rem;
    font-weight: 550;
    transition: background 0.15s ease, color 0.15s ease;
}

.sidebar-link i {
    font-size: 1.05rem;
    color: var(--muted);
    transition: color 0.15s ease;
}

.sidebar-link:hover {
    background: var(--surface-2);
    color: var(--ink);
}

.sidebar-link:hover i {
    color: var(--ink-2);
}

.sidebar-link.active {
    background: var(--brand-soft);
    color: var(--brand-deep);
    font-weight: 650;
}

.sidebar-link.active i {
    color: var(--brand);
}

.sidebar-foot {
    margin-top: auto;
    padding-top: 14px;
    border-top: 1px solid var(--border-soft);
}

.sidebar-foot .sidebar-link {
    font-size: 0.86rem;
}

.sidebar-tier {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
    padding: 10px 12px;
    border-radius: var(--r);
    background: var(--surface-soft);
    border: 1px solid var(--border-soft);
}

.sidebar-tier .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 0 3px var(--success-soft);
}

.sidebar-tier span {
    color: var(--muted);
    font-size: 0.74rem;
    font-weight: 600;
}

/* Sidebar backdrop (mobile) */
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1035;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

body.sidebar-open .sidebar-backdrop {
    opacity: 1;
    visibility: visible;
}

/* ---- Content column ---- */
.app-content {
    flex: 1;
    min-width: 0;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
}

/* ---- Top bar ---- */
.app-topbar {
    position: sticky;
    top: 0;
    z-index: 1020;
    display: flex;
    align-items: center;
    gap: 16px;
    height: var(--topbar-h);
    padding: 0 28px;
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--border);
}

.topbar-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: 1px solid var(--border);
    border-radius: var(--r);
    background: var(--surface);
    color: var(--ink-2);
    font-size: 1.1rem;
}

.topbar-search {
    position: relative;
    flex: 1;
    max-width: 460px;
}

.topbar-search i {
    position: absolute;
    top: 50%;
    left: 14px;
    transform: translateY(-50%);
    color: var(--muted-2);
    font-size: 0.95rem;
}

.topbar-search input {
    width: 100%;
    height: 42px;
    padding: 0 14px 0 40px;
    border: 1px solid var(--border);
    border-radius: var(--r);
    background: var(--surface-soft);
    color: var(--ink);
    font-size: 0.9rem;
    transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.topbar-search input::placeholder {
    color: var(--muted-2);
}

.topbar-search input:focus {
    outline: none;
    background: var(--surface);
    border-color: var(--brand);
    box-shadow: 0 0 0 4px var(--brand-ring);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

.topbar-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 40px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: var(--r);
    background: var(--surface);
    color: var(--ink-2);
    font-size: 0.86rem;
    font-weight: 600;
    transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.topbar-btn:hover {
    border-color: var(--border-strong);
    background: var(--surface-soft);
    color: var(--ink);
}

.topbar-icon {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: var(--r);
    background: var(--surface);
    color: var(--ink-2);
    font-size: 1.05rem;
    transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.topbar-icon:hover {
    border-color: var(--border-strong);
    background: var(--surface-soft);
    color: var(--ink);
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-left: 6px;
}

.topbar-avatar {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-deep) 100%);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 700;
}

.topbar-user-meta {
    line-height: 1.15;
}

.topbar-user-meta strong {
    display: block;
    font-size: 0.82rem;
    font-weight: 650;
    color: var(--ink);
}

.topbar-user-meta span {
    font-size: 0.7rem;
    color: var(--muted);
}

/* ---- Main ---- */
.app-main {
    flex: 1;
    padding: 28px;
}

.app-container {
    max-width: var(--content-max);
    margin: 0 auto;
}

/* ============================================================
   PAGE HEADER
   ============================================================ */
.page-toolbar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
}

.page-kicker {
    margin: 0 0 6px;
    color: var(--brand);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.page-title {
    margin: 0;
    color: var(--ink);
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: -0.025em;
}

.page-title span {
    color: var(--muted);
    font-weight: 600;
}

/* ============================================================
   CARDS
   ============================================================ */
.app-card,
.card.app-card {
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.app-card .card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--border-soft);
    background: transparent;
    color: var(--ink);
    font-size: 0.94rem;
    font-weight: 650;
    letter-spacing: -0.01em;
    padding: 16px 20px;
}

.app-card .card-header i {
    color: var(--brand);
}

.app-card .card-body {
    padding: 20px;
}

.register-card .card-body,
.document-card .card-body {
    padding: 0;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    border-radius: var(--r);
    font-size: 0.88rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    padding: 0.55rem 1rem;
    box-shadow: none !important;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.btn:active {
    transform: translateY(1px);
}

.btn-primary {
    border-color: var(--brand);
    background: var(--brand);
}

.btn-primary:hover,
.btn-primary:focus {
    border-color: var(--brand-strong);
    background: var(--brand-strong);
}

.btn-outline-secondary {
    border-color: var(--border);
    color: var(--ink-2);
    background: var(--surface);
}

.btn-outline-secondary:hover,
.btn-outline-secondary:focus {
    border-color: var(--border-strong);
    background: var(--surface-soft);
    color: var(--ink);
}

.btn-warning {
    border-color: #f59e0b;
    background: #f59e0b;
    color: #3b2503;
}

.btn-warning:hover,
.btn-warning:focus {
    border-color: #d97706;
    background: #d97706;
    color: #2a1a02;
}

.btn-danger {
    border-color: var(--danger);
    background: var(--danger);
}

.btn-danger:hover,
.btn-danger:focus {
    border-color: #991b1b;
    background: #991b1b;
}

.btn-info {
    border-color: var(--brand);
    background: var(--brand);
    color: #fff;
}

.btn-info:hover,
.btn-info:focus {
    border-color: var(--brand-strong);
    background: var(--brand-strong);
    color: #fff;
}

.btn-outline-info {
    border-color: var(--brand);
    color: var(--brand-deep);
    background: var(--surface);
}

.btn-outline-info:hover,
.btn-outline-info:focus {
    border-color: var(--brand);
    background: var(--brand-soft);
    color: var(--brand-deep);
}

.btn-success {
    border-color: var(--success);
    background: var(--success);
}

.btn-success:hover,
.btn-success:focus {
    border-color: #166534;
    background: #166534;
}

.btn-secondary {
    border-color: var(--ink-2);
    background: var(--ink-2);
}

.btn-outline-success {
    border-color: var(--success);
    color: var(--success);
    background: var(--surface);
}

.btn-outline-success:hover {
    background: var(--success-soft);
    color: var(--success);
    border-color: var(--success);
}

.btn-sm {
    padding: 0.4rem 0.65rem;
    font-size: 0.8rem;
    border-radius: var(--r-sm);
}

/* Action button cluster in tables — square icon buttons */
.table .btn-sm,
.draft-item .btn-sm {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

/* ============================================================
   ALERTS
   ============================================================ */
.alert {
    border-radius: var(--r-md);
    border: 1px solid transparent;
    font-size: 0.9rem;
    padding: 14px 16px;
}

.app-alert {
    box-shadow: var(--shadow-sm);
}

.alert-success {
    background: var(--success-soft);
    border-color: #bbf7d0;
    color: #14532d;
}

.alert-danger {
    background: var(--danger-soft);
    border-color: #fecaca;
    color: #7f1d1d;
}

.alert-warning {
    background: var(--warning-soft);
    border-color: #fde68a;
    color: #78350f;
}

.alert-info {
    background: var(--info-soft);
    border-color: #bae6fd;
    color: #075985;
}

.alert-link {
    font-weight: 650;
}

/* ============================================================
   SECTION HEADINGS / FORMS
   ============================================================ */
.section-heading {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 8px 0 2px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-soft);
    color: var(--ink);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

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

.form-label.fw-semibold,
.form-label {
    color: var(--ink-2);
    font-size: 0.8rem;
    font-weight: 600 !important;
    margin-bottom: 6px;
}

.form-control,
.form-select {
    min-height: 44px;
    border: 1px solid var(--border);
    border-radius: var(--r);
    background: var(--surface);
    color: var(--ink);
    font-size: 0.9rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

textarea.form-control {
    min-height: auto;
    line-height: 1.55;
}

.form-control::placeholder {
    color: var(--muted-2);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 4px var(--brand-ring);
}

.form-text {
    color: var(--muted);
    font-size: 0.8rem;
}

.form-card .row {
    --bs-gutter-x: 1.1rem;
    --bs-gutter-y: 1.1rem;
}

.form-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding-top: 6px;
}

/* ============================================================
   FILTER BAR
   ============================================================ */
.filter-bar {
    display: grid;
    grid-template-columns: repeat(4, minmax(160px, 1fr));
    gap: 14px;
    align-items: end;
    margin-bottom: 18px;
    padding: 16px 18px;
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.filter-bar .form-label {
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.filter-actions {
    display: flex;
    justify-content: flex-end;
}

/* ============================================================
   STATUS PILLS
   ============================================================ */
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border-radius: var(--r-pill);
    background: var(--surface-2);
    color: var(--ink-2);
    font-size: 0.74rem;
    font-weight: 650;
    line-height: 1;
    padding: 0.42rem 0.7rem;
    white-space: nowrap;
}

.status-pill::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.85;
}

.status-received {
    background: var(--brand-soft);
    color: var(--brand-deep);
}

.status-draft {
    background: var(--surface-2);
    color: #475569;
}

.status-under-review {
    background: var(--warning-soft);
    color: #92400e;
}

.status-final,
.status-finalized {
    background: var(--success-soft);
    color: #166534;
}

.status-replied {
    background: #e0e7ff;
    color: #3730a3;
}

.status-closed {
    background: #e2e8f0;
    color: #475569;
}

.roadmap-mini {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 600;
}

.roadmap-mini i {
    color: var(--brand);
}

/* ============================================================
   TIMELINE
   ============================================================ */
.timeline {
    position: relative;
    display: grid;
    gap: 14px;
}

.timeline::before {
    content: "";
    position: absolute;
    left: 11px;
    top: 12px;
    bottom: 12px;
    width: 2px;
    background: var(--border);
}

.timeline-item {
    position: relative;
    display: grid;
    grid-template-columns: 24px 1fr;
    gap: 14px;
}

.timeline-dot {
    width: 22px;
    height: 22px;
    margin-top: 2px;
    border: 4px solid var(--brand-soft);
    border-radius: 50%;
    background: var(--brand);
    z-index: 1;
}

.timeline-item.muted .timeline-dot {
    background: var(--muted-2);
    border-color: var(--surface-2);
}

.timeline-content {
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--surface-soft);
    padding: 14px 16px;
}

.timeline-title {
    color: var(--ink);
    font-weight: 650;
}

.timeline-meta {
    margin-top: 3px;
    color: var(--muted);
    font-size: 0.84rem;
    font-weight: 500;
}

.timeline-content p {
    margin: 8px 0 0;
    color: var(--ink-2);
}

/* ============================================================
   AI / KNOWLEDGE BASE / DRAFTS
   ============================================================ */
.reply-editor {
    min-height: 440px;
    line-height: 1.6;
    font-size: 0.92rem;
}

.kb-note {
    color: var(--muted);
    font-size: 0.86rem;
    line-height: 1.5;
}

.kb-list {
    display: grid;
    gap: 10px;
    margin-top: 14px;
}

.kb-item {
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--surface-soft);
    padding: 12px 14px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.kb-item:hover {
    border-color: var(--brand);
    box-shadow: var(--shadow-sm);
}

.kb-title {
    color: var(--brand-deep);
    font-size: 0.86rem;
    font-weight: 700;
}

.kb-detail {
    margin-top: 4px;
    color: var(--ink-2);
    font-size: 0.88rem;
    line-height: 1.5;
}

.ask-ai-box .form-control {
    min-height: 48px;
}

.ai-answer {
    border: 1px solid var(--brand-soft-2);
    border-left: 4px solid var(--brand);
    border-radius: var(--r-md);
    background: var(--brand-soft);
    color: var(--ink);
    line-height: 1.6;
    padding: 14px 16px;
    white-space: pre-wrap;
}

.draft-list {
    display: grid;
    gap: 12px;
}

.draft-item {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--surface-soft);
    padding: 14px 16px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.draft-item:hover {
    border-color: var(--brand);
    box-shadow: var(--shadow);
    transform: translateY(-1px);
}

.draft-item p {
    margin: 6px 0 0;
    color: var(--ink-2);
    font-size: 0.9rem;
}

/* ============================================================
   TABLES
   ============================================================ */
.table {
    margin-bottom: 0;
    color: var(--ink-2);
}

#lettersTable,
.register-card .table {
    border-color: var(--border);
}

#lettersTable thead th,
.register-card .table thead th {
    border-bottom: 1px solid var(--border);
    background: var(--surface-soft);
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    white-space: nowrap;
    padding: 14px 16px;
}

#lettersTable tbody td,
.register-card .table tbody td {
    border-color: var(--border-soft);
    color: var(--ink-2);
    font-size: 0.88rem;
    vertical-align: middle;
    padding: 14px 16px;
}

#lettersTable tbody tr,
.register-card .table tbody tr {
    transition: background 0.12s ease;
}

#lettersTable tbody tr:hover td,
.register-card .table tbody tr:hover td {
    background: var(--brand-soft);
}

.table tbody td small.text-muted {
    color: var(--muted) !important;
}

.dataTables_wrapper {
    padding: 16px 18px;
}

.dataTables_wrapper .row:first-child {
    align-items: center;
    gap: 12px 0;
    margin-bottom: 14px;
}

.dataTables_length label,
.dataTables_filter label,
.dataTables_info {
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 500;
}

.dataTables_length select,
.dataTables_filter input {
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 0.4rem 0.6rem;
    background: var(--surface-soft);
    color: var(--ink);
}

.dataTables_length select:focus,
.dataTables_filter input:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 4px var(--brand-ring);
}

.dataTables_filter input {
    min-width: 260px;
    margin-left: 0.5rem;
}

.dataTables_paginate {
    padding-top: 6px;
}

.page-link {
    border-color: var(--border);
    color: var(--ink-2);
    border-radius: var(--r-sm) !important;
    margin: 0 2px;
    font-size: 0.85rem;
}

.page-link:hover {
    background: var(--surface-2);
    color: var(--ink);
}

.active > .page-link,
.page-link.active {
    border-color: var(--brand);
    background: var(--brand);
    color: #fff;
}

.dataTables_processing {
    border: 1px solid var(--border) !important;
    border-radius: var(--r-md);
    background: rgba(255, 255, 255, 0.96) !important;
    box-shadow: var(--shadow-lg);
    color: var(--ink);
    font-weight: 600;
    padding: 0.75rem 1.5rem !important;
}

/* ============================================================
   DEFINITION LISTS / MISC
   ============================================================ */
dl.row {
    row-gap: 0.55rem;
}

dl dt {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    padding-top: 6px;
}

dl dd {
    color: var(--ink);
    font-size: 0.92rem;
    padding-top: 4px;
}

.badge.fs-6 {
    border-radius: var(--r-pill);
    font-size: 0.8rem !important;
    font-weight: 650;
    padding: 0.42rem 0.7rem;
}

.badge.text-bg-primary {
    background: var(--brand) !important;
}

blockquote.blockquote {
    margin: 0;
    border: 1px solid var(--border);
    border-left: 4px solid var(--brand);
    border-radius: var(--r-md);
    background: var(--surface-soft);
    color: var(--ink);
    font-size: 0.96rem;
    line-height: 1.65;
    padding: 16px 18px;
}

.card-body iframe {
    min-height: 640px;
    background: var(--surface-soft);
}

.text-muted {
    color: var(--muted) !important;
}

/* ============================================================
   LETTER DETAIL — COMPACT HEADER + METADATA PANEL + VIEWER
   ============================================================ */
.letter-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
    margin-bottom: 18px;
    padding: 22px 24px;
}

.letter-head-main {
    min-width: 0;
}

.letter-ref-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

.letter-ref {
    color: var(--muted);
    font-size: 0.92rem;
    font-weight: 650;
    letter-spacing: 0.01em;
}

.letter-title {
    margin: 0;
    color: var(--ink);
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1.22;
    letter-spacing: -0.025em;
}

.letter-subline {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 22px;
    margin-top: 14px;
    color: var(--muted);
    font-size: 0.88rem;
}

.letter-subline > span {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.letter-subline i {
    color: var(--muted-2);
    font-size: 0.95rem;
}

.letter-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: flex-start;
}

.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-icon.btn-sm {
    width: 36px;
    height: 36px;
}

.btn-outline-danger {
    border-color: #fecaca;
    color: var(--danger);
    background: var(--surface);
}

.btn-outline-danger:hover,
.btn-outline-danger:focus {
    border-color: var(--danger);
    background: var(--danger-soft);
    color: var(--danger);
}

/* Collapsible metadata panel */
.detail-panel {
    margin-bottom: 18px;
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.detail-panel > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 15px 20px;
    cursor: pointer;
    list-style: none;
    font-size: 0.96rem;
    font-weight: 650;
    color: var(--ink);
    background: var(--surface-soft);
    transition: background 0.15s ease;
}

.detail-panel > summary::-webkit-details-marker {
    display: none;
}

.detail-panel > summary:hover {
    background: var(--surface-2);
}

.summary-label {
    display: flex;
    align-items: center;
    gap: 10px;
}

.summary-label i {
    color: var(--brand);
}

.detail-panel > summary .chev {
    color: var(--muted);
    transition: transform 0.2s ease;
}

.detail-panel[open] > summary .chev {
    transform: rotate(180deg);
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
    padding: 20px 22px;
    border-top: 1px solid var(--border-soft);
}

.detail-col {
    display: flex;
    flex-direction: column;
    gap: 9px;
    min-width: 0;
}

.detail-col-label {
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.detail-kv {
    display: flex;
    gap: 10px;
    font-size: 0.9rem;
    color: var(--ink);
    line-height: 1.45;
}

.detail-kv .k {
    flex: 0 0 56px;
    color: var(--muted);
    font-weight: 600;
}

.detail-kv .v {
    font-weight: 550;
    min-width: 0;
    word-break: break-word;
}

.detail-kv .v small {
    display: block;
    color: var(--muted);
    font-weight: 500;
}

.detail-remarks {
    grid-column: 1 / -1;
    margin-top: 2px;
    padding-top: 16px;
    border-top: 1px solid var(--border-soft);
    font-size: 0.9rem;
    color: var(--ink-2);
    line-height: 1.55;
}

.detail-remarks .detail-col-label {
    display: block;
    margin-bottom: 6px;
}

/* Full-width document viewer */
.doc-viewer {
    margin-bottom: 18px;
}

.doc-viewer .card-body {
    padding: 0;
}

.doc-viewer iframe {
    width: 100%;
    height: 82vh;
    min-height: 720px;
    border: 0;
    display: block;
    background: var(--surface-soft);
}

.doc-attach {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px 20px;
}

.doc-attach .file-glyph {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: var(--r-md);
    background: var(--surface-2);
    font-size: 1.3rem;
}

@media (max-width: 991.98px) {
    .detail-grid {
        grid-template-columns: 1fr;
        gap: 18px;
    }

    .letter-actions {
        width: 100%;
    }

    .doc-viewer iframe {
        height: 70vh;
        min-height: 520px;
    }
}

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes pulse-info {
    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.42);
    }
    50% {
        box-shadow: 0 0 0 6px rgba(37, 99, 235, 0);
    }
}

#listenBtn.speaking {
    animation: pulse-info 1.5s infinite;
}

.app-main {
    animation: fade-in 0.3s ease;
}

@keyframes fade-in {
    from {
        opacity: 0;
        transform: translateY(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 991.98px) {
    .app-sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: var(--shadow-lg);
    }

    body.sidebar-open .app-sidebar {
        transform: translateX(0);
    }

    .app-content {
        margin-left: 0;
    }

    .topbar-toggle {
        display: inline-flex;
    }
}

@media (max-width: 767.98px) {
    .app-topbar {
        padding: 0 16px;
        gap: 10px;
    }

    .app-main {
        padding: 18px 16px;
    }

    .page-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .page-toolbar > .d-flex {
        flex-wrap: wrap;
    }

    .page-title {
        font-size: 1.4rem;
    }

    .topbar-user-meta,
    .topbar-btn span {
        display: none;
    }

    .dataTables_filter input {
        width: 100%;
        min-width: 0;
        margin: 0.35rem 0 0;
    }

    .filter-bar {
        grid-template-columns: 1fr;
    }

    .filter-actions {
        justify-content: stretch;
    }

    .filter-actions .btn {
        width: 100%;
    }
}
