:root {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --text: #0f172a;
    --text-muted: #475569;
    --text-soft: #64748b;
    --primary: #1d4ed8;
    --primary-hover: #1e40af;
    --primary-soft: #eff6ff;
    --success: #047857;
    --success-bg: #ecfdf5;
    --success-border: #a7f3d0;
    --danger: #b91c1c;
    --danger-bg: #fef2f2;
    --danger-border: #fecaca;
    --warning: #b45309;
    --warning-bg: #fffbeb;
    --warning-border: #fde68a;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.07);
    --radius: 12px;
    --radius-sm: 8px;
}

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

html, body {
    margin: 0;
    padding: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

a:hover {
    text-decoration: underline;
}

/* Top Navbar */
.topbar {
    background: #0f172a;
    color: #ffffff;
    border-bottom: 1px solid #1e293b;
}

.topbar-inner {
    max-width: 1140px;
    margin: 0 auto;
    padding: 0.875rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    color: #ffffff;
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: -0.01em;
}

.brand:hover {
    text-decoration: none;
}

.brand-icon {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    background: linear-gradient(135deg, #2563eb, #0ea5e9);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    flex-wrap: wrap;
}

.topbar-user {
    font-size: 0.875rem;
    color: #cbd5e1;
    margin-right: 0.25rem;
}

/* Containers */
.container {
    max-width: 1140px;
    margin: 0 auto;
    padding: 1.75rem 1.25rem 3rem;
}

.container-narrow {
    max-width: 760px;
    margin: 0 auto;
    padding: 2rem 1.25rem 3rem;
}

.container-auth {
    max-width: 430px;
    margin: 3.5rem auto;
    padding: 0 1.25rem;
}

/* Cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
}

.card-header {
    margin-bottom: 1.25rem;
}

.card-title {
    margin: 0 0 0.25rem;
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.015em;
}

.card-subtitle {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.94rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.58rem 1rem;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
    text-decoration: none;
    font-family: inherit;
    line-height: 1.25;
}

.btn:hover {
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: #ffffff;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border-strong);
}

.btn-secondary:hover {
    background: var(--surface-muted);
}

.btn-dark-outline {
    background: transparent;
    color: #e2e8f0;
    border-color: #334155;
}

.btn-dark-outline:hover {
    background: #1e293b;
    color: #ffffff;
}

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

.btn-danger:hover {
    background: #991b1b;
}

.btn-sm {
    padding: 0.38rem 0.7rem;
    font-size: 0.81rem;
}

.btn-block {
    width: 100%;
}

/* Alerts */
.alert {
    padding: 0.9rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    margin-bottom: 1.25rem;
    font-size: 0.92rem;
}

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

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

.alert-warning {
    background: var(--warning-bg);
    border-color: var(--warning-border);
    color: var(--warning);
}

.alert-title {
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.alert ul {
    margin: 0.35rem 0 0 1.15rem;
    padding: 0;
}

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

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

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

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

.form-hint {
    font-size: 0.8rem;
    color: var(--text-soft);
    margin-top: 0.3rem;
}

.form-control {
    width: 100%;
    padding: 0.6rem 0.78rem;
    font-size: 0.94rem;
    font-family: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.14);
}

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

/* Dropzone */
.dropzone {
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface-muted);
    padding: 2rem 1.25rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s ease, background-color 0.15s ease;
    position: relative;
}

.dropzone:hover,
.dropzone.is-dragover {
    border-color: var(--primary);
    background: var(--primary-soft);
}

.dropzone-input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
}

.dropzone-icon {
    width: 44px;
    height: 44px;
    margin: 0 auto 0.65rem;
    border-radius: 50%;
    background: #dbeafe;
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.dropzone-title {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text);
}

.dropzone-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

.file-queue {
    margin-top: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.file-queue-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.55rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
}

.file-queue-item.is-invalid {
    border-color: var(--danger-border);
    background: var(--danger-bg);
}

.file-queue-name {
    font-weight: 600;
    word-break: break-word;
}

.file-queue-meta {
    font-size: 0.78rem;
    color: var(--text-soft);
    white-space: nowrap;
}

/* Receipt list after upload */
.receipt-list {
    margin-top: 0.65rem;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.receipt-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: rgba(255, 255, 255, 0.75);
    border: 1px solid var(--success-border);
    border-radius: 6px;
    font-size: 0.875rem;
}

.code-pill {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.8rem;
    background: #f1f5f9;
    color: #0f172a;
    padding: 0.15rem 0.45rem;
    border-radius: 5px;
    border: 1px solid var(--border);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1.25rem;
}

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

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.2rem;
    box-shadow: var(--shadow-sm);
}

.stat-label {
    font-size: 0.82rem;
    color: var(--text-soft);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.stat-value {
    font-size: 1.6rem;
    font-weight: 800;
    margin-top: 0.2rem;
    color: var(--text);
}

/* Filter Bar */
.filter-bar {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
    align-items: center;
}

.filter-search {
    flex: 1 1 240px;
}

.filter-select {
    flex: 0 1 190px;
}

/* Table */
.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.89rem;
    background: var(--surface);
}

table.data-table th {
    text-align: left;
    padding: 0.72rem 0.85rem;
    background: var(--surface-muted);
    color: var(--text-muted);
    font-weight: 700;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

table.data-table td {
    padding: 0.8rem 0.85rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

table.data-table tr:last-child td {
    border-bottom: none;
}

table.data-table tbody tr:hover {
    background: #f8fafc;
}

.doc-title {
    font-weight: 600;
    color: var(--text);
    word-break: break-word;
}

.doc-notes {
    font-size: 0.81rem;
    color: var(--text-soft);
    margin-top: 0.2rem;
    word-break: break-word;
}

.action-group {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.16rem 0.48rem;
    border-radius: 5px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.badge-red { background: #fee2e2; color: #991b1b; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-orange { background: #ffedd5; color: #9a3412; }
.badge-purple { background: #f3e8ff; color: #6b21a8; }
.badge-amber { background: #fef3c7; color: #92400e; }
.badge-slate { background: #e2e8f0; color: #334155; }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--text-soft);
}

/* Modal Preview */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 1000;
}

.modal-backdrop.is-open {
    display: flex;
}

.modal-dialog {
    background: var(--surface);
    border-radius: var(--radius);
    width: 100%;
    max-width: 960px;
    height: 86vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

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

.modal-title {
    font-weight: 700;
    font-size: 0.98rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.modal-body {
    flex: 1;
    background: #1e293b;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
}

.modal-body iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: #ffffff;
}

.modal-body img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.footer-note {
    text-align: center;
    color: var(--text-soft);
    font-size: 0.82rem;
    margin-top: 1.5rem;
}
