/* === RESET & BASE === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --green: #0d8650;
    --green-light: #e6f4ec;
    --red: #CE1126;
    --yellow: #FCD116;
    --dark: #1a1a2e;
    --text: #2d2d2d;
    --text-light: #666;
    --bg: #f5f6f8;
    --white: #fff;
    --border: #e2e5ea;
    --radius: 12px;
    --shadow: 0 4px 16px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.14);
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    padding-bottom: max(80px, calc(80px + env(safe-area-inset-bottom)));
}

a {
    color: var(--green);
    text-decoration: none;
}

/* === TOP BAR === */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    padding-top: max(14px, env(safe-area-inset-top));
    background: var(--green);
    color: var(--white);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.app-title {
    font-size: 1.1rem;
    font-weight: 600;
}

.btn-back {
    color: var(--white);
    font-size: 1.1rem;
    padding: 8px 12px;
    border-radius: 8px;
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.12);
    transition: background 0.2s;
}

.btn-back:hover {
    background: rgba(255,255,255,0.25);
}

.btn-lang {
    background: rgba(255,255,255,0.2);
    color: var(--white);
    border: 1px solid rgba(255,255,255,0.4);
    padding: 4px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
}

.btn-lang:hover {
    background: rgba(255,255,255,0.3);
}

/* Notification bell on green topbar */
.notif-btn {
    position: relative;
    background: none;
    border: none;
    color: var(--white);
    padding: 8px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
}

.notif-btn:hover {
    background: rgba(255,255,255,0.15);
}

/* Notification badge */
.notif-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    background: #E53935;
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    line-height: 1;
}

/* Notification dropdown */
.notif-dropdown {
    position: fixed;
    top: 56px;
    right: 12px;
    width: 320px;
    max-height: 400px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.15);
    z-index: 200;
    opacity: 0;
    transform: translateY(-8px) scale(0.97);
    pointer-events: none;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.notif-dropdown.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.notif-dropdown-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 10px;
    border-bottom: 1px solid #f0f0f0;
    font-size: 0.9rem;
}

.notif-clear {
    background: none;
    border: none;
    color: var(--green);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
}

.notif-list {
    max-height: 320px;
    overflow-y: auto;
}

.notif-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid #f8f8f8;
    transition: background 0.15s;
    color: inherit;
    text-decoration: none;
    cursor: pointer;
}

.notif-item:hover {
    background: #f8f9fb;
}

.notif-item.unread {
    background: #f0faf4;
}

.notif-icon {
    font-size: 1.2rem;
    flex-shrink: 0;
    margin-top: 2px;
}

.notif-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.notif-text {
    font-size: 0.82rem;
    color: #333;
    line-height: 1.4;
}

.notif-time {
    font-size: 0.7rem;
    color: #999;
}

.notif-delete {
    background: none;
    border: none;
    color: #bbb;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0 4px;
    margin-left: auto;
    flex-shrink: 0;
    line-height: 1;
    min-width: 28px;
    min-height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.notif-delete:hover {
    color: #E53935;
}

.notif-empty {
    padding: 32px 16px;
    text-align: center;
    color: #aaa;
    font-size: 0.85rem;
}

.btn-icon {
    color: var(--white);
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
}

.btn-icon:hover {
    background: rgba(255,255,255,0.15);
}

/* === ALERTS === */
.alert {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 0.88rem;
    flex-wrap: wrap;
    border-radius: 12px;
    margin: 16px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.06);
    line-height: 1.5;
}

.alert-icon {
    flex-shrink: 0;
    color: #007A3D;
}

.alert-warning {
    background: #f0f9f4;
    color: #1a3c2a;
    border-left: 4px solid #007A3D;
    border-bottom: none;
}

.alert-cta {
    margin-left: auto;
    flex-shrink: 0;
    background: #007A3D;
    color: #fff;
    padding: 8px 18px;
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.2s, transform 0.15s;
    white-space: nowrap;
}

.alert-cta:hover {
    background: #009b4d;
    transform: translateY(-1px);
}

.alert-link {
    font-weight: 600;
    text-decoration: underline;
}

/* === CONTAINER === */
.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 16px;
    overflow-x: hidden;
}

/* === SECTIONS === */
.section {
    background: var(--white);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.section-title {
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: 14px;
    border-left: 3px solid var(--green);
    padding-left: 12px;
    color: var(--dark);
}

.section-desc {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-bottom: 16px;
}

/* === DOCUMENT CARDS === */
.doc-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
}

.doc-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 20px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    transition: all 0.2s;
    color: var(--text);
    cursor: pointer;
}

.doc-card:hover {
    border-color: var(--green);
    background: var(--green-light);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.doc-card-icon {
    font-size: 2rem;
    margin-bottom: 8px;
}

.doc-card-title {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.doc-card-desc {
    font-size: 0.8rem;
    color: var(--text-light);
}

/* === UPLOAD ZONE === */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-light);
}

.upload-zone:hover,
.upload-zone.drag-over {
    border-color: var(--green);
    background: var(--green-light);
    color: var(--green);
}

.upload-zone svg {
    margin-bottom: 8px;
    opacity: 0.5;
}

/* === FORMS === */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    max-width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
    background: #f8f9fa;
    -webkit-appearance: none;
    appearance: none;
}

.form-input:hover,
.form-select:hover,
.form-textarea:hover {
    border-color: #ccc;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--green);
    background: var(--white);
    box-shadow: 0 0 0 3px rgba(13, 134, 80, 0.12);
}

.form-input::placeholder,
.form-textarea::placeholder {
    color: #bbb;
    font-style: italic;
}

.form-textarea {
    min-height: 120px;
    resize: vertical;
}

.form-help {
    display: block;
    font-size: 0.78rem;
    color: #888;
    margin-top: 5px;
    font-style: italic;
}

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

@media (min-width: 600px) {
    .form-row {
        grid-template-columns: 1fr 1fr;
    }
    .form-row.three-col {
        grid-template-columns: 1fr 1fr 1fr;
    }
}

/* === HIERARCHY LEVELS === */
.level-item {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 8px;
    position: relative;
}

.level-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.level-number {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--green);
    background: var(--green-light);
    padding: 2px 8px;
    border-radius: 12px;
}

.level-remove {
    background: none;
    border: none;
    color: var(--red);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 2px 6px;
    border-radius: 4px;
}

.level-remove:hover {
    background: rgba(206, 17, 38, 0.1);
}

.level-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.level-fields input {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.85rem;
}

.level-fields input:focus {
    outline: none;
    border-color: var(--green);
}

/* === COAT OF ARMS === */
.coat-upload-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.coat-preview {
    width: 100px;
    height: 100px;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-light);
    overflow: hidden;
}

.coat-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* === BUTTONS === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.btn-lg {
    padding: 14px 28px;
    font-size: 1rem;
}

.btn-primary {
    background: var(--green);
    color: var(--white);
}

.btn-primary:hover {
    background: #006832;
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--green);
    color: var(--green);
}

.btn-outline:hover {
    background: var(--green-light);
}

/* === ACTION BAR === */
.action-bar {
    display: flex;
    gap: 12px;
    justify-content: center;
    padding: 20px 16px;
    flex-wrap: wrap;
}

/* === HEADER PREVIEW === */
.header-preview {
    background: #fafbfc;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    font-family: 'Times New Roman', Times, serif;
    font-size: 0.7rem;
    text-align: center;
    overflow-x: auto;
}

.header-preview.compact {
    padding: 10px;
    font-size: 0.55rem;
}

.preview-placeholder {
    color: var(--text-light);
    font-style: italic;
    font-family: inherit;
}

.header-table {
    width: 100%;
    border-collapse: collapse;
}

.header-table td {
    vertical-align: top;
    padding: 1px 2px;
    text-align: center;
}

.header-table .col-fr { width: 40%; }
.header-table .col-coat { width: 20%; }
.header-table .col-en { width: 40%; }

.header-level {
    font-weight: bold;
    text-transform: uppercase;
    font-size: 0.65rem;
}

.header-motto {
    font-style: italic;
    font-size: 0.6rem;
}

.header-separator {
    font-size: 0.5rem;
    color: var(--text-light);
}

/* === MODAL === */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-content {
    background: var(--white);
    border-radius: var(--radius);
    max-width: 700px;
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 1.1rem;
}

.btn-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-light);
    padding: 0 4px;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    font-family: 'Times New Roman', Times, serif;
    font-size: 0.85rem;
}

.modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
}

/* === DOCUMENT PREVIEW STYLES === */
/* These classes match the actual .docx output formatting */

/* Preview disclaimer notice */
.doc-preview-notice {
    background: #fff8e1;
    color: #6d5c10;
    font-size: 0.78rem;
    padding: 8px 14px;
    text-align: center;
    border-bottom: 1px solid #f0e4b0;
}

/* PDF-like page container */
.doc-preview-scaler {
    background: #e8e8e8;
    padding: 12px;
    border-radius: 4px;
    overflow: hidden;
}

.doc-preview {
    font-family: 'Times New Roman', Times, serif;
    font-size: 12pt;
    line-height: 1.15;
    color: #000;
    padding: 40px 50px;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    max-width: 595px;
    margin: 0 auto;
    min-height: 400px;
}

/* Remove card styling from header-preview inside doc-preview */
.doc-preview .header-preview,
.doc-preview .header-preview.compact {
    background: none;
    border: none;
    border-radius: 0;
    padding: 0;
    font-size: 0.6rem;
    overflow: visible;
}

.doc-preview p,
.doc-preview .doc-body-para {
    text-align: justify;
    text-indent: 0.5in;
    margin: 0 0 5pt 0;
}

.doc-preview .doc-title {
    text-align: center;
    font-size: 14pt;
    font-weight: bold;
    text-decoration: underline;
    margin: 15pt 0 10pt 0;
    text-indent: 0;
}

.doc-preview .doc-simple {
    margin: 0 0 5pt 0;
    text-indent: 0;
}

.doc-preview .doc-objet {
    padding-left: 0.85in;
    text-indent: -0.85in;
    margin: 10pt 0 5pt 0;
}

.doc-preview .doc-right-block {
    text-align: center;
    margin-left: 3in;
}

.doc-preview .doc-ref-date {
    display: flex;
    justify-content: space-between;
    margin: 10pt 0;
    text-indent: 0;
}

.doc-preview .doc-signatory {
    text-align: right;
    margin-top: 25pt;
    text-indent: 0;
}

.doc-preview .doc-signatory-title {
    font-weight: bold;
    text-decoration: underline;
}

.doc-preview .doc-signatory-name {
    font-weight: bold;
    margin-top: 40pt;
}

.doc-preview .doc-ampliations {
    margin-top: 20pt;
    font-size: 10pt;
    text-indent: 0;
}

.doc-preview .doc-ampliations-header {
    font-weight: bold;
    text-decoration: underline;
    margin-bottom: 2pt;
}

.doc-preview .doc-ampliations-item {
    padding-left: 0.25in;
    margin: 2pt 0;
}

.doc-preview .doc-pj {
    margin-top: 15pt;
    text-indent: 0;
}

/* === LOADING === */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,0.9);
    z-index: 300;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border);
    border-top-color: var(--green);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* === FOOTER === */
.footer {
    text-align: center;
    padding: 20px 16px;
    font-size: 0.75rem;
    color: var(--text-light);
}

/* === DYNAMIC FIELDS === */
.field-group-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--green);
    margin: 16px 0 8px 0;
    padding-bottom: 4px;
    border-bottom: 2px solid var(--green-light);
}

.repeater-group {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 8px;
    background: var(--bg);
}

.repeater-group .form-row {
    margin-bottom: 0;
}

.btn-add-row {
    background: none;
    border: 1px dashed var(--green);
    color: var(--green);
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    width: 100%;
    margin-top: 8px;
}

.btn-add-row:hover {
    background: var(--green-light);
}

.btn-remove-row {
    background: none;
    border: none;
    color: var(--red);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 4px;
}

/* === REFERENCE COMPOSITE INPUT === */
.ref-composite {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.ref-prefix-label {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text);
    white-space: nowrap;
}

.ref-number {
    width: 100px !important;
    flex: 0 0 auto;
    text-align: center;
}

.ref-prefix-value {
    font-size: 0.9rem;
    color: var(--text-light);
    font-weight: 500;
    white-space: nowrap;
    word-break: break-all;
}

/* === AI ASSIST MODAL === */
.ai-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 250;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.ai-modal-content {
    background: var(--white);
    border-radius: var(--radius);
    max-width: 560px;
    width: 100%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}

.ai-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: none;
    background: linear-gradient(135deg, #0d8650, #0a6e42);
    border-radius: var(--radius) var(--radius) 0 0;
}

.ai-modal-header h3 {
    font-size: 1.05rem;
    font-weight: 700;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-modal-header .btn-close {
    color: rgba(255,255,255,0.8);
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-modal-header .btn-close:hover {
    color: #fff;
}

.dom-header-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.4);
    object-fit: cover;
}

.ai-modal-body {
    padding: 20px;
    overflow-y: auto;
}

.ai-modal-body .form-group {
    margin-bottom: 14px;
}

.ai-modal-body .context-summary {
    background: #f0f4f8;
    border: none;
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 0.82rem;
    color: var(--text-light);
    line-height: 1.6;
    margin-bottom: 16px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.ai-modal-body .context-summary strong {
    color: var(--text);
}

.ai-modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.ai-modal-footer .btn {
    min-height: 44px;
    border-radius: 10px;
    padding: 10px 20px;
}

.ai-modal-footer .btn-outline {
    color: #666;
    border-color: #ddd;
}

.ai-modal-footer .btn-primary {
    box-shadow: 0 2px 8px rgba(13,134,80,0.25);
}

.ai-result {
    background: #f0faf4;
    border: none;
    border-left: 3px solid var(--green);
    border-radius: 10px;
    padding: 14px;
    font-size: 0.88rem;
    white-space: pre-wrap;
    max-height: 250px;
    overflow-y: auto;
    margin-top: 12px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.ai-error {
    background: #fce4e4;
    border: 1px solid var(--red);
    border-radius: 6px;
    padding: 10px 12px;
    font-size: 0.85rem;
    color: #c0392b;
    margin-top: 12px;
}

.ai-loading {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px;
    justify-content: center;
    color: var(--text-light);
}

.ai-loading {
    color: #888;
    font-size: 0.85rem;
}

.ai-loading .spinner {
    width: 28px;
    height: 28px;
    border-width: 3px;
}

/* Attachment zone */
.attachment-zone {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
}

.attachment-hint {
    font-size: 0.78rem;
    color: #999;
}

.attachment-list {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 4px;
}

.attachment-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.82rem;
}

.attachment-item.processing {
    color: var(--text-light);
    font-style: italic;
}

.attachment-item small {
    color: var(--text-light);
    margin-left: 4px;
}

.btn-remove-attachment {
    background: none;
    border: none;
    color: var(--red);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.btn-remove-attachment:hover {
    color: #c0392b;
}

.attachment-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--green);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-right: 6px;
    vertical-align: middle;
}

/* Audio recorder */
.audio-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    margin-top: 6px;
}

.btn-record {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: 1.5px solid var(--green);
    color: var(--green);
    border-radius: 8px;
    padding: 6px 14px;
    font-size: 0.8rem;
    min-height: 36px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-record:hover {
    background: var(--green-light);
}

.recording-strip {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    background: #fde8e8;
    border: 1.5px solid #e74c3c;
    border-radius: 8px;
    padding: 10px 14px;
    margin-top: 6px;
}

.recording-dot {
    width: 12px;
    height: 12px;
    background: var(--red);
    border-radius: 50%;
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.recording-timer {
    font-family: monospace;
    font-size: 0.95rem;
    font-variant-numeric: tabular-nums;
    color: var(--red);
    min-width: 44px;
}

.btn-stop {
    background: var(--red);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 6px 14px;
    font-size: 0.8rem;
    min-height: 32px;
    cursor: pointer;
}

.btn-stop:hover {
    opacity: 0.85;
}

.audio-attachment {
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    margin-top: 6px;
    width: 100%;
}

.audio-attachment-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.8rem;
}

.audio-attachment-header small {
    color: var(--text-light);
    margin-left: 4px;
}

.audio-attachment audio {
    width: 100%;
    height: 40px;
    border-radius: 8px;
}

/* === RESPONSIVE === */
@media (max-width: 600px) {
    /* Touch-friendly inputs */
    .form-input, .form-select {
        padding: 12px 14px;
        min-height: 44px;
        font-size: 1rem;
    }

    .form-label {
        font-size: 0.9rem;
    }

    .form-help {
        font-size: 0.8rem;
    }

    /* Hierarchy levels */
    .level-fields {
        grid-template-columns: 1fr;
    }

    .level-fields input {
        padding: 10px 12px;
        font-size: 0.9rem;
        min-height: 44px;
    }

    .level-item {
        padding: 16px;
    }

    .level-remove {
        min-width: 36px;
        min-height: 36px;
        font-size: 1.4rem;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .level-number {
        font-size: 0.85rem;
        padding: 3px 10px;
    }

    /* Header preview compact */
    .header-preview.compact {
        font-size: 0.55rem;
        padding: 10px;
    }

    .header-preview.compact .header-level {
        font-size: 0.52rem;
    }

    .header-preview.compact .header-motto {
        font-size: 0.48rem;
    }

    .header-preview.compact .header-separator {
        font-size: 0.42rem;
    }

    /* Save button full width */
    .btn-lg {
        width: 100%;
        padding: 16px 28px;
        justify-content: center;
    }

    /* Textareas shorter on mobile */
    .form-textarea {
        min-height: 80px;
    }

    /* Tighter form group spacing */
    .form-group {
        margin-bottom: 12px;
    }

    .form-group label {
        margin-bottom: 6px;
    }

    /* Sticky action bar */
    .action-bar {
        position: sticky;
        bottom: 0;
        background: #fff;
        border-top: 1px solid var(--border);
        box-shadow: 0 -2px 12px rgba(0,0,0,0.08);
        z-index: 50;
        padding: 12px 16px;
        flex-direction: column;
        gap: 8px;
    }

    .action-bar .btn {
        width: 100%;
        justify-content: center;
        min-height: 48px;
    }

    /* Add level button touch-friendly */
    .btn-outline {
        min-height: 44px;
    }

    /* Full-screen modals on mobile */
    .modal, .ai-modal {
        padding: 0;
    }

    .modal-content, .ai-modal-content {
        max-width: 100%;
        max-height: 100vh;
        height: 100%;
        border-radius: 0;
    }

    .modal-body, .ai-modal-body {
        padding: 14px;
    }

    .modal-header, .ai-modal-header {
        padding: 12px 14px;
    }

    .ai-modal-header {
        border-radius: 0;
    }

    .modal-footer, .ai-modal-footer {
        padding: 10px 14px;
    }

    .btn-close {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.6rem;
    }

    /* Reference composite compact */
    .ref-composite {
        gap: 6px;
    }

    .ref-number {
        width: 70px !important;
    }

    .ref-prefix-value {
        white-space: normal;
        word-break: break-word;
        font-size: 0.82rem;
    }

    /* Denomination table compact */
    .denomination-table input[type=number] {
        width: 60px;
        padding: 6px 4px;
        font-size: 0.85rem;
        min-height: 36px;
    }

    .denomination-table td {
        padding: 3px 4px;
        font-size: 0.82rem;
    }

    .denomination-table th {
        padding: 6px 4px;
        font-size: 0.72rem;
    }

    /* PDF-like preview scaling on mobile */
    .doc-preview-scaler {
        padding: 8px;
    }

    .doc-preview {
        width: 595px;
        max-width: none;
        transform-origin: top left;
    }

    /* Remove modal-body padding when showing doc preview */
    .modal-body:has(.doc-preview-scaler) {
        padding: 0;
    }
}

@media (max-width: 480px) {
    .doc-grid {
        grid-template-columns: 1fr;
    }

    .header-preview {
        font-size: 0.55rem;
    }

    .container {
        padding: 10px;
    }

    .section {
        padding: 16px;
        border-radius: 6px;
    }

    .doc-preview-scaler {
        padding: 4px;
        border-radius: 0;
    }
}

@media (max-width: 360px) {
    .app-title {
        font-size: 1rem;
    }

    .btn-back {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* === MONTH PICKER INFO === */
.month-info {
    margin-top: 6px;
    font-size: 0.85rem;
    color: var(--text-light);
    background: var(--green-light);
    padding: 6px 10px;
    border-radius: var(--radius);
}

/* === DENOMINATION TABLE === */
.denomination-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.denomination-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8px;
}

.denomination-table th {
    background: var(--dark);
    color: var(--white);
    padding: 8px 10px;
    text-align: center;
    font-size: 0.8rem;
    font-weight: 600;
}

.denomination-table td {
    padding: 4px 8px;
    border: 1px solid var(--border);
    text-align: center;
    font-size: 0.9rem;
}

.denomination-table .section-header td {
    background: #f0f0f0;
    font-weight: 700;
    text-align: center;
    padding: 6px;
    font-size: 0.85rem;
}

.denomination-table .denom-label {
    text-align: right;
    font-weight: 500;
    padding-right: 12px;
}

.denomination-table input[type=number] {
    width: 80px;
    padding: 4px 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    text-align: center;
    font-size: 0.9rem;
}

.denomination-table input[type=number]:focus {
    border-color: var(--green);
    outline: none;
    box-shadow: 0 0 0 2px rgba(0,122,61,0.15);
}

.denomination-table .computed-amount {
    font-weight: 500;
    color: var(--text);
    text-align: right;
    padding-right: 12px;
}

.denomination-table .total-row td {
    background: var(--green-light);
    font-weight: 700;
    font-size: 0.95rem;
    border-top: 2px solid var(--green);
}

.denomination-toolbar {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 8px;
}

.mismatch-warning {
    background: #fff3cd;
    color: #856404;
    padding: 6px 10px;
    border-radius: var(--radius);
    font-size: 0.85rem;
    margin-top: 6px;
    display: none;
}

.mismatch-warning.visible {
    display: block;
}
