/* ========================================
   Smulmaatjies Invoicing Tool — Styles
   Matches main site branding
   ======================================== */

/* --- Custom Properties --- */
:root {
    --red: #E8453C;
    --red-hover: #d63a31;
    --green: #4CAF50;
    --green-hover: #43a047;
    --gold: #F5A623;
    --cream: #FFF8F0;
    --white: #FFFFFF;
    --dark: #3B2A1A;
    --pink: #FFD6CC;
    --radius: 1rem;
    --radius-lg: 1.5rem;
    --max-width: 900px;
    --shadow: 0 4px 20px rgba(59, 42, 26, 0.08);
    --shadow-hover: 0 8px 30px rgba(59, 42, 26, 0.14);
    --font-display: 'Pacifico', cursive;
    --font-heading: 'Baloo 2', cursive;
    --font-body: 'Nunito', sans-serif;
}

/* --- Reset & Base --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-body);
    font-size: 1rem;
    line-height: 1.6;
    color: var(--dark);
    background-color: var(--cream);
    min-height: 100vh;
}

/* --- Password Gate --- */
.auth-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem 1.25rem;
    text-align: center;
}

.auth-screen__logo {
    width: 10rem;
    height: 10rem;
    border-radius: 50%;
    object-fit: cover;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}

.auth-screen__title {
    font-family: var(--font-display);
    font-size: 2rem;
    color: var(--dark);
    margin-bottom: 0.25rem;
}

.auth-screen__title .text-red { color: var(--red); }
.auth-screen__title .text-green { color: var(--green); }

.auth-screen__subtitle {
    font-family: var(--font-heading);
    font-size: 1rem;
    color: var(--gold);
    margin-bottom: 2rem;
    font-weight: 700;
}

.auth-screen__form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
    max-width: 20rem;
}

.auth-screen__input {
    padding: 0.75rem 1rem;
    border: 2px solid var(--pink);
    border-radius: var(--radius);
    font-family: var(--font-body);
    font-size: 1rem;
    background: var(--white);
    text-align: center;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.auth-screen__input:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(245, 166, 35, 0.2);
}

.auth-screen__error {
    color: var(--red);
    font-size: 0.875rem;
    font-weight: 600;
    min-height: 1.25rem;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.75rem;
    border: none;
    border-radius: 50px;
    font-family: var(--font-heading);
    font-size: 1.05rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.btn:active {
    transform: translateY(0);
}

.btn--primary {
    background-color: var(--red);
    color: var(--white);
}

.btn--primary:hover {
    background-color: var(--red-hover);
}

.btn--secondary {
    background-color: var(--white);
    color: var(--dark);
    border: 2px solid var(--pink);
}

.btn--secondary:hover {
    background-color: var(--cream);
}

.btn--green {
    background-color: var(--green);
    color: var(--white);
}

.btn--green:hover {
    background-color: var(--green-hover);
}

.btn--small {
    padding: 0.5rem 1.25rem;
    font-size: 0.9rem;
}

.btn--icon {
    padding: 0.4rem 0.7rem;
    border-radius: var(--radius);
    font-size: 1.1rem;
    min-width: 2rem;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* --- Application Select Loader --- */
.application-select-wrapper {
    position: relative;
}

.application-select-wrapper.is-loading .form-select {
    background: linear-gradient(90deg, var(--cream) 25%, var(--pink) 50%, var(--cream) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    color: transparent;
    pointer-events: none;
}

.application-select-wrapper.is-loading::after {
    content: 'Loading applications...';
    position: absolute;
    left: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    font-family: var(--font-body);
    font-size: 0.95rem;
    color: var(--dark);
    opacity: 0.6;
    pointer-events: none;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* --- Main App Layout --- */
.app {
    display: none;
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1.25rem 3rem;
}

.app.is-visible {
    display: block;
}

/* --- Header --- */
.header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem 0;
    margin-bottom: 1.5rem;
    border-bottom: 2px dashed var(--pink);
}

.header__logo {
    width: 3.5rem;
    height: 3.5rem;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.header__text {
    flex: 1;
}

.header__title {
    font-family: var(--font-display);
    font-size: 1.5rem;
    color: var(--dark);
    line-height: 1.2;
}

.header__title .text-red { color: var(--red); }
.header__title .text-green { color: var(--green); }

.header__label {
    font-family: var(--font-heading);
    font-size: 0.85rem;
    color: var(--gold);
    font-weight: 700;
}

/* --- Form Sections --- */
.form-section {
    background: var(--white);
    border: 2px dashed var(--pink);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow);
}

.form-section__title {
    font-family: var(--font-heading);
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--red);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px dashed var(--pink);
}

/* --- Form Fields --- */
.form-group {
    margin-bottom: 1rem;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-label {
    display: block;
    font-family: var(--font-heading);
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--dark);
    margin-bottom: 0.3rem;
}

.form-input,
.form-select {
    width: 100%;
    padding: 0.65rem 0.85rem;
    border: 2px solid var(--pink);
    border-radius: var(--radius);
    font-family: var(--font-body);
    font-size: 0.95rem;
    background: var(--cream);
    color: var(--dark);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
}

.form-input:focus,
.form-select:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(245, 166, 35, 0.2);
}

.form-input--error {
    border-color: var(--red);
    box-shadow: 0 0 0 3px rgba(232, 69, 60, 0.12);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

/* --- Customer Section --- */
.customer-search-wrapper {
    position: relative;
}

.customer-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--white);
    border: 2px solid var(--pink);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    max-height: 12rem;
    overflow-y: auto;
    z-index: 10;
    display: none;
    box-shadow: var(--shadow);
}

.customer-dropdown.is-visible {
    display: block;
}

.customer-dropdown__item {
    padding: 0.6rem 0.85rem;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background-color 0.15s ease;
}

.customer-dropdown__item:hover,
.customer-dropdown__item.is-active {
    background-color: var(--cream);
}

.customer-dropdown__item--new {
    color: var(--green);
    font-weight: 700;
    border-top: 1px solid var(--pink);
}

.customer-badge {
    display: inline-block;
    padding: 0.2rem 0.75rem;
    border-radius: 50px;
    font-family: var(--font-heading);
    font-size: 0.75rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
}

.customer-badge--existing {
    background-color: rgba(76, 175, 80, 0.12);
    color: var(--green);
}

.customer-badge--new {
    background-color: rgba(245, 166, 35, 0.12);
    color: var(--gold);
}

.new-customer-fields {
    display: none;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px dashed var(--pink);
}

.new-customer-fields.is-visible {
    display: block;
}

/* --- Line Items Table --- */
.line-items-table {
    width: 100%;
    border-collapse: collapse;
}

.line-items-table th {
    font-family: var(--font-heading);
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--dark);
    text-align: left;
    padding: 0.5rem 0.35rem;
    border-bottom: 2px solid var(--pink);
    white-space: nowrap;
}

.line-items-table td {
    padding: 0.4rem 0.35rem;
    vertical-align: top;
}

.line-items-table .col-desc { width: 45%; }
.line-items-table .col-qty { width: 12%; }
.line-items-table .col-price { width: 18%; }
.line-items-table .col-total { width: 18%; }
.line-items-table .col-action { width: 7%; text-align: center; }

.line-items-table .form-input {
    padding: 0.5rem 0.6rem;
    font-size: 0.9rem;
}

.line-items-table .line-total-display {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 0.95rem;
    padding: 0.5rem 0.6rem;
    color: var(--dark);
}

.btn-remove-line {
    background: none;
    border: none;
    color: var(--red);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 0.3rem;
    border-radius: var(--radius);
    transition: background-color 0.15s ease;
    line-height: 1;
}

.btn-remove-line:hover {
    background-color: rgba(232, 69, 60, 0.1);
}

.add-line-row {
    padding-top: 0.75rem;
}

/* --- Totals --- */
.totals {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 2px dashed var(--pink);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.3rem;
}

.totals__row {
    display: flex;
    justify-content: space-between;
    width: 14rem;
    font-size: 0.95rem;
}

.totals__row--total {
    font-family: var(--font-heading);
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--red);
    padding-top: 0.5rem;
    margin-top: 0.25rem;
    border-top: 2px solid var(--gold);
}

.totals__label {
    color: var(--dark);
}

.totals__value {
    font-weight: 700;
    text-align: right;
}

/* --- Submit Area --- */
.submit-area {
    margin-top: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.submit-area .btn {
    width: 100%;
    max-width: 20rem;
    padding: 1rem 2rem;
    font-size: 1.15rem;
}

/* --- Loading Spinner --- */
.spinner {
    display: inline-block;
    width: 1.25rem;
    height: 1.25rem;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: var(--white);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* --- Animated Loading Dots --- */
span.loading-dots::after {
    content: '';
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
    0%   { content: ''; }
    25%  { content: '.'; }
    50%  { content: '..'; }
    75%  { content: '...'; }
    100% { content: ''; }
}

/* --- Success / Error Messages --- */
.message {
    padding: 1.25rem 1.5rem;
    border-radius: var(--radius-lg);
    text-align: center;
    margin-top: 1rem;
    display: none;
}

.message.is-visible {
    display: block;
}

.message--success {
    background-color: rgba(76, 175, 80, 0.1);
    border: 2px solid var(--green);
    color: var(--dark);
}

.message--error {
    background-color: rgba(232, 69, 60, 0.1);
    border: 2px solid var(--red);
    color: var(--dark);
}

.message__title {
    font-family: var(--font-heading);
    font-size: 1.15rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
}

.message--success .message__title {
    color: var(--green);
}

.message--error .message__title {
    color: var(--red);
}

.message__link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--green);
    font-weight: 700;
    text-decoration: none;
    margin-top: 0.5rem;
}

.message__link:hover {
    text-decoration: underline;
}

/* --- Footer --- */
.footer {
    text-align: center;
    padding: 1.5rem 1.25rem;
    font-size: 0.8rem;
    color: var(--dark);
    opacity: 0.5;
}

/* --- Utility --- */
.hidden {
    display: none !important;
}

.text-red { color: var(--red); }
.text-green { color: var(--green); }
.text-gold { color: var(--gold); }

/* --- Responsive --- */
@media (min-width: 768px) {
    .auth-screen__logo {
        width: 12rem;
        height: 12rem;
    }

    .auth-screen__title {
        font-size: 2.5rem;
    }

    .form-section {
        padding: 2rem;
    }

    .header__title {
        font-size: 1.75rem;
    }
}

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

    .line-items-table .col-desc { width: auto; }

    .line-items-table th,
    .line-items-table td {
        padding: 0.3rem 0.2rem;
    }

    .line-items-table .form-input {
        padding: 0.4rem 0.5rem;
        font-size: 0.85rem;
    }

    .totals__row {
        width: 100%;
    }
}

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