/* ============================================================================
   FINON SHARED UI
   Depends on: theme.css
   Core shared primitives, tables, utilities, and domain-specific shared styles
   ============================================================================ */

/* ============================================================================
   SHARED HELPERS
   ============================================================================ */
.col-date {
    white-space: nowrap;
    min-width: 110px;
}

.fs-group-card-static .fs-group-summary {
    cursor: default;
}

.mono-font,
.ai-text {
    font-family: var(--font-family-mono);
}

.border-dashed {
    border: 2px dashed var(--border-subtle);
}

.form-label-strong {
    font-weight: 600;
    color: var(--text-color);
}

.input-min-md {
    min-height: 44px;
}

/* ============================================================================
   PAGE / LAYOUT PRIMITIVES
   ============================================================================ */
.page-card {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.page-header-card {
    padding: 1.25rem 1.35rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.page-toolbar-card {
    padding: 1rem 1.25rem;
}

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

.page-toolbar-filters {
    width: 100%;
}

.page-eyebrow {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 0.2rem;
}

.page-title {
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-color);
}

.page-subtitle {
    font-size: 0.95rem;
}

.page-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.55rem 0.9rem;
    border-radius: 999px;
    background: var(--accent-bg);
    border: 1px solid var(--accent-border);
    color: var(--text-color);
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
}

/* ============================================================================
   PANELS / SECTIONS
   ============================================================================ */
.page-panel {
    padding: 1rem 1.1rem;
}

.page-panel-header,
.section-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    padding-bottom: 0.85rem;
    border-bottom: 1px solid var(--border-subtle);
}

.section-card {
    padding: 1rem 1.1rem;
}

/* ============================================================================
   METRICS
   ============================================================================ */
.metric-card {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    padding: 1rem 1.1rem;
    height: 100%;
}

.metric-label {
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.metric-value {
    font-size: 1.7rem;
    line-height: 1.15;
    font-weight: 700;
    color: var(--text-color);
}

.metric-note {
    font-size: 0.85rem;
    margin-top: 0.35rem;
}

/* ============================================================================
   TEXT / STATUS UTILITIES
   ============================================================================ */
.money {
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
    font-family: var(--font-family-mono);
    letter-spacing: 0.01em;
}

.money-strong {
    font-weight: 700;
}

.money-muted {
    color: var(--text-soft);
}

.money-positive {
    color: var(--success-color);
}

.money-negative {
    color: var(--danger-color);
}

.money-zero {
    color: var(--text-soft);
}

.balance-debet,
.text-positive {
    color: var(--success-color);
}

.balance-credit,
.text-negative {
    color: var(--danger-color);
}

.text-zero {
    color: var(--text-soft);
}

.text-purple {
    color: var(--purple-color);
}

.badge-purple {
    background-color: var(--purple-color);
    color: #fff;
    font-weight: 700;
}

.text-efarm {
    color: var(--efarm-color);
}

.summary-value-badge {
    padding: 0.25em 0.5em;
    border-radius: 0.25rem;
    font-weight: 700;
    color: #fff;
}

.profit {
    background-color: var(--success-color);
}

.loss {
    background-color: var(--danger-color);
}

/* ============================================================================
   GRADIENT TEXT
   ============================================================================ */
.gradient-text {
    background: linear-gradient(135deg, #72b2f6 0%, #6f42c1 40%, #6f42c1 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    color: transparent;
}

.gradient-reverse-text {
    font-weight: 700;
    background: linear-gradient(135deg, #6f42c1 0%, #72b2f6 40%, #72b2f6 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    color: transparent;
}

.gradient-efarm-text {
    background: linear-gradient(135deg, #f3d2f7 0%, #2ce165 40%, #215316 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    color: transparent;
}

.gradient-efarm-reverse-text {
    font-weight: 700;
    background: linear-gradient(135deg, #215316 0%, #2ce165 40%, #f3d2f7 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    color: transparent;
}

/* ============================================================================
   AI INSTRUCTION INPUT
   ============================================================================ */
.ai-instruction-area {
    height: 400px;
    font-family: var(--font-family-mono);
    font-size: 1rem;
    border: 2px solid var(--primary-color);
    border-radius: 8px;
    padding: 12px;
    background-color: #f0f8ff;
    transition: box-shadow 0.3s ease;
}

.ai-instruction-area:focus {
    box-shadow: 0 0 10px rgba(0, 123, 255, 0.5);
    outline: none;
}

.blinking-cursor {
    position: absolute;
    top: 12px;
    left: 12px;
    font-size: 1rem;
    color: var(--primary-color);
    animation: blink 1s step-start infinite;
    pointer-events: none;
}

@keyframes blink {
    50% {
        opacity: 0;
    }
}

/* ============================================================================
   TOOLTIP
   ============================================================================ */
.amount-cell {
    position: relative;
    text-align: right;
    width: 120px;
}

.blazor-tooltip {
    position: absolute;
    bottom: 100%;
    right: 0;
    margin-bottom: 8px;
    z-index: 10;
    background-color: #343a40;
    color: #fff;
    padding: 6px 12px;
    border-radius: 4px;
    font-family: var(--font-family-sans);
    font-size: 0.85rem;
    white-space: nowrap;
    animation: fade-in 0.2s ease-in-out;
}

.blazor-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    right: 20px;
    border-width: 5px;
    border-style: solid;
    border-color: #343a40 transparent transparent transparent;
}

@keyframes fade-in {
    from {
        opacity: 0;
        transform: translateY(5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================================================
   TABLE SYSTEM
   Shared table styling for reports, AI output and admin views
   ============================================================================ */
.table-wrap,
.ai-table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0.75rem 0;
}

.table-clean,
.ai-table,
.report-table {
    width: 100%;
    min-width: 100%;
    table-layout: auto;
    border-collapse: collapse;
    background: var(--surface);
    color: var(--text-color);
    font-size: 0.9rem;
    border: 1px solid var(--table-border-outer) !important;
}

.table-clean th,
.table-clean td,
.ai-table th,
.ai-table td,
.report-table th,
.report-table td {
    padding: 0.75rem 1rem;
    border: 1px solid var(--table-border) !important;
    border-width: 1px !important;
    border-style: solid !important;
    vertical-align: top;
}

.table-clean th,
.ai-table th,
.report-table th {
    text-align: left;
    font-weight: 600;
    background: var(--table-header-bg);
    color: var(--text-color);
}

.table-clean td,
.ai-table td,
.report-table td {
    color: var(--text-color);
}

.table-clean tbody tr:nth-child(even),
.ai-table tbody tr:nth-child(even),
.report-table tbody tr:nth-child(even) {
    background: var(--table-row-alt-bg);
}

.table-clean tbody tr:hover td,
.ai-table tbody tr:hover td,
.report-table tbody tr:hover td {
    background: var(--table-row-hover-bg);
}

.table-clean .amount,
.ai-table .amount,
.report-table .amount,
.table-clean .numeric,
.ai-table .numeric,
.report-table .numeric {
    text-align: right !important;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.table-clean td:last-child,
.table-clean th:last-child,
.ai-table td:last-child,
.ai-table th:last-child,
.report-table td:last-child,
.report-table th:last-child {
    text-align: right;
}

.table-clean th:nth-child(2),
.table-clean td:nth-child(2),
.ai-table th:nth-child(2),
.ai-table td:nth-child(2),
.report-table th:nth-child(2),
.report-table td:nth-child(2) {
    min-width: 320px;
    white-space: normal;
}

.table-compact th,
.table-compact td {
    padding: 0.45rem 0.65rem;
    font-size: 0.85rem;
}

.table-loose th,
.table-loose td {
    padding: 0.9rem 1.1rem;
}

.table-section-title {
    margin-top: 12px;
    font-weight: 600;
    color: var(--text-muted);
}

.row-positive td {
    color: var(--success-color);
}

.row-negative td {
    color: var(--danger-color);
}

.row-muted td {
    color: var(--text-muted);
}

.amount-accounting,
.numeric-accounting {
    text-align: right !important;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
    font-family: var(--font-family-mono);
}

.amount-total {
    font-weight: 700;
}

.amount-zero {
    color: var(--text-soft);
}

.amount-positive {
    color: var(--success-color);
}

.amount-negative {
    color: var(--danger-color);
}

/* ============================================================================
   ACCOUNT / FINANCIAL TABLE HELPERS
   ============================================================================ */
.account-table {
    width: 100%;
    border-collapse: collapse;
    position: relative;
    z-index: 2;
}

.account-table td,
.account-table th {
    padding: 0.6rem 1rem;
    border-bottom: 1px solid #f1f3f5;
    vertical-align: middle;
}

.account-table.sub-table {
    width: 100%;
    margin-left: 0;
    border-bottom: none;
}

.account-table.sub-table td,
.account-table.sub-table th {
    border: none;
}

.account-cell {
    position: relative;
}

.account-cell .account-name {
    margin-left: 0.5rem;
}

.account-cell .account-id.mono-font {
    display: inline-block;
    width: 60px;
    color: var(--text-soft);
}

.account-table.sub-table .account-cell,
.account-table.sub-table .account-cell-header {
    padding-left: 2.5rem;
}

/* ============================================================================
   JOURNAL VIEW
   ============================================================================ */
.account-group-container {
    position: relative;
    padding-left: 20px;
}

.account-group-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 10px;
    height: 100%;
    width: 2px;
    background-color: #e9ecef;
    z-index: 0;
}

.journal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    transition: background-color 0.2s ease-in-out, border-color 0.2s ease-in-out;
}

.journal-header:hover,
.journal-header.expanded {
    background-color: var(--surface-muted);
}

.entry-line {
    position: absolute;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    width: 1.5rem;
    height: 2px;
    background-color: #e9ecef;
}

.entry-line.last::after {
    content: '';
    position: absolute;
    top: 0;
    left: -10px;
    width: 2px;
    height: calc(50% + 15px);
    background-color: var(--surface);
}

.journal-entry-row {
    transition: background-color 0.2s ease;
    cursor: grab;
}

.journal-entry-row:hover {
    background-color: var(--surface-muted);
}

.journal-entry-row:active {
    cursor: grabbing;
}

.journal-entry-row.dragging {
    opacity: 0.7;
    border: 2px dashed var(--border-subtle);
}

.journal-header.drop-target-active {
    background-color: #f2eefe;
    outline: 2px dashed var(--purple-color);
    outline-offset: 2px;
    transform: scale(0.99);
    animation: pulse-animation 1.5s infinite;
}

@keyframes pulse-animation {
    0% { opacity: 1; }
    50% { opacity: 0.6; }
    100% { opacity: 1; }
}

/* ============================================================================
   STATUS TOASTS
   ============================================================================ */
.status-message-container {
    position: fixed;
    top: 1.25rem;
    right: 1.25rem;
    z-index: 2050;
    pointer-events: none;
}

.status-message-container .alert {
    min-width: 350px;
    max-width: 450px;
    margin-bottom: 0.5rem;
    box-shadow: 0 0.25rem 0.75rem rgba(0, 0, 0, 0.1);
    pointer-events: auto;
    animation: slide-in-down 0.4s ease-out forwards;
}

@keyframes slide-in-down {
    from {
        opacity: 0;
        transform: translateY(-100%);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================================================
   ENTRY / ACCOUNTING WORKSPACE
   ============================================================================ */
.entry-workspace {
    min-height: 760px;
    display: flex;
    flex-direction: column;
}

.entry-grid-wrap {
    flex: 1;
    min-height: 0;
}

.entry-grid-scroll {
    min-height: 420px;
    max-height: 640px;
    overflow-y: auto;
}

.entry-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--table-header-bg);
}

.entry-totals {
    display: flex;
    gap: 2rem;
    align-items: center;
    flex-wrap: wrap;
}

.entry-badge-balanced {
    background: #f0fdf4;
    border-color: #bbf7d0;
    color: #166534;
}

.entry-badge-unbalanced {
    background: #fff7ed;
    border-color: #fed7aa;
    color: #9a3412;
}
.entry-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-subtle);
}

.entry-footer-primary,
.entry-footer-secondary {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.entry-grid-wrap + .entry-footer,
.entry-grid-scroll + .entry-footer,
.table-wrap + .entry-footer {
    margin-top: 0.75rem;
}

/* ============================================================================
   RESPONSIVE
   ============================================================================ */
@media (max-width: 991.98px) {
    .page-header-card,
    .page-toolbar-head,
    .page-panel-header,
    .section-card-header {
        flex-direction: column;
        align-items: flex-start;
    }
}

@media (max-width: 768px) {
    .account-cell,
    .account-cell-header {
        padding-left: 1rem !important;
    }

    .entry-line {
        width: 1rem;
    }

    .account-group-container {
        padding-left: 15px;
    }

    .account-group-container::before {
        left: 8px;
    }
}
@media (max-width: 768px) {
    .entry-footer {
        flex-direction: column;
        align-items: stretch;
    }

    .entry-footer-primary,
    .entry-footer-secondary {
        width: 100%;
    }

    .entry-footer-secondary {
        justify-content: flex-start;
    }
}