/* ==========================================================================
   Finance Tracker — Payment Plans, Milestones & Finance Summary
   Follows ChampCourts dashboard CSS conventions (mobile-first, inline-style
   supplement for dynamic values; class-based for structural / reusable pieces)
   ========================================================================== */

/* ---------------------------------------------------------------------------
   Screen shell
   --------------------------------------------------------------------------- */

.ft {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 56px - 56px); /* header + bottom nav */
    background: #F8F9FA;
    font-family: Arial, Helvetica, sans-serif;
}

/* ---------------------------------------------------------------------------
   Screen header bar (title + refresh)
   --------------------------------------------------------------------------- */

.ft__header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 2px solid #1A365D;
    background: #fff;
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 10;
}

.ft__title {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: #1A365D;
    flex: 1;
}

.ft__header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

/* ---------------------------------------------------------------------------
   KPI Summary Cards (top row)
   --------------------------------------------------------------------------- */

.ft__kpi-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 16px;
}

@media (min-width: 600px) {
    .ft__kpi-row {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 900px) {
    .ft__kpi-row {
        grid-template-columns: repeat(5, 1fr);
    }
}

.ft__kpi-card {
    background: #fff;
    border: 1px solid #E2E8F0;
    border-radius: 8px;
    padding: 14px 16px;
    position: relative;
    overflow: hidden;
}

.ft__kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: #1A365D;
}

.ft__kpi-card--gold::before  { background: #D4A012; }
.ft__kpi-card--green::before { background: #27AE60; }
.ft__kpi-card--amber::before { background: #F39C12; }
.ft__kpi-card--red::before   { background: #E74C3C; }
.ft__kpi-card--navy::before  { background: #1A365D; }

.ft__kpi-label {
    font-size: 11px;
    font-weight: 600;
    color: #718096;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 6px;
}

.ft__kpi-value {
    font-size: 20px;
    font-weight: 700;
    color: #2D3748;
    line-height: 1;
}

.ft__kpi-sub {
    font-size: 11px;
    color: #A0AEC0;
    margin-top: 4px;
}

/* ---------------------------------------------------------------------------
   Body layout (plans list + overdue panel side-by-side on desktop)
   --------------------------------------------------------------------------- */

.ft__body {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 0 16px 32px;
}

@media (min-width: 900px) {
    .ft__body {
        flex-direction: row;
        align-items: flex-start;
    }
}

/* ---------------------------------------------------------------------------
   Section: Plans list
   --------------------------------------------------------------------------- */

.ft__plans {
    flex: 1;
    min-width: 0;
}

.ft__section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #1A365D;
    color: #fff;
    padding: 10px 14px;
    border-radius: 6px 6px 0 0;
    font-size: 13px;
    font-weight: 700;
}

.ft__section-count {
    font-size: 12px;
    font-weight: 400;
    opacity: 0.75;
    margin-left: 8px;
}

/* ---------------------------------------------------------------------------
   Individual project plan row
   --------------------------------------------------------------------------- */

.ft__plan-list {
    border: 1px solid #E2E8F0;
    border-top: none;
    border-radius: 0 0 6px 6px;
    background: #fff;
    overflow: hidden;
}

.ft__plan-row {
    border-bottom: 1px solid #F0F4F8;
    cursor: pointer;
    transition: background 0.12s ease;
}

.ft__plan-row:last-child {
    border-bottom: none;
}

.ft__plan-row:hover {
    background: #F7FAFC;
}

.ft__plan-row--expanded {
    background: #F0F7FF;
}

.ft__plan-summary {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px;
    flex-wrap: wrap;
}

.ft__plan-main {
    flex: 1;
    min-width: 0;
}

.ft__plan-name {
    font-size: 14px;
    font-weight: 700;
    color: #1A365D;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ft__plan-meta {
    font-size: 12px;
    color: #718096;
    margin-top: 3px;
}

.ft__plan-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    flex-shrink: 0;
}

.ft__plan-total {
    font-size: 15px;
    font-weight: 700;
    color: #2D3748;
}

.ft__plan-outstanding {
    font-size: 12px;
    color: #E74C3C;
    font-weight: 600;
}

.ft__plan-outstanding--clear {
    color: #27AE60;
}

/* ---------------------------------------------------------------------------
   Milestone progress strip
   --------------------------------------------------------------------------- */

.ft__milestone-strip {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 14px 12px;
    flex-wrap: wrap;
}

.ft__ms-dot {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    flex-shrink: 0;
    border: 2px solid transparent;
    position: relative;
}

.ft__ms-dot--paid {
    background: #27AE60;
    border-color: #1E8449;
    color: #fff;
}

.ft__ms-dot--invoiced {
    background: #F39C12;
    border-color: #D68910;
    color: #fff;
}

.ft__ms-dot--overdue {
    background: #E74C3C;
    border-color: #C0392B;
    color: #fff;
}

.ft__ms-dot--pending {
    background: #fff;
    border-color: #CBD5E0;
    color: #A0AEC0;
}

.ft__ms-connector {
    flex: 1;
    min-width: 12px;
    height: 2px;
    background: #E2E8F0;
    flex-shrink: 0;
    max-width: 24px;
}

.ft__ms-connector--paid {
    background: #27AE60;
}

/* ---------------------------------------------------------------------------
   Plan action buttons (row-level)
   --------------------------------------------------------------------------- */

.ft__plan-actions {
    display: flex;
    gap: 8px;
    padding: 0 14px 12px;
    flex-wrap: wrap;
}

/* ---------------------------------------------------------------------------
   Expanded milestone detail panel
   --------------------------------------------------------------------------- */

.ft__plan-detail {
    border-top: 1px solid #E2E8F0;
    padding: 14px;
    background: #F7FAFC;
    display: none;
}

.ft__plan-row--expanded .ft__plan-detail {
    display: block;
}

.ft__milestone-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.ft__milestone-table th {
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    color: #fff;
    background: #1A365D;
    padding: 7px 10px;
    border-bottom: 2px solid #D4A012;
}

.ft__milestone-table th:last-child {
    text-align: right;
}

.ft__milestone-table td {
    padding: 9px 10px;
    border-bottom: 1px solid #EDF2F7;
    vertical-align: top;
    color: #2D3748;
}

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

.ft__milestone-table tr:hover td {
    background: #EDF2F7;
}

.ft__milestone-table td:last-child {
    text-align: right;
}

/* ---------------------------------------------------------------------------
   Milestone status badges
   --------------------------------------------------------------------------- */

.ft__badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 100px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}

.ft__badge--paid {
    background: #F0FFF4;
    color: #22543D;
    border: 1px solid #9AE6B4;
}

.ft__badge--invoiced {
    background: #FFFBEB;
    color: #744210;
    border: 1px solid #F6AD55;
}

.ft__badge--overdue {
    background: #FFF5F5;
    color: #742A2A;
    border: 1px solid #FC8181;
}

.ft__badge--pending {
    background: #F7FAFC;
    color: #718096;
    border: 1px solid #CBD5E0;
}

/* ---------------------------------------------------------------------------
   Scope badge
   --------------------------------------------------------------------------- */

.ft__scope-badge {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
}

.ft__scope-badge--si {
    background: #EBF8FF;
    color: #2C5282;
    border: 1px solid #BEE3F8;
}

.ft__scope-badge--so {
    background: #FAF5FF;
    color: #44337A;
    border: 1px solid #D6BCFA;
}

/* ---------------------------------------------------------------------------
   Section: Overdue alerts panel
   --------------------------------------------------------------------------- */

.ft__overdue {
    width: 100%;
}

@media (min-width: 900px) {
    .ft__overdue {
        width: 300px;
        flex-shrink: 0;
    }
}

.ft__overdue-list {
    border: 1px solid #E2E8F0;
    border-top: none;
    border-radius: 0 0 6px 6px;
    background: #fff;
    overflow: hidden;
}

.ft__overdue-item {
    padding: 12px 14px;
    border-bottom: 1px solid #F0F4F8;
}

.ft__overdue-item:last-child {
    border-bottom: none;
}

.ft__overdue-client {
    font-size: 13px;
    font-weight: 700;
    color: #1A365D;
}

.ft__overdue-label {
    font-size: 12px;
    color: #718096;
    margin-top: 2px;
}

.ft__overdue-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 6px;
}

.ft__overdue-amount {
    font-size: 14px;
    font-weight: 700;
    color: #E74C3C;
}

.ft__overdue-days {
    font-size: 11px;
    font-weight: 700;
    background: #FFF5F5;
    color: #C53030;
    border: 1px solid #FC8181;
    border-radius: 100px;
    padding: 1px 8px;
}

.ft__overdue-empty {
    padding: 24px;
    text-align: center;
    color: #27AE60;
    font-size: 13px;
    font-weight: 600;
}

/* ---------------------------------------------------------------------------
   Buttons (reuse dashboard btn vocabulary with local overrides)
   --------------------------------------------------------------------------- */

.ft-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    border-radius: 5px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    border: none;
    font-family: Arial, Helvetica, sans-serif;
    transition: opacity 0.15s ease;
    white-space: nowrap;
}

.ft-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.ft-btn--gold {
    background: #D4A012;
    color: #1A365D;
}

.ft-btn--gold:hover:not(:disabled) {
    background: #B8870D;
}

.ft-btn--navy {
    background: #1A365D;
    color: #fff;
}

.ft-btn--navy:hover:not(:disabled) {
    background: #152C4E;
}

.ft-btn--outline {
    background: #fff;
    color: #4A5568;
    border: 1px solid #CBD5E0;
}

.ft-btn--outline:hover:not(:disabled) {
    background: #EDF2F7;
}

.ft-btn--danger {
    background: #FFF5F5;
    color: #C53030;
    border: 1px solid #FC8181;
}

.ft-btn--danger:hover:not(:disabled) {
    background: #FED7D7;
}

.ft-btn--green {
    background: #F0FFF4;
    color: #22543D;
    border: 1px solid #9AE6B4;
}

.ft-btn--green:hover:not(:disabled) {
    background: #C6F6D5;
}

.ft-btn--sm {
    padding: 4px 10px;
    font-size: 11px;
}

/* ---------------------------------------------------------------------------
   Loading skeleton
   --------------------------------------------------------------------------- */

.ft__skeleton {
    padding: 32px;
    text-align: center;
    color: #718096;
    font-size: 14px;
}

/* ---------------------------------------------------------------------------
   Empty state
   --------------------------------------------------------------------------- */

.ft__empty {
    padding: 48px 24px;
    text-align: center;
    color: #718096;
    font-size: 14px;
    background: #fff;
    border: 1px solid #E2E8F0;
    border-top: none;
    border-radius: 0 0 6px 6px;
}

/* ---------------------------------------------------------------------------
   "Deal Won" modal trigger area (top of plans section, admin only)
   --------------------------------------------------------------------------- */

.ft__deal-won-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: #FFF9E6;
    border: 1px solid #F6AD55;
    border-radius: 6px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.ft__deal-won-bar label {
    font-size: 13px;
    font-weight: 600;
    color: #744210;
    white-space: nowrap;
}

.ft__deal-won-bar input {
    flex: 1;
    min-width: 160px;
    padding: 6px 10px;
    border: 1px solid #F6AD55;
    border-radius: 5px;
    font-size: 13px;
    font-family: Arial, Helvetica, sans-serif;
    color: #2D3748;
    background: #fff;
}

.ft__deal-won-bar input:focus {
    outline: 2px solid #D4A012;
    outline-offset: 1px;
}

/* ---------------------------------------------------------------------------
   Milestone trigger (inline CTA inside table row)
   --------------------------------------------------------------------------- */

.ft__trigger-row td {
    background: #FFFBEB;
}

/* ---------------------------------------------------------------------------
   Update milestone inline form (appears inside expanded panel)
   --------------------------------------------------------------------------- */

.ft__update-form {
    margin-top: 10px;
    padding: 12px;
    background: #EBF8FF;
    border: 1px solid #BEE3F8;
    border-radius: 6px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    align-items: end;
}

@media (max-width: 480px) {
    .ft__update-form {
        grid-template-columns: 1fr;
    }
}

.ft__update-form label {
    font-size: 11px;
    font-weight: 700;
    color: #2C5282;
    display: block;
    margin-bottom: 4px;
}

.ft__update-form input,
.ft__update-form select {
    width: 100%;
    padding: 6px 9px;
    border: 1px solid #90CDF4;
    border-radius: 4px;
    font-size: 13px;
    font-family: Arial, Helvetica, sans-serif;
    color: #2D3748;
    background: #fff;
    box-sizing: border-box;
}

.ft__update-form input:focus,
.ft__update-form select:focus {
    outline: 2px solid #1A365D;
    outline-offset: 1px;
}

.ft__update-form__actions {
    grid-column: 1 / -1;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* ---------------------------------------------------------------------------
   Error / warning banners
   --------------------------------------------------------------------------- */

.ft__error-banner {
    margin: 12px 16px;
    padding: 14px 16px;
    background: #FFF3CD;
    border: 1px solid #F39C12;
    border-radius: 6px;
    color: #856404;
    font-size: 14px;
}

/* ---------------------------------------------------------------------------
   Chevron expand indicator
   --------------------------------------------------------------------------- */

.ft__chevron {
    display: inline-block;
    width: 0;
    height: 0;
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    border-left: 7px solid #718096;
    transition: transform 0.2s ease;
    flex-shrink: 0;
    margin-top: 2px;
}

.ft__plan-row--expanded .ft__chevron {
    transform: rotate(90deg);
    border-left-color: #1A365D;
}

/* ---------------------------------------------------------------------------
   E-Way Bill badges (inline in milestone table)
   --------------------------------------------------------------------------- */

.ft-eway {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
}

.ft-eway--ok {
    background: #C6F6D5;
    color: #22543D;
}

.ft-eway--needed {
    background: #FEFCBF;
    color: #744210;
}

/* ---------------------------------------------------------------------------
   Vendor Bills display (list of previously uploaded bills)
   --------------------------------------------------------------------------- */

.ft-vendor-bills {
    margin-top: 12px;
    border-top: 1px solid #E2E8F0;
    padding-top: 12px;
}

.ft-vendor-bills__title {
    font-size: 13px;
    font-weight: 600;
    color: #4A5568;
    margin: 0 0 8px;
}

.ft-vendor-bill {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 8px;
    border-radius: 4px;
    font-size: 12px;
}

.ft-vendor-bill:nth-child(even) {
    background: #F7FAFC;
}

.ft-vendor-bill--flagged {
    background: #FFF5F5 !important;
    border-left: 3px solid #E53E3E;
}

.ft-vendor-bill__name {
    font-weight: 500;
    min-width: 120px;
}

.ft-vendor-bill__amount {
    font-weight: 600;
    min-width: 80px;
}

.ft-vendor-bill__number {
    color: #718096;
    min-width: 80px;
}

.ft-vendor-bill__date {
    color: #A0AEC0;
}

.ft-vendor-bill__flag {
    color: #E53E3E;
    font-weight: 600;
    font-size: 11px;
}

/* ---------------------------------------------------------------------------
   Vendor Bill Upload Form (inline, toggled via button)
   --------------------------------------------------------------------------- */

.ft-upload-form {
    margin-top: 12px;
    border: 1px solid #E2E8F0;
    border-radius: 8px;
    padding: 16px;
    background: #F7FAFC;
}

.ft-upload-form__inner h4 {
    margin: 0 0 12px;
    font-size: 14px;
    color: #1A365D;
}

.ft-upload-form label {
    display: block;
    font-size: 12px;
    color: #4A5568;
    margin-bottom: 8px;
}

.ft-upload-form input {
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: 6px 8px;
    border: 1px solid #CBD5E0;
    border-radius: 4px;
    font-size: 13px;
    font-family: Arial, Helvetica, sans-serif;
    box-sizing: border-box;
}

.ft-upload-form input[type="file"] {
    padding: 4px;
}

.ft-upload-form__progress {
    height: 4px;
    background: #E2E8F0;
    border-radius: 2px;
    margin: 8px 0;
    overflow: hidden;
}

.ft-upload-form__bar {
    height: 100%;
    background: #D4A012;
    width: 0;
    transition: width 0.2s ease;
}

.ft-upload-form__actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.ft-upload-form__status {
    margin-top: 8px;
    font-size: 12px;
}

.ft-upload-form__status--ok {
    color: #38A169;
}

.ft-upload-form__status--error {
    color: #E53E3E;
}

/* ---------------------------------------------------------------------------
   Vendor Bill button variant
   --------------------------------------------------------------------------- */

.ft-btn--vendor-bill {
    background: #EBF8FF;
    color: #2B6CB0;
    border: 1px solid #BEE3F8;
}

.ft-btn--vendor-bill:hover:not(:disabled) {
    background: #BEE3F8;
}
