:root {
    --bg-dark: #0a1929;
    --bg-card: #0f2744;
    --bg-sidebar: #042C53;
    --primary: #85B7EB;
    --primary-variant: #185FA5;
    --secondary: #85B7EB;
    --text-main: #e8edf3;
    --text-muted: #8da4bf;
    --danger: #f44336;
    --success: #4caf50;
    --warning: #ffb74d;
    --border: #1a3a5c;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: 'DM Sans', 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 0;
    display: flex;
    min-height: 100vh;
}

a {
    text-decoration: none;
    color: inherit;
    transition: color 0.2s;
}

a:hover {
    color: var(--primary);
}

/* Layout */
.app-container {
    display: flex;
    width: 100%;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    transition: width 0.3s ease;
    z-index: 1000;
}

.sidebar.collapsed {
    width: 70px;
}

/* Brand Area & Toggle */
.brand {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    /* Space for toggle */
    white-space: nowrap;
    overflow: hidden;
    height: 40px;
    /* Fixed height for alignment */
}

.toggle-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 5px;
    transition: color 0.2s;
    display: flex;
    /* Ensure visible */
    align-items: center;
    justify-content: center;
    min-width: 30px;
    margin-right: 15px;
    /* Safely pull away from edge */
}

.toggle-btn:hover {
    color: var(--primary);
}

.sidebar.collapsed .brand {
    justify-content: center;
    /* Center icon when collapsed */
    padding-left: 0;
}

.sidebar.collapsed .brand span {
    display: none;
    /* Hide text if separate span used */
}

/* Nav Links */
.nav-links {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.nav-item {
    padding: 12px 16px;
    border-radius: 8px;
    color: var(--text-muted);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 12px;
    white-space: nowrap;
    overflow: hidden;
    transition: background-color 0.2s, color 0.2s;
}

.sidebar.collapsed .nav-item span {
    display: none;
}

.sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 12px;
}

.nav-item:hover,
.nav-item.active {
    background-color: rgba(187, 134, 252, 0.1);
    color: var(--primary);
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.sidebar.collapsed .sidebar-footer .nav-item span {
    display: none;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 30px;
    background: radial-gradient(circle at top right, #1f1f1f 0%, var(--bg-dark) 40%);
    transition: margin-left 0.3s ease;
    min-height: 100vh;
}

.main-content.expanded {
    margin-left: 70px;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    height: 50px;
    /* Align check */
}

.page-title {
    font-size: 1.8rem;
    font-weight: 700;
    margin: 0;
}

/* Cards */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
    align-items: stretch;
    /* Cards same height */
}

.card {
    background-color: rgba(30, 30, 30, 0.7);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s, border-color 0.2s;

    /* Flex column to push footer down */
    display: flex;
    flex-direction: column;
    min-height: 100%;
    /* Ensure full height in grid */
}

.card:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
}

.card h3 {
    margin-top: 0;
    font-size: 1.1rem;
    color: var(--text-muted);
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-main);
}

/* Push footer/actions to bottom of card */
.card .text-right {
    margin-top: auto;
    /* Sticky bottom */
    padding-top: 15px;
}

/* Tables */
.table-container {
    background-color: var(--bg-card);
    border-radius: 12px;
    overflow-x: auto;
    /* Horizontal scroll instead of hidden */
    border: 1px solid var(--border);
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
    /* Prevent column crushing */
}

th,
td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

th {
    background-color: rgba(255, 255, 255, 0.02);
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.8rem;
    position: sticky;
    top: 0;
    z-index: 2;
}

tr:hover td {
    background-color: rgba(255, 255, 255, 0.02);
}

/* Badges */
.badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
    /* Don't shrink in flex containers */
}

.badge-success {
    background: rgba(0, 230, 118, 0.2);
    color: var(--success);
}

.badge-danger {
    background: rgba(207, 102, 121, 0.2);
    color: var(--danger);
}

.badge-warning {
    background: rgba(255, 183, 77, 0.2);
    color: var(--warning);
}

/* Forms */
input,
select,
textarea {
    background-color: #2c2c2c;
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 10px 14px;
    border-radius: 6px;
    width: 100%;
    box-sizing: border-box;
    font-family: inherit;
}

input:focus {
    outline: none;
    border-color: var(--primary);
}

.btn {
    padding: 10px 20px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-weight: 600;
    display: inline-block;
    transition: filter 0.2s;
}

.btn-primary {
    background-color: var(--primary);
    color: #000;
}

.btn-danger {
    background-color: var(--danger);
    color: #000;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.9rem;
}

.btn:hover {
    filter: brightness(1.1);
}

/* Dropdown Menus - z-index fix */
.dropdown,
[style*="position: relative"] {
    position: relative;
}

.dropdown-menu,
.renewal-dropdown {
    position: absolute;
    z-index: 100;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    min-width: 120px;
}

.dropdown-menu a,
.renewal-dropdown a {
    display: block;
    padding: 8px 14px;
    color: var(--text-main);
    font-size: 0.85rem;
    transition: background 0.15s;
}

.dropdown-menu a:hover,
.renewal-dropdown a:hover {
    background: rgba(187, 134, 252, 0.15);
    color: var(--primary);
}

/* Utilities */
.text-right {
    text-align: right;
}

.mt-4 {
    margin-top: 1.5rem;
}

.flex {
    display: flex;
    gap: 10px;
}

.justify-between {
    justify-content: space-between;
}

.items-center {
    align-items: center;
}

/* Text Truncation */
.text-truncate {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    max-width: 100%;
}

/* Card Updates */
.card p {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 20px;
}

/* Alerts */
.alert {
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    border-left: 4px solid transparent;
}

.alert-success {
    background: rgba(0, 230, 118, 0.1);
    border-color: var(--success);
}

.alert-danger {
    background: rgba(207, 102, 121, 0.1);
    border-color: var(--danger);
}

/* Pulse animation for alert banner */
@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.85;
    }
}

/* Header responsive fix */
.header {
    flex-wrap: wrap;
    gap: 10px;
}

/* Mobile hamburger button (visible only on mobile) */
.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-main);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 5px 10px;
    margin-right: 10px;
}

/* Sidebar backdrop overlay for mobile */
.sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

/* Toast Notification System */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: var(--bg-card);
    color: var(--text-main);
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    border-radius: 8px;
    padding: 12px 20px;
    min-width: 280px;
    max-width: 400px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    pointer-events: all;
    animation: toastSlideIn 0.3s ease-out;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
}

.toast.toast-success {
    border-left-color: var(--success);
}

.toast.toast-error {
    border-left-color: var(--danger);
}

.toast.toast-warning {
    border-left-color: var(--warning);
}

.toast.toast-info {
    border-left-color: var(--primary);
}

.toast .toast-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}

.toast.toast-success .toast-icon {
    color: var(--success);
}

.toast.toast-error .toast-icon {
    color: var(--danger);
}

.toast.toast-warning .toast-icon {
    color: var(--warning);
}

.toast.toast-info .toast-icon {
    color: var(--primary);
}

.toast.removing {
    animation: toastSlideOut 0.3s ease-in forwards;
}

@keyframes toastSlideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes toastSlideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }

    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* Mobile Response */
@media (max-width: 768px) {
    .mobile-menu-btn {
        display: flex;
        align-items: center;
    }

    .sidebar {
        width: 260px;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .sidebar-backdrop.active {
        display: block;
    }

    .brand .toggle-btn {
        display: none;
    }

    .main-content {
        margin-left: 0;
        padding: 15px;
    }

    .page-title {
        font-size: 1.3rem;
    }

    .header {
        height: auto;
        margin-bottom: 15px;
    }

    table {
        min-width: 500px;
    }
}

/* Medium screen: stack dashboard grid */
@media (max-width: 900px) {
    .activity-perf-grid {
        grid-template-columns: 1fr !important;
    }
}