/* ==========================================================================
   iTravCo Unified Portal — Component Styles
   KPI cards, tables, buttons, tabs, forms, toasts, modals, badges, etc.
   Design System: iTravCo Brand (Blue Royal + Rose Magenta)
   ========================================================================== */

/* ---------- KPI Cards ---------- */
.kpi-row {
    display: grid;
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--color-bg-card);
    border-radius: var(--radius-lg);
    padding: 20px;
    border: 1px solid var(--color-border-light);
    box-shadow: var(--shadow-sm);
    text-align: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    position: relative;
    overflow: hidden;
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--color-accent);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

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

.kpi-icon {
    font-size: 24px;
    margin-bottom: 8px;
}

.kpi-value {
    font-family: var(--font-display);
    font-size: 32px;
    font-weight: 700;
    color: var(--color-primary);
    line-height: 1.2;
}

.kpi-label {
    font-size: 13px;
    color: var(--color-text-muted);
    margin-top: 4px;
}

.kpi-delta {
    font-size: 12px;
    margin-top: 6px;
    font-weight: 600;
}

.kpi-delta.up {
    color: var(--color-success);
}

.kpi-delta.down {
    color: var(--color-danger);
}

/* ---------- Data Tables ---------- */
.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--color-bg-card);
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--color-border-light);
    box-shadow: var(--shadow-sm);
}

.data-table th {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    color: #fff;
    padding: 12px 16px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    white-space: nowrap;
}

.data-table th:first-child {
    border-top-left-radius: var(--radius-lg);
}

.data-table th:last-child {
    border-top-right-radius: var(--radius-lg);
}

.data-table td {
    padding: 10px 16px;
    border-bottom: 1px solid var(--color-border-light);
    font-size: 14px;
    vertical-align: middle;
}

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

.data-table tr:hover td {
    background: var(--color-bg-hover);
}

.data-table td.actions {
    white-space: nowrap;
}

.data-table .text-right {
    text-align: right;
}

.data-table .text-center {
    text-align: center;
}

/* Table wrapper for horizontal scroll */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    margin-bottom: 20px;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    gap: 6px;
    line-height: 1.4;
}

.btn:hover {
    text-decoration: none;
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

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

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

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

.btn-accent {
    background: var(--color-accent);
    color: #fff;
}

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

.btn-success {
    background: var(--color-success);
    color: #fff;
}

.btn-success:hover {
    background: #247A4D;
}

.btn-danger {
    background: var(--color-danger);
    color: #fff;
}

.btn-danger:hover {
    background: #B53838;
}

.btn-warning {
    background: var(--color-warning);
    color: #fff;
}

.btn-warning:hover {
    background: #B87332;
}

.btn-outline {
    background: transparent;
    color: var(--color-primary);
    border: 1px solid var(--color-primary);
}

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

.btn-ghost {
    background: transparent;
    color: var(--color-text-secondary);
}

.btn-ghost:hover {
    background: var(--color-bg-hover);
    color: var(--color-text);
}

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
    border-radius: var(--radius-sm);
}

.btn-lg {
    padding: 12px 24px;
    font-size: 16px;
    border-radius: var(--radius-md);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-group {
    display: inline-flex;
    gap: 0;
}

.btn-group .btn {
    border-radius: 0;
}

.btn-group .btn:first-child {
    border-radius: var(--radius-md) 0 0 var(--radius-md);
}

.btn-group .btn:last-child {
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

/* ---------- Tabs ---------- */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--color-border);
    margin-bottom: 20px;
    overflow-x: auto;
}

.tab {
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 500;
    color: var(--color-text-muted);
    background: none;
    border: none;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.tab:hover {
    color: var(--color-primary);
}

.tab.active {
    color: var(--color-accent);
    border-bottom-color: var(--color-accent);
    font-weight: 600;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Tab caption */
.tab-caption {
    font-size: 14px;
    color: var(--color-text-secondary);
    margin-bottom: 16px;
}

.tab-caption a {
    color: var(--color-accent);
    font-weight: 500;
}

/* ---------- Forms ---------- */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text-secondary);
    margin-bottom: 4px;
}

.form-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    background: var(--color-bg-card);
    color: var(--color-text);
}

.form-input:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(229, 74, 137, 0.15);
}

.form-input::placeholder {
    color: var(--color-text-muted);
}

.form-select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    background: var(--color-bg-card);
    color: var(--color-text);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239B9389' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.form-select:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(229, 74, 137, 0.15);
}

.form-textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    background: var(--color-bg-card);
    color: var(--color-text);
    min-height: 80px;
    resize: vertical;
}

.form-textarea:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(229, 74, 137, 0.15);
}

.form-hint {
    font-size: 12px;
    color: var(--color-text-muted);
    margin-top: 4px;
}

.form-error {
    font-size: 12px;
    color: var(--color-danger);
    margin-top: 4px;
}

.form-input.error {
    border-color: var(--color-danger);
}

.form-row {
    display: flex;
    gap: 16px;
}

.form-row .form-group {
    flex: 1;
}

.form-inline {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

/* Checkbox & Radio */
.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    cursor: pointer;
}

.form-check input[type="checkbox"],
.form-check input[type="radio"] {
    accent-color: var(--color-accent);
    width: 16px;
    height: 16px;
}

/* Input email (workflow send forms) */
.input-email {
    padding: 6px 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 13px;
    font-family: inherit;
    flex: 1;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input-email:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(229, 74, 137, 0.15);
}

/* ---------- Toast Notifications ---------- */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-md);
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    animation: slideIn 0.3s ease, fadeOut 0.3s ease 2.7s forwards;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.toast-success {
    background: var(--color-success);
}

.toast-error {
    background: var(--color-danger);
}

.toast-warning {
    background: var(--color-warning);
}

.toast-info {
    background: var(--color-info);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

/* ---------- Modal ---------- */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 500;
    background: rgba(16, 85, 154, 0.45);
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(3px);
}

.modal.open {
    display: flex;
}

.modal-content {
    background: var(--color-bg-card);
    border-radius: var(--radius-xl);
    padding: 24px;
    max-width: 800px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    position: relative;
    animation: modalAppear 0.2s ease;
}

@keyframes modalAppear {
    from {
        transform: scale(0.95);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--color-text-muted);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    transition: all 0.15s ease;
}

.modal-close:hover {
    background: var(--color-bg-hover);
    color: var(--color-text);
}

.modal-title {
    font-family: var(--font-display);
    font-size: 18px;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 16px;
    padding-right: 32px;
}

.modal-footer {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--color-border-light);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* Modal sizes */
.modal-sm .modal-content {
    max-width: 400px;
}

.modal-lg .modal-content {
    max-width: 1000px;
}

/* ---------- Badges / Tags ---------- */
.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
}

.badge-blue {
    background: var(--color-primary-light);
    color: var(--color-primary);
}

.badge-green {
    background: var(--color-success-light);
    color: var(--color-success);
}

.badge-red {
    background: var(--color-danger-light);
    color: var(--color-danger);
}

.badge-orange {
    background: var(--color-warning-light);
    color: var(--color-warning);
}

.badge-gray {
    background: var(--color-bg-muted);
    color: var(--color-text-muted);
}

.badge-purple {
    background: #F4ECF7;
    color: #8E6BAD;
}

.badge-accent {
    background: var(--color-accent-light);
    color: var(--color-accent);
}

/* ---------- HTMX Indicator / Spinner ---------- */
.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator {
    display: inline-block;
}

.htmx-request.htmx-indicator {
    display: inline-block;
}

.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--color-border);
    border-top-color: var(--color-accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.spinner-lg {
    width: 32px;
    height: 32px;
    border-width: 3px;
}

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

/* Loading overlay */
.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-lg);
    z-index: 10;
}

/* ---------- Expander / Details ---------- */
.expander {
    background: var(--color-bg-card);
    border-radius: var(--radius-md);
    margin-bottom: 12px;
    border: 1px solid var(--color-border-light);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.expander summary {
    padding: 14px 20px;
    cursor: pointer;
    font-weight: 500;
    font-size: 14px;
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.15s ease;
}

.expander summary:hover {
    background: var(--color-bg-hover);
}

.expander summary::-webkit-details-marker {
    display: none;
}

.expander summary::after {
    content: "\25B8";
    transition: transform 0.2s ease;
    color: var(--color-text-muted);
    font-size: 12px;
}

.expander[open] summary::after {
    transform: rotate(90deg);
}

.expander-body {
    padding: 0 20px 20px;
}

/* ---------- Chart Container ---------- */
.chart-container {
    background: var(--color-bg-card);
    border-radius: var(--radius-lg);
    padding: 20px;
    border: 1px solid var(--color-border-light);
    box-shadow: var(--shadow-sm);
    margin-bottom: 20px;
    position: relative;
}

.chart-title {
    font-family: var(--font-display);
    font-size: 15px;
    font-weight: 600;
    color: var(--color-primary);
    margin-bottom: 12px;
}

.chart-subtitle {
    font-size: 12px;
    color: var(--color-text-muted);
    margin-top: -8px;
    margin-bottom: 12px;
}

.chart-canvas-wrapper {
    position: relative;
    height: 300px;
}

/* ---------- Empty State ---------- */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--color-text-muted);
}

.empty-state .icon {
    font-size: 48px;
    margin-bottom: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--color-accent-light);
}

.empty-state p {
    font-size: 15px;
}

.empty-state .btn {
    margin-top: 16px;
}

/* ---------- Toolbar ---------- */
.toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.toolbar-search {
    position: relative;
    flex: 1;
    min-width: 200px;
}

.toolbar-search .form-input {
    padding-left: 32px;
}

.toolbar-search .search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-text-muted);
    font-size: 14px;
}

/* ---------- Pagination ---------- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    margin-top: 20px;
}

.pagination .page-btn {
    padding: 6px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-bg-card);
    color: var(--color-text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.pagination .page-btn:hover {
    background: var(--color-bg-hover);
}

.pagination .page-btn.active {
    background: var(--color-accent);
    color: #fff;
    border-color: var(--color-accent);
}

.pagination .page-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ---------- Status Dot ---------- */
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
}

.status-dot.green {
    background: var(--color-success);
}

.status-dot.red {
    background: var(--color-danger);
}

.status-dot.orange {
    background: var(--color-warning);
}

.status-dot.gray {
    background: var(--color-border);
}

/* ---------- Workflow Cards ---------- */
.workflow-cards {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.workflow-card {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.workflow-card-header {
    padding: 14px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.15s ease;
}

.workflow-card-header:hover {
    background: var(--color-bg-hover);
}

.workflow-card-header .hotel-name {
    font-weight: 600;
    color: var(--color-primary);
}

.workflow-card-header .conf-num {
    color: var(--color-text-muted);
    font-size: 13px;
}

.workflow-card-header .guest {
    color: var(--color-text-secondary);
}

.workflow-card-header .dates {
    color: var(--color-text-muted);
    font-size: 13px;
}

.workflow-card-header .price {
    font-weight: 600;
    color: var(--color-accent);
    margin-left: auto;
}

.workflow-card-body {
    padding: 0 20px 20px;
}

.workflow-card-error {
    border-left: 3px solid var(--color-danger);
}

.card-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 8px;
    margin-bottom: 16px;
}

.detail-row {
    font-size: 13px;
    color: var(--color-text-secondary);
    padding: 4px 0;
}

.detail-label {
    font-weight: 600;
    color: var(--color-text);
}

.error-detail code {
    background: var(--color-danger-light);
    color: var(--color-danger);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-size: 12px;
}

.send-form {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--color-border-light);
}

.send-form label {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text-secondary);
    margin-bottom: 6px;
    display: block;
}

.send-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.email-hint {
    display: block;
    font-size: 11px;
    color: var(--color-text-muted);
    margin-top: 4px;
}

/* Status icons in workflow cards */
.status-icon {
    font-size: 16px;
}

.status-red {
    color: var(--color-danger);
}

.status-orange {
    color: var(--color-warning);
}

/* ---------- Divider ---------- */
.divider {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: 20px 0;
}

/* ---------- Tooltip ---------- */
[data-tooltip] {
    position: relative;
}

[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-text);
    color: #fff;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    white-space: nowrap;
    z-index: 50;
    pointer-events: none;
}

/* ---------- Responsive Form ---------- */
@media (max-width: 768px) {
    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar-search {
        min-width: unset;
    }

    .modal-content {
        width: 95%;
        margin: 16px;
        max-height: 90vh;
    }

    .pagination {
        flex-wrap: wrap;
    }

    .card-details {
        grid-template-columns: 1fr;
    }

    .send-row {
        flex-direction: column;
    }
}
