/* --- Main App Container --- */
#fta-app-wrapper {
    background: #f0f4f8; /* Light blue/grey background for the page */
    border: 1px solid #cddde9;
    border-radius: 6px;
    margin: 20px 0;
    max-width: 1000px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    overflow: hidden; /* Contains the rounded corners */
}

/* --- Tab Navigation --- */
.fta-tab-nav {
    display: flex;
    flex-wrap: nowrap; /* Prevents wrapping */
    overflow-x: auto; /* Allows horizontal scrolling on mobile */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    background: #f0f4f8;
    border-bottom: 1px solid #cddde9;
    padding: 0 10px;
}
.fta-tab-link {
    padding: 14px 22px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: #555;
    border-bottom: 3px solid transparent;
    margin-bottom: -1px; /* Sits on top of the border */
    flex-shrink: 0; /* Prevents shrinking */
    white-space: nowrap; /* Prevents text wrapping */
}
.fta-tab-link:hover {
    background: #e4eaf1;
    color: #000;
}
.fta-tab-link.active {
    background: #fff;
    color: #005a9c;
    border-bottom-color: #0073aa;
    border-left: 1px solid #cddde9;
    border-right: 1px solid #cddde9;
    border-top: 2px solid #0073aa;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
}

/* --- Tab Content --- */
.fta-tab-content-wrapper {
    padding: 25px;
    background: #fff;
}
.fta-tab-content {
    display: none;
}
.fta-tab-content.active {
    display: block;
}

/* --- Help/Info Box --- */
.fta-help-box {
    background: #F0F8FF;
    border: 1px solid #B0D0E0;
    padding: 15px;
    margin: 10px 0 25px 0;
    border-radius: 4px;
    font-size: 14px;
    line-height: 1.6;
}
.fta-help-box b {
    color: #004578;
}
.fta-help-box ol {
    padding-left: 20px; 
    margin: 10px 0 0 0;
}

/* --- Forms (Responsive Grid) --- */
.fta-form-grid {
    display: grid;
    grid-template-columns: 1fr; /* Single column on mobile */
    gap: 15px;
    align-items: center;
}
.fta-form-grid label {
    font-weight: 600;
    text-align: left; /* Mobile-first alignment */
    margin-bottom: -5px; /* Tighter spacing in single column */
}
.fta-form-grid h3,
.fta-form-grid h4 {
    grid-column: 1 / -1;
    margin-top: 20px;
    margin-bottom: 0;
    border-bottom: 1px solid #ddd;
    padding-bottom: 5px;
    color: #004578;
}
.fta-form-grid input[type="text"],
.fta-form-grid input[type="email"],
.fta-form-grid input[type="number"],
.fta-form-grid input[type="date"],
.fta-form-grid select,
.fta-form-grid textarea {
    width: 100%;
    max-width: 100%; /* Full width on mobile */
}
.fta-form-full-width {
    grid-column: 1 / -1;
}

/* --- Desktop Form Grid --- */
@media (min-width: 769px) {
    .fta-form-grid {
        grid-template-columns: 220px 1fr; /* Two columns on desktop */
        gap: 15px 20px;
    }
    .fta-form-grid label {
        text-align: right; /* Right-align labels on desktop */
        margin-bottom: 0;
    }
    .fta-form-grid input[type="text"],
    .fta-form-grid input[type="email"],
    .fta-form-grid input[type="number"],
    .fta-form-grid input[type="date"],
    .fta-form-grid select,
    .fta-form-grid textarea {
        max-width: 450px; /* Max width on desktop */
    }
}


/* --- Section Break --- */
.fta-section-break {
    margin-top: 40px !important;
    border-top: 1px solid #ccc !important;
    padding-top: 20px !important;
}

/* --- Split Layout (Expenses Tab) --- */
.fta-container-split {
    display: flex;
    flex-wrap: wrap; /* MODIFIED: Ensure wrapping */
    gap: 30px;
}
.fta-column-left { 
    flex: 1; 
    min-width: 320px; 
}
.fta-column-right { 
    flex: 1.5; 
    min-width: 400px; 
    overflow-x: auto; /* Add scroll if table is too wide */
}
.fta-tax-year-selector { 
    margin-bottom: 10px; 
}
.fta-tax-year-selector label {
    display: inline-block;
    margin-right: 5px;
}
.fta-tax-year-selector select { 
    display: inline-block; 
    width: auto; 
    margin-right: 15px; 
}

/* --- Tables --- */
.fta-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border: 1px solid #ddd;
}
.fta-table th, .fta-table td {
    padding: 12px 10px;
    text-align: left;
    border-bottom: 1px solid #eee;
    vertical-align: middle;
}
.fta-table th { background: #f7f7f7; font-weight: 600; }
.fta-table button.fta-delete-expense {
    font-size: 12px; padding: 3px 8px; background: #dc3232;
    color: #fff; border: none; border-radius: 3px; cursor: pointer;
}

/* --- Invoice Table Actions Cell --- */
.fta-actions-cell {
    display: flex;
    align-items: center;
    flex-wrap: wrap; /* Allow wrapping on small screens if needed */
    gap: 10px;
    width: 260px;
}
.fta-table button.fta-download-pdf,
.fta-table button.fta-delete-invoice {
    padding: 3px 10px;
    font-size: 12px;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    text-decoration: none;
    color: #fff;
}
.fta-table button.fta-download-pdf {
    background: #6c757d;
}
.fta-table button.fta-download-pdf:hover { background: #5a6268; }

.fta-table button.fta-delete-invoice {
    background: #dc3232;
}
.fta-table button.fta-delete-invoice:hover {
    background: #a00;
}

/* --- Toggle Switch Styles --- */
.fta-toggle-switch {
    position: relative; display: inline-block;
    width: 100px; height: 28px; cursor: pointer; flex-shrink: 0;
}
.fta-toggle-switch input { opacity: 0; width: 0; height: 0; }
.fta-toggle-slider {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background-color: #dc3232; border-radius: 28px; transition: .4s;
}
.fta-toggle-slider:before {
    position: absolute; content: "";
    height: 20px; width: 20px; left: 4px; bottom: 4px;
    background-color: white; border-radius: 50%; transition: .4s;
}
.fta-toggle-slider span {
    position: absolute; top: 50%; transform: translateY(-50%);
    font-size: 10px; font-weight: 600; color: white; user-select: none;
}
.fta-toggle-label-unpaid { left: 30px; opacity: 1; }
.fta-toggle-label-paid { right: 35px; opacity: 0; }
input:checked + .fta-toggle-slider { background-color: #008000; }
input:checked + .fta-toggle-slider:before { transform: translateX(72px); }
input:checked + .fta-toggle-slider .fta-toggle-label-unpaid { opacity: 0; }
input:checked + .fta-toggle-slider .fta-toggle-label-paid { opacity: 1; }

/* --- Invoice Items --- */
.fta-invoice-item-header {
    display: none; /* Hide on mobile */
}
.fta-invoice-item-row { 
    display: grid;
    grid-template-columns: 1fr 1fr; /* 2-column on mobile */
    gap: 10px;
    align-items: center;
    margin-bottom: 15px;
    padding: 10px;
    background: #fdfdfd;
    border: 1px solid #eee;
    border-radius: 4px;
}
.item-desc  { grid-column: 1 / -1; }
.item-qty   { }
.item-unit  { }
.item-price { grid-column: 1 / 2; }
.item-total { grid-column: 2 / 3; font-weight: 600; text-align: right; font-size: 1.2em; }
.fta-invoice-item-row .fta-remove-item {
    grid-column: 1 / -1;
    background: #dc3232; color: #fff; border: none;
    border-radius: 3px; cursor: pointer;
    padding: 5px;
    text-align: center;
}

/* --- Desktop Invoice Items --- */
@media (min-width: 769px) {
    .fta-invoice-item-header {
        display: flex; gap: 10px; font-weight: 600; font-size: 0.9em;
        color: #555; padding: 0 5px 5px 5px; border-bottom: 1px solid #ddd;
        margin-right: 34px;
    }
    .fta-invoice-item-row {
        display: flex;
        gap: 10px;
        margin-bottom: 5px;
        padding: 0;
        background: none;
        border: none;
    }
    .item-desc  { flex: 4; }
    .item-qty   { flex: 1.5; }
    .item-unit  { flex: 1.5; }
    .item-price { flex: 1.5; }
    .item-total { flex: 1.5; text-align: right; }
    .fta-invoice-item-row .fta-remove-item {
        grid-column: auto; /* Reset grid */
        flex-basis: 24px;
        border-radius: 50%;
        width: 24px;
        height: 24px;
        padding: 0;
    }
}

/* --- Invoice Totals Grid --- */
.fta-totals-grid {
    display: grid; 
    grid-template-columns: 1fr auto; /* 2-column on mobile */
    gap: 5px 15px; 
    justify-content: end; 
    align-items: center; 
    font-size: 1.1em;
    padding-top: 15px;
    border-top: 1px solid #eee;
    margin-top: 15px;
}
.fta-totals-grid label { font-weight: 600; text-align: right; }
.fta-totals-grid span { font-weight: 600; text-align: right; padding-right: 5px; }
.fta-totals-grid input { max-width: 100px; text-align: right; }
.fta-totals-grid .fta-total-label { font-size: 1.3em; font-weight: 700; color: #000; }

@media (min-width: 769px) {
    .fta-totals-grid {
        grid-template-columns: auto auto; /* Revert to auto on desktop */
    }
}

/* --- Summary Tab --- */
.fta-summary-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px;
}
.fta-summary-box {
    background: #fff; border: 1px solid #ddd; padding: 20px;
    border-radius: 4px; text-align: center;
}
.fta-summary-title { font-size: 14px; font-weight: 600; color: #555; margin-bottom: 10px; }
.fta-summary-value { font-size: 2em; font-weight: 700; color: #004578; }
.fta-summary-box.profit .fta-summary-value { color: #006400; }
.fta-summary-box.loss .fta-summary-value { color: #aa0000; }

/* --- Tax Sim & VAT Sim --- */
#fta-run-sim, #fta-run-vat-sim { font-size: 1.2em; padding: 12px 20px; margin-bottom: 20px; width: 100%; }
#fta-sim-results input, .fta-vat-box input {
    background: #f0f0f0; font-weight: 600; color: #000;
}
#fta-sim-total { font-size: 1.3em; color: #006400; }

@media (min-width: 769px) {
    #fta-run-sim, #fta-run-vat-sim { width: auto; }
}

/* --- VAT Return Grid --- */
.fta-vat-grid {
    display: grid;
    grid-template-columns: 1fr; /* Single column on mobile */
    gap: 15px;
    margin-top: 20px;
}
@media (min-width: 769px) {
    .fta-vat-grid {
        grid-template-columns: repeat(3, 1fr); /* 3 columns on desktop */
    }
}
.fta-vat-box {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 15px;
}
.fta-vat-box label {
    display: block;
    font-weight: 600;
    font-size: 13px;
    color: #555;
    margin-bottom: 8px;
}
.fta-vat-box input {
    width: 100%;
    font-size: 1.3em;
}
.fta-vat-box.manual input {
    background: #fff;
    border: 1px solid #999;
}
.fta-vat-box.total input {
    background: #e9f5ff;
}
.fta-vat-box.total.final input {
    background: #dff0d8;
    color: #3c763d;
    font-weight: 700;
}

/* --- Help Section --- */
.fta-help-section {
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid #ddd;
}
.fta-help-section h3 {
    grid-column: 1 / -1;
    margin: 0 0 15px 0;
    border-bottom: none;
    color: #004578;
}
.fta-help-section p, .fta-help-section li {
    font-size: 14px;
    line-height: 1.6;
}
.fta-help-section ul {
    list-style: disc;
    padding-left: 20px;
    margin-top: 10px;
}

/* --- Message Bar --- */
#fta-message-bar {
    padding: 10px 25px; 
    text-align: center; 
    display: none;
    margin: 0; 
    font-weight: 600;
    border-top: 1px solid #cddde9;
}
#fta-message-bar.success {
    background: #dff0d8; color: #3c763d;
}
#fta-message-bar.error {
    background: #f2dede; color: #a94442;
}