/* ============================================================
   Invoicer - Application stylesheet
   ============================================================ */

:root {
    --ivr-primary: #2563eb;
    --ivr-primary-rgb: 37, 99, 235;
    --ivr-primary-dark: #1d4ed8;
    --ivr-primary-light: #dbeafe;
    --ivr-accent: #0ea5e9;
    --ivr-success: #16a34a;
    --ivr-warning: #d97706;
    --ivr-danger: #dc2626;
    --ivr-info: #0891b2;
    --ivr-bg: #f1f5f9;
    --ivr-surface: #ffffff;
    --ivr-surface-2: #f8fafc;
    --ivr-border: #e2e8f0;
    --ivr-text: #0f172a;
    --ivr-text-muted: #64748b;
    --ivr-sidebar-bg: #0f172a;
    --ivr-sidebar-text: #94a3b8;
    --ivr-sidebar-active: #ffffff;
    --ivr-shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
    --ivr-shadow-lg: 0 10px 25px rgba(15, 23, 42, 0.12);
    --ivr-radius: 0.75rem;
    --ivr-transition: 0.2s ease;
}

[data-bs-theme="dark"] {
    --ivr-bg: #0b1120;
    --ivr-surface: #111a2e;
    --ivr-surface-2: #0f1729;
    --ivr-border: #1e293b;
    --ivr-text: #e2e8f0;
    --ivr-text-muted: #94a3b8;
    --ivr-primary-light: #1e3a8a;
    --ivr-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    --ivr-shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.5);
    --ivr-sidebar-bg: #0a0f1e;
    --ivr-sidebar-text: #7c8aa0;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    background: var(--ivr-bg);
    color: var(--ivr-text);
    font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    font-size: 0.925rem;
    transition: background var(--ivr-transition), color var(--ivr-transition);
}

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

a:hover {
    color: var(--ivr-primary-dark);
}

/* ------------------------------------------------------------
   Auth layout
   ------------------------------------------------------------ */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: linear-gradient(135deg, var(--ivr-primary-dark) 0%, var(--ivr-primary) 45%, var(--ivr-accent) 100%);
}

.auth-card {
    width: 100%;
    max-width: 430px;
    background: var(--ivr-surface);
    border-radius: var(--ivr-radius);
    box-shadow: var(--ivr-shadow-lg);
    padding: 2.25rem;
    animation: fadeInUp 0.4s ease;
}

.auth-logo {
    text-align: center;
    margin-bottom: 1.75rem;
}

.auth-logo img {
    max-height: 64px;
    max-width: 200px;
    margin-bottom: 0.5rem;
}

.auth-logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
    color: var(--ivr-text);
}

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

/* ------------------------------------------------------------
   App shell (sidebar + topbar)
   ------------------------------------------------------------ */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    flex-shrink: 0;
    background: var(--ivr-sidebar-bg);
    color: var(--ivr-sidebar-text);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 1040;
    transition: margin-left 0.25s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 1.1rem 1.25rem;
    color: var(--ivr-sidebar-active);
    font-weight: 700;
    font-size: 1.15rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-brand img {
    max-height: 34px;
    max-width: 34px;
    border-radius: 8px;
    object-fit: contain;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 0.5rem;
}

.sidebar-nav .nav-section {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 1rem 0.85rem 0.35rem;
    color: rgba(148, 163, 184, 0.6);
}

.sidebar-nav a.nav-link {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    color: var(--ivr-sidebar-text);
    padding: 0.55rem 0.85rem;
    border-radius: 0.5rem;
    font-weight: 500;
    transition: background var(--ivr-transition), color var(--ivr-transition);
    position: relative;
}

.sidebar-nav a.nav-link i {
    font-size: 1.05rem;
    width: 1.25rem;
    text-align: center;
}

.sidebar-nav a.nav-link:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--ivr-sidebar-active);
}

.sidebar-nav a.nav-link.active {
    background: linear-gradient(135deg, var(--ivr-primary) 0%, var(--ivr-primary-dark) 100%);
    color: var(--ivr-sidebar-active);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    font-size: 0.78rem;
    color: rgba(148, 163, 184, 0.7);
}

.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    background: var(--ivr-surface);
    border-bottom: 1px solid var(--ivr-border);
    padding: 0.65rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 1030;
}

.topbar h5 {
    margin: 0;
    font-weight: 600;
}

.content {
    padding: 1.5rem;
    flex: 1;
}

/* ------------------------------------------------------------
   Cards & widgets
   ------------------------------------------------------------ */
.card {
    background: var(--ivr-surface);
    border: 1px solid var(--ivr-border);
    border-radius: var(--ivr-radius);
    box-shadow: var(--ivr-shadow);
    transition: box-shadow var(--ivr-transition), transform var(--ivr-transition);
}

.card-header {
    background: var(--ivr-surface-2);
    border-bottom: 1px solid var(--ivr-border);
    font-weight: 600;
    padding: 0.9rem 1.25rem;
}

.stat-card {
    position: relative;
    overflow: hidden;
    padding: 1.25rem;
    border-radius: var(--ivr-radius);
    height: 100%;
}

.stat-card .stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    margin-bottom: 0.9rem;
}

.stat-card .stat-label {
    color: var(--ivr-text-muted);
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.25rem;
}

.stat-card .stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1.1;
}

.stat-card .stat-trend {
    font-size: 0.8rem;
    margin-top: 0.4rem;
}

.bg-primary-soft { background: rgba(var(--ivr-primary-rgb), 0.12); color: var(--ivr-primary); }
.bg-success-soft { background: rgba(22, 163, 74, 0.12); color: var(--ivr-success); }
.bg-warning-soft { background: rgba(217, 119, 6, 0.12); color: var(--ivr-warning); }
.bg-danger-soft  { background: rgba(220, 38, 38, 0.12); color: var(--ivr-danger); }
.bg-info-soft    { background: rgba(8, 145, 178, 0.12); color: var(--ivr-info); }

/* ------------------------------------------------------------
   Status badges
   ------------------------------------------------------------ */
.badge-status {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35em 0.7em;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 999px;
    text-transform: capitalize;
}

.badge-status::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.status-draft     { background: #e2e8f0; color: #475569; }
.status-sent      { background: #dbeafe; color: #1d4ed8; }
.status-paid      { background: #dcfce7; color: #15803d; }
.status-partial   { background: #fef3c7; color: #b45309; }
.status-overdue   { background: #fee2e2; color: #b91c1c; }
.status-cancelled { background: #f1f5f9; color: #64748b; }
.status-draft-b   { background: #e2e8f0; color: #475569; }
.status-accepted  { background: #dcfce7; color: #15803d; }
.status-declined  { background: #fee2e2; color: #b91c1c; }
.status-expired   { background: #fef3c7; color: #b45309; }
.status-converted { background: #dbeafe; color: #1d4ed8; }

/* ------------------------------------------------------------
   Tables
   ------------------------------------------------------------ */
.table-app {
    margin: 0;
}

.table-app thead th {
    background: var(--ivr-surface-2);
    color: var(--ivr-text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--ivr-border);
    padding: 0.7rem 1rem;
    white-space: nowrap;
}

.table-app tbody td {
    padding: 0.8rem 1rem;
    border-bottom: 1px solid var(--ivr-border);
    vertical-align: middle;
}

.table-app tbody tr {
    transition: background var(--ivr-transition);
}

.table-app tbody tr:hover {
    background: var(--ivr-surface-2);
}

/* ------------------------------------------------------------
   Forms
   ------------------------------------------------------------ */
.form-label {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--ivr-text);
}

.form-control,
.form-select {
    background-color: var(--ivr-surface);
    border-color: var(--ivr-border);
    color: var(--ivr-text);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--ivr-primary);
    box-shadow: 0 0 0 0.2rem rgba(var(--ivr-primary-rgb), 0.15);
}

.form-control::placeholder {
    color: var(--ivr-text-muted);
    opacity: 0.7;
}

.form-text {
    color: var(--ivr-text-muted);
}

.btn {
    border-radius: 0.5rem;
    font-weight: 600;
    transition: all var(--ivr-transition);
}

.btn-primary {
    background: var(--ivr-primary);
    border-color: var(--ivr-primary);
}

.btn-primary:hover {
    background: var(--ivr-primary-dark);
    border-color: var(--ivr-primary-dark);
    transform: translateY(-1px);
}

.btn-outline-secondary {
    color: var(--ivr-text-muted);
    border-color: var(--ivr-border);
}

/* ------------------------------------------------------------
   Flash toasts
   ------------------------------------------------------------ */
.toast-container {
    z-index: 1080;
}

/* ------------------------------------------------------------
   Invoice / quote document view
   ------------------------------------------------------------ */
.doc-card {
    max-width: 840px;
    margin: 0 auto;
}

.doc-body {
    padding: 2.5rem;
}

.doc-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.doc-title {
    font-size: 1.9rem;
    font-weight: 800;
    letter-spacing: 0.02em;
    color: var(--ivr-primary);
    margin: 0;
}

.doc-logo {
    max-height: 70px;
    max-width: 220px;
    object-fit: contain;
}

.doc-totals {
    width: 100%;
    max-width: 320px;
    margin-left: auto;
}

.doc-totals tr td {
    padding: 0.35rem 0;
}

.doc-totals .grand {
    font-size: 1.15rem;
    font-weight: 700;
    border-top: 2px solid var(--ivr-border);
    padding-top: 0.6rem;
}

/* ------------------------------------------------------------
   Buttons / misc
   ------------------------------------------------------------ */
.dropdown-item i {
    width: 1.15rem;
}

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.filters-bar {
    background: var(--ivr-surface);
    border: 1px solid var(--ivr-border);
    border-radius: var(--ivr-radius);
    padding: 0.9rem 1rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--ivr-shadow);
}

.avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--ivr-primary), var(--ivr-accent));
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
}

.activity-item {
    display: flex;
    gap: 0.85rem;
    padding: 0.6rem 0;
}

.activity-item .activity-icon {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.activity-item small {
    color: var(--ivr-text-muted);
}

/* Line item editor */
.line-item-row {
    border: 1px dashed var(--ivr-border);
    border-radius: 0.6rem;
    padding: 0.75rem;
    margin-bottom: 0.6rem;
    background: var(--ivr-surface-2);
    animation: fadeInUp 0.25s ease;
}

.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--ivr-text-muted);
}

.empty-state i {
    font-size: 3rem;
    color: var(--ivr-border);
    display: block;
    margin-bottom: 0.75rem;
}

.business-card {
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.business-card:hover {
    box-shadow: var(--ivr-shadow-lg);
    transform: translateY(-2px);
}

.business-logo {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    background: var(--ivr-surface-2);
    border: 1px solid var(--ivr-border);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--ivr-text-muted);
    font-size: 1.5rem;
    flex-shrink: 0;
    overflow: hidden;
}

.business-logo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.min-w-0 {
    min-width: 0;
}

/* ------------------------------------------------------------
   Responsive
   ------------------------------------------------------------ */
@media (max-width: 991.98px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        margin-left: -260px;
        box-shadow: var(--ivr-shadow-lg);
    }

    .sidebar.show {
        margin-left: 0;
    }

    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.5);
        z-index: 1035;
        display: none;
    }

    .sidebar-backdrop.show {
        display: block;
    }

    .content {
        padding: 1rem;
    }

    .doc-body {
        padding: 1.25rem;
    }
}

@media (max-width: 575.98px) {
    .topbar {
        padding: 0.6rem 0.85rem;
    }

    .content {
        padding: 0.85rem;
    }

    .stat-card .stat-value {
        font-size: 1.3rem;
    }

    .doc-header {
        flex-direction: column;
    }
}

/* ------------------------------------------------------------
   Print
   ------------------------------------------------------------ */
@media print {
    .no-print {
        display: none !important;
    }

    .sidebar,
    .topbar,
    .toast-container {
        display: none !important;
    }

    .content {
        padding: 0 !important;
    }

    body {
        background: #fff !important;
    }

    .card {
        border: none !important;
        box-shadow: none !important;
    }
}
