/* ==========================================================================
   Billing System — front-end app styles
   ========================================================================== */

#ybill-app, #ybill-app * {
    box-sizing: border-box;
}

#ybill-app {
    --ybill-primary: #007cba;
    --ybill-primary-dark: #005a87;
    --ybill-sidebar-bg: #1e293b;
    --ybill-sidebar-text: #94a3b8;
    --ybill-sidebar-active-bg: rgba(255, 255, 255, 0.12);
    --ybill-sidebar-active-text: #ffffff;
    --ybill-border: #e2e8f0;
    --ybill-bg: #f8f9fb;
    --ybill-text: #1e293b;
    --ybill-text-muted: #64748b;
    --ybill-danger: #dc2626;
    --ybill-success: #16a34a;
    --ybill-radius: 10px;

    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    color: var(--ybill-text);
    background: var(--ybill-bg);
    border-radius: var(--ybill-radius);
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.ybill-icon-btn {
    padding: 0 !important;
    background: transparent !important;
    color: red !important;
    font-size: 22px !important;
    margin-right: 25px;
}
.ybill-icon-btn .fas.fa-pen{
    color: #00c700 !important;
}
.ybill-icon-btn .fas.fa-copy {
    color: #008fd3 !important;
}
.ybill-icon-btn:not(:last-child) {
    margin-right: 10px;
}
.ybill-nav-logout {
    background: #fff;
}
/* ---------------------------------------------------------------------- */
/* Loader                                                                  */
/* ---------------------------------------------------------------------- */

.ybill-app-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 80px 20px;
    color: var(--ybill-text-muted);
    font-size: 15px;
}

.ybill-loader-spinner {
    width: 34px;
    height: 34px;
    border: 3px solid var(--ybill-border);
    border-top-color: var(--ybill-primary);
    border-radius: 50%;
    animation: ybill-spin 0.8s linear infinite;
}

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

/* ---------------------------------------------------------------------- */
/* Top nav                                                                 */
/* ---------------------------------------------------------------------- */

.ybill-nav {
    background: var(--ybill-sidebar-bg);
    color: var(--ybill-sidebar-text);
}

.ybill-nav-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.ybill-nav-toggle {
    display: none;
    background: none;
    border: none;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
}

.ybill-nav-brand {
    font-size: 17px;
    font-weight: 700;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ybill-nav-user {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
}

.ybill-user-name {
    color: var(--ybill-sidebar-text);
}

.ybill-nav-logout {
    color: var(--ybill-sidebar-text);
    text-decoration: none;
    font-size: 16px;
    padding: 6px 8px;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
}

.ybill-nav-logout:hover {
    background: var(--ybill-sidebar-active-bg);
    color: #fff;
}

.ybill-nav-menu {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    margin: 0;
    padding: 6px 12px 10px;
    gap: 4px;
}

.ybill-nav-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--ybill-sidebar-text);
    transition: background 0.15s, color 0.15s;
    user-select: none;
}

.ybill-nav-item:hover {
    background: var(--ybill-sidebar-active-bg);
    color: var(--ybill-sidebar-active-text);
}

.ybill-nav-item.active {
    background: var(--ybill-primary);
    color: #fff;
}

/* ---------------------------------------------------------------------- */
/* Sections / generic layout                                              */
/* ---------------------------------------------------------------------- */

.ybill-section {
    padding: 24px 28px 40px;
}

.ybill-section h2 {
    margin: 0 0 6px;
    font-size: 21px;
}

.ybill-section h3 {
    font-size: 15px;
    margin: 22px 0 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--ybill-border);
    color: var(--ybill-text);
}

/* ---------------------------------------------------------------------- */
/* Buttons                                                                 */
/* ---------------------------------------------------------------------- */

.ybill-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, transform 0.05s, box-shadow 0.15s;
    line-height: 1.2;
    background: green !important;
}

.ybill-btn:active { transform: translateY(1px); }

.ybill-btn-primary {
    background: var(--ybill-primary);
    color: #fff;
}
.ybill-btn-primary:hover { background: var(--ybill-primary-dark); color: #fff; }

.ybill-btn-secondary {
    background: #4e2d8a !important;
    color: #fff !important;
    font-size: 14px !important;
    padding: 8px 15px !important;
}
.ybill-btn-secondary:hover { background: #e2e6ec; }

.ybill-btn-danger {
    background: #fee2e2;
    color: var(--ybill-danger);
}
.ybill-btn-danger:hover { background: #fecaca; }

.ybill-icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--ybill-text-muted);
    font-size: 14px;
    padding: 6px 8px;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
}
.ybill-icon-btn:hover { background: #eef1f5; color: var(--ybill-primary); }
.ybill-icon-btn-danger:hover { background: #fee2e2; color: var(--ybill-danger); }

/* ---------------------------------------------------------------------- */
/* Dashboard                                                               */
/* ---------------------------------------------------------------------- */

.ybill-dashboard-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}

.ybill-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 30px;
}

.ybill-stat-card {
    background: #fff;
    border: 1px solid var(--ybill-border);
    border-radius: var(--ybill-radius);
    padding: 18px;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.ybill-stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #e0f2fe;
    color: var(--ybill-primary);
    font-size: 18px;
    flex-shrink: 0;
}

.ybill-stat-paid .ybill-stat-icon { background: #dcfce7; color: #166534; }
.ybill-stat-pending .ybill-stat-icon { background: #fef9c3; color: #854d0e; }
.ybill-stat-overdue .ybill-stat-icon { background: #fee2e2; color: #991b1b; }

.ybill-stat-number {
    font-size: 24px;
    font-weight: 700;
    line-height: 1.1;
}

.ybill-stat-label {
    font-size: 13px;
    color: var(--ybill-text-muted);
    margin-top: 2px;
}

.ybill-recent-invoices h3 {
    border: none;
    margin-top: 0;
}

/* ---------------------------------------------------------------------- */
/* Forms                                                                   */
/* ---------------------------------------------------------------------- */

.ybill-form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 14px;
}

.ybill-form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1 1 200px;
    min-width: 160px;
}

.ybill-form-group.ybill-full-width {
    flex-basis: 100%;
}

.ybill-form-group label {
    font-size: 13px;
    font-weight: 600;
    color: var(--ybill-text-muted);
}

.ybill-form-group input[type="text"],
.ybill-form-group input[type="email"],
.ybill-form-group input[type="tel"],
.ybill-form-group input[type="url"],
.ybill-form-group input[type="date"],
.ybill-form-group input[type="number"],
.ybill-form-group select,
.ybill-form-group textarea,
#ybill-customer-search {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 14px;
    background: #fff;
    color: var(--ybill-text);
    transition: border-color 0.15s, box-shadow 0.15s;
    font-family: inherit;
}

.ybill-form-group input:focus,
.ybill-form-group select:focus,
.ybill-form-group textarea:focus,
#ybill-customer-search:focus {
    outline: none;
    border-color: var(--ybill-primary);
    box-shadow: 0 0 0 3px rgba(0, 124, 186, 0.12);
}

.ybill-form-group input[readonly] {
    background: #f1f5f9;
    color: var(--ybill-text-muted);
}

.ybill-form-actions {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--ybill-border);
}

.ybill-field-help {
    font-size: 12px;
    color: var(--ybill-text-muted);
    margin: 4px 0 0;
}

/* Customer search results dropdown */
.ybill-customer-search {
    position: relative;
}

#ybill-customer-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 20;
    background: #fff;
    border: 1px solid var(--ybill-border);
    border-radius: 8px;
    margin-top: 4px;
    max-height: 220px;
    overflow-y: auto;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
    display: none;
}

.ybill-customer-result-item {
    padding: 10px 14px;
    font-size: 14px;
    cursor: pointer;
    border-bottom: 1px solid #f1f5f9;
}
.ybill-customer-result-item:last-child { border-bottom: none; }
.ybill-customer-result-item:hover { background: #f1f5f9; }

/* ---------------------------------------------------------------------- */
/* Invoice builder                                                         */
/* ---------------------------------------------------------------------- */

.ybill-invoice-builder-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 20px;
}

.ybill-invoice-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.ybill-invoice-form {
    background: #fff;
    border: 1px solid var(--ybill-border);
    border-radius: var(--ybill-radius);
    padding: 22px;
}

.ybill-items-section {
    margin-top: 10px;
}

#ybill-items-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
}

.ybill-item-row {
    display: grid;
    grid-template-columns: 2fr 0.8fr 1fr 0.8fr 1fr auto;
    gap: 10px;
    align-items: end;
    background: #f8f9fb;
    border: 1px solid var(--ybill-border);
    border-radius: 8px;
    padding: 10px;
}

.ybill-item-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ybill-item-field label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--ybill-text-muted);
    font-weight: 600;
}

.ybill-field-optional {
    text-transform: none;
    font-weight: 400;
    color: var(--ybill-text-muted);
    letter-spacing: normal;
}

.ybill-item-field input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--ybill-border);
    border-radius: 6px;
    font-size: 13px;
    background: #fff;
}

.ybill-item-total input {
    font-weight: 700;
    background: #eef6fb;
    color: var(--ybill-primary);
}

.ybill-item-remove {
    background: none;
    border: none;
    color: var(--ybill-danger);
    cursor: pointer;
    font-size: 15px;
    padding: 8px;
    border-radius: 6px;
    height: 38px;
}
.ybill-item-remove:hover { background: #fee2e2; }

.ybill-summary-section {
    display: flex;
    justify-content: flex-end;
    margin-top: 18px;
}

.ybill-summary {
    width: 100%;
    max-width: 320px;
    background: #f8f9fb;
    border: 1px solid var(--ybill-border);
    border-radius: 8px;
    padding: 14px 18px;
}

.ybill-summary-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 14px;
    color: var(--ybill-text-muted);
}

.ybill-summary-row.ybill-grand-total {
    border-top: 1px solid var(--ybill-border);
    margin-top: 6px;
    padding-top: 10px;
    font-size: 17px;
    font-weight: 700;
    color: var(--ybill-primary);
}

.ybill-notes-section {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin-top: 20px;
}
.ybill-notes-section .ybill-form-group { flex: 1 1 260px; }

/* ---------------------------------------------------------------------- */
/* Data tables (invoice history / customers)                              */
/* ---------------------------------------------------------------------- */

.ybill-history-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
    margin-bottom: 18px;
}
.ybill-history-filters .ybill-form-group { flex: 1 1 220px; margin-bottom: 0; }

.ybill-customers-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}

.ybill-customers-search { margin-bottom: 16px; }

.ybill-table-wrap {
    background: #fff;
    border: 1px solid var(--ybill-border);
    border-radius: var(--ybill-radius);
    overflow-x: auto;
}

.ybill-data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.ybill-data-table th {
    text-align: left;
    padding: 12px 16px;
    background: #f8f9fb;
    color: var(--ybill-text-muted);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 1px solid var(--ybill-border);
    white-space: nowrap;
}

.ybill-data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}

.ybill-data-table tbody tr:last-child td { border-bottom: none; }
.ybill-data-table tbody tr:hover { background: #f8fafc; }

.ybill-actions-col {
    white-space: nowrap;
    text-align: right;
}

.ybill-empty-state {
    text-align: center;
    color: var(--ybill-text-muted);
    padding: 30px 10px;
    font-size: 14px;
}

.ybill-pagination {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin-top: 16px;
    flex-wrap: wrap;
}

.ybill-page-btn,
.ybill-page-btn-customers {
    min-width: 34px;
    padding: 7px 10px;
    border: 1px solid var(--ybill-border);
    background: #fff;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
}
.ybill-page-btn:hover,
.ybill-page-btn-customers:hover { background: #f1f5f9; }
.ybill-page-btn.active,
.ybill-page-btn-customers.active {
    background: var(--ybill-primary);
    border-color: var(--ybill-primary);
    color: #fff;
}

/* Status badges */
.ybill-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    text-transform: capitalize;
}
.ybill-badge-estimate { background: #e0f2fe; color: #0369a1; }
.ybill-badge-bill { background: #dcfce7; color: #166534; }

/* ---------------------------------------------------------------------- */
/* Profile: logo                                                           */
/* ---------------------------------------------------------------------- */

.ybill-profile-manager {
    background: #fff;
    border: 1px solid var(--ybill-border);
    border-radius: var(--ybill-radius);
    padding: 24px;
    max-width: 900px;
}

.ybill-logo-section {
    margin-bottom: 22px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--ybill-border);
}

.ybill-logo-upload {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

#ybill-logo-preview {
    width: 90px;
    height: 90px;
    border-radius: 10px;
    background: #f1f5f9;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
    color: #94a3b8;
    overflow: hidden;
    flex-shrink: 0;
    border: 1px dashed var(--ybill-border);
}
#ybill-logo-preview img { width: 100%; height: 100%; object-fit: contain; }

.ybill-logo-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
}
.ybill-logo-actions .ybill-btn { align-self: flex-start; }

/* ---------------------------------------------------------------------- */
/* Modal (Add / Edit customer)                                            */
/* ---------------------------------------------------------------------- */

.ybill-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100000;
    padding: 20px;
}

.ybill-modal {
    background: #fff;
    border-radius: var(--ybill-radius);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

.ybill-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid var(--ybill-border);
}
/* Match the icon + heading treatment used by the other section headers
   (Dashboard, Customers, Profile) so the popup reads as part of the
   same design language rather than a generic browser dialog. */
.ybill-modal-header h3 {
    margin: 0;
    font-size: 17px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--ybill-text);
}
.ybill-modal-header h3 i { color: var(--ybill-primary); font-size: 15px; }

.ybill-modal-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    color: var(--ybill-text-muted);
    padding: 6px;
}

.ybill-modal-body {
    padding: 20px 22px;
}

.ybill-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 22px;
    border-top: 1px solid var(--ybill-border);
}

/* ---------------------------------------------------------------------- */
/* Toasts                                                                  */
/* ---------------------------------------------------------------------- */

.ybill-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: #1e293b;
    color: #fff;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.25s, transform 0.25s;
    z-index: 100001;
    max-width: 320px;
}
.ybill-toast-visible { opacity: 1; transform: translateY(0); }
.ybill-toast-error { background: #dc2626; }
.ybill-toast-success { background: #16a34a; }

/* ---------------------------------------------------------------------- */
/* Login-required screen (also used by class-security.php inline markup)  */
/* ---------------------------------------------------------------------- */

.ybill-login-required {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 400px;
    padding: 60px 20px;
    background: #f8f9fb;
    border-radius: var(--ybill-radius);
}
.ybill-login-container { text-align: center; max-width: 460px; width: 100%; }
.ybill-login-icon { font-size: 56px; color: var(--ybill-primary); margin-bottom: 18px; }
.ybill-login-container h2 { font-size: 21px; margin-bottom: 10px; }
.ybill-login-container p { color: var(--ybill-text-muted); margin-bottom: 26px; }
.ybill-login-buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* ---------------------------------------------------------------------- */
/* Responsive                                                              */
/* ---------------------------------------------------------------------- */

@media (max-width: 900px) {
    .ybill-item-row {
        grid-template-columns: 1fr 1fr;
    }
    .ybill-item-name { grid-column: 1 / -1; }
}

@media (max-width: 782px) {
    .ybill-nav-toggle { display: inline-flex; }
    .ybill-nav-menu {
        display: none;
        flex-direction: column;
        width: 100%;
    }
    .ybill-nav-menu.ybill-nav-open { display: flex; }
    .ybill-nav-item { width: 100%; }
    .ybill-section { padding: 18px 16px 30px; }
    .ybill-invoice-form, .ybill-profile-manager { padding: 16px; }
    .ybill-form-group { min-width: 100%; }
}
