/* ============================================
   ALS Web Solution – SaaS Design System
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    /* Brand Colors */
    --primary: #0f172a;
    --primary-light: #1e293b;
    --primary-lighter: #334155;
    --accent: #2563eb;
    --accent-light: #3b82f6;
    --accent-dark: #1d4ed8;
    --accent-glow: rgba(37, 99, 235, 0.15);

    /* Neutral */
    --bg: #f1f5f9;
    --bg-card: #ffffff;
    --bg-sidebar: #0f172a;
    --bg-input: #f8fafc;
    --text: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --divider: #e2e8f0;

    /* Status Colors */
    --status-draft: #94a3b8;
    --status-sent: #3b82f6;
    --status-viewed: #8b5cf6;
    --status-partial: #f59e0b;
    --status-paid: #10b981;
    --status-overdue: #ef4444;
    --status-cancelled: #475569;

    /* Feedback */
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --info: #3b82f6;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07), 0 2px 4px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.08), 0 4px 6px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.1), 0 8px 10px rgba(0, 0, 0, 0.06);
    --shadow-glass: 0 8px 32px rgba(0, 0, 0, 0.08);

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    /* Radius */
    --radius-sm: 6px;
    --radius: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;

    /* Typography */
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-display: 'Poppins', var(--font);
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    /* Transitions */
    --transition: all 0.2s ease;
    --transition-slow: all 0.3s ease;
    --transition-spring: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);

    /* Layout */
    --sidebar-width: 260px;
    --sidebar-collapsed: 72px;
    --header-height: 64px;
    --bottom-nav-height: 64px;
}

/* --- Dark Mode --- */
[data-theme="dark"] {
    --bg: #0b1120;
    --bg-card: #1a2236;
    --bg-sidebar: #0f172a;
    --bg-input: #1e293b;
    --text: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border: #2d3a4f;
    --border-light: #1e293b;
    --divider: #2d3a4f;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.3);
    --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.4);
    --shadow-glass: 0 8px 32px rgba(0, 0, 0, 0.3);
}

/* --- Reset & Base --- */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: var(--transition);
}

a:hover {
    color: var(--accent-light);
}

img {
    max-width: 100%;
    display: block;
}

button,
input,
select,
textarea {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    outline: none;
}

/* --- Typography --- */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: var(--font-display);
    font-weight: 600;
    line-height: 1.3;
    color: var(--text);
}

h1 {
    font-size: 1.75rem;
}

h2 {
    font-size: 1.5rem;
}

h3 {
    font-size: 1.25rem;
}

h4 {
    font-size: 1.1rem;
}

/* --- Layout --- */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: var(--space-xl);
    transition: var(--transition-slow);
    min-height: 100vh;
    overflow-x: hidden;
    width: 0;
    min-width: 0;
}

.sidebar-collapsed .main-content {
    margin-left: var(--sidebar-collapsed);
}

/* --- Sidebar --- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: var(--transition-slow);
    overflow: hidden;
}

.sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed);
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-lg);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    min-height: var(--header-height);
}

.sidebar-logo {
    width: 36px;
    height: 36px;
    background: var(--accent);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #fff;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.sidebar-brand {
    color: #fff;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.1rem;
    white-space: nowrap;
    opacity: 1;
    transition: var(--transition);
}

.sidebar-collapsed .sidebar-brand {
    opacity: 0;
    width: 0;
}

.sidebar-toggle {
    position: absolute;
    top: 20px;
    right: -14px;
    width: 28px;
    height: 28px;
    background: var(--accent);
    border: 3px solid var(--bg);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 0.75rem;
    transition: var(--transition);
    z-index: 101;
}

.sidebar-toggle:hover {
    transform: scale(1.1);
}

.sidebar-nav {
    flex: 1;
    padding: var(--space-md) var(--space-sm);
    overflow-y: auto;
}

.nav-section-title {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: rgba(255, 255, 255, 0.35);
    padding: var(--space-md) var(--space-md) var(--space-xs);
    white-space: nowrap;
}

.sidebar-collapsed .nav-section-title {
    opacity: 0;
    height: 0;
    padding: 0;
    overflow: hidden;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: 10px var(--space-md);
    border-radius: var(--radius);
    color: rgba(255, 255, 255, 0.65);
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 2px;
    white-space: nowrap;
    text-decoration: none;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.nav-item.active {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.nav-item i {
    width: 20px;
    text-align: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.nav-item span {
    opacity: 1;
    transition: var(--transition);
}

.sidebar-collapsed .nav-item span {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

.sidebar-footer {
    padding: var(--space-lg);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.sidebar-user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-light));
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 600;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.sidebar-user-info {
    opacity: 1;
    transition: var(--transition);
    overflow: hidden;
}

.sidebar-collapsed .sidebar-user-info {
    opacity: 0;
    width: 0;
}

.sidebar-user-name {
    color: #fff;
    font-weight: 500;
    font-size: 0.85rem;
}

.sidebar-user-email {
    color: rgba(255, 255, 255, 0.45);
    font-size: 0.7rem;
}

/* --- Page Header --- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-xl);
    flex-wrap: wrap;
    gap: var(--space-md);
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
}

.page-subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 2px;
}

/* --- Cards (Glassmorphism) --- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    box-shadow: var(--shadow);
    transition: var(--transition);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-glass {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

[data-theme="dark"] .card-glass {
    background: rgba(26, 34, 54, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

/* --- Stat Cards --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: var(--space-md);
    margin-bottom: var(--space-xl);
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    display: flex;
    align-items: flex-start;
    gap: var(--space-md);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--accent);
    border-radius: 0 4px 4px 0;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.stat-icon.blue {
    background: rgba(37, 99, 235, 0.1);
    color: var(--accent);
}

.stat-icon.green {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.stat-icon.orange {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
}

.stat-icon.red {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error);
}

.stat-icon.purple {
    background: rgba(139, 92, 246, 0.1);
    color: #8b5cf6;
}

.stat-icon.pink {
    background: rgba(236, 72, 153, 0.1);
    color: #ec4899;
}

.form-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
    line-height: 1.4;
}

.stat-info {
    flex: 1;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.stat-value {
    font-size: 1.35rem;
    font-weight: 700;
    font-family: var(--font-display);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.stat-change {
    font-size: 0.75rem;
    margin-top: 4px;
}

.stat-change.up {
    color: var(--success);
}

.stat-change.down {
    color: var(--error);
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 10px 20px;
    border-radius: var(--radius);
    font-weight: 500;
    font-size: 0.875rem;
    cursor: pointer;
    border: none;
    transition: var(--transition);
    white-space: nowrap;
    text-decoration: none;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}

.btn-primary:hover {
    background: var(--accent-dark);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
    transform: translateY(-1px);
    color: #fff;
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-outline {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--accent);
}

.btn-outline:hover {
    background: var(--accent);
    color: #fff;
}

.btn-danger {
    background: var(--error);
    color: #fff;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    padding: 8px 12px;
}

.btn-ghost:hover {
    background: var(--bg-input);
    color: var(--text);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.btn-lg {
    padding: 12px 28px;
    font-size: 1rem;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    justify-content: center;
    border-radius: var(--radius);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* --- Form Controls --- */
.form-group {
    margin-bottom: var(--space-md);
}

.form-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    transition: var(--transition);
    font-size: 0.9rem;
}

.form-control:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-control::placeholder {
    color: var(--text-muted);
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
    cursor: pointer;
}

textarea.form-control {
    resize: vertical;
    min-height: 80px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
}

.form-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* --- Status Badges --- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-draft {
    background: rgba(148, 163, 184, 0.15);
    color: var(--status-draft);
}

.badge-sent {
    background: rgba(59, 130, 246, 0.12);
    color: var(--status-sent);
}

.badge-viewed {
    background: rgba(139, 92, 246, 0.12);
    color: var(--status-viewed);
}

.badge-partial {
    background: rgba(245, 158, 11, 0.12);
    color: var(--status-partial);
}

.badge-paid {
    background: rgba(16, 185, 129, 0.12);
    color: var(--status-paid);
}

.badge-overdue {
    background: rgba(239, 68, 68, 0.12);
    color: var(--status-overdue);
}

.badge-cancelled {
    background: rgba(71, 85, 105, 0.15);
    color: var(--status-cancelled);
}

/* New Quotation Badges */
.badge-accepted {
    background: rgba(16, 185, 129, 0.15);
    color: #047857;
}

.badge-rejected {
    background: rgba(239, 68, 68, 0.15);
    color: #b91c1c;
}

.badge-expired {
    background: rgba(245, 158, 11, 0.15);
    color: #b45309;
}

.badge-converted {
    background: rgba(59, 130, 246, 0.15);
    color: #1d4ed8;
}

/* --- Tables --- */
.table-container {
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--bg-card);
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background: var(--bg-input);
}

th {
    padding: 12px 16px;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}

td {
    padding: 12px 16px;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background: var(--bg-input);
}

/* --- Invoice Live Preview --- */
.invoice-editor {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-xl);
    align-items: start;
}

.invoice-form {
    position: sticky;
    top: var(--space-xl);
}

.invoice-preview-wrapper {
    position: sticky;
    top: var(--space-xl);
}

.invoice-preview {
    background: #fff;
    color: #0f172a;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    padding: 40px;
    min-height: 842px;
    width: 100%;
    max-width: 595px;
    margin: 0 auto;
    font-size: 12px;
    line-height: 1.5;
    position: relative;
    overflow: hidden;
}

.invoice-preview .preview-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid #e2e8f0;
}

.invoice-preview .preview-logo img {
    max-height: 50px;
    max-width: 150px;
}

.invoice-preview .preview-company-name {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    font-family: var(--font-display);
}

.invoice-preview .preview-invoice-badge {
    font-size: 24px;
    font-weight: 700;
    color: var(--accent);
    text-align: right;
}

.invoice-preview .preview-invoice-id {
    font-size: 11px;
    color: #64748b;
    text-align: right;
}

.preview-meta-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

.preview-section-title {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #94a3b8;
    margin-bottom: 6px;
    font-weight: 600;
}

.preview-items-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
}

.preview-items-table th {
    background: var(--primary);
    color: #fff;
    padding: 8px 10px;
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: left;
}

.preview-items-table th:first-child {
    border-radius: 6px 0 0 0;
}

.preview-items-table th:last-child {
    border-radius: 0 6px 0 0;
    text-align: right;
}

.preview-items-table td {
    padding: 8px 10px;
    font-size: 11px;
    border-bottom: 1px solid #f1f5f9;
}

.preview-items-table tr:nth-child(even) td {
    background: #f8fafc;
}

.preview-items-table td:last-child {
    text-align: right;
    font-weight: 600;
}

.preview-totals {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 24px;
}

.preview-totals-table {
    width: 220px;
}

.preview-totals-table .total-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 11px;
}

.preview-totals-table .grand-total {
    font-size: 16px;
    font-weight: 700;
    color: var(--accent);
    border-top: 2px solid var(--primary);
    margin-top: 6px;
    padding-top: 8px;
}

.preview-stages {
    margin-bottom: 20px;
    padding: 12px;
    background: #f8fafc;
    border-radius: var(--radius);
}

.preview-stage-bar {
    height: 8px;
    background: #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
    margin-top: 8px;
}

.preview-stage-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--success));
    border-radius: 4px;
    transition: width 0.5s ease;
}

.preview-payments {
    margin-bottom: 20px;
}

.preview-footer {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid #e2e8f0;
    font-size: 10px;
    color: #94a3b8;
}

/* --- PDF Page-Break Avoidance --- */
.preview-header,
.preview-meta-grid,
.preview-totals,
.preview-footer,
.preview-stages,
.preview-payments,
#previewDescription {
    page-break-inside: avoid;
    break-inside: avoid;
}

.preview-items-table thead {
    page-break-inside: avoid;
    break-inside: avoid;
}

.preview-items-table tr {
    page-break-inside: avoid;
    break-inside: avoid;
}

/* Long content word-wrapping for PDF */
#previewDescription,
#previewNotes,
#previewTerms,
.preview-items-table td {
    overflow-wrap: break-word;
    word-break: break-word;
}

.preview-signature {
    margin-top: 20px;
    text-align: right;
}

.preview-signature img {
    max-height: 50px;
    display: inline-block;
}

/* --- Invoice Items Editor (Card Layout for all screens) --- */
.items-table-editor {
    width: 100%;
    border-collapse: collapse;
    display: block;
}

.items-table-editor thead {
    display: none;
}

.items-table-editor tbody,
.items-table-editor tr {
    display: block;
    width: 100%;
}

.items-table-editor tr {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: var(--space-sm);
    padding: var(--space-md);
    position: relative;
}

.items-table-editor td {
    padding: 4px 0;
    display: block;
    border: none;
}

/* Full-width fields: Item name & description */
.items-table-editor td[data-label="Item"],
.items-table-editor td[data-label="Description"] {
    display: block;
    width: 100%;
    margin-bottom: 8px;
}

/* Numeric fields */
.items-table-editor td.col-qty,
.items-table-editor td.col-price,
.items-table-editor td.col-tax,
.items-table-editor td.col-disc {
    display: inline-block;
    margin-bottom: 8px;
    vertical-align: top;
}

/* Total & delete */
.items-table-editor td.col-total {
    display: inline-block;
    width: auto;
    font-weight: 600;
    color: var(--accent);
    font-size: 1rem;
    vertical-align: middle;
    margin-top: 6px;
}

.items-table-editor td.col-action {
    display: inline-block;
    position: absolute;
    top: var(--space-md);
    right: var(--space-md);
    width: auto;
    border: none;
    padding: 0;
}

/* Show labels above each field */
.items-table-editor td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.items-table-editor td.col-action::before {
    display: none;
}

.items-table-editor .item-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text);
    font-size: 0.85rem;
    transition: var(--transition);
}

.items-table-editor .item-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.item-total-display {
    display: inline-block;
    padding: 6px 0;
}

.btn-remove-item {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(239, 68, 68, 0.1);
    color: var(--error);
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.btn-remove-item:hover {
    background: var(--error);
    color: #fff;
}

/* Responsive grid for numeric fields */
@media (min-width: 769px) {
    .items-table-editor td.col-qty,
    .items-table-editor td.col-price,
    .items-table-editor td.col-tax,
    .items-table-editor td.col-disc {
        width: calc(25% - 10px);
        margin-right: 10px;
    }
    .items-table-editor td.col-disc {
        margin-right: 0;
    }
}

/* --- Stage Editor --- */
.stage-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm);
    background: var(--bg-input);
    border-radius: var(--radius);
    margin-bottom: var(--space-sm);
    animation: slideIn 0.3s ease;
}

.stage-progress {
    width: 100%;
    height: 10px;
    background: var(--border);
    border-radius: 5px;
    overflow: hidden;
    margin-top: var(--space-sm);
}

.stage-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--success));
    border-radius: 5px;
    transition: width 0.5s ease;
}

/* --- Payments List --- */
.payment-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md);
    background: var(--bg-input);
    border-radius: var(--radius);
    margin-bottom: var(--space-sm);
    border-left: 3px solid var(--success);
}

.payment-amount {
    font-weight: 700;
    font-size: 1rem;
    color: var(--success);
}

/* --- Search & Filters --- */
.toolbar {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
    flex-wrap: wrap;
}

.search-box {
    position: relative;
    flex: 1;
    min-width: 200px;
    max-width: 360px;
}

.search-box i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.9rem;
}

.search-box input {
    width: 100%;
    padding: 10px 14px 10px 38px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.875rem;
}

.search-box input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.filter-group {
    display: flex;
    gap: var(--space-sm);
    align-items: center;
}

/* --- Modal --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.modal {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    width: 90%;
    max-width: 560px;
    max-height: 85vh;
    overflow-y: auto;
    transform: scale(0.95) translateY(10px);
    transition: var(--transition-spring);
}

.modal-overlay.active .modal {
    transform: scale(1) translateY(0);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-lg);
    border-bottom: 1px solid var(--border);
}

.modal-title {
    font-size: 1.1rem;
    font-weight: 600;
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--bg-input);
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.modal-close:hover {
    background: var(--error);
    color: #fff;
}

.modal-body {
    padding: var(--space-lg);
}

.modal-footer {
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
}

/* --- Tabs --- */
.tabs {
    display: flex;
    gap: 2px;
    border-bottom: 2px solid var(--border);
    margin-bottom: var(--space-lg);
}

.tab {
    padding: 10px 20px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    border: none;
    background: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: var(--transition);
}

.tab:hover {
    color: var(--text);
}

.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

/* --- Toast Notifications --- */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: 14px 20px;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    border-left: 4px solid var(--accent);
    min-width: 300px;
    max-width: 450px;
    animation: slideInRight 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    transition: var(--transition);
}

.toast.toast-success {
    border-left-color: var(--success);
}

.toast.toast-error {
    border-left-color: var(--error);
}

.toast.toast-warning {
    border-left-color: var(--warning);
}

.toast.toast-info {
    border-left-color: var(--info);
}

.toast-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}

.toast-success .toast-icon {
    color: var(--success);
}

.toast-error .toast-icon {
    color: var(--error);
}

.toast-warning .toast-icon {
    color: var(--warning);
}

.toast-info .toast-icon {
    color: var(--info);
}

.toast-message {
    flex: 1;
    font-size: 0.85rem;
}

.toast-close {
    cursor: pointer;
    color: var(--text-muted);
    background: none;
    border: none;
    font-size: 1rem;
    padding: 4px;
    transition: var(--transition);
}

.toast-close:hover {
    color: var(--text);
}

.toast.removing {
    animation: slideOutRight 0.3s ease forwards;
}

/* --- Loading Spinner --- */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
}

.loading-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.spinner {
    width: 44px;
    height: 44px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* --- Auto-Save Indicator --- */
.autosave-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 4px 10px;
    border-radius: var(--radius-full);
    background: var(--bg-input);
    opacity: 0;
    transition: var(--transition);
}

.autosave-indicator.visible {
    opacity: 1;
}

.autosave-indicator.saving {
    color: var(--warning);
}

.autosave-indicator.saved {
    color: var(--success);
}

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: var(--space-2xl);
    color: var(--text-muted);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: var(--space-md);
    opacity: 0.3;
}

.empty-state h3 {
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
}

/* --- Charts --- */
.chart-container {
    position: relative;
    height: 300px;
    width: 100%;
}

/* --- Login Page --- */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
    padding: var(--space-lg);
    position: relative;
    overflow: hidden;
}

.auth-page::before {
    content: '';
    position: absolute;
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, rgba(37, 99, 235, 0.15), transparent 70%);
    top: -100px;
    right: -100px;
    border-radius: 50%;
}

.auth-page::after {
    content: '';
    position: absolute;
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, rgba(37, 99, 235, 0.1), transparent 70%);
    bottom: -100px;
    left: -100px;
    border-radius: 50%;
}

.auth-card {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 440px;
    padding: var(--space-2xl);
    position: relative;
    z-index: 1;
    animation: fadeInUp 0.5s ease;
}

.auth-logo {
    text-align: center;
    margin-bottom: var(--space-xl);
}

.auth-logo-icon {
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, var(--accent), var(--accent-light));
    border-radius: var(--radius-md);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: var(--space-md);
    box-shadow: 0 4px 15px rgba(37, 99, 235, 0.3);
}

.auth-logo h1 {
    font-size: 1.5rem;
    color: var(--primary);
    font-family: var(--font-display);
}

.auth-logo p {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-top: 4px;
}

.auth-tabs {
    display: flex;
    background: #f1f5f9;
    border-radius: var(--radius);
    padding: 4px;
    margin-bottom: var(--space-xl);
}

.auth-tab {
    flex: 1;
    padding: 10px;
    text-align: center;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    transition: var(--transition);
}

.auth-tab.active {
    background: #fff;
    color: var(--accent);
    box-shadow: var(--shadow-sm);
}

.auth-form {
    display: none;
}

.auth-form.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

.auth-form .form-control {
    background: #f8fafc;
    border-color: #e2e8f0;
}

.auth-submit {
    width: 100%;
    padding: 12px;
    margin-top: var(--space-md);
}

.auth-link {
    text-align: center;
    margin-top: var(--space-md);
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.auth-link a {
    font-weight: 500;
}

/* --- Animations --- */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideOutRight {
    from {
        opacity: 1;
        transform: translateX(0);
    }

    to {
        opacity: 0;
        transform: translateX(100px);
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

/* --- Public Invoice View --- */
.public-invoice-page {
    min-height: 100vh;
    background: var(--bg);
    padding: var(--space-xl);
    display: flex;
    justify-content: center;
}

.public-invoice-container {
    max-width: 800px;
    width: 100%;
}

.public-invoice-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
    margin-bottom: var(--space-lg);
}

/* Quotation Specific Additions */
.public-invoice-actions .btn-success {
    background: #10b981;
    color: white;
    border: none;
}
.public-invoice-actions .btn-success:hover {
    background: #059669;
}
.public-invoice-actions .btn-danger {
    background: #ef4444;
    color: white;
    border: none;
}
.public-invoice-actions .btn-danger:hover {
    background: #dc2626;
}
.comment-box {
    width: 100%;
    margin-top: 1rem;
    padding: 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-input);
}
.email-template-box {
    background: var(--bg-input);
    padding: 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    font-family: inherit;
    font-size: 0.9rem;
    white-space: pre-wrap;
    max-height: 300px;
    overflow-y: auto;
}

/* --- Theme Color Picker --- */
.color-picker-grid {
    display: flex;
    gap: var(--space-sm);
    flex-wrap: wrap;
}

.color-swatch {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid transparent;
    transition: var(--transition);
}

.color-swatch:hover {
    transform: scale(1.15);
}

.color-swatch.active {
    border-color: var(--text);
    box-shadow: 0 0 0 2px var(--bg);
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* --- Mobile Bottom Nav --- */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    z-index: 100;
    justify-content: space-around;
    align-items: center;
    padding: 0 var(--space-sm);
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    font-size: 0.65rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px 12px;
    border-radius: var(--radius);
    transition: var(--transition);
    text-decoration: none;
    border: none;
    background: none;
}

.bottom-nav-item i {
    font-size: 1.15rem;
}

.bottom-nav-item.active {
    color: var(--accent);
}

.bottom-nav-item:hover {
    color: var(--accent);
}

/* ============================================
   RESPONSIVE SYSTEM – Single authoritative source
   No duplicates. Mobile-first breakpoints.
   ============================================ */

/* --- Loading Overlay & Spinner --- */
.loading-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: var(--space-md);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.loading-overlay.active {
    display: flex;
}

.spinner {
    width: 44px;
    height: 44px;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loading-overlay .loading-text {
    color: #fff;
    font-size: 0.9rem;
    font-weight: 500;
    letter-spacing: 0.3px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Skeleton shimmer loading */
.skeleton {
    background: linear-gradient(90deg,
            var(--bg-input) 25%,
            var(--border-light) 50%,
            var(--bg-input) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
}

.skeleton-text {
    height: 14px;
    margin-bottom: 8px;
    width: 80%;
}

.skeleton-text:last-child {
    width: 60%;
}

.skeleton-card {
    height: 80px;
    margin-bottom: var(--space-md);
}

.skeleton-row {
    height: 48px;
    margin-bottom: var(--space-sm);
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

/* Disabled button state */
button:disabled,
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* --- Utility Classes --- */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.mt-sm {
    margin-top: var(--space-sm);
}

.mt-md {
    margin-top: var(--space-md);
}

.mt-lg {
    margin-top: var(--space-lg);
}

.mb-md {
    margin-bottom: var(--space-md);
}

.mb-lg {
    margin-bottom: var(--space-lg);
}

.gap-sm {
    gap: var(--space-sm);
}

.flex {
    display: flex;
}

.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

.flex-wrap {
    flex-wrap: wrap;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
}

/* Desktop-only / Mobile-only */
.desktop-only {
    display: initial;
}

.mobile-only {
    display: none !important;
}

/* Mobile overlay */
.mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 150;
    cursor: pointer;
}

.mobile-overlay.active {
    display: block;
}

/* Mobile hamburger button – hidden on desktop, shown via CSS on mobile */
.mobile-menu-btn {
    display: none;
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 1.1rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    flex-shrink: 0;
}

.mobile-menu-btn:hover {
    background: var(--bg-input);
}

/* ---- Tablet ≤ 1024px ---- */
@media (max-width: 1024px) {
    .invoice-editor {
        grid-template-columns: 1fr;
    }

    .invoice-preview-wrapper {
        position: relative;
        top: 0;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ---- Mobile (768px) ---- */
@media (max-width: 768px) {

    /* Sidebar: slide off-screen on mobile, ignore collapsed state */
    .sidebar {
        transform: translateX(-100%);
        z-index: 200;
        width: var(--sidebar-width) !important;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: var(--shadow-xl);
    }

    /* Fix: sidebar-collapsed class should NOT affect layout on mobile */
    .main-content,
    .sidebar-collapsed .main-content {
        margin-left: 0 !important;
        padding: var(--space-md);
        padding-bottom: calc(var(--bottom-nav-height) + var(--space-md));
    }

    /* Show bottom nav, hide sidebar toggle */
    .bottom-nav {
        display: flex;
    }

    .sidebar-toggle {
        display: none;
    }

    /* Page header: stack vertically, keep button accessible */
    .page-header {
        flex-direction: column;
        align-items: stretch;
        gap: var(--space-sm);
    }

    .page-header .btn {
        align-self: stretch;
        justify-content: center;
    }

    /* Stats: 2-column on mobile */
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: var(--space-sm);
    }

    .stat-card {
        padding: var(--space-sm) var(--space-md);
    }

    .stat-value {
        font-size: 1rem;
    }

    .stat-icon {
        width: 36px;
        height: 36px;
        font-size: 0.9rem;
    }

    .stat-label {
        font-size: 0.7rem;
    }

    /* Toolbar: stack */
    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .search-box {
        max-width: 100%;
    }

    .filter-group {
        flex-wrap: wrap;
    }

    .filter-group select {
        flex: 1;
        min-width: 0;
    }

    /* Forms: single column */
    .form-row {
        grid-template-columns: 1fr;
    }

    .grid-2 {
        grid-template-columns: 1fr;
    }

    /* Auth card */
    .auth-card {
        padding: var(--space-lg);
    }

    /* Invoice preview – scaled down to fit mobile, keeps desktop proportions */
    .invoice-preview-wrapper {
        overflow: hidden;
    }

    .invoice-preview {
        padding: 40px !important;
        font-size: 12px !important;
        min-height: auto;
        max-width: none;
        width: 595px;
        min-width: 595px;
        box-sizing: border-box;
        transform-origin: top left;
        /* Scale is set dynamically via JS */
    }

    .invoice-preview .preview-header {
        flex-direction: row !important;
        justify-content: space-between !important;
        gap: var(--space-md);
        margin-bottom: 30px;
        padding-bottom: 20px;
    }

    .invoice-preview .preview-invoice-badge {
        text-align: right !important;
        font-size: 24px !important;
    }

    .invoice-preview .preview-invoice-id {
        text-align: right !important;
    }

    /* Tabs: scrollable on mobile */
    .tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .tabs::-webkit-scrollbar {
        display: none;
    }

    .tab {
        padding: 8px 14px;
        font-size: 0.8rem;
        flex-shrink: 0;
    }

    /* Cards: reduce padding on mobile */
    .card {
        padding: var(--space-md);
    }

    /* Toast: full width on mobile */
    .toast-container {
        left: 12px;
        right: 12px;
        top: 12px;
    }

    .toast {
        min-width: auto;
        max-width: 100%;
    }

    /* Modal: full-width on small screens */
    .modal {
        width: 95%;
        max-height: 90vh;
    }

    /* ---- TABLE → CARD CONVERSION on mobile ---- */
    .table-container {
        border: none;
        background: transparent;
        overflow: visible;
    }

    .table-container table,
    .table-container thead,
    .table-container tbody,
    .table-container th,
    .table-container tr {
        display: block;
    }

    .table-container thead {
        display: none;
    }

    .table-container tr {
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: var(--radius-md);
        padding: var(--space-md);
        margin-bottom: var(--space-sm);
        display: flex;
        flex-wrap: wrap;
        gap: var(--space-xs) var(--space-md);
        align-items: center;
        position: relative;
        box-shadow: var(--shadow-sm);
    }

    .table-container tr:hover td {
        background: transparent;
    }

    .table-container td {
        border: none;
        padding: 2px 0;
        font-size: 0.85rem;
        display: inline-flex;
        align-items: center;
    }

    .table-container td::before {
        content: attr(data-label);
        font-size: 0.7rem;
        font-weight: 600;
        color: var(--text-muted);
        text-transform: uppercase;
        letter-spacing: 0.5px;
        margin-right: 6px;
        display: none;
    }

    /* Mobile adjustments for item cards */
    .items-table-editor tr {
        padding: var(--space-sm);
    }
    .items-table-editor td.col-action {
        top: var(--space-sm);
        right: var(--space-sm);
    }
    .items-table-editor td.col-qty,
    .items-table-editor td.col-price,
    .items-table-editor td.col-tax,
    .items-table-editor td.col-disc {
        width: calc(50% - 6px);
    }
    .items-table-editor td.col-qty,
    .items-table-editor td.col-tax {
        margin-right: 6px;
    }

    /* Invoice totals display on mobile */
    .preview-totals {
        justify-content: stretch;
    }

    .preview-totals-table {
        width: 100%;
    }

    /* Stage item: wrap on mobile */
    .stage-item {
        flex-wrap: wrap;
    }

    .stage-item .form-control {
        min-width: 0;
    }

    /* Payment item: stack */
    .payment-item {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-xs);
    }

    /* Public invoice actions */
    .public-invoice-actions {
        flex-wrap: wrap;
    }
}

/* ---- Small phone (480px) ---- */
@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
        gap: var(--space-sm);
    }

    h1 {
        font-size: 1.25rem;
    }

    h2 {
        font-size: 1.15rem;
    }

    .page-title {
        font-size: 1.2rem;
    }

    .main-content {
        padding: var(--space-sm) !important;
        padding-bottom: calc(var(--bottom-nav-height) + var(--space-sm)) !important;
    }

    .btn {
        padding: 8px 14px;
        font-size: 0.8rem;
    }

    .btn-sm {
        padding: 5px 10px;
        font-size: 0.75rem;
    }

    .stat-card {
        padding: var(--space-sm) var(--space-md);
    }

    .stat-label {
        font-size: 0.7rem;
    }

    .stat-value {
        font-size: 1.1rem;
    }

    .stat-icon {
        width: 36px;
        height: 36px;
        font-size: 0.9rem;
    }

    .preview-meta-grid {
        grid-template-columns: 1fr 1fr;
        gap: var(--space-sm);
    }

    .invoice-preview .preview-company-name {
        font-size: 14px;
    }

    .invoice-preview .preview-invoice-badge {
        font-size: 16px;
    }
}


/* ---- Show mobile-menu-btn & toggle desktop/mobile visibility at 768px ---- */
@media (max-width: 768px) {
    .mobile-menu-btn {
        display: flex;
    }

    .desktop-only {
        display: none !important;
    }

    .mobile-only {
        display: initial !important;
    }

    /* Mobile invoice editor: hide preview wrapper, show via tab */
    .invoice-preview-wrapper {
        display: none;
    }

    .invoice-preview-wrapper.mobile-tab-active {
        display: block;
    }
}

/* ---- Print Media ---- */
@media print {

    .public-invoice-actions,
    .bottom-nav,
    .sidebar,
    .mobile-overlay,
    .mobile-menu-btn,
    .toast-container,
    .loading-overlay,
    .page-header .btn,
    nav {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
        padding: 0 !important;
    }

    .invoice-preview {
        box-shadow: none !important;
        border-radius: 0 !important;
    }
}

/* --- Modern Confirm Dialog --- */
.confirm-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.confirm-overlay.active {
    display: flex;
}

.confirm-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    max-width: 400px;
    width: 90%;
    box-shadow: var(--shadow-xl);
    text-align: center;
    animation: confirmSlideIn 0.25s ease;
}

@keyframes confirmSlideIn {
    from {
        opacity: 0;
        transform: translateY(-16px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.confirm-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: rgba(239, 68, 68, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto var(--space-md);
    font-size: 1.5rem;
    color: var(--error);
}

.confirm-title {
    font-family: var(--font-display);
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: var(--space-sm);
}

.confirm-message {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-lg);
    line-height: 1.5;
}

.confirm-actions {
    display: flex;
    gap: var(--space-sm);
    justify-content: center;
}

.confirm-actions .btn {
    min-width: 100px;
    justify-content: center;
}