/* ==========================================================================
   Invoice Generator — application design tokens & components
   (kept separate from static/css/invoice.css, which styles the printable
   invoice document only)
   ========================================================================== */

:root {
    --color-primary: #1E3A5F;
    --color-primary-hover: #16324f;
    --color-secondary: #2563EB;
    --color-accent: #059669;
    --color-accent-hover: #047a56;

    --color-background: #F8FAFC;
    --color-foreground: #0F172A;
    --color-card: #FFFFFF;
    --color-card-foreground: #0F172A;
    --color-muted: #F1F3F5;
    --color-muted-foreground: #475569;
    --color-border: #E4E7EB;

    --color-success: #059669;
    --color-success-bg: #ECFDF5;
    --color-warning: #D97706;
    --color-warning-bg: #FFFBEB;
    --color-destructive: #DC2626;
    --color-destructive-bg: #FEF2F2;
    --color-info: #2563EB;
    --color-info-bg: #EFF6FF;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);

    --sidebar-width: 248px;
    --topbar-height: 64px;

    color-scheme: light;
}

* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    background: var(--color-background);
    color: var(--color-foreground);
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

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

.text-muted-2 { color: var(--color-muted-foreground) !important; }

/* ---------------------------------------------------------------------- */
/* Auth screens                                                            */
/* ---------------------------------------------------------------------- */
.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, #0F172A 0%, #1E3A5F 55%, #16324f 100%);
    padding: 24px;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--color-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 40px 36px;
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--color-primary);
    margin-bottom: 28px;
}

.auth-brand .brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--color-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

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

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: #0F1B2E;
    color: #CBD5E1;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1030;
    transition: transform 0.2s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 20px;
    color: #fff;
    font-weight: 700;
    font-size: 1.05rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-brand .brand-mark {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--color-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #fff;
    font-size: 0.9rem;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 16px 12px;
}

.sidebar-section-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #64748B;
    padding: 14px 12px 6px;
    font-weight: 600;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: #CBD5E1;
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 2px;
    transition: background 0.15s ease, color 0.15s ease;
}

.sidebar-link i, .sidebar-link .bi {
    font-size: 1.05rem;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-link:hover {
    background: rgba(255,255,255,0.06);
    color: #fff;
}

.sidebar-link.active {
    background: var(--color-accent);
    color: #fff;
}

.sidebar-footer {
    padding: 14px 20px;
    border-top: 1px solid rgba(255,255,255,0.08);
    font-size: 0.78rem;
    color: #64748B;
}

.main-wrap {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    width: calc(100% - var(--sidebar-width));
}

.topbar {
    height: var(--topbar-height);
    background: var(--color-card);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 1020;
}

.topbar-title {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--color-foreground);
}

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

.user-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 999px;
    background: var(--color-muted);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-foreground);
}

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 999px;
    background: var(--color-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.78rem;
    font-weight: 700;
}

.role-badge {
    font-size: 0.68rem;
    padding: 2px 8px;
    border-radius: 999px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.role-badge.admin { background: var(--color-info-bg); color: var(--color-info); }
.role-badge.user { background: var(--color-muted); color: var(--color-muted-foreground); }

.sidebar-toggle-btn {
    display: none;
}

.content-area {
    padding: 24px 28px 48px;
    flex: 1;
}

/* ---------------------------------------------------------------------- */
/* Cards & surfaces                                                       */
/* ---------------------------------------------------------------------- */
.surface-card {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.surface-card .surface-card-header {
    padding: 18px 22px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.surface-card .surface-card-body {
    padding: 22px;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
    flex-wrap: wrap;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 4px;
}

.page-header p {
    color: var(--color-muted-foreground);
    margin: 0;
    font-size: 0.92rem;
}

/* Stat cards */
.stat-card {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
    height: 100%;
}

.stat-card .stat-label {
    font-size: 0.78rem;
    color: var(--color-muted-foreground);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.stat-card .stat-icon {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.stat-card .stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    margin-top: 8px;
    letter-spacing: -0.01em;
    word-break: break-word;
}

.stat-card .stat-sub {
    font-size: 0.8rem;
    color: var(--color-muted-foreground);
    margin-top: 4px;
}

.icon-tile-primary { background: #EFF3F8; color: var(--color-primary); }
.icon-tile-accent { background: var(--color-success-bg); color: var(--color-accent); }
.icon-tile-info { background: var(--color-info-bg); color: var(--color-info); }
.icon-tile-warning { background: var(--color-warning-bg); color: var(--color-warning); }

/* ---------------------------------------------------------------------- */
/* Buttons                                                                */
/* ---------------------------------------------------------------------- */
.btn {
    font-weight: 600;
    font-size: 0.88rem;
    border-radius: var(--radius-sm);
    padding: 8px 16px;
}

.btn-primary {
    background: var(--color-primary);
    border-color: var(--color-primary);
}
.btn-primary:hover, .btn-primary:focus {
    background: var(--color-primary-hover);
    border-color: var(--color-primary-hover);
}

.btn-accent {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: #fff;
}
.btn-accent:hover {
    background: var(--color-accent-hover);
    border-color: var(--color-accent-hover);
    color: #fff;
}

.btn-outline-soft {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    color: var(--color-foreground);
}
.btn-outline-soft:hover {
    background: var(--color-muted);
    color: var(--color-foreground);
}

.btn:focus-visible, a:focus-visible, .form-control:focus, .form-select:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25);
}

/* ---------------------------------------------------------------------- */
/* Tables                                                                  */
/* ---------------------------------------------------------------------- */
.table-clean {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.88rem;
}

.table-clean thead th {
    background: var(--color-muted);
    color: var(--color-muted-foreground);
    font-weight: 600;
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 10px 14px;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}

.table-clean tbody td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}

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

.table-clean tbody tr:hover {
    background: #FAFBFC;
}

.table-responsive-clean {
    overflow-x: auto;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
}

/* ---------------------------------------------------------------------- */
/* Badges / status pills                                                  */
/* ---------------------------------------------------------------------- */
.pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 700;
}

.pill-success { background: var(--color-success-bg); color: var(--color-accent); }
.pill-warning { background: var(--color-warning-bg); color: var(--color-warning); }
.pill-danger { background: var(--color-destructive-bg); color: var(--color-destructive); }
.pill-neutral { background: var(--color-muted); color: var(--color-muted-foreground); }
.pill-info { background: var(--color-info-bg); color: var(--color-info); }

/* ---------------------------------------------------------------------- */
/* Forms                                                                   */
/* ---------------------------------------------------------------------- */
.form-label {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--color-foreground);
    margin-bottom: 4px;
}

.form-control, .form-select {
    border-radius: var(--radius-sm);
    border-color: var(--color-border);
    font-size: 0.9rem;
    padding: 9px 12px;
}

.form-text {
    font-size: 0.78rem;
    color: var(--color-muted-foreground);
}

.required-mark { color: var(--color-destructive); }

/* Fallback styling for form widgets rendered without explicit Bootstrap classes
   (e.g. Django's built-in PasswordChangeForm / PasswordResetForm) */
form input[type="text"]:not(.form-control),
form input[type="password"]:not(.form-control),
form input[type="email"]:not(.form-control),
form input[type="number"]:not(.form-control) {
    display: block;
    width: 100%;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    font-size: 0.9rem;
    padding: 9px 12px;
}

/* ---------------------------------------------------------------------- */
/* Upload dropzone                                                        */
/* ---------------------------------------------------------------------- */
.dropzone {
    position: relative;
    border: 2px dashed var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-muted);
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone input[type="file"] {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    overflow: hidden;
}

.dropzone:hover, .dropzone.dragover {
    border-color: var(--color-secondary);
    background: var(--color-info-bg);
}

.dropzone .dz-icon {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-lg);
    background: var(--color-card);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    font-size: 1.4rem;
    color: var(--color-secondary);
    box-shadow: var(--shadow-sm);
}

.file-chip {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    background: var(--color-info-bg);
    border: 1px solid #BFDBFE;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-primary);
}

/* ---------------------------------------------------------------------- */
/* Empty states                                                            */
/* ---------------------------------------------------------------------- */
.empty-state {
    text-align: center;
    padding: 56px 24px;
    color: var(--color-muted-foreground);
}

.empty-state .empty-icon {
    width: 64px;
    height: 64px;
    border-radius: 999px;
    background: var(--color-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    font-size: 1.6rem;
    color: var(--color-muted-foreground);
}

/* ---------------------------------------------------------------------- */
/* Toasts                                                                   */
/* ---------------------------------------------------------------------- */
.toast-stack {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1080;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 340px;
    max-width: calc(100vw - 40px);
}

/* ---------------------------------------------------------------------- */
/* Invoice preview frame                                                   */
/* ---------------------------------------------------------------------- */
.preview-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.preview-frame-wrap {
    background: #E9EDF2;
    border: 1px solid var(--color-border);
    border-top: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    padding: 28px;
    overflow: auto;
    display: flex;
    justify-content: center;
}

.preview-frame {
    background: #fff;
    box-shadow: var(--shadow-lg);
    width: 794px;
    min-height: 1123px;
    transform-origin: top center;
    border: none;
}

/* ---------------------------------------------------------------------- */
/* Utility                                                                  */
/* ---------------------------------------------------------------------- */
.mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.fw-semibold { font-weight: 600; }
.section-divider { border-top: 1px solid var(--color-border); margin: 24px 0; }

@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }
    .main-wrap {
        margin-left: 0;
        width: 100%;
    }
    .sidebar-toggle-btn {
        display: inline-flex;
    }
    .preview-frame {
        width: 100%;
        min-width: 640px;
    }
}

@media (max-width: 575.98px) {
    .stat-card .stat-value {
        font-size: 1.25rem;
    }
}
