/* StructuraDocs – Paper-inspired academic theme */

:root {
    /* Primary (Authority + Structure) */
    --primary: #5B3A29;
    --accent: #B45309;
    --accent-soft: rgba(180, 83, 9, 0.12);
    /* Background (Paper inspired) */
    --bg: #FAF7F2;
    --surface: #F5EFE6;
    --surface2: #EDE6DC;
    --card-bg: #FFFFFF;
    /* Text */
    --text: #2C1E16;
    --text-secondary: #6B4E3D;
    --muted: #9A7B67;
    /* Semantic */
    --success: #2F6F4E;
    --warning: #C2410C;
    --error: #7F1D1D;
    /* UI */
    --radius: 12px;
    --shadow-warm: 0 2px 8px rgba(91, 58, 41, 0.12);
    --font-sans: 'DM Sans', system-ui, -apple-system, sans-serif;
    --font-serif: 'Literata', 'Times New Roman', serif;
    /* Paper sheet (body content editor) */
    --paper-bg: #FDFCF9;
    --paper-shadow: 0 2px 4px rgba(91, 58, 41, 0.08), 0 8px 24px rgba(91, 58, 41, 0.12);
    --paper-border: #E8E2D9;
}

/* Dark mode – elegant research / library at night */
[data-theme="dark"] {
    --primary: #C6A27E;
    --accent: #D97706;
    --accent-soft: rgba(217, 119, 6, 0.2);
    --bg: #1A1410;
    --surface: #2A1F19;
    --surface2: #3D2E26;
    --card-bg: #2A1F19;
    --text: #F5EFE6;
    --text-secondary: #E5DED4;
    --muted: #9A8B7A;
    --success: #2F6F4E;
    --warning: #C2410C;
    --error: #7F1D1D;
    --shadow-warm: 0 2px 12px rgba(0, 0, 0, 0.35);
    --paper-bg: #352A22;
    --paper-shadow: 0 2px 8px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(0, 0, 0, 0.4);
    --paper-border: #4A3D32;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.6;
    min-height: 100vh;
}

.site-header {
    text-align: center;
    padding: 2rem 1rem;
    border-bottom: 1px solid var(--surface2);
}

.site-header .header-inner {
    max-width: 1000px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.site-header .header-inner .nav-main {
    display: flex;
    gap: 1rem;
}

.site-header .header-inner .nav-main a {
    color: var(--muted);
    text-decoration: none;
    font-weight: 500;
}

.site-header .header-inner .nav-main a:hover,
.site-header .header-inner .nav-main a.nav-active {
    color: var(--accent);
}

.theme-toggle {
    background: none;
    border: none;
    color: var(--muted);
    font: inherit;
    font-size: 0.95rem;
    cursor: pointer;
    padding: 0.25rem 0;
}

.theme-toggle:hover {
    color: var(--accent);
}

/* Bootstrap Icons – align with text */
.bi {
    vertical-align: -0.15em;
}
.btn .bi,
.theme-toggle .bi {
    margin-right: 0.35em;
}
.btn .bi:last-child,
.theme-toggle .bi:last-child {
    margin-right: 0;
    margin-left: 0.35em;
}
.style-link .bi {
    margin-left: 0.25em;
}
.feature-icon .bi,
.download-icon .bi {
    font-size: 1.5rem;
    display: block;
    margin: 0;
}
.source-row .remove-source .bi {
    margin: 0;
    font-size: 1rem;
}

.logo {
    display: inline-block;
    margin: 0 0 0.25rem 0;
    text-decoration: none;
    line-height: 0;
}

.logo img {
    display: block;
    height: auto;
    max-height: 2.5rem;
    width: auto;
    max-width: 100%;
}

.logo:hover img {
    opacity: 0.9;
}

.tagline {
    margin: 0;
    color: var(--muted);
    font-size: 0.95rem;
}

.alert {
    max-width: 720px;
    margin: 1rem auto;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
}

.alert-success {
    background: rgba(47, 111, 78, 0.15);
    color: var(--success);
}

.alert-error {
    background: rgba(127, 29, 29, 0.12);
    color: var(--error);
}

.tabs {
    display: flex;
    justify-content: center;
    gap: 0;
    padding: 0 1rem;
    border-bottom: 1px solid var(--surface2);
    background: var(--surface);
}

.tab {
    padding: 0.9rem 1.5rem;
    color: var(--muted);
    text-decoration: none;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    transition: color 0.2s, border-color 0.2s;
}

.tab:hover {
    color: var(--text);
}

.tab.active {
    color: var(--primary);
    border-bottom-color: var(--accent);
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1.5rem 3rem;
}

.panel {
    display: none;
}

.panel.active {
    display: block;
}

.form-document .form-row,
.form-document .form-group,
.form-document .form-grid {
    margin-bottom: 1.25rem;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-group.full {
    grid-column: 1 / -1;
}

label {
    display: block;
    margin-bottom: 0.35rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="url"],
textarea,
select {
    width: 100%;
    padding: 0.6rem 0.85rem;
    background: var(--card-bg);
    border: 1px solid var(--surface2);
    border-radius: var(--radius);
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

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

/* Body content as a sheet of paper */
.body-content-paper-wrap {
    margin-top: 0.5rem;
}

.body-content-paper-wrap > label {
    display: block;
    margin-bottom: 0.5rem;
}

/* Real paper look: same in light and dark theme so editor and viewer match a PDF */
.paper-sheet {
    max-width: 8.5in;
    margin: 0 auto;
    padding: 1.25in 1in;
    min-height: 11in;
    background: #FDFCF9;
    border: 1px solid #E0DCD5;
    border-radius: 2px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.1);
    position: relative;
}

.paper-sheet::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    background: linear-gradient(180deg, rgba(91, 58, 41, 0.03) 0%, transparent 8%);
}

.paper-sheet textarea {
    display: block;
    width: 100%;
    min-height: 9in;
    padding: 0;
    margin: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    color: #1a1a1a;
    font-family: 'Times New Roman', Times, serif;
    font-size: 12pt;
    line-height: 2;
    resize: vertical;
    box-shadow: none;
}

.paper-sheet textarea::placeholder {
    color: #8a8378;
}

.paper-sheet textarea:focus {
    outline: none;
    border: none;
    box-shadow: none;
}

.paper-sheet:focus-within {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.1), 0 0 0 2px var(--accent);
}

@media (max-width: 720px) {
    .paper-sheet {
        max-width: 100%;
        padding: 1.5rem 1.25rem;
        min-height: 0;
    }
    .paper-sheet textarea {
        min-height: 320px;
    }
}

.style-select select {
    max-width: 240px;
}

.btn {
    display: inline-block;
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: #FFFFFF !important;
    box-shadow: var(--shadow-warm);
    border: 1px solid transparent;
}

.btn-primary:hover {
    background: var(--accent);
    box-shadow: 0 4px 12px rgba(91, 58, 41, 0.2);
}

.btn-secondary {
    background: var(--surface2);
    color: var(--text);
}

.btn-secondary:hover {
    background: var(--surface2);
    filter: brightness(0.96);
}

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

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

.form-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-top: 1.5rem;
}

.sources-block {
    margin-top: 2rem;
    padding: 1.25rem;
    background: var(--card-bg);
    border-radius: var(--radius);
    border: 1px solid var(--surface2);
    box-shadow: var(--shadow-warm);
}

.sources-block h3 {
    margin: 0 0 0.5rem 0;
    font-size: 1rem;
}

.sources-block .hint {
    margin: 0 0 1rem 0;
    color: var(--muted);
    font-size: 0.85rem;
}

.import-block {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--card-bg);
    border-radius: var(--radius);
    border: 1px solid var(--surface2);
    box-shadow: var(--shadow-warm);
}

.import-block h3 {
    margin: 0 0 0.5rem 0;
    font-size: 1rem;
}

.import-block .hint {
    margin: 0 0 0.75rem 0;
    color: var(--muted);
    font-size: 0.85rem;
}

.import-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
}

.import-upload-form {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.import-upload-form input[type="file"] {
    max-width: 220px;
}

/* Import drag-and-drop zone */
.import-drop-zone {
    position: relative;
    border: 2px dashed var(--surface2);
    border-radius: var(--radius);
    padding: 2rem;
    text-align: center;
    background: var(--surface);
    transition: border-color 0.2s, background 0.2s;
    margin-bottom: 0.75rem;
}

.import-drop-zone:hover,
.import-drop-zone.import-drop-zone-active {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.import-drop-zone .import-file-input {
    position: absolute;
    width: 0.1px;
    height: 0.1px;
    opacity: 0;
    overflow: hidden;
    z-index: -1;
}

.import-drop-zone-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.import-drop-zone-inner .bi {
    font-size: 2rem;
    color: var(--muted);
}

.import-drop-zone-active .import-drop-zone-inner .bi {
    color: var(--accent);
}

.import-drop-text {
    font-weight: 500;
    color: var(--text-secondary);
}

.import-drop-or {
    font-size: 0.85rem;
    color: var(--muted);
}

.import-drop-zone-progress {
    padding: 0.5rem 0;
}

.import-drop-zone-progress-text {
    font-size: 0.9rem;
    color: var(--muted);
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* Document viewer / preview panel */
.document-viewer-wrap {
    margin-bottom: 1.5rem;
}

.document-viewer-actions {
    margin-bottom: 0.75rem;
}

.document-preview-panel {
    margin-top: 0.5rem;
    padding: 1.25rem;
    background: #FDFCF9;
    border: 1px solid #E0DCD5;
    border-radius: 2px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.1);
}

.document-preview-paper {
    max-width: 100%;
    font-family: var(--font-serif);
    font-size: 12pt;
    line-height: 1.8;
    color: #1a1a1a;
}

.document-preview-header {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #E0DCD5;
}

.document-preview-title {
    font-size: 1.25rem;
    margin: 0 0 0.25rem 0;
    color: #2C1E16;
}

.document-preview-meta {
    font-size: 0.9rem;
    color: #6B4E3D;
    margin: 0;
}

.document-preview-body {
    white-space: pre-wrap;
    word-wrap: break-word;
}

.document-preview-body p {
    margin: 0 0 0.75rem 0;
}

.document-preview-empty {
    color: #8a8378;
    font-style: italic;
}

/* Formatted output: embed (iframe) for document view, div for print */
.document-viewer-embed {
    display: block;
    width: 100%;
    max-width: 8.5in;
    min-height: 70vh;
    height: 80vh;
    margin: 0 auto;
    border: 1px solid #E0DCD5;
    border-radius: 2px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.1);
    background: #FDFCF9;
}

.document-viewer-print-only {
    display: none;
}

/* Formatted output as document viewer – same paper look (used for print) */
.document-viewer-output .document-viewer-content {
    max-height: 70vh;
    overflow-y: auto;
    padding: 1in;
    background: #FDFCF9 !important;
    color: #1a1a1a !important;
    border: 1px solid #E0DCD5;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.1);
}

.document-viewer-output .document-viewer-content,
.document-viewer-output .document-viewer-content .apa-document,
.document-viewer-output .document-viewer-content .mla-document,
.document-viewer-output .document-viewer-content .chicago-document {
    color: #1a1a1a !important;
}

.document-viewer-output .document-viewer-content .apa-document a,
.document-viewer-output .document-viewer-content .mla-document a,
.document-viewer-output .document-viewer-content .chicago-document a {
    color: #5B3A29;
}

.my-docs-section {
    max-width: 720px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

.my-docs-section h2 {
    margin: 0 0 1rem 0;
}

.my-docs-section .btn {
    margin-bottom: 1.5rem;
}

.doc-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.doc-list li {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--surface2);
}

.doc-list li a {
    color: var(--accent);
    text-decoration: none;
}

.doc-list li a:hover {
    text-decoration: underline;
}

.doc-list .meta {
    display: block;
    font-size: 0.85rem;
    color: var(--muted);
    margin-top: 0.25rem;
}

.source-row {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 0.75rem;
    border: 1px solid var(--surface2);
}

.source-row .row-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.source-row select {
    width: auto;
    min-width: 120px;
}

.source-row .remove-source {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 0.25rem;
    font-size: 1.1rem;
}

.source-row .remove-source:hover {
    color: var(--error);
}

.source-row .fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.source-row .fields .full {
    grid-column: 1 / -1;
}

.source-row input,
.source-row select {
    padding: 0.4rem 0.6rem;
    font-size: 0.9rem;
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 1rem;
}

.modal[aria-hidden="true"] {
    display: none;
}

.modal-content {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 1.5rem;
    max-width: 400px;
    width: 100%;
    border: 1px solid var(--surface2);
    box-shadow: var(--shadow-warm);
}

.modal-content h3 {
    margin: 0 0 1rem 0;
}

.modal-content .form-group {
    margin-bottom: 1rem;
}

.modal-content .btn {
    margin-right: 0.5rem;
}

.output-section {
    margin-top: 2.5rem;
    padding-top: 2rem;
    border-top: 1px solid var(--surface2);
}

.output-section h2 {
    margin: 0 0 1rem 0;
    font-size: 1.15rem;
}

.output-actions {
    margin-bottom: 1rem;
}

.formatted-output {
    background: #FDFCF9 !important;
    color: #1a1a1a !important;
    padding: 1in;
    border-radius: 2px;
    font-family: 'Times New Roman', Times, serif;
    font-size: 12pt;
    line-height: 2;
    max-width: 8.5in;
    margin-left: auto;
    margin-right: auto;
    overflow-x: auto;
    border: 1px solid #E0DCD5;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.1);
}

.formatted-output .apa-document,
.formatted-output .mla-document,
.formatted-output .chicago-document {
    color: #1a1a1a !important;
}

/* Academic document defaults (Google Docs–style: 1" margins, Times New Roman 12pt, double spacing) */
.formatted-output,
.document-viewer-embed,
.apa-document,
.mla-document,
.chicago-document {
    font-family: 'Times New Roman', Times, serif;
    font-size: 12pt;
    line-height: 2;
}
.formatted-output p,
.apa-document p,
.mla-document p,
.chicago-document p { margin: 0 0 0 0; }
.formatted-output .apa-content,
.formatted-output .mla-content,
.formatted-output .chicago-content,
.apa-content,
.mla-content,
.chicago-content {
    text-indent: 0.5in;
}
.formatted-output .apa-content p:first-of-type,
.formatted-output .mla-content p:first-of-type,
.formatted-output .chicago-content p:first-of-type,
.apa-content p:first-of-type,
.mla-content p:first-of-type,
.chicago-content p:first-of-type { margin: 0; }

/* APA */
.apa-document { font-family: 'Times New Roman', Times, serif; }
.apa-title-page { text-align: center; margin-bottom: 2rem; }
.apa-running-head { font-size: 12pt; text-transform: uppercase; }
.apa-title { font-size: 12pt; font-weight: normal; margin: 1rem 0; text-align: center; }
.apa-author, .apa-affiliation, .apa-course, .apa-date { margin: 0; line-height: 2; }
.apa-body { margin-top: 2rem; }
.apa-running-head-page { font-size: 12pt; text-align: right; margin-bottom: 0.5rem; }
.apa-content { text-indent: 0.5in; text-align: justify; }
.apa-references { margin-top: 2rem; page-break-before: always; }
.apa-ref-heading { font-size: 12pt; font-weight: bold; margin-bottom: 1rem; text-align: center; }
.apa-document .source-entry { text-indent: -0.5in; padding-left: 0.5in; margin-bottom: 0.5rem; }

/* MLA */
.mla-document { font-family: 'Times New Roman', Times, serif; }
.mla-running-header { display: block; text-align: right; font-size: 12pt; line-height: 2; margin-bottom: 0.5rem; white-space: nowrap; }
.mla-header { margin-bottom: 2rem; }
.mla-header .mla-name,
.mla-header .mla-instructor,
.mla-header .mla-course,
.mla-header .mla-date { margin: 0; line-height: 2; font-weight: normal; }
.mla-name { font-weight: normal; }
.mla-title { text-align: center !important; font-size: 12pt; font-weight: normal; margin: 1rem 0 2rem 0; text-decoration: none; }
.mla-content { text-align: left; display: block; line-height: 2; text-indent: 0.5in; }
.mla-works-cited { margin-top: 2rem; page-break-before: always; }
.mla-wc-heading { font-size: 12pt; font-weight: bold; margin-bottom: 1rem; text-align: center; }
.mla-document .source-entry { margin-bottom: 0.5rem; text-indent: -0.5in; padding-left: 0.5in; }

/* Chicago */
.chicago-document { font-family: 'Times New Roman', Times, serif; }
.chicago-title-block { text-align: center; margin-bottom: 2rem; }
.chicago-title { font-size: 12pt; font-weight: normal; margin: 0 0 0.5rem 0; }
.chicago-bibliography { margin-top: 2rem; page-break-before: always; }
.chicago-bib-heading { font-size: 12pt; font-weight: bold; margin-bottom: 1rem; text-align: center; }
.chicago-document .source-entry { margin-bottom: 0.5rem; text-indent: -0.5in; padding-left: 0.5in; }

.site-footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--muted);
    font-size: 0.85rem;
    border-top: 1px solid var(--surface2);
}

@media (max-width: 640px) {
    .form-grid,
    .source-row .fields {
        grid-template-columns: 1fr;
    }
}
