/* Design System & Aesthetics */
:root {
    --bg-base: #090d16;
    --bg-surface: #0f172a;
    --bg-surface-elevated: #1e293b;
    --bg-surface-card: rgba(30, 41, 59, 0.7);
    --border-subtle: #273549;
    --border-highlight: #3b82f6;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-glow: rgba(99, 102, 241, 0.35);
    
    --success: #10b981;
    --success-bg: rgba(16, 185, 129, 0.15);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.15);
    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.15);
    
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --shadow-card: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
    --shadow-modal: 0 25px 50px -12px rgba(0, 0, 0, 0.75);
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

.app-layout {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px 32px 64px 32px;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 28px;
    background: var(--bg-surface-card);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    margin-bottom: 24px;
    box-shadow: var(--shadow-card);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 16px;
}

.brand-badge {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1px;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    box-shadow: 0 0 15px var(--primary-glow);
}

.brand-titles h1 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: var(--text-primary);
}

.subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    padding: 6px 14px;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 500;
}

.status-dot {
    width: 8px;
    height: 8px;
    background-color: var(--success);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--success);
}

.user-badge {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    padding: 5px 12px;
    border-radius: var(--radius-md);
}

.user-details {
    display: flex;
    flex-direction: column;
    text-align: right;
}

.user-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.2;
}

.user-email {
    font-size: 11px;
    color: var(--text-secondary);
    line-height: 1.2;
}

.btn-logout {
    padding: 4px 8px !important;
    font-size: 11px !important;
    font-weight: 500;
    text-decoration: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
}

.btn-logout:hover {
    color: var(--danger) !important;
    border-color: rgba(239, 68, 68, 0.3) !important;
    background: rgba(239, 68, 68, 0.1) !important;
}

/* Settings Panel */
.settings-panel {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    margin-bottom: 24px;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease, margin-bottom 0.3s ease;
    max-height: 500px;
    opacity: 1;
}

.settings-panel.collapsed {
    max-height: 0;
    opacity: 0;
    margin-bottom: 0;
    border-color: transparent;
}

.settings-content {
    padding: 24px;
}

.settings-content h3 {
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
}

/* Card Components */
.card {
    background: var(--bg-surface-card);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    margin-bottom: 24px;
}

/* Filter Bar */
.filter-card {
    padding: 20px 24px;
}

.filter-header {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 16px;
}

.filter-header h2 {
    font-size: 16px;
    font-weight: 600;
}

.filter-tip {
    font-size: 12px;
    color: var(--text-muted);
}

.filter-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 16px;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.filter-group label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
}

.filter-actions {
    display: flex;
    gap: 8px;
}

.search-box {
    margin-left: auto;
    min-width: 280px;
}

/* Form Inputs */
.form-input, .form-select {
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: inherit;
    transition: var(--transition);
}

.form-input:focus, .form-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.form-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    display: block;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: var(--transition);
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-primary {
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    color: #fff;
    box-shadow: 0 4px 14px var(--primary-glow);
}

.btn-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, #4f46e5, #4338ca);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px var(--primary-glow);
}

.btn-secondary {
    background: var(--bg-surface-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
}

.btn-secondary:hover:not(:disabled) {
    background: #2a3a52;
    border-color: #3b82f6;
}

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

.btn-ghost:hover:not(:disabled) {
    color: var(--text-primary);
    background: var(--bg-surface-elevated);
}

.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
}

.btn-icon {
    padding: 8px 12px;
}

/* Table Toolbar */
.table-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-subtle);
    background: rgba(15, 23, 42, 0.4);
}

.toolbar-left, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.selection-pill {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-surface-elevated);
    padding: 4px 12px;
    border-radius: 9999px;
    border: 1px solid var(--border-subtle);
}

.selection-pill span {
    color: #818cf8;
    font-weight: 700;
}

/* Custom Checkbox */
.checkbox-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
}

.custom-checkbox {
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--bg-surface-elevated);
    border: 1.5px solid var(--border-subtle);
    border-radius: 4px;
    cursor: pointer;
    position: relative;
    transition: var(--transition);
}

.custom-checkbox:checked {
    background: var(--primary);
    border-color: var(--primary);
}

.custom-checkbox:checked::after {
    content: '';
    position: absolute;
    left: 5px;
    top: 2px;
    width: 4px;
    height: 8px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.checkbox-label {
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
}

/* Table */
.table-responsive {
    overflow-x: auto;
}

.posts-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    text-align: left;
}

.posts-table th {
    background: rgba(15, 23, 42, 0.6);
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-subtle);
}

.posts-table td {
    padding: 14px 16px;
    border-bottom: 1px solid rgba(51, 65, 85, 0.4);
    color: var(--text-primary);
    vertical-align: middle;
}

.posts-table tbody tr {
    transition: var(--transition);
}

.posts-table tbody tr:hover {
    background: rgba(99, 102, 241, 0.05);
}

.posts-table tbody tr.selected {
    background: rgba(99, 102, 241, 0.1);
}

.col-select {
    width: 40px;
    text-align: center;
}

.post-badge {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    color: #818cf8;
    background: rgba(99, 102, 241, 0.15);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(99, 102, 241, 0.3);
}

.badge-batches {
    background: var(--bg-surface-elevated);
    color: var(--text-secondary);
    padding: 3px 8px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 600;
}

.user-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
}

.user-avatar {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #334155;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    color: #94a3b8;
}

/* Modals */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(5, 8, 16, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 24px;
}

.modal-backdrop.hidden {
    display: none;
}

.modal-window {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-modal);
    width: 100%;
    max-width: 960px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalSlideUp 0.25s ease-out;
}

.modal-window.modal-lg {
    max-width: 1100px;
}

@keyframes modalSlideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

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

.modal-header h3 {
    font-size: 18px;
    font-weight: 700;
}

.modal-subtitle {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.modal-header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
    transition: var(--transition);
}

.btn-close:hover {
    color: var(--text-primary);
}

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

.modal-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    border-top: 1px solid var(--border-subtle);
    background: rgba(15, 23, 42, 0.4);
}

.footer-actions-right {
    display: flex;
    gap: 10px;
}

/* Post Preview Cards */
.post-preview-card {
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    overflow: hidden;
}

.post-preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    background: rgba(15, 23, 42, 0.5);
    border-bottom: 1px solid var(--border-subtle);
}

.post-preview-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
    font-size: 14px;
}

.badge {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: var(--radius-sm);
}

.badge-success {
    background: var(--success-bg);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-danger {
    background: var(--danger-bg);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.section-block {
    padding: 16px 18px;
    border-bottom: 1px solid rgba(51, 65, 85, 0.4);
}

.section-block:last-child {
    border-bottom: none;
}

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

.section-header h4 {
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.section-type-badge {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 3px;
    background: #334155;
    color: #e2e8f0;
}

.section-memo {
    font-size: 12px;
    color: var(--text-muted);
}

.preview-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    font-family: 'JetBrains Mono', monospace;
}

.preview-table th {
    color: var(--text-muted);
    font-weight: 500;
    text-align: left;
    padding: 6px 10px;
    border-bottom: 1px solid var(--border-subtle);
}

.preview-table td {
    padding: 6px 10px;
    border-bottom: 1px solid rgba(51, 65, 85, 0.25);
}

.amount-debit {
    color: #38bdf8;
    text-align: right;
    font-weight: 500;
}

.amount-credit {
    color: #f472b6;
    text-align: right;
    font-weight: 500;
}

.raw-iif-code {
    background: #050811;
    color: #a5f3fc;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    line-height: 1.6;
    padding: 16px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    white-space: pre;
    max-height: 60vh;
}

/* Spinner */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.15);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: inline-block;
}

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

.loading-cell {
    text-align: center;
    padding: 40px !important;
    color: var(--text-secondary);
}

.loading-cell span {
    display: block;
    margin-top: 12px;
}

/* Toast */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 2000;
}

.toast {
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    padding: 12px 18px;
    border-radius: var(--radius-sm);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: toastIn 0.25s ease-out;
}

.toast.toast-success {
    border-left: 4px solid var(--success);
}

.toast.toast-error {
    border-left: 4px solid var(--danger);
}

@keyframes toastIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
