/* DMS v1.0 – Dark Theme */
:root {
    --bg: #0f172a;
    --bg-card: #1e293b;
    --bg-hover: #334155;
    --bg-input: #0f172a;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --purple: #8b5cf6;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.3);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Navbar */
.navbar {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    height: 56px;
    gap: 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--primary);
    white-space: nowrap;
    text-decoration: none;
}
.nav-brand svg { flex-shrink: 0; }

.nav-links {
    display: flex;
    gap: .25rem;
    flex: 1;
    overflow-x: auto;
}

.nav-links a {
    color: var(--text-muted);
    text-decoration: none;
    padding: .5rem .75rem;
    border-radius: var(--radius);
    font-size: .875rem;
    white-space: nowrap;
    transition: all .15s;
}
.nav-links a:hover, .nav-links a.active {
    color: var(--text);
    background: var(--bg-hover);
}

.nav-badge {
    background: var(--danger);
    color: #fff;
    font-size: .7rem;
    padding: .1rem .4rem;
    border-radius: 10px;
    margin-left: .25rem;
}

.nav-user {
    display: flex;
    align-items: center;
    gap: .75rem;
    white-space: nowrap;
}

.user-badge {
    font-size: .8rem;
    padding: .25rem .6rem;
    border-radius: 20px;
    font-weight: 500;
    background: var(--bg-hover);
    color: var(--text);
}
.user-badge.admin { background: var(--primary); color: #fff; }

.logout-btn {
    color: var(--text-muted);
    text-decoration: none;
    font-size: .8rem;
}
.logout-btn:hover { color: var(--danger); }

/* Container */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
}

h1 { font-size: 1.5rem; margin-bottom: 1rem; }
h1 .count { color: var(--text-muted); font-weight: 400; font-size: 1rem; }
h2 { font-size: 1.15rem; margin-bottom: .75rem; }
h3 { font-size: 1rem; margin-bottom: .5rem; }

/* Page Header */
.page-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}
.page-header h1 { margin-bottom: 0; flex: 1; }
.header-actions { display: flex; gap: .5rem; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .5rem 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    font-size: .875rem;
    cursor: pointer;
    transition: all .15s;
    text-decoration: none;
    white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-warning { background: var(--warning); border-color: var(--warning); color: #000; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--bg-hover); }
.btn-sm { padding: .3rem .6rem; font-size: .8rem; }
.btn-xs { padding: .15rem .4rem; font-size: .75rem; }
.btn-lg { padding: .7rem 1.5rem; font-size: 1rem; }
.btn-block { width: 100%; justify-content: center; }
.btn-danger-text { color: var(--danger); }
.btn-danger-text:hover { background: #ef444420; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: .85rem; color: var(--text-muted); margin-bottom: .3rem; }
.form-input {
    width: 100%;
    padding: .6rem .8rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: .9rem;
    transition: border-color .15s;
}
.form-input:focus { outline: none; border-color: var(--primary); }
.form-input-sm { padding: .4rem .6rem; font-size: .8rem; }
.form-input-lg { padding: .7rem 1rem; font-size: 1.1rem; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
.form-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; }

select.form-input { cursor: pointer; }
textarea.form-input { resize: vertical; min-height: 60px; }
input[type="date"].form-input::-webkit-calendar-picker-indicator { filter: invert(.7); cursor: pointer; }
input[type="color"] { width: 40px; height: 36px; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; background: none; padding: 2px; }

/* Alerts */
.alert {
    padding: .75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: .875rem;
}
.alert-danger { background: #ef444420; color: #fca5a5; border: 1px solid #ef444440; }
.alert-warning { background: #f59e0b20; color: #fcd34d; border: 1px solid #f59e0b40; }
.alert-success { background: #22c55e20; color: #86efac; border: 1px solid #22c55e40; }

/* Stat Cards */
.stat-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    text-align: center;
}
.stat-value { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: .8rem; color: var(--text-muted); margin-top: .25rem; }
.stat-warning .stat-value { color: var(--warning); }
.stat-info .stat-value { color: var(--purple); }

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
}
@media (max-width: 900px) { .dashboard-grid { grid-template-columns: 1fr; } }

.dash-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}
.section-header h2 { margin-bottom: 0; }
.link-more { font-size: .8rem; color: var(--primary); }

/* Document List */
.doc-list { display: flex; flex-direction: column; gap: .5rem; }
.doc-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .75rem;
    background: var(--bg);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    transition: background .15s;
}
.doc-item:hover { background: var(--bg-hover); text-decoration: none; }

.doc-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.doc-icon.pdf { background: #ef444420; color: var(--danger); }
.doc-icon.img { background: #8b5cf620; color: var(--purple); }
.doc-icon.file { background: #3b82f620; color: var(--primary); }

.doc-info { flex: 1; min-width: 0; }
.doc-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-meta { display: flex; gap: .75rem; font-size: .75rem; color: var(--text-muted); flex-wrap: wrap; }
.doc-badges { display: flex; gap: .25rem; flex-wrap: wrap; }

/* Badges */
.badge {
    display: inline-block;
    padding: .15rem .5rem;
    border-radius: 12px;
    font-size: .7rem;
    font-weight: 500;
    white-space: nowrap;
}
.badge-archived { background: #22c55e20; color: var(--success); }
.badge-admin { background: var(--primary); color: #fff; }
.badge-action { background: var(--bg-hover); color: var(--text); }

/* Tags */
.tag-pill {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    padding: .1rem .5rem;
    border-radius: 12px;
    font-size: .7rem;
    font-weight: 500;
}
.tag-pill-lg { padding: .25rem .75rem; font-size: .8rem; }
.tag-remove { background: none; border: none; color: inherit; cursor: pointer; font-size: .9rem; opacity: .7; }
.tag-remove:hover { opacity: 1; }
.tag-more { background: var(--bg-hover); color: var(--text-muted); }

.tag-add { display: flex; gap: .5rem; margin-top: .5rem; }
.tag-add input { flex: 1; }

.tags-display { display: flex; flex-wrap: wrap; gap: .25rem; }

/* Tag Grid */
.tag-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: .75rem;
}
.tag-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: .5rem;
}
.tag-count { font-size: .75rem; color: var(--text-muted); }
.tag-actions { display: flex; gap: .25rem; }

/* Document Table */
.doc-table { overflow-x: auto; }
.doc-table table { width: 100%; border-collapse: collapse; }
.doc-table th {
    text-align: left;
    padding: .6rem .75rem;
    font-size: .75rem;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
}
.doc-table td {
    padding: .6rem .75rem;
    border-bottom: 1px solid var(--border);
    font-size: .85rem;
    vertical-align: middle;
}
.doc-table tr.clickable { cursor: pointer; transition: background .15s; }
.doc-table tr.clickable:hover { background: var(--bg-hover); }

.doc-cell-title { font-weight: 500; }
.doc-cell-nr { font-size: .7rem; color: var(--text-muted); }
.doc-cell-tags { display: flex; gap: .25rem; margin-top: .25rem; flex-wrap: wrap; }

.cat-badge, .type-badge {
    display: inline-block;
    padding: .15rem .5rem;
    border-radius: 12px;
    font-size: .7rem;
    font-weight: 500;
    white-space: nowrap;
}

/* Filter Bar */
.filter-bar {
    display: flex;
    gap: .5rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    align-items: center;
}
.filter-bar .form-input { width: auto; min-width: 120px; }

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .75rem;
    margin-top: 1.5rem;
}
.page-info { font-size: .85rem; color: var(--text-muted); }

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}
.empty-state p { margin-bottom: .75rem; }

/* Detail Grid */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 1.5rem;
    align-items: start;
}
@media (max-width: 1000px) { .detail-grid { grid-template-columns: 1fr; } }

.detail-preview {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    min-height: 500px;
}

.pdf-viewer {
    width: 100%;
    height: 80vh;
    border: none;
    background: #fff;
}

.img-preview {
    width: 100%;
    height: auto;
    display: block;
}

.no-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    color: var(--text-muted);
    gap: .75rem;
}

.detail-meta { display: flex; flex-direction: column; gap: 1rem; }

.meta-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
}

.meta-field {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: .4rem 0;
    gap: 1rem;
}
.meta-field label {
    font-size: .8rem;
    color: var(--text-muted);
    white-space: nowrap;
    min-width: 100px;
}
.meta-value { font-size: .85rem; word-break: break-all; }
.meta-value.hash { font-family: monospace; font-size: .7rem; }

.meta-field .form-input { flex: 1; }

.ai-summary { font-size: .85rem; color: var(--text); line-height: 1.7; }

.fulltext-box {
    max-height: 300px;
    overflow-y: auto;
    background: var(--bg);
    border-radius: var(--radius);
    padding: .75rem;
    margin-top: .5rem;
}
.fulltext-box pre {
    font-size: .75rem;
    white-space: pre-wrap;
    word-wrap: break-word;
    color: var(--text-muted);
}

/* Version list */
.version-list { display: flex; flex-direction: column; gap: .25rem; }
.version-item {
    display: flex;
    justify-content: space-between;
    padding: .4rem .5rem;
    border-radius: 4px;
    font-size: .8rem;
    color: var(--text-muted);
    text-decoration: none;
}
.version-item:hover { background: var(--bg-hover); }
.version-item.current { background: var(--primary)15; color: var(--primary); }

/* Audit list */
.audit-list { display: flex; flex-direction: column; gap: .25rem; }
.audit-entry {
    display: flex;
    gap: .75rem;
    font-size: .75rem;
    padding: .3rem 0;
    border-bottom: 1px solid var(--border);
}
.audit-action { font-weight: 500; min-width: 60px; }
.audit-user { color: var(--text-muted); flex: 1; }
.audit-date { color: var(--text-muted); white-space: nowrap; }

/* Audit table */
.audit-table { overflow-x: auto; }
.audit-table table { width: 100%; border-collapse: collapse; }
.audit-table th {
    text-align: left; padding: .5rem .6rem; font-size: .75rem;
    color: var(--text-muted); border-bottom: 1px solid var(--border);
}
.audit-table td {
    padding: .5rem .6rem; font-size: .8rem;
    border-bottom: 1px solid var(--border); vertical-align: middle;
}
.details-cell { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hash-cell { font-family: monospace; font-size: .7rem; }

/* Upload Page */
.upload-page { max-width: 800px; margin: 0 auto; }

.upload-zone-large {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 3rem 2rem;
    text-align: center;
    transition: all .2s;
    cursor: pointer;
    margin-bottom: 1.5rem;
}
.upload-zone-large:hover, .upload-zone-large.dragover {
    border-color: var(--primary);
    background: var(--primary)08;
}
.upload-zone-large svg { color: var(--text-muted); margin-bottom: .75rem; }
.upload-zone-large h2 { font-size: 1.2rem; margin-bottom: .5rem; }
.upload-buttons { display: flex; gap: .75rem; justify-content: center; margin-top: 1rem; }

.upload-options {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}

.upload-queue { margin-top: 1rem; }
.upload-queue h3 { margin-bottom: .75rem; }
.upload-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .75rem;
    margin-bottom: .5rem;
}
.upload-item-info { display: flex; justify-content: space-between; margin-bottom: .5rem; }
.upload-item-name { font-weight: 500; font-size: .85rem; }
.upload-item-size { color: var(--text-muted); font-size: .8rem; }
.upload-item-progress { height: 4px; background: var(--bg); border-radius: 2px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--primary); border-radius: 2px; transition: width .2s; width: 0; }
.upload-item-status { font-size: .8rem; color: var(--text-muted); margin-top: .25rem; }
.upload-item.upload-success { border-color: var(--success); }
.upload-item.upload-success .progress-bar { background: var(--success); width: 100%; }
.upload-item.upload-success .upload-item-status { color: var(--success); }
.upload-item.upload-success .upload-item-status a { color: var(--success); }
.upload-item.upload-error { border-color: var(--danger); }
.upload-item.upload-error .progress-bar { background: var(--danger); }
.upload-item.upload-error .upload-item-status { color: var(--danger); }

/* Quick upload (dashboard) */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: all .2s;
}
.upload-zone:hover, .upload-zone.dragover { border-color: var(--primary); background: var(--primary)08; }
.upload-zone svg { color: var(--text-muted); margin-bottom: .5rem; }
.upload-zone p { font-size: .85rem; }

/* Search */
.search-page { max-width: 900px; margin: 0 auto; }
.search-box { display: flex; gap: .75rem; margin-bottom: 1rem; }
.search-box .form-input { flex: 1; }
.search-filters { display: flex; gap: .5rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.search-results-page .results-count { font-size: .85rem; color: var(--text-muted); margin-bottom: 1rem; }

/* Inbox */
.inbox-list { display: flex; flex-direction: column; gap: .75rem; }
.inbox-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
}
.inbox-card-header { display: flex; justify-content: space-between; margin-bottom: .5rem; }
.inbox-source-badge {
    padding: .15rem .5rem;
    border-radius: 12px;
    font-size: .7rem;
    font-weight: 500;
    background: var(--primary)20;
    color: var(--primary);
}
.inbox-date { font-size: .75rem; color: var(--text-muted); }
.inbox-file-name { font-weight: 500; margin-bottom: .25rem; }
.inbox-subject, .inbox-from { font-size: .8rem; color: var(--text-muted); }
.inbox-size { font-size: .75rem; color: var(--text-muted); margin-top: .25rem; }
.inbox-suggestion {
    background: var(--bg);
    border-radius: var(--radius);
    padding: .5rem;
    margin-top: .5rem;
    font-size: .8rem;
}
.inbox-card-actions { display: flex; gap: .5rem; margin-top: .75rem; }

.inbox-preview .inbox-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: .5rem 0;
    border-bottom: 1px solid var(--border);
    font-size: .8rem;
}
.inbox-source { color: var(--primary); font-size: .7rem; }

/* Tab Bar */
.tab-bar { display: flex; gap: .25rem; margin-bottom: 1.5rem; border-bottom: 1px solid var(--border); }
.tab {
    padding: .5rem 1rem;
    color: var(--text-muted);
    font-size: .85rem;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    text-decoration: none;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Categories */
.cat-list { display: flex; flex-direction: column; gap: .5rem; }
.cat-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .6rem .75rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    flex-wrap: wrap;
}
.cat-child { margin-left: 2rem; }
.cat-children { width: 100%; display: flex; flex-direction: column; gap: .5rem; margin-top: .5rem; }
.cat-color { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.cat-name { font-weight: 500; flex: 1; }
.cat-retention { font-size: .75rem; color: var(--text-muted); }
.cat-count { font-size: .75rem; color: var(--text-muted); }

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 1rem;
}
.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}
.modal-sm { max-width: 500px; }

/* Toast */
.toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: .6rem 1.2rem;
    border-radius: var(--radius);
    font-size: .85rem;
    opacity: 0;
    transition: all .3s;
    z-index: 300;
    pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.success { background: var(--success); color: #fff; }
.toast.error { background: var(--danger); color: #fff; }
.toast.info { background: var(--bg-card); border: 1px solid var(--border); color: var(--text); }

/* Login */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}
.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
    width: 100%;
    max-width: 380px;
    text-align: center;
}
.login-logo { margin-bottom: 1rem; }
.login-card h1 { font-size: 1.5rem; margin-bottom: .25rem; }
.login-subtitle { color: var(--text-muted); margin-bottom: 1.5rem; font-size: .9rem; }
.login-card .form-group { text-align: left; }

/* Report */
.gobd-report { max-width: 900px; }
.report-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
}
.report-section h2 { color: var(--primary); }
.report-section ul { padding-left: 1.5rem; }
.report-section li { margin-bottom: .5rem; font-size: .875rem; }

.report-table { width: 100%; border-collapse: collapse; }
.report-table th, .report-table td {
    padding: .5rem .75rem;
    border-bottom: 1px solid var(--border);
    font-size: .85rem;
    text-align: left;
}
.report-table th { color: var(--text-muted); font-weight: 600; }

/* Settings */
.settings-grid { display: flex; flex-direction: column; gap: 1.5rem; }
.settings-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

/* Utility */
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }

/* Print */
@media print {
    .navbar, .page-header .btn, .filter-bar { display: none !important; }
    body { background: #fff; color: #000; }
    .container { max-width: 100%; }
    .report-section { border: 1px solid #ddd; break-inside: avoid; }
}

/* Responsive */
@media (max-width: 768px) {
    .navbar { gap: .5rem; padding: 0 .75rem; }
    .nav-links { gap: 0; }
    .nav-links a { padding: .5rem .5rem; font-size: .8rem; }
    .container { padding: 1rem; }
    .filter-bar { flex-direction: column; }
    .filter-bar .form-input { width: 100%; min-width: auto; }
    .stat-cards { grid-template-columns: repeat(2, 1fr); }
    .detail-grid { grid-template-columns: 1fr; }
    .doc-table th:nth-child(n+5), .doc-table td:nth-child(n+5) { display: none; }
    .form-row { grid-template-columns: 1fr; }
}
