/* Custom styles for SaaS Platform */

/* Global typography: readable UI stack with better Windows/macOS parity */
:root {
    --font-ui: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI Variable",
        "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans",
        "Liberation Sans", sans-serif;

    /* ===================================================
       STRIPE DESIGN TOKENS — Light Mode
       =================================================== */

    /* Surfaces */
    --s-surface:          #ffffff;
    --s-surface-subtle:   #f6f9fc;
    --s-surface-hover:    rgba(0, 0, 0, 0.04);

    /* Borders */
    --s-border:           #e5edf5;
    --s-border-purple:    #d6d9fc;
    --s-border-dashed:    #d6d9fc;

    /* Text */
    --s-text-heading:     #061b31;
    --s-text-body:        #64748d;
    --s-text-label:       #273951;
    --s-text-purple:      #533afd;
    --s-text-purple-hover: #4434d4;
    --s-text-success:     #108c3d;
    --s-text-warning:     #9b6829;
    --s-text-danger:      #ef4444;

    /* Purple tinted surfaces (info cards, sidebars) */
    --s-purple-bg:        rgba(83,58,253,0.05);
    --s-purple-bg-solid:  #f6f5ff;
    --s-purple-hover:     rgba(83,58,253,0.02);
    --s-purple-hover-dark: rgba(83,58,253,0.08);
    --s-icon-purple-bg:   rgba(83,58,253,0.08);

    /* Success surfaces */
    --s-success-bg:       rgba(21,190,83,0.08);
    --s-success-bg-solid: #ecfaf1;
    --s-success-border:   rgba(21,190,83,0.3);

    /* Warning surfaces */
    --s-warning-bg:       rgba(155,104,41,0.08);
    --s-warning-border:   rgba(155,104,41,0.3);

    /* Inputs */
    --s-input-bg:         #ffffff;

    /* Code badges */
    --s-code-bg:          rgba(83,58,253,0.06);
    --s-code-color:       #533afd;
    --s-code-border:      rgba(83,58,253,0.2);

    /* Semantic colors */
    --s-green:            #16a34a;
    --s-red:              #dc2626;
}

/* ===================================================
   UTILITY CLASSES
   =================================================== */
.s-hover:hover {
  background-color: var(--s-surface-hover) !important;
}

/* ===================================================
   STRIPE DESIGN TOKENS — Dark Mode
   =================================================== */
.dark {
    /* Surfaces */
    --s-surface:          #1e293b;
    --s-surface-subtle:   #0f172a;
    --s-surface-hover:    rgba(255, 255, 255, 0.06);

    /* Borders */
    --s-border:           #334155;
    --s-border-purple:    rgba(99,102,241,0.35);
    --s-border-dashed:    rgba(99,102,241,0.35);

    /* Text */
    --s-text-heading:     #f1f5f9;
    --s-text-body:        #94a3b8;
    --s-text-label:       #cbd5e1;
    --s-text-purple:      #818cf8;
    --s-text-purple-hover: #4434d4;
    --s-text-success:     #4ade80;
    --s-text-warning:     #fbbf24;
    --s-text-danger:      #ef4444;

    /* Purple tinted surfaces */
    --s-purple-bg:        rgba(83,58,253,0.15);
    --s-purple-bg-solid:  #262c58;
    --s-purple-hover:     rgba(83,58,253,0.08);
    --s-purple-hover-dark: rgba(83,58,253,0.2);
    --s-icon-purple-bg:   rgba(83,58,253,0.2);

    /* Success surfaces */
    --s-success-bg:       rgba(21,190,83,0.12);
    --s-success-bg-solid: #1d3b3e;
    --s-success-border:   rgba(21,190,83,0.4);

    /* Warning surfaces */
    --s-warning-bg:       rgba(155,104,41,0.15);
    --s-warning-border:   rgba(155,104,41,0.4);

    /* Inputs */
    --s-input-bg:         #1e293b;

    /* Code badges */
    --s-code-bg:          rgba(129,140,248,0.15);
    --s-code-color:       #a5b4fc;
    --s-code-border:      rgba(129,140,248,0.3);

    /* Semantic colors */
    --s-green:            #4ade80;
    --s-red:              #f87171;

    /* Surface hover - for interactive elements */
    --s-surface-hover:    rgba(255, 255, 255, 0.06);
}

/* ===================================================
   STRIPE PSEUDO-CLASS STYLES
   (inline styles can't handle :hover/:focus — only these need CSS classes)
   =================================================== */

/* Drop zone states */
.s-drop-zone:hover,
.s-drop-zone.drag-over {
    border-color: #533afd !important;
    background: var(--s-purple-hover) !important;
}
.s-drop-zone.has-file {
    border-color: #15be53 !important;
    background: var(--s-success-bg) !important;
}

/* Table row hover */
.s-table-row:hover {
    background: var(--s-purple-hover) !important;
}

/* Input focus */
.s-input:focus {
    border-color: #533afd !important;
    outline: none !important;
}

/* Form controls (reduce inline-style repetition in templates) */
.s-input,
.s-select,
.s-textarea {
    /* Use tokens and force override against Tailwind CDN / UA defaults */
    background: var(--s-input-bg) !important;
    border: 1px solid var(--s-border) !important;
    border-radius: 4px;
    padding: 9px 12px;
    font-size: 14px;
    color: var(--s-text-heading) !important;
    font-family: var(--font-ui);
    box-sizing: border-box;
}

.s-select {
    padding-right: 32px;
}

html {
    font-family: var(--font-ui);
    font-size: 17px;
    line-height: 1.5;
    /* Ensure native form controls (e.g., <select> dropdown panels) follow the active theme */
    color-scheme: light;
    -webkit-text-size-adjust: 100%;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

html.dark {
    color-scheme: dark;
}

/* ---------------------------------------------------
   Native form controls (dark mode consistency)
   --------------------------------------------------- */

select,
option,
optgroup {
    background: var(--s-input-bg);
    color: var(--s-text-heading);
}

select {
    color-scheme: inherit;
}

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
select:-webkit-autofill,
textarea:-webkit-autofill {
    -webkit-text-fill-color: var(--s-text-heading);
    -webkit-box-shadow: 0 0 0px 1000px var(--s-input-bg) inset;
    box-shadow: 0 0 0px 1000px var(--s-input-bg) inset;
    caret-color: var(--s-text-heading);
}

@media (max-width: 768px) {
    html {
        font-size: 16px;
    }
}

input,
button,
textarea,
select {
    font: inherit;
}

/* HTMX loading indicator */
.htmx-request .htmx-indicator {
    display: inline-block;
}

.htmx-indicator {
    display: none;
}

/* Smooth transitions for HTMX swaps */
.htmx-swapping {
    opacity: 0;
    transition: opacity 0.3s ease-out;
}

.htmx-added {
    opacity: 0;
    animation: fadeIn 0.3s ease-out forwards;
}

/* ===================================================
   AUTH LAYOUT
   =================================================== */

.auth-page {
    min-height: 100vh;
    background:
        radial-gradient(circle at top left, var(--s-purple-bg) 0, transparent 38%),
        linear-gradient(180deg, var(--s-surface-subtle) 0%, var(--s-surface-subtle) 100%);
}

.auth-shell {
    min-height: 100vh;
    width: 100%;
    max-width: 1180px;
    margin: 0 auto;
    padding: 32px 24px;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: center;
    gap: 32px;
}

.auth-panel {
    display: none;
}

.auth-brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.auth-brand-mark {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: var(--s-text-purple);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 700;
    box-shadow: 0 20px 40px -28px rgba(83, 58, 253, 0.8);
}

.auth-brand-copy {
    color: var(--s-text-heading);
}

.auth-panel-title {
    margin: 0 0 12px;
    color: var(--s-text-heading);
    font-size: 32px;
    line-height: 1.15;
    letter-spacing: -0.04em;
    font-weight: 600;
}

.auth-panel-body {
    max-width: 480px;
    margin: 0;
    color: var(--s-text-body);
    font-size: 15px;
    line-height: 1.6;
}

.auth-card-wrap {
    width: 100%;
    max-width: 520px;
    justify-self: center;
}

.auth-card {
    background: var(--s-surface);
    border: 1px solid var(--s-border);
    border-radius: 12px;
    padding: 28px;
    box-shadow: 0 30px 60px -42px rgba(15, 23, 42, 0.45);
}

.auth-card-title {
    margin: 0 0 6px;
    color: var(--s-text-heading);
    font-size: 24px;
    line-height: 1.2;
    letter-spacing: -0.03em;
    font-weight: 600;
}

.auth-card-subtitle {
    margin: 0 0 24px;
    color: var(--s-text-body);
    font-size: 14px;
    line-height: 1.5;
}

.auth-field {
    margin-bottom: 30px;
}

.auth-label {
    display: block;
    margin-bottom: 6px;
    color: var(--s-text-label);
    font-size: 13px;
    font-weight: 500;
}

.auth-password-wrap {
    position: relative;
}

.auth-password-input {
    padding-right: 44px !important;
}

.auth-password-toggle {
    position: absolute;
    top: 50%;
    right: 10px;
    transform: translateY(-50%);
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--s-text-body);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.auth-password-toggle:hover {
    background: var(--s-surface-hover);
    color: var(--s-text-heading);
}

.auth-password-toggle:focus-visible {
    outline: 2px solid var(--s-text-purple);
    outline-offset: 2px;
}

.auth-error {
    margin-top: 8px;
    color: var(--s-red);
    font-size: 13px;
}

.auth-alert {
    margin-bottom: 20px;
    padding: 12px 14px;
    border-radius: 8px;
    border: 1px solid rgba(220, 38, 38, 0.2);
    background: var(--s-red-bg);
    color: var(--s-red);
    font-size: 13px;
    line-height: 1.45;
}

.auth-actions-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin: 32px 0 32px;
}

.auth-check {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--s-text-body);
    font-size: 14px;
}

.auth-check input {
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: var(--s-text-purple);
}

.auth-link {
    color: var(--s-text-purple);
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
}

.auth-link:hover {
    text-decoration: underline;
}

.auth-submit {
    width: 100%;
    min-height: 44px;
    border: 0;
    border-radius: 6px;
    background: var(--s-text-purple);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: filter 0.15s ease, transform 0.15s ease;
}

.auth-submit:hover {
    filter: brightness(1.05);
}

.auth-submit:focus-visible {
    outline: 2px solid var(--s-text-purple);
    outline-offset: 2px;
}

.auth-theme-toggle {
    background: var(--s-surface);
    border: 1px solid var(--s-border);
    color: var(--s-text-body);
    box-shadow: 0 20px 40px -34px rgba(15, 23, 42, 0.5);
}

.auth-theme-toggle:hover {
    background: var(--s-surface-hover);
    color: var(--s-text-heading);
}

@media (min-width: 1024px) {
    .auth-shell {
        grid-template-columns: minmax(0, 1fr) minmax(420px, 520px);
        padding: 40px 24px;
    }

    .auth-panel {
        display: block;
        padding-right: 24px;
    }

    .auth-card-wrap {
        justify-self: end;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

.s-drop-zone:focus-visible {
    outline: 2px solid var(--s-border-purple);
    outline-offset: 2px;
}

#bank-statement-add-row:focus-visible {
    outline: 2px solid var(--s-border-purple);
    outline-offset: 2px;
}

/* Custom scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

/* Focus styles */
input:focus,
select:focus,
textarea:focus {
    outline: none;
}

/* Table row hover animation */
tr.hover-row {
    transition: background-color 0.15s ease-in-out;
}

/* Button loading state */
.btn-loading {
    position: relative;
    pointer-events: none;
}

.btn-loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -8px;
    border: 2px solid #ffffff;
    border-radius: 50%;
    border-top-color: transparent;
    animation: spinner 0.8s linear infinite;
}

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

/* Toast notifications */
.toast-container {
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    animation: slideIn 0.3s ease-out;
}

.toast.is-dismissing {
    opacity: 0;
    transform: translateY(-4px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

@keyframes slideIn {
    from {
        transform: translateY(-8px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Modal backdrop */
.modal-backdrop {
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

/* Form validation styles */
input:invalid:not(:placeholder-shown) {
    border-color: #ef4444;
}

input:valid:not(:placeholder-shown) {
    border-color: #22c55e;
}

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

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .border-gray-300 {
        border-color: #000000;
    }
}

/* Breadcrumb trail — DESIGN.md §5.10 (gap G3), same rules as HDAPortal's base.css.
   Parent links purple at rest (navigation-link exception, §5.1A); current item neutral. */
.page-breadcrumb {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    margin: 0 0 0.9rem 0;
    font-size: 0.875rem;
    font-weight: 500;
}
.page-breadcrumb-link {
    color: var(--s-text-purple);
    text-decoration: none;
    transition: color 0.15s ease;
}
.page-breadcrumb-link:hover {
    text-decoration: underline;
    text-underline-offset: 2px;
}
.page-breadcrumb-link:focus-visible {
    outline: 2px solid var(--s-text-purple);
    outline-offset: 2px;
    border-radius: 4px;
}
.page-breadcrumb-current {
    color: var(--s-text-heading);
}
.page-breadcrumb-separator {
    color: var(--s-text-label);
    margin: 0 0.45rem;
}


/* Per-cell skeleton while a list refreshes — DESIGN.md §6.0A "Refresh feedback" (gap G5); rows built by
   static/js/ui/table_skeleton.js on <table data-skeleton>. Tokens only, so dark mode follows. */
.table-skeleton-cell { padding: 10px 12px; box-sizing: border-box; }
.skeleton-bar {
    height: 0.9rem;
    border-radius: 4px;
    background: linear-gradient(90deg, var(--s-border) 25%, color-mix(in srgb, var(--s-border) 55%, var(--s-surface)) 50%, var(--s-border) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.2s linear infinite;
}
@keyframes skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
.table-skeleton-status { font-size: 12px; color: var(--s-text-label); padding: 6px 12px; }
@media (prefers-reduced-motion: reduce) { .skeleton-bar { animation: none; } }


/* DF-e list rows open "Ver nota" themselves — DESIGN.md §6 "Row affordance" (user, 2026-10-18): hover marks the line
   and turns its text to the accent (§5.1A active interaction); cells holding pills (.fiscal-pills: Ações, Situação,
   Conteúdo) keep their own colors. Zebra stays: the hover tint is translucent over the row's stripe. */
.fiscal-row { cursor: pointer; }
.fiscal-row:hover > td, .fiscal-row:focus-visible > td { background-color: var(--s-surface-hover); }
.fiscal-row:hover > td:not(.fiscal-pills), .fiscal-row:hover > td:not(.fiscal-pills) *,
.fiscal-row:focus-visible > td:not(.fiscal-pills), .fiscal-row:focus-visible > td:not(.fiscal-pills) * { color: var(--s-text-purple) !important; }
.fiscal-row:focus-visible { outline: 2px solid var(--s-text-purple); outline-offset: -2px; }

/* "⋮" items not built yet (DF-e events): visible, disabled, tagged "em breve" — nothing is sent. Two classes: must
   beat .recon-menu-item in reconciliation-table.css, which loads after this file. */
.recon-menu-item.recon-menu-soon { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--s-text-body); cursor: not-allowed; }
.recon-menu-item.recon-menu-soon:hover { background: transparent; }
.recon-menu-soon-tag { font-size: 11px; padding: 1px 8px; border-radius: 9999px; border: 1px solid var(--s-border); background: var(--s-surface-subtle); color: var(--s-text-label); white-space: nowrap; }
