/* ===== Accounting App — Professional Stylesheet ===== */

/* --- Base & Reset --- */
*, *::before, *::after { box-sizing: border-box; }

table { border-collapse: collapse; }

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* --- Focus & Form Styles --- */
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

input.field-error, select.field-error, textarea.field-error {
    border-color: #ef4444 !important;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.field-error-msg {
    color: #ef4444;
    font-size: 0.75rem;
    margin-top: 0.25rem;
    display: block;
    animation: fadeSlideIn 0.2s ease;
}

/* --- Tabular Numbers --- */
.font-mono { font-variant-numeric: tabular-nums; }

/* --- Sidebar --- */
#sidebar {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 40;
}

@media (max-width: 1023px) {
    #sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        transform: translateX(-100%);
    }
    #sidebar.sidebar-open {
        transform: translateX(0);
    }
}

@media (min-width: 1024px) {
    #sidebar { transform: translateX(0) !important; }
    #mobile-menu-btn { display: none !important; }
}

aside nav a.active {
    background-color: rgba(255, 255, 255, 0.12);
    color: white;
    border-left: 3px solid #3b82f6;
    padding-left: 13px;
}

aside nav a {
    transition: background-color 0.15s ease, color 0.15s ease;
    border-left: 3px solid transparent;
}

/* --- Breadcrumbs --- */
.breadcrumbs {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.8125rem;
    color: #6b7280;
    padding: 0.5rem 0;
    flex-wrap: wrap;
}

.breadcrumbs a {
    color: #3b82f6;
    text-decoration: none;
    transition: color 0.15s;
}

.breadcrumbs a:hover {
    color: #1d4ed8;
    text-decoration: underline;
}

.breadcrumbs .separator {
    color: #d1d5db;
    user-select: none;
}

.breadcrumbs .current {
    color: #374151;
    font-weight: 500;
}

/* --- Toast Notifications --- */
#toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
    max-width: 24rem;
}

.toast {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    border-radius: 0.5rem;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
    animation: toastIn 0.35s cubic-bezier(0.21, 1.02, 0.73, 1) forwards;
    border-left: 4px solid;
    background: white;
    min-width: 18rem;
}

.toast.removing {
    animation: toastOut 0.3s ease forwards;
}

.toast-success {
    border-left-color: #22c55e;
}
.toast-success .toast-icon { color: #22c55e; }

.toast-error {
    border-left-color: #ef4444;
}
.toast-error .toast-icon { color: #ef4444; }

.toast-warning {
    border-left-color: #f59e0b;
}
.toast-warning .toast-icon { color: #f59e0b; }

.toast-info {
    border-left-color: #3b82f6;
}
.toast-info .toast-icon { color: #3b82f6; }

.toast-icon {
    flex-shrink: 0;
    width: 1.25rem;
    height: 1.25rem;
    margin-top: 0.0625rem;
}

.toast-body {
    flex: 1;
    min-width: 0;
}

.toast-title {
    font-weight: 600;
    font-size: 0.875rem;
    color: #111827;
    line-height: 1.25;
}

.toast-message {
    font-size: 0.8125rem;
    color: #6b7280;
    margin-top: 0.125rem;
    line-height: 1.4;
}

.toast-close {
    flex-shrink: 0;
    background: none;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    padding: 0.125rem;
    line-height: 1;
    font-size: 1.125rem;
    transition: color 0.15s;
}

.toast-close:hover {
    color: #374151;
}

.toast-progress {
    position: absolute;
    bottom: 0;
    left: 4px;
    right: 0;
    height: 3px;
    border-radius: 0 0 0.5rem 0;
    background: currentColor;
    opacity: 0.2;
    animation: toastProgress var(--toast-duration, 5s) linear forwards;
}

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

@keyframes toastOut {
    from { opacity: 1; transform: translateX(0); max-height: 120px; margin-bottom: 0; }
    to { opacity: 0; transform: translateX(100%); max-height: 0; margin-bottom: -0.5rem; }
}

@keyframes toastProgress {
    from { width: 100%; }
    to { width: 0%; }
}

/* --- Loading / Spinner --- */
.btn-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.75;
}

.btn-loading::after {
    content: '';
    position: absolute;
    right: 0.75rem;
    top: 50%;
    margin-top: -0.5rem;
    width: 1rem;
    height: 1rem;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.btn-loading span { visibility: hidden; }

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

/* Global loading bar for HTMX */
#htmx-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    background: linear-gradient(90deg, #3b82f6, #8b5cf6);
    z-index: 9998;
    transition: width 0.3s ease;
    width: 0%;
    opacity: 0;
}

#htmx-progress.active {
    opacity: 1;
}

/* HTMX indicators */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { display: inline-block; }

.htmx-swapping { opacity: 0; transition: opacity 0.15s ease-out; }
.htmx-settling { opacity: 1; transition: opacity 0.15s ease-in; }

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
}

.empty-state-icon {
    width: 2.5rem;
    height: 2.5rem;
    margin: 0 auto 0.75rem;
    color: #d1d5db;
}

.empty-state-title {
    font-size: 1rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 0.375rem;
}

.empty-state-text {
    font-size: 0.875rem;
    color: #9ca3af;
    margin-bottom: 1.25rem;
}

.empty-state-action {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 1rem;
    background: #3b82f6;
    color: white;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    transition: background 0.15s;
}

.empty-state-action:hover {
    background: #2563eb;
}

/* --- Sortable Table Headers --- */
th[data-sort] {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 1.5rem !important;
}

th[data-sort]:hover {
    background-color: #e5e7eb;
}

th[data-sort]::after {
    content: '\2195';
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.7rem;
    color: #9ca3af;
    transition: color 0.15s;
}

th[data-sort].sort-asc::after {
    content: '\2191';
    color: #3b82f6;
}

th[data-sort].sort-desc::after {
    content: '\2193';
    color: #3b82f6;
}

/* --- Confirmation Dialog --- */
.confirm-overlay {
    backdrop-filter: blur(2px);
}

#confirm-modal .modal-panel {
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* --- Sticky Table Headers --- */
thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background-color: inherit;
}

/* --- Cards & Hover --- */
.card-hover {
    transition: box-shadow 0.2s ease, transform 0.15s ease;
}
.card-hover:hover {
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
    transform: translateY(-1px);
}

/* --- Print Styles --- */
@media print {
    .no-print, aside, #sidebar, #sidebar-overlay, header, footer,
    #toast-container, #htmx-progress, .breadcrumbs, #mobile-menu-btn,
    button[type="submit"], .actions-col { display: none !important; }
    main { padding: 0 !important; overflow: visible !important; }
    body { background: white !important; }
    .bg-white { box-shadow: none !important; }
    @page { margin: 1.5cm; }
}

/* --- Animations --- */
@keyframes fadeSlideIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.animate-fade-in { animation: fadeIn 0.3s ease; }

/* --- Error Pages --- */
.error-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    text-align: center;
    padding: 2rem;
    background: #f9fafb;
}

.error-code {
    font-size: 8rem;
    font-weight: 800;
    color: #e5e7eb;
    line-height: 1;
    margin-bottom: 0.5rem;
}

.error-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: #111827;
    margin-bottom: 0.5rem;
}

.error-message {
    font-size: 1rem;
    color: #6b7280;
    margin-bottom: 2rem;
    max-width: 24rem;
}

/* --- Responsive helpers --- */
@media (max-width: 640px) {
    .hide-mobile { display: none !important; }
}

/* --- Scrollbar polish --- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }
