﻿/* ============================================
   Phoenix Activation System - Components
   Tables, Badges, Modals, Alerts, Tooltips
   ============================================ */

/* ========== Table ========== */
.table-container {
    width: 100%;
    overflow-x: auto;
    background-color: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    border: 1px solid var(--color-border);
}

/* A table box with the screen height: the column names stay in view while the box scrolls.
   216 / 168 px = the header, the section margin, the page and main padding, the bottom navigation below 1024 px, and 8 px. */
.table-container-scroll {
    max-height: calc(100vh - 216px);
    max-height: calc(100dvh - 216px);
    overflow: auto;
}

@media (min-width: 1024px) {
    .table-container-scroll {
        max-height: calc(100vh - 168px);
        max-height: calc(100dvh - 168px);
    }
}

/* The th carries the bottom line (it moves with the sticky cell); the thead border would add a second one. */
.table-container-scroll .table thead {
    border-bottom: 0;
}

.table-container-scroll .table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background-color: var(--bg-secondary);
    box-shadow: inset 0 -2px 0 var(--color-border);
}

.table {
    width: 100%;
    border-collapse: collapse;
}

    .table thead {
        background-color: var(--bg-secondary);
        border-bottom: 2px solid var(--color-border);
    }

    .table th {
        padding: var(--space-md) var(--space-lg);
        text-align: left;
        font-size: var(--font-size-xs);
        font-weight: var(--font-weight-semibold);
        color: var(--text-primary);
        text-transform: uppercase;
        letter-spacing: 0.04em;
    }

    .table td {
        padding: var(--space-md) var(--space-lg);
        font-size: var(--font-size-sm);
        font-variant-numeric: tabular-nums;
        color: var(--text-secondary);
        border-bottom: 1px solid var(--color-border);
    }

    .table tbody tr {
        transition: background-color var(--transition-fast);
    }

@media (hover: hover) {
    .table tbody tr:hover {
        background-color: var(--bg-secondary);
    }
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table-compact td,
.table-compact th {
    padding: var(--space-sm) var(--space-md);
}

/* ========== Badge ========== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-md);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    border-radius: var(--radius-full);
    white-space: nowrap;
}

.badge-primary {
    background-color: var(--color-primary-light);
    color: var(--color-primary-dark);
}

.badge-success {
    background-color: var(--color-success-light);
    color: var(--color-success-dark);
}

.badge-warning {
    background-color: var(--color-warning-light);
    color: var(--color-warning-dark);
}

.badge-danger {
    background-color: var(--color-danger-light);
    color: var(--color-danger-dark);
}

.badge-info {
    background-color: var(--color-info-light);
    color: var(--color-info-dark);
}

.badge-secondary {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Status Badges for Subscriptions */
.badge-active {
    background-color: var(--color-success-light);
    color: var(--color-success-dark);
}

.badge-pending {
    background-color: var(--color-warning-light);
    color: var(--color-warning-dark);
}

.badge-suspended {
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
}

.badge-dot {
    width: 6px;
    height: 6px;
    border-radius: var(--radius-full);
    background-color: currentColor;
}

/* ========== Alert ========== */
.alert {
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-md);
    border-left: 4px solid;
    display: flex;
    align-items: flex-start;
    gap: var(--space-md);
    margin-bottom: var(--space-md);
}

.alert-icon {
    font-size: var(--font-size-xl);
    flex-shrink: 0;
}

.alert-content {
    flex: 1;
}

.alert-title {
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    margin-bottom: var(--space-xs);
}

.alert-message {
    font-size: var(--font-size-sm);
    line-height: var(--line-height-relaxed);
}

.alert-close {
    width: 24px;
    height: 24px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition-control);
    flex-shrink: 0;
}

.alert-success {
    background-color: var(--color-success-light);
    border-left-color: var(--color-success);
    color: var(--color-success-dark);
}

.alert-warning {
    background-color: var(--color-warning-light);
    border-left-color: var(--color-warning);
    color: var(--color-warning-dark);
}

.alert-danger {
    background-color: var(--color-danger-light);
    border-left-color: var(--color-danger);
    color: var(--color-danger-dark);
}

.alert-info {
    background-color: var(--color-info-light);
    border-left-color: var(--color-info);
    color: var(--color-info-dark);
}

@media (hover: hover) {
    .alert-success .alert-close:hover {
        background-color: var(--color-success);
        color: var(--text-inverse);
    }

    .alert-warning .alert-close:hover {
        background-color: var(--color-warning);
        color: var(--text-inverse);
    }

    .alert-danger .alert-close:hover {
        background-color: var(--color-danger);
        color: var(--text-inverse);
    }

    .alert-info .alert-close:hover {
        background-color: var(--color-info);
        color: var(--text-inverse);
    }
}

/* ========== Modal ========== */
.modal {
    background-color: var(--bg-primary);
    border-top-left-radius: var(--radius-lg);
    border-top-right-radius: var(--radius-lg);
    box-shadow: var(--shadow-overlay);
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    z-index: var(--z-modal);
    animation: slideUp var(--transition-base);
}

/* One definition per global animation name (T-20261122-01 C4): this body won the name from pwa-styles.css until then, so the
   motion of .modal (the phone "More" sheet) stays as it was. KeyframeNameTests holds the rule. */
@keyframes slideUp {
    from {
        transform: translateX(-50%) translateY(120%);
        opacity: 0;
    }
    to {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
}

/* ========== Form Modal (Centered Modal for Forms) ========== */
.form-modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    z-index: 1050;
    display: flex;
    align-items: center;
    justify-content: center;
    /*padding: var(--space-lg);*/
    animation: fadeInBackdrop var(--transition-base);
}

@keyframes fadeInBackdrop {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* The close at once (T-20261030-03 C1, the B0b pattern): the layout script (layout.js) adds form-modal-closing to the backdrop
   at a click on a control with data-close-now (or on a backdrop that carries it), not while the window carries
   data-busy; the server removes the window after its round trip. (0,2,0) wins over the display of the backdrop. */
.form-modal-backdrop.form-modal-closing {
    display: none;
}

.form-modal {
    background-color: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-overlay);
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    max-height: 90dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    z-index: 1051;
    animation: slideUpModal var(--transition-base);
    position: relative;
}

@keyframes slideUpModal {
    from {
        transform: translateY(30px) scale(0.95);
        opacity: 0;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.form-modal-sm {
    max-width: 400px;
}

.form-modal-lg {
    max-width: 800px;
}

.form-modal-xl {
    max-width: 1200px;
}

.form-modal-header {
    padding: var(--space-lg) var(--space-xl);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--bg-secondary);
}

.form-modal-title {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.form-modal-title i {
    font-size: var(--font-size-lg);
    color: var(--color-primary);
}

.form-modal-close {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition-control);
    color: var(--text-secondary);
    background: transparent;
    border: none;
    font-size: var(--font-size-xl);
}

@media (hover: hover) {
    .form-modal-close:hover {
        background-color: var(--bg-tertiary);
        color: var(--text-primary);
    }
}

.form-modal-close:active {
    transform: scale(0.95);
}

/* The window x is 44 x 44 px on a touch screen (T-20261030-03 D7); 36 px with a mouse. */
@media (pointer: coarse) {
    .form-modal-close {
        min-width: var(--tap-min);
        min-height: var(--tap-min);
    }
}

.form-modal-body {
    padding: var(--space-xl);
    overflow-y: auto;
    overscroll-behavior: contain;
    flex: 1;
}

.form-modal-body::-webkit-scrollbar {
    width: 8px;
}

.form-modal-body::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: var(--radius-full);
}

.form-modal-body::-webkit-scrollbar-thumb {
    background: var(--text-tertiary);
    border-radius: var(--radius-full);
}

@media (hover: hover) {
    .form-modal-body::-webkit-scrollbar-thumb:hover {
        background: var(--text-secondary);
    }
}

.form-modal-footer {
    padding: var(--space-lg) var(--space-xl);
    border-top: 1px solid var(--color-border);
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
    background-color: var(--bg-secondary);
}

/* A section heading inside a form window (T-20261122-01 C1, D338, D341): the three Settings windows and the Branch form.
   div.form-modal-section > h4.form-modal-section-title; before, the same two style attributes on 11 headings. */
.form-modal-section {
    margin: var(--space-lg) 0 var(--space-md);
    padding-bottom: var(--space-sm);
    border-bottom: 2px solid var(--color-border);
}

.form-modal-section-title {
    margin: 0;
    color: var(--color-primary);
    font-size: var(--font-size-base);
    font-weight: 600;
}

/* A short list of points under a message (T-20261122-01 C1): the validation errors of the Client, Branch and Tier forms
   and the list of Boss Branches */
.note-list {
    margin: var(--space-sm) 0 0 20px;
    padding: 0;
}

/* Responsive adjustments for form modals */
@media (max-width: 768px) {
    .form-modal {
        max-width: calc(100% - 32px);
        max-height: calc(100vh - 32px);
        max-height: calc(100dvh - 32px);
        margin: var(--space-md);
    }

    .form-modal-header,
    .form-modal-body,
    .form-modal-footer {
        padding: var(--space-md) var(--space-lg);
    }

    .form-modal-title {
        font-size: var(--font-size-lg);
    }

    /* Stack buttons vertically on mobile */
    .form-modal-footer {
        flex-direction: column-reverse;
        gap: var(--space-xs);
    }

    .form-modal-footer .btn {
        width: 100%;
        justify-content: center;
    }
}

.modal-header {
    padding: var(--space-lg) var(--space-xl);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-close {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition-control);
    color: var(--text-secondary);
}

@media (hover: hover) {
    .modal-close:hover {
        background-color: var(--bg-tertiary);
        color: var(--text-primary);
    }
}

.modal-body {
    padding: var(--space-xl);
    overflow-y: auto;
    flex: 1;
}

/* ========== Dropdown ========== */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-item {
    padding: var(--space-sm) var(--space-md);
    font-size: var(--font-size-sm);
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition-control);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

@media (hover: hover) {
    .dropdown-item:hover {
        background-color: var(--bg-secondary);
    }
}

.dropdown-item:first-child {
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.dropdown-item:last-child {
    border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.dropdown-divider {
    height: 1px;
    background-color: var(--color-border);
    margin: var(--space-xs) 0;
}

/* ========== Progress Bar ========== */
.progress {
    width: 100%;
    height: 8px;
    background-color: var(--bg-tertiary);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background-color: var(--color-primary);
    border-radius: var(--radius-full);
    transition: width var(--transition-slow);
}

.progress-sm {
    height: 4px;
}

/* ========== Loading Spinner ========== */
.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--bg-tertiary);
    border-top-color: var(--color-primary);
    border-radius: var(--radius-full);
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ========== Empty State ========== */
.empty-state {
    text-align: center;
    padding: var(--space-3xl) var(--space-lg);
}
