/* 
  Ace10X - Components Stylesheet 
  Buttons, Cards, Tables, Forms, Badges, Layout
*/

/* ──────────────────────────────────────────────
   Buttons
   ────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 18px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    gap: 0.5rem;
    white-space: nowrap;
    flex-shrink: 0;
}

.btn:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(21, 101, 192, 0.3);
}

.btn-sm {
    padding: 0.35rem 0.875rem;
    font-size: 0.8125rem;
    border-radius: 12px;
}

.btn-primary {
    background-color: var(--primary-blue);
    color: var(--white);
}
.btn-primary:hover {
    background-color: var(--hero-blue);
    color: var(--white);
}

.btn-secondary {
    background-color: var(--white);
    color: var(--primary-blue);
    border-color: var(--primary-blue);
}
.btn-secondary:hover {
    background-color: var(--page-bg);
}

.btn-danger {
    background-color: var(--error);
    color: var(--white);
    border-color: var(--error);
}
.btn-danger:hover {
    background-color: #DC2626;
    color: var(--white);
}

.btn-success {
    background-color: var(--success);
    color: var(--white);
    border-color: var(--success);
}
.btn-success:hover {
    background-color: #16A34A;
    color: var(--white);
}

.btn-warning {
    background-color: var(--warning);
    color: var(--white);
    border-color: var(--warning);
}
.btn-warning:hover {
    background-color: #D97706;
    color: var(--white);
}

.btn-light {
    background-color: #F1F5F9;
    color: var(--primary-text);
    border-color: #E2E8F0;
}
.btn-light:hover {
    background-color: #E2E8F0;
}

.btn-outline-primary {
    background-color: transparent;
    color: var(--primary-blue);
    border-color: var(--primary-blue);
}
.btn-outline-primary:hover {
    background-color: var(--primary-blue);
    color: var(--white);
}

.btn-outline-danger {
    background-color: transparent;
    color: var(--error);
    border-color: var(--error);
}
.btn-outline-danger:hover {
    background-color: var(--error);
    color: var(--white);
}

/* ──────────────────────────────────────────────
   Cards
   ────────────────────────────────────────────── */
.card {
    background-color: var(--white);
    border: 1px solid #E6EEF7;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0,0,0,.06);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--divider-color);
}

.card-title {
    font-size: 1.0625rem;
    font-weight: 600;
    margin: 0;
    color: var(--primary-text);
}

.card-body {
    /* no extra padding needed — card already has padding */
}

/* KPI Cards */
.kpi-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 0.25rem;
}
.kpi-card .kpi-value {
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--primary-text);
    margin: 0.35rem 0;
    line-height: 1.2;
}
.kpi-card .kpi-label {
    font-size: 0.8125rem;
    color: var(--secondary-text);
    font-weight: 500;
}

/* ──────────────────────────────────────────────
   Forms
   ────────────────────────────────────────────── */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--primary-text);
}

.form-control {
    display: block;
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 0.875rem;
    font-family: inherit;
    line-height: 1.5;
    color: var(--primary-text);
    background-color: var(--white);
    background-clip: padding-box;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
    min-width: 0; /* allows it to shrink in flex */
}

.form-control::placeholder {
    color: #9CA3AF;
}

.form-control:focus {
    color: var(--primary-text);
    background-color: var(--white);
    border-color: var(--primary-blue);
    outline: 0;
    box-shadow: 0 0 0 3px rgba(21, 101, 192, 0.1);
}

.form-control.is-invalid {
    border-color: var(--error);
}
.form-control.is-invalid:focus {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

/* ──────────────────────────────────────────────
   Tables
   ────────────────────────────────────────────── */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
}

.table {
    width: 100%;
    min-width: 500px; /* prevents crushing on small screens */
    margin-bottom: 0;
    color: var(--primary-text);
    border-collapse: separate;
    border-spacing: 0;
}

.table th,
.table td {
    padding: 0.875rem 1rem;
    vertical-align: middle;
    border-top: 1px solid #E6EEF7;
    text-align: left;
    font-size: 0.875rem;
    white-space: nowrap;
}

.table thead th {
    vertical-align: bottom;
    border-bottom: 2px solid #E6EEF7;
    background-color: #F8FAFC;
    color: var(--secondary-text);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.06em;
    border-top: none;
}

.table tbody tr {
    background-color: var(--white);
    transition: background-color 0.15s;
}
.table tbody tr:nth-of-type(even) {
    background-color: #FAFBFD;
}
.table tbody tr:hover {
    background-color: #F2F7FF;
}

/* ──────────────────────────────────────────────
   Badges
   ────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 0.275em 0.65em;
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1;
    text-align: center;
    white-space: nowrap;
    vertical-align: baseline;
    border-radius: 9999px;
}

.badge-success { background-color: #DCFCE7; color: #15803D; }
.badge-warning { background-color: #FEF3C7; color: #B45309; }
.badge-danger  { background-color: #FEE2E2; color: #B91C1C; }
.badge-info    { background-color: #DBEAFE; color: var(--primary-blue); }

/* ──────────────────────────────────────────────
   Layout – Sidebar & Main
   ────────────────────────────────────────────── */
.layout-wrapper {
    display: flex;
    min-height: 100vh;
    width: 100%;
    position: relative;
}

/* Sidebar overlay (mobile) */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 99;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.25s ease;
}
.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.sidebar {
    width: var(--sidebar-width);
    background-color: var(--primary-blue);
    color: var(--white);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    z-index: 100;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header {
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 1;
    background-color: var(--primary-blue);
}

.sidebar-brand {
    color: var(--white);
    font-size: 1.125rem;
    font-weight: 700;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.sidebar-brand:hover {
    color: var(--white);
}

/* Close button inside sidebar (mobile) */
.sidebar-close-btn {
    display: none;
    background: none;
    border: none;
    color: rgba(255,255,255,0.8);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: background 0.2s;
    flex-shrink: 0;
}
.sidebar-close-btn:hover {
    background: rgba(255,255,255,0.15);
    color: var(--white);
}

.sidebar-nav {
    flex-grow: 1;
    padding: 1.25rem 0;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    overflow-y: auto;
}

.sidebar-item {
    padding: 0 0.875rem;
}

.sidebar-link {
    display: flex;
    align-items: center;
    padding: 0.7rem 1rem;
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.18s;
    font-weight: 500;
    font-size: 0.875rem;
    gap: 0.75rem;
}
.sidebar-link:hover {
    background-color: rgba(255,255,255,0.12);
    color: var(--white);
}
.sidebar-link.active {
    background-color: rgba(255,255,255,0.18);
    color: var(--white);
}

.sidebar-icon {
    width: 18px;
    height: 18px;
    fill: currentColor;
    flex-shrink: 0;
}

/* ──────────────────────────────────────────────
   Layout – Main Content
   ────────────────────────────────────────────── */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background-color: var(--page-bg);
    overflow-x: hidden;
    margin-left: var(--sidebar-width);
    transition: margin-left 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

/* When a page doesn't render a sidebar block, don't reserve sidebar space */
.layout-wrapper > .main-content:only-child {
    margin-left: 0;
}

/* ──────────────────────────────────────────────
   Layout – Navbar
   ────────────────────────────────────────────── */
.navbar {
    height: 64px;
    background-color: var(--white);
    border-bottom: 1px solid #E5E7EB;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.75rem;
    position: sticky;
    top: 0;
    z-index: 90;
    gap: 1rem;
}

/* Hamburger toggle (mobile) */
.navbar-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--primary-text);
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    transition: background 0.2s;
    flex-shrink: 0;
}
.navbar-toggle:hover {
    background: var(--page-bg);
}

.navbar-brand {
    display: none;
    align-items: center;
    gap: 0.5rem;
    color: var(--primary-blue);
    font-weight: 700;
    font-size: 1rem;
    text-decoration: none;
}
.navbar-brand:hover {
    color: var(--deep-blue);
}

.navbar-user {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    margin-left: auto;
    flex-shrink: 0;
}

.navbar .flex-grow-1 {
    min-width: 0;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: var(--primary-blue);
    color: var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.8125rem;
    flex-shrink: 0;
}

/* ──────────────────────────────────────────────
   Page Content
   ────────────────────────────────────────────── */
.page-content {
    padding: 1.75rem 2rem;
    flex-grow: 1;
    overflow-x: hidden;
}

.page-header {
    margin-bottom: 1.75rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 1rem;
}

.page-title {
    font-size: 1.375rem;
    font-weight: 700;
    color: var(--primary-text);
    margin: 0;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

/* ──────────────────────────────────────────────
   Dashboard Grids
   ────────────────────────────────────────────── */
.grid-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

.grid-charts {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

.grid-charts > .card,
.grid-cards > .card {
    min-width: 0;
    margin-bottom: 0;
}

/* ──────────────────────────────────────────────
   Custom Modal
   ────────────────────────────────────────────── */
.custom-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, backdrop-filter 0.25s ease;
    padding: 1rem;
}
.custom-modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.custom-modal-box {
    background: #FFFFFF;
    border-radius: 20px;
    width: 100%;
    max-width: 440px;
    padding: 1.75rem;
    box-shadow: 0 25px 50px -12px rgba(15, 23, 42, 0.25);
    transform: scale(0.92);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    border: 1px solid #E2E8F0;
}
.custom-modal-overlay.active .custom-modal-box {
    transform: scale(1);
}

.custom-modal-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.custom-modal-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.custom-modal-icon.icon-primary  { background: #EFF6FF; color: #0D6EFD; }
.custom-modal-icon.icon-success  { background: #ECFDF5; color: #10B981; }
.custom-modal-icon.icon-warning  { background: #FEF3C7; color: #F59E0B; }

.custom-modal-title {
    font-size: 1.125rem;
    font-weight: 700;
    color: #0F172A;
    margin: 0;
}

.custom-modal-body {
    font-size: 0.9125rem;
    color: #475569;
    line-height: 1.6;
    margin-bottom: 1.5rem;
    white-space: pre-line;
}

.custom-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    flex-wrap: wrap;
}

/* ──────────────────────────────────────────────
   Alert Styles (inline flash messages)
   ────────────────────────────────────────────── */
.alert-success {
    background-color: #DCFCE7;
    color: #15803D;
    border: 1px solid #22C55E;
    border-radius: 8px;
    padding: 0.75rem 1rem;
}
.alert-warning {
    background-color: #FEF3C7;
    color: #B45309;
    border: 1px solid #F59E0B;
    border-radius: 8px;
    padding: 0.75rem 1rem;
}
.alert-danger {
    background-color: #FEE2E2;
    color: #B91C1C;
    border: 1px solid #EF4444;
    border-radius: 8px;
    padding: 0.75rem 1rem;
}

/* ──────────────────────────────────────────────
   RESPONSIVE BREAKPOINTS
   ────────────────────────────────────────────── */

/* ── Tablet (≤ 1024px) ── */
@media (max-width: 1024px) {
    .grid-cards {
        grid-template-columns: repeat(2, 1fr);
    }
    .page-content {
        padding: 1.5rem;
    }
}

/* ── Mobile (≤ 768px) ── */
@media (max-width: 768px) {
    /* Show sidebar overlay */
    .sidebar-overlay {
        display: block;
    }

    /* Sidebar slides in from left */
    .sidebar {
        width: min(86vw, 320px);
        transform: translateX(-100%);
        box-shadow: none;
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 30px rgba(15, 23, 42, 0.18);
    }
    .sidebar-close-btn {
        display: flex;
    }

    /* Main content takes full width */
    .main-content {
        margin-left: 0;
    }

    /* Show hamburger & brand in navbar */
    .navbar-toggle {
        display: flex;
    }
    .navbar-brand {
        display: flex;
    }
    .navbar {
        padding: 0 1rem;
    }

    .navbar .flex-grow-1 {
        display: none;
    }

    .navbar-user {
        gap: 0.5rem;
    }

    /* Page content tighter on mobile */
    .page-content {
        padding: 1rem;
    }

    /* Page header stacks */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }
    .header-actions {
        width: 100%;
    }
    .header-actions form {
        width: 100%;
        flex-direction: column;
    }
    .header-actions .form-control {
        width: 100%;
    }
    .header-actions .btn {
        width: 100%;
        justify-content: center;
    }

    /* Grid collapses to 1 col */
    .grid-cards {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    .grid-charts {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    /* KPI values slightly smaller */
    .kpi-card .kpi-value {
        font-size: 1.625rem;
    }

    /* Referral link row wraps */
    .referral-link-row {
        flex-wrap: wrap !important;
    }
    .referral-link-row .btn {
        flex-shrink: 0;
    }

    /* Table cells allow wrapping names */
    .table th,
    .table td {
        font-size: 0.8125rem;
        padding: 0.75rem 0.75rem;
    }

    /* Card inner padding reduced */
    .card {
        padding: 1.125rem;
    }

    /* Modal fullscreen-ish on mobile */
    .custom-modal-box {
        padding: 1.25rem;
    }
    .custom-modal-actions {
        flex-direction: column-reverse;
    }
    .custom-modal-actions .btn {
        width: 100%;
        justify-content: center;
    }
}

/* ── Small Mobile (≤ 480px) ── */
@media (max-width: 480px) {
    .page-title {
        font-size: 1.125rem;
    }
    .navbar {
        height: 56px;
        padding: 0 0.75rem;
    }

    .navbar-user .btn {
        padding-left: 0.7rem;
        padding-right: 0.7rem;
    }

    .avatar {
        width: 32px;
        height: 32px;
        font-size: 0.75rem;
    }
    .btn:not(.btn-sm) {
        padding: 0.5rem 1rem;
        font-size: 0.8125rem;
    }
    .card {
        padding: 1rem;
        border-radius: 12px;
    }
}
