/* =============================================
   SimpleInvoice v2 - Base Styles
   ============================================= */

:root {
    /* Core Colors */
    --bg-dark: #0f0f14;
    --bg-card: #18181f;
    --bg-elevated: #1f1f28;

    /* Accent - Configurable via JS */
    --accent: #6366f1;
    --accent-glow: rgba(99, 102, 241, 0.3);
    --accent-soft: rgba(99, 102, 241, 0.1);

    /* Neutrals */
    --text-primary: #ffffff;
    --text-secondary: #a1a1aa;
    --text-muted: #52525b;
    --border: rgba(255, 255, 255, 0.08);
    --border-focus: rgba(255, 255, 255, 0.2);

    /* Document Colors */
    --doc-bg: #ffffff;
    --doc-text: #1a1a1a;
    --doc-secondary: #6b7280;
    --doc-border: #e5e7eb;

    /* Sidebar */
    --sidebar-width: 280px;

    /* Spacing */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;

    /* Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    /* Transitions */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --transition-fast: 0.15s var(--ease-out);
    --transition-normal: 0.3s var(--ease-out);

    /* Typography */
    --font-sans: 'Outfit', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

/* Reset */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Ambient Background */
.ambient-bg {
    position: fixed;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: 0;
}

.gradient-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.4;
    animation: float 20s ease-in-out infinite;
}

.orb-1 {
    width: 600px;
    height: 600px;
    background: var(--accent);
    top: -200px;
    right: -100px;
    animation-delay: 0s;
}

.orb-2 {
    width: 500px;
    height: 500px;
    background: #ec4899;
    bottom: -150px;
    left: -100px;
    animation-delay: -7s;
}

.orb-3 {
    width: 400px;
    height: 400px;
    background: #14b8a6;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation-delay: -14s;
}

@keyframes float {

    0%,
    100% {
        transform: translate(0, 0) scale(1);
    }

    25% {
        transform: translate(30px, -30px) scale(1.05);
    }

    50% {
        transform: translate(-20px, 20px) scale(0.95);
    }

    75% {
        transform: translate(20px, 30px) scale(1.02);
    }
}

/* App Container */
#app {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    padding: var(--space-6);
    padding-top: 120px;
    margin-left: var(--sidebar-width);
    margin-right: var(--sidebar-width);
    transition: margin var(--transition-normal);
}

body.sidebar-left-collapsed #app {
    margin-left: 48px;
}

body.sidebar-right-collapsed #app {
    margin-right: 48px;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-elevated);
    border-radius: 5px;
    border: 2px solid var(--bg-dark);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Common Sidebar Styles */
.sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: rgba(24, 24, 31, 0.98);
    backdrop-filter: blur(20px);
    z-index: 100;
    display: flex;
    flex-direction: column;
    transition: width var(--transition-normal);
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4);
    border-bottom: 1px solid var(--border);
}

.sidebar-title {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.sidebar-title svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: var(--accent);
    stroke-width: 2;
}

.sidebar-toggle {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.sidebar-toggle:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.sidebar-toggle svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    transition: transform var(--transition-fast);
}

.sidebar-content {
    flex: 1;
    overflow: hidden;
    /* Changed from auto to hidden to allow inner sections to scroll independently */
    display: flex;
    flex-direction: column;
}

.sidebar.collapsed .sidebar-title span,
.sidebar.collapsed .sidebar-content,
.sidebar.collapsed .section-header span,
.sidebar.collapsed .collapsible-content {
    display: none;
}

.sidebar.collapsed .sidebar-header {
    justify-content: center;
    padding: var(--space-3);
}

.sidebar.collapsed .sidebar-title {
    display: none;
}

/* Responsive */
@media (min-width: 769px) {
    .sidebar {
        width: var(--sidebar-width);
    }
}

@media (max-width: 1100px) {
    #app {
        margin-left: 48px;
    }
}

@media (max-width: 768px) {

    /* Mobile Sidebar - Overlay Mode */
    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        width: 85vw;
        /* Not full screen, leave gap */
        max-width: 320px;
        height: 100dvh;
        /* Use dynamic viewport height */
        transform: translateX(-100%);
        z-index: 1000;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
    }

    #sidebar-right {
        right: 0;
        left: auto;
        transform: translateX(100%);
        border-left: 1px solid var(--border);
    }

    .sidebar.expanded {
        transform: translateX(0);
    }

    /* When Right Sidebar is expanded */
    #sidebar-right:not(.collapsed) {
        transform: translateX(0);
    }

    .sidebar.collapsed {
        /* On mobile, collapsed means hidden off-screen */
        width: 85vw;
        transform: translateX(-100%);
    }

    #sidebar-right.collapsed {
        transform: translateX(100%);
    }

    /* Hide the mini-strip logic on mobile */
    .sidebar.collapsed .sidebar-title svg,
    .sidebar.collapsed .sidebar-toggle {
        display: none;
    }

    /* App Content */
    #app {
        margin-left: 0 !important;
        margin-right: 0 !important;
        padding: var(--space-4);
        padding-top: 80px;
        /* Space for fixed header */
        width: 100%;
        max-width: 100vw;
        overflow-x: hidden;
    }

    /* App Header / Toolbar needs to be fixed */
    .app-header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 900;
        background: rgba(15, 15, 20, 0.95);
        backdrop-filter: blur(12px);
        padding: var(--space-2) var(--space-4);
        height: 64px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        border-bottom: 1px solid var(--border);
    }

    /* Backdrop for open sidebars */
    body.sidebar-open::before {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.7);
        z-index: 950;
        backdrop-filter: blur(2px);
    }
}

/* GDPR Feature Styles */
.cookie-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-top: 1px solid var(--accent);
    padding: var(--space-4);
    z-index: 1000;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
}

.cookie-content {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
}

.cookie-content p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    flex: 1;
    min-width: 200px;
}

.cookie-actions {
    display: flex;
    gap: var(--space-3);
    align-items: center;
}

.cookie-btn {
    padding: var(--space-2) var(--space-4);
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
}

.cookie-link {
    background: none;
    border: none;
    color: var(--text-muted);
    text-decoration: underline;
    cursor: pointer;
    font-size: 0.9rem;
    white-space: nowrap;
}

/* 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: 1100;
}

.modal-content {
    background: var(--bg-card);
    width: 90%;
    max-width: 500px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    animation: modalSlide 0.3s var(--ease-out);
}

@keyframes modalSlide {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-4);
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 1.25rem;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: var(--space-1);
    border-radius: var(--radius-sm);
    display: flex;
}

.modal-close:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.modal-close svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
}

.modal-body {
    padding: var(--space-4);
    max-height: 70vh;
    overflow-y: auto;
}

.modal-body h3 {
    font-size: 1rem;
    color: var(--accent);
    margin-bottom: var(--space-2);
    margin-top: var(--space-4);
}

.modal-body h3:first-child {
    margin-top: 0;
}

.modal-body p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    /* Added color for better readability */
    line-height: 1.6;
    margin-bottom: var(--space-2);
}

/* App Footer */
.app-footer {
    max-width: 800px;
    margin: var(--space-10) auto 0;
    padding: var(--space-6);
    border-top: 1px solid var(--border);
    text-align: center;
    color: var(--text-secondary);
}

.footer-links {
    display: flex;
    justify-content: center;
    gap: var(--space-6);
    margin-bottom: var(--space-4);
    flex-wrap: wrap;
}

.footer-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color var(--transition-fast);
}

.footer-link:hover {
    color: var(--accent);
}

.footer-copy {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* SEO / Intro Section */
.seo-intro-section {
    max-width: 800px;
    margin: var(--space-8) auto;
    padding: var(--space-6);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    text-align: center;
}

.seo-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}

.seo-description {
    color: var(--text-secondary);
    margin-bottom: var(--space-6);
    line-height: 1.6;
}

.seo-checklist {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: var(--space-4);
    text-align: left;
}

.seo-checklist li {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    color: var(--text-secondary);
    background: var(--bg-elevated);
    padding: var(--space-3);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    transition: transform var(--transition-fast), border-color var(--transition-fast);
}

.seo-checklist li:hover {
    transform: translateY(-2px);
    border-color: var(--accent-soft);
}

.check-icon {
    width: 20px;
    height: 20px;
    min-width: 20px;
    fill: none;
    stroke: var(--accent);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    margin-top: 2px;
}

/* SEO Templates Section */
.seo-templates-section {
    margin-top: var(--space-4);
}

.seo-subtitle {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: var(--space-4);
}

.seo-two-column {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-6);
    margin-bottom: var(--space-6);
    text-align: left;
}

@media (max-width: 768px) {
    .seo-two-column {
        grid-template-columns: 1fr;
    }
}

.seo-column {
    background: var(--bg-elevated);
    padding: var(--space-5);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

.seo-steps {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.seo-steps li {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    color: var(--text-secondary);
    line-height: 1.5;
}

.step-number {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    min-width: 24px;
    background: var(--accent);
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
    border-radius: 50%;
}

.seo-feature-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.seo-feature-list li {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.seo-feature-list .check-icon {
    width: 16px;
    height: 16px;
    min-width: 16px;
}

.seo-tip {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1) 0%, rgba(168, 85, 247, 0.1) 100%);
    border: 1px solid var(--accent-soft);
    border-left: 3px solid var(--accent);
    padding: var(--space-4);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.6;
    text-align: left;
}

/* =============================================
   Translation Modal
   ============================================= */
.modal-large {
    width: 95%;
    max-width: 800px;
    max-height: 90vh;
}

.modal-large .modal-body {
    max-height: calc(90vh - 80px);
}

.translation-intro {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--border);
}

.translation-grid {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.translation-category {
    background: var(--bg-elevated);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    border: 1px solid var(--border);
}

.translation-category-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: var(--space-3);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.translation-rows {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.translation-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
    align-items: center;
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--border);
}

.translation-row:last-child {
    border-bottom: none;
}

.translation-english {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.translation-english label {
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
}

.translation-key {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.translation-input input {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: var(--font-sans);
    transition: border-color var(--transition-fast);
}

.translation-input input:focus {
    outline: none;
    border-color: var(--accent);
}

.translation-input input::placeholder {
    color: var(--text-muted);
    font-style: italic;
}

.translation-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
    margin-top: var(--space-4);
    padding-top: var(--space-4);
    border-top: 1px solid var(--border);
}

.btn-primary,
.btn-secondary {
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font-sans);
}

.btn-primary {
    background: var(--accent);
    color: white;
    border: none;
}

.btn-primary:hover {
    background: #5558e3;
}

.btn-secondary {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--text-muted);
}

/* =============================================
   RTL (Right-to-Left) Mode
   ============================================= */
body.rtl-mode .canvas-container {
    direction: rtl;
}

body.rtl-mode .page {
    direction: rtl;
    text-align: right;
}

body.rtl-mode .page .invoice-header {
    flex-direction: row-reverse;
}

body.rtl-mode .page .meta-section {
    flex-direction: row-reverse;
}

body.rtl-mode .page .items-table th,
body.rtl-mode .page .items-table td {
    text-align: right;
}

body.rtl-mode .page .items-table th:last-child,
body.rtl-mode .page .items-table td:last-child {
    text-align: left;
}

body.rtl-mode .page .detail-row {
    flex-direction: row-reverse;
}

body.rtl-mode .page .totals-section {
    align-items: flex-start;
}

body.rtl-mode .page .total-row {
    flex-direction: row-reverse;
}

body.rtl-mode .page .total-label {
    text-align: left;
}

body.rtl-mode .page .total-value {
    text-align: right;
}

body.rtl-mode .page .notes-section {
    text-align: right;
}

body.rtl-mode .page .client-block {
    text-align: right;
}

body.rtl-mode .page .company-block {
    text-align: right;
}

/* RTL Button Active State */
#toggle-rtl.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* Responsive Translation Modal */
@media (max-width: 600px) {
    .translation-row {
        grid-template-columns: 1fr;
        gap: var(--space-2);
    }

    .translation-english {
        padding-bottom: var(--space-1);
    }

    .translation-actions {
        flex-direction: column;
    }

    .translation-actions button {
        width: 100%;
    }
}

/* =============================================
   Date Format Picker
   ============================================= */
.date-format-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 0;
    margin-bottom: 4px;
    border-bottom: 1px dashed var(--border);
}

.date-format-picker {
    position: relative;
}

.date-format-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px 10px;
    font-size: 0.8rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: inherit;
}

.date-format-toggle:hover {
    border-color: var(--accent);
    background: var(--bg-card);
}

.date-format-toggle svg {
    width: 14px;
    height: 14px;
    fill: none;
    stroke: var(--text-muted);
    stroke-width: 2;
    transition: transform var(--transition-fast);
}

.date-format-toggle.open svg {
    transform: rotate(180deg);
}

.date-format-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    min-width: 180px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    z-index: 100;
    display: none;
    overflow: hidden;
}

.date-format-dropdown.visible {
    display: block;
}

.date-format-option {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.date-format-option:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.date-format-option.active {
    background: var(--accent-soft);
    color: var(--accent);
}

.format-example {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

/* =============================================
   Print Only Elements (hidden in editor)
   ============================================= */
.print-only {
    display: none !important;
}

/* Show print-only elements during PDF generation */
.pdf-generating .print-only {
    display: inline !important;
}

/* Hide date inputs during PDF generation */
.pdf-generating .date-input {
    display: none !important;
}

/* =============================================
   Date Input Wrapper with Overlay
   ============================================= */
.date-input-wrapper {
    position: relative;
    display: inline-block;
}

.date-input-wrapper .date-input {
    opacity: 0;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    z-index: 2;
}

.date-formatted-overlay {
    display: inline-block;
    padding: 4px 8px;
    font-size: 0.9rem;
    color: var(--doc-text);
    background: transparent;
    cursor: pointer;
    min-width: 100px;
    border-bottom: 1px dashed var(--doc-border);
    transition: all 0.15s ease;
}

.date-formatted-overlay:hover {
    border-bottom-color: var(--accent);
    color: var(--accent);
}

.date-formatted-overlay:not(.has-value) {
    color: var(--doc-secondary);
    font-style: italic;
}

/* Calendar icon indicator */
.date-formatted-overlay::after {
    content: '';
    display: inline-block;
    width: 14px;
    height: 14px;
    margin-left: 6px;
    vertical-align: middle;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Crect x='3' y='4' width='18' height='18' rx='2' ry='2'/%3E%3Cline x1='16' y1='2' x2='16' y2='6'/%3E%3Cline x1='8' y1='2' x2='8' y2='6'/%3E%3Cline x1='3' y1='10' x2='21' y2='10'/%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
    opacity: 0.6;
}

.date-formatted-overlay:hover::after {
    opacity: 1;
}