/* Canvas Crew Web Portal Reconstruction - Exact Common Shell & Layout Stylesheet */
:root {
    --primary-blue: #1565C0;
    --primary-hover: #0D47A1;
    --sidebar-bg: #222d32;
    --sidebar-hover: #1e282c;
    --sidebar-text: #b8c7ce;
    --sidebar-active-bg: #1a2226;
    --content-bg: #f4f6f9;
    --card-border: #e3e6f0;
}

* {
    box-sizing: border-box;
}

html, body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--content-bg);
    margin: 0;
    padding: 0;
    color: #333333;
    font-size: 13.5px;
    line-height: 1.5;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

/* Master Wrapper */
.portal-wrapper {
    min-height: 100vh;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Recovered Data Notice Banner */
.recovered-data-banner {
    background-color: #fff3cd;
    color: #856404;
    border-bottom: 1px solid #ffeeba;
    padding: 7px 16px;
    font-size: 12.5px;
    font-weight: 600;
    text-align: center;
    letter-spacing: 0.2px;
    z-index: 1001;
}

/* Top Horizontal Header */
.top-navbar {
    min-height: 50px;
    background-color: var(--primary-blue);
    color: #ffffff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 18px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    position: sticky;
    top: 0;
    width: 100%;
    box-sizing: border-box;
}

.navbar-header-main {
    display: flex;
    align-items: center;
    gap: 15px;
}

.navbar-brand-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-toggle {
    display: none; /* hidden on desktop */
    background: transparent;
    border: none;
    color: #ffffff;
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    line-height: 1;
}

.sidebar-toggle:hover, .sidebar-toggle:focus {
    background: rgba(255, 255, 255, 0.15);
    outline: 2px solid rgba(255, 255, 255, 0.5);
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.brand-title {
    color: #ffffff;
}

.brand-sub {
    background: rgba(255, 255, 255, 0.2);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.navbar-demo-bar {
    display: flex;
    align-items: center;
    gap: 15px;
}

.institution-display {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
}

.inst-label {
    color: rgba(255, 255, 255, 0.7);
    font-size: 11px;
    font-weight: 600;
}

.inst-name {
    color: #ffffff;
    font-weight: 700;
}

.tenant-switcher-form {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0;
}

.switcher-label {
    font-size: 12px;
    color: #e0e0e0;
}

.switcher-select {
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 12px;
    background: #ffffff;
    color: #333333;
    border: 1px solid #ced4da;
    outline: none;
    cursor: pointer;
}

.navbar-right {
    display: flex;
    align-items: center;
    gap: 15px;
    font-size: 12.5px;
}

.user-email {
    color: rgba(255, 255, 255, 0.9);
}

.nav-icon-link {
    color: #ffffff;
    text-decoration: none;
    font-size: 15px;
    opacity: 0.9;
    transition: opacity 0.2s;
}

.nav-icon-link:hover {
    opacity: 1;
}

.sidebar-header-mobile {
    display: none;
}

.sidebar-backdrop {
    display: none;
}

/* Portal Body: Horizontal Split (Sidebar Beside Content) */
.portal-body {
    display: flex;
    flex: 1 1 auto;
    min-height: calc(100vh - 50px - 40px);
}

/* Left Sidebar (230px Desktop) */
.sidebar {
    width: 230px;
    min-width: 230px;
    max-width: 230px;
    flex-shrink: 0;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
}

.sidebar-user-panel {
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid #1a2226;
    background-color: rgba(0, 0, 0, 0.1);
}

.user-avatar {
    font-size: 24px;
}

.user-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.user-name {
    margin: 0;
    font-size: 12.5px;
    font-weight: 600;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 11px;
    color: #8aa4af;
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
}

.status-dot {
    width: 7px;
    height: 7px;
    background-color: #28a745;
    border-radius: 50%;
    display: inline-block;
}

.sidebar-menu {
    list-style: none;
    padding: 0;
    margin: 0;
    flex: 1 1 auto;
}

.header-item {
    padding: 12px 16px 6px;
    font-size: 11px;
    font-weight: 600;
    color: #4b646f;
    background-color: #1a2226;
    letter-spacing: 0.5px;
}

.menu-item {
    position: relative;
}

.menu-item a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 13px;
    border-left: 3px solid transparent;
    transition: all 0.15s ease-in-out;
}

.menu-item a:hover {
    color: #ffffff;
    background-color: var(--sidebar-hover);
    border-left-color: var(--primary-blue);
}

.menu-item.active > a {
    color: #ffffff;
    background-color: var(--sidebar-hover);
    border-left-color: var(--primary-blue);
    font-weight: 600;
}

.menu-item .icon {
    width: 18px;
    text-align: center;
    font-size: 14px;
}

.menu-item .label {
    flex: 1 1 auto;
}

.pull-right-arrow {
    font-size: 10px;
    transition: transform 0.2s;
}

.treeview.menu-open .pull-right-arrow {
    transform: rotate(180deg);
}

.treeview-menu {
    display: none;
    list-style: none;
    padding: 0;
    margin: 0;
    background-color: #2c3b41;
}

.treeview.menu-open .treeview-menu {
    display: block;
}

.treeview-menu li a {
    padding: 8px 16px 8px 36px;
    font-size: 12px;
    border-left: none;
}

.treeview-menu li a:hover,
.treeview-menu li.sub-active a {
    color: #ffffff;
    background-color: #202a2f;
    font-weight: 600;
}

/* Main Dashboard / Content Beside Sidebar */
.main-content {
    flex: 1 1 auto;
    min-width: 0;
    padding: 22px 24px;
    background-color: var(--content-bg);
}

.content-container {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
}

/* Page Header & Breadcrumb */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.page-title {
    font-size: 22px;
    font-weight: 600;
    color: #333333;
    margin: 0;
}

.breadcrumb {
    font-size: 12px;
    color: #777777;
}

.breadcrumb a {
    color: var(--primary-blue);
    text-decoration: none;
}

.breadcrumb a:hover {
    text-decoration: underline;
}

/* KPI Cards Row (4 Columns on Desktop) */
.dashboard-cards-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.metric-card {
    border-radius: 4px;
    color: #ffffff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.card-cyan, .card-blue { background: #00c0ef; color: #ffffff; }
.card-orange, .card-yellow { background: #f39c12; color: #ffffff; }
.card-green { background: #00a65a; color: #ffffff; }
.card-red { background: #dd4b39; color: #ffffff; }

.card-inner {
    padding: 16px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-content {
    display: flex;
    flex-direction: column;
}

.card-value {
    font-size: 28px;
    font-weight: 700;
    line-height: 1.1;
}

.card-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    margin-top: 5px;
    letter-spacing: 0.5px;
    opacity: 0.95;
}

.card-icon {
    font-size: 32px;
    opacity: 0.35;
}

.card-footer-link {
    background: rgba(0, 0, 0, 0.15);
    color: #ffffff;
    text-decoration: none;
    font-size: 12px;
    padding: 6px 18px;
    text-align: right;
    display: block;
    transition: background 0.2s;
}

.card-footer-link:hover {
    background: rgba(0, 0, 0, 0.25);
    color: #ffffff;
}

/* Panels & Cards */
.card-panel {
    background: #ffffff;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    border-top: 3px solid var(--primary-blue);
    margin-bottom: 24px;
    min-width: 0;
    max-width: 100%;
    width: 100%;
    overflow: hidden;
}

.card-panel-header {
    padding: 14px 18px;
    border-bottom: 1px solid #eeeeee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-title {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: #333333;
}

.card-panel-body {
    padding: 16px 18px;
    min-width: 0;
    max-width: 100%;
    width: 100%;
    box-sizing: border-box;
}

/* Filter Bar */
.card-panel-filter {
    background: #ffffff;
    padding: 14px 18px;
    border-bottom: 1px solid #eeeeee;
    border-top: 3px solid var(--primary-blue);
    border-radius: 4px 4px 0 0;
}

.filter-form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    align-items: flex-end;
}

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

.filter-field label {
    font-size: 11.5px;
    font-weight: 600;
    color: #555555;
    text-transform: uppercase;
}

.filter-actions {
    display: flex;
    flex-direction: row;
    gap: 8px;
    align-items: flex-end;
}

.form-control {
    padding: 6px 10px;
    font-size: 13px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    outline: none;
    background: #ffffff;
}

.form-control:focus {
    border-color: var(--primary-blue);
}

.form-control-sm {
    padding: 4px 8px;
    font-size: 12px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    outline: none;
}

/* Buttons */
.btn {
    padding: 6px 16px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background 0.2s;
}

.btn-primary { background: var(--primary-blue); color: #ffffff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: #6c757d; color: #ffffff; }
.btn-secondary:hover { background: #5a6268; }
.btn-success { background: #2e7d32; color: #ffffff; }
.btn-success:hover { background: #1b5e20; }
.btn-lg { padding: 10px 22px; font-size: 14px; }

.btn-action-edit, .btn-action-view {
    background: #f0f4f8;
    border: 1px solid #d0d7de;
    padding: 3px 8px;
    border-radius: 3px;
    font-size: 11.5px;
    cursor: pointer;
    color: #333333;
}

.btn-action-edit:hover, .btn-action-view:hover {
    background: #e2e8f0;
}

/* Tables */
.table-responsive {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    display: block;
    margin: 0;
}

.portal-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.portal-table th {
    background: #fafafa;
    color: #495057;
    font-weight: 600;
    text-align: left;
    padding: 10px 12px;
    border-bottom: 2px solid #dee2e6;
    white-space: nowrap;
}

.portal-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #eeeeee;
    vertical-align: middle;
    color: #333333;
}

.portal-table tr:hover td {
    background: #f8f9fa;
}

/* Table Controls Bar & Footers */
.table-controls-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}

.table-footer-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 14px;
    font-size: 12px;
    color: #666666;
}

.pagination-controls {
    display: flex;
    gap: 4px;
    align-items: center;
}

.page-btn {
    padding: 4px 10px;
    border: 1px solid #ced4da;
    background: #ffffff;
    color: #333333;
    border-radius: 3px;
    text-decoration: none;
    font-size: 12px;
}

.page-btn.active {
    background: var(--primary-blue);
    color: #ffffff;
    border-color: var(--primary-blue);
    font-weight: 600;
}

.page-btn.disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 2px 7px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 3px;
}

.badge-primary { background: #e3f2fd; color: #1565C0; }
.badge-success { background: #e8f5e9; color: #2e7d32; }
.badge-danger { background: #ffebee; color: #c62828; }
.badge-warning { background: #fff8e1; color: #f57f17; }
.badge-secondary { background: #eceff1; color: #455a64; }
.badge-info { background: #e0f7fa; color: #00838f; }

/* Empty States & Alerts */
.empty-state-box {
    padding: 36px 16px;
    text-align: center;
    color: #888888;
    font-size: 13.5px;
    font-style: italic;
}

.alert {
    padding: 12px 16px;
    border-radius: 4px;
    margin-bottom: 20px;
    font-size: 13px;
}

.alert-info { background: #e8f4fd; color: #004085; border: 1px solid #b8daff; }
.alert-warning { background: #fff3cd; color: #856404; border: 1px solid #ffeeba; }

/* Wallet Grid */
.wallet-cards-grid {
    display: grid;
    grid-template-columns: 280px 280px auto;
    gap: 16px;
    align-items: center;
}

.wallet-metric-card {
    padding: 18px 22px;
    border-radius: 4px;
    color: #ffffff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.balance-card { background: #2e7d32; }
.spend-card { background: #c62828; }

.wallet-card-header {
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.5px;
    opacity: 0.9;
}

.wallet-card-value {
    font-size: 32px;
    font-weight: 700;
    margin: 4px 0;
    line-height: 1.1;
}

.wallet-card-sub {
    font-size: 11px;
    opacity: 0.8;
}

.wallet-action-container {
    padding-left: 10px;
}

/* API Token Container */
.api-token-container {
    background: #fdfdfd;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    padding: 20px;
}

.token-input-group {
    display: flex;
    gap: 8px;
    max-width: 480px;
    margin-top: 6px;
}

.token-field {
    font-family: monospace;
    font-size: 13px;
    flex: 1 1 auto;
}

/* Footer */
.main-footer {
    height: 40px;
    background: #ffffff;
    border-top: 1px solid #eeeeee;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: #666666;
}

/* Responsive Breakpoints */
@media (max-width: 1024px) {
    .dashboard-cards-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .wallet-cards-grid {
        grid-template-columns: 1fr 1fr;
    }
    .wallet-action-container {
        grid-column: span 2;
        padding-left: 0;
    }
}

@media (max-width: 768px) {
    /* Compact Top Header */
    .top-navbar {
        min-height: auto;
        height: auto;
        flex-direction: column;
        padding: 0;
        align-items: stretch;
        position: sticky;
        top: 0;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    .navbar-header-main {
        height: 48px;
        padding: 0 12px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        background-color: var(--primary-blue);
        width: 100%;
        box-sizing: border-box;
    }

    .sidebar-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 34px;
        height: 34px;
        font-size: 20px;
        color: #ffffff;
        background: transparent;
        border: none;
        cursor: pointer;
        border-radius: 4px;
    }

    .navbar-brand-group {
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .user-email {
        max-width: 125px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 11px;
    }

    .navbar-right {
        display: flex;
        align-items: center;
        gap: 8px;
        font-size: 12px;
    }

    /* Stacked synthetic-demo bar on mobile without overflow */
    .navbar-demo-bar {
        background: rgba(0, 0, 0, 0.18);
        padding: 6px 12px;
        display: flex;
        flex-direction: column;
        gap: 4px;
        width: 100%;
        max-width: 100%;
        border-top: 1px solid rgba(255, 255, 255, 0.12);
        box-sizing: border-box;
    }

    .institution-display {
        font-size: 11.5px;
        display: flex;
        flex-wrap: wrap;
        align-items: baseline;
        gap: 4px;
        width: 100%;
    }

    .inst-name {
        word-break: break-word;
    }

    .tenant-switcher-form {
        display: flex;
        align-items: center;
        gap: 6px;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    .switcher-label {
        font-size: 11px;
        white-space: nowrap;
        flex-shrink: 0;
    }

    .switcher-select {
        flex: 1 1 auto;
        min-width: 0;
        width: 100%;
        max-width: 100%;
        font-size: 11.5px;
        padding: 3px 6px;
        box-sizing: border-box;
    }

    /* Layout & Sidebar on Mobile: Collapsed by Default */
    .portal-body {
        flex-direction: column;
        min-width: 0;
        width: 100%;
        max-width: 100%;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 260px;
        max-width: 82vw;
        height: 100vh;
        z-index: 1200;
        background-color: var(--sidebar-bg);
        transform: translateX(-100%);
        transition: transform 0.25s ease-in-out;
        box-shadow: none;
        overflow-y: auto;
        display: flex;
        flex-direction: column;
    }

    .portal-wrapper.sidebar-open .sidebar {
        transform: translateX(0);
        box-shadow: 4px 0 16px rgba(0, 0, 0, 0.5);
    }

    .sidebar-backdrop {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1150;
        opacity: 0;
        transition: opacity 0.25s ease-in-out;
    }

    .portal-wrapper.sidebar-open .sidebar-backdrop {
        display: block;
        opacity: 1;
    }

    .sidebar-header-mobile {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 12px 16px;
        background: #1a2226;
        border-bottom: 1px solid #2c3b41;
    }

    .mobile-sidebar-title {
        color: #ffffff;
        font-weight: 700;
        font-size: 13px;
        letter-spacing: 0.5px;
    }

    .sidebar-close-btn {
        background: transparent;
        border: none;
        color: #ffffff;
        font-size: 24px;
        cursor: pointer;
        padding: 0 4px;
        line-height: 1;
    }

    .sidebar-close-btn:hover, .sidebar-close-btn:focus {
        color: #ff6b6b;
        outline: 2px solid #ffffff;
    }

    /* Content Area: sits immediately below compact header */
    .main-content {
        padding: 14px 12px;
        width: 100%;
        max-width: 100%;
        min-width: 0;
        box-sizing: border-box;
    }

    .content-container {
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }

    .dashboard-cards-grid,
    .wallet-cards-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .filter-form-row {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-field {
        width: 100%;
    }

    .table-controls-bar,
    .table-footer-bar {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }

    .pagination-controls {
        flex-wrap: wrap;
        justify-content: center;
    }
}
