/* ============================================================
   MixPay Partners PRM — CSS
   Dark/Light theme, Sidebar layout, Mobile-first
   ============================================================ */

/* --- CSS Variables: Dark Theme (default) --- */
:root,
[data-theme="dark"] {
    --bg-primary: #0a0a0a;
    --bg-secondary: #111111;
    --bg-card: #181818;
    --bg-input: #1f1f1f;
    --sidebar-bg: #0d0f1a;
    --sidebar-hover: rgba(255, 107, 53, 0.10);
    --sidebar-active: rgba(255, 107, 53, 0.18);
    --topbar-bg: rgba(14, 14, 14, 0.92);
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --text-tertiary: #666666;
    --text-muted: #444444;
    --accent: #ff6b35;
    --accent-end: #f7931e;
    --accent-gradient: linear-gradient(135deg, #ff6b35 0%, #f7931e 100%);
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --info: #3b82f6;
    --border: #222222;
    --border-light: #2a2a2a;
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --sidebar-width: 220px;
    --sidebar-collapsed: 60px;
    --topbar-height: 56px;
    --font: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* --- Light Theme --- */
[data-theme="light"] {
    --bg-primary: #f2f3f5;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-input: #f0f0f0;
    --sidebar-bg: #1a1f3a;
    --sidebar-hover: rgba(255, 107, 53, 0.12);
    --sidebar-active: rgba(255, 107, 53, 0.22);
    --topbar-bg: rgba(255, 255, 255, 0.94);
    --text-primary: #1a1a1a;
    --text-secondary: #555555;
    --text-tertiary: #999999;
    --text-muted: #cccccc;
    --border: #e0e0e0;
    --border-light: #eeeeee;
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; height: 100%; }

body {
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-primary);
    min-height: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--accent-end); }

h1, h2, h3, h4 { color: var(--text-primary); font-weight: 700; line-height: 1.3; }
h1 { font-size: clamp(20px, 3vw, 26px); }
h2 { font-size: clamp(16px, 2.2vw, 20px); }
h3 { font-size: 15px; font-weight: 600; }

hr { border: 0; height: 1px; background: var(--border); margin: 16px 0; }

code {
    display: inline-block; padding: 2px 8px; border-radius: 6px;
    background: var(--bg-input); border: 1px solid var(--border);
    color: var(--accent); font-size: 12px; word-break: break-all;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    display: flex; flex-direction: column;
    z-index: 100;
    border-right: 1px solid rgba(255,255,255,0.06);
    transition: width 0.25s cubic-bezier(0.4,0,0.2,1), transform 0.3s cubic-bezier(0.4,0,0.2,1);
    overflow-y: auto; overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.sidebar-header {
    padding: 18px 16px 8px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}
.sidebar-header-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-logo {
    display: flex; align-items: center; gap: 10px;
    text-decoration: none; color: #fff;
}

.sidebar-logo-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; border-radius: 10px;
    background: var(--accent-gradient);
    color: #000; font-size: 16px; font-weight: 800;
    box-shadow: 0 4px 12px rgba(255,107,53,0.3);
    flex-shrink: 0;
}

.sidebar-logo-text {
    font-size: 16px; font-weight: 800; letter-spacing: 0.5px; color: #fff;
}

/* Light theme: guest header needs dark text/controls */
[data-theme="light"] .guest-header .sidebar-logo-text { color: var(--text-primary); }
[data-theme="light"] .guest-header .sidebar-logo-icon { box-shadow: 0 4px 12px rgba(255,107,53,0.25); }

.sidebar-label {
    display: block; font-size: 11px; color: rgba(255,255,255,0.45);
    margin-top: 6px; padding-left: 2px;
}

.sidebar-nav {
    flex: 1; padding: 10px 8px; display: flex; flex-direction: column; gap: 2px;
}

.sidebar-link {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-radius: var(--radius-sm);
    color: rgba(255,255,255,0.7); font-size: 13px; font-weight: 500;
    text-decoration: none; transition: background 0.2s, color 0.2s;
    min-height: 40px; position: relative;
}

.sidebar-link:hover {
    background: var(--sidebar-hover); color: #fff;
}

.sidebar-link.active {
    background: var(--sidebar-active); color: #fff; font-weight: 600;
}

.sidebar-link.active::before {
    content: ''; position: absolute; left: 0; top: 8px; bottom: 8px;
    width: 3px; border-radius: 0 3px 3px 0;
    background: var(--accent);
}

.sidebar-icon {
    width: 18px; height: 18px; flex-shrink: 0; opacity: 0.7;
}

.sidebar-link.active .sidebar-icon { opacity: 1; }

.sidebar-link-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-badge {
    margin-left: auto; padding: 2px 7px; border-radius: 999px;
    background: var(--accent); color: #000;
    font-size: 9px; font-weight: 700; text-transform: uppercase;
}

.sidebar-footer {
    padding: 12px 16px; border-top: 1px solid rgba(255,255,255,0.06);
    display: flex; align-items: center; justify-content: space-between;
}

.sidebar-id { font-size: 11px; color: rgba(255,255,255,0.35); }

.sidebar-overlay {
    display: none; position: fixed; inset: 0; z-index: 99;
    background: rgba(0,0,0,0.5); backdrop-filter: blur(2px);
}

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
    position: fixed; top: 0; right: 0;
    left: var(--sidebar-width);
    height: var(--topbar-height);
    background: var(--topbar-bg);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center;
    padding: 0 20px; gap: 12px;
    z-index: 90;
    transition: left 0.3s cubic-bezier(0.4,0,0.2,1);
}

.topbar-burger {
    display: none; background: none; border: none; cursor: pointer;
    width: 36px; height: 36px; padding: 6px;
    flex-direction: column; justify-content: center; gap: 5px;
}

.topbar-burger span {
    display: block; height: 2px; background: var(--text-primary);
    border-radius: 2px; transition: 0.2s;
}

.topbar-title {
    font-size: 17px; font-weight: 700; color: var(--text-primary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.topbar-right {
    margin-left: auto; display: flex; align-items: center; gap: 10px;
}

/* theme/lang always visible in topbar (desktop + mobile) */

.topbar-user {
    display: flex; align-items: center; gap: 8px;
}

.topbar-avatar {
    width: 34px; height: 34px; border-radius: 999px;
    background: var(--accent-gradient); color: #000;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; font-weight: 700; flex-shrink: 0;
}

.topbar-user-name { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.topbar-user-role {
    font-size: 10px; font-weight: 600; text-transform: uppercase;
    padding: 2px 8px; border-radius: 999px;
    background: var(--accent); color: #000;
}

.topbar-logout-form { margin: 0; }
.topbar-logout {
    background: none; border: 1px solid var(--border); border-radius: var(--radius-sm);
    cursor: pointer; padding: 6px; display: flex; color: var(--text-secondary);
    transition: color 0.2s, border-color 0.2s;
}
.topbar-logout:hover { color: var(--error); border-color: var(--error); }
.topbar-logout-icon { width: 18px; height: 18px; }

/* ============================================================
   MAIN CONTENT AREA
   ============================================================ */
.main-content {
    margin-left: var(--sidebar-width);
    margin-top: var(--topbar-height);
    min-height: calc(100vh - var(--topbar-height));
    transition: margin-left 0.3s cubic-bezier(0.4,0,0.2,1);
    overflow-x: hidden;
}

.content-inner {
    max-width: 1400px;
    padding: 24px 24px 40px;
    width: 100%;
    box-sizing: border-box;
}

/* ============================================================
   THEME TOGGLE
   ============================================================ */
.theme-toggle {
    width: 36px; height: 36px; border-radius: var(--radius-sm);
    background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.1);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    color: rgba(255,255,255,0.6); transition: background 0.2s, color 0.2s;
    padding: 0; flex-shrink: 0;
}

.theme-toggle:hover { background: rgba(255,255,255,0.14); color: #fff; }

.theme-icon { width: 18px; height: 18px; }
.theme-icon-moon { display: none; }

[data-theme="light"] .theme-icon-sun { display: none; }
[data-theme="light"] .theme-icon-moon { display: block; }
[data-theme="light"] .theme-toggle {
    background: var(--bg-input); border-color: var(--border);
    color: var(--text-secondary);
}

/* ============================================================
   LANGUAGE SWITCHER
   ============================================================ */
.lang-switcher {
    display: inline-flex; align-items: center; gap: 2px;
    background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.1);
    border-radius: var(--radius-sm); overflow: hidden; flex-shrink: 0;
}

.lang-btn {
    padding: 6px 10px; border: none; background: transparent;
    color: rgba(255,255,255,0.5); font-size: 12px; font-weight: 600;
    font-family: var(--font); cursor: pointer; transition: 0.2s;
    text-transform: uppercase;
}

.lang-btn:hover { color: #fff; }
.lang-btn.active { background: var(--accent); color: #000; }

[data-theme="light"] .lang-switcher {
    background: var(--bg-input); border-color: var(--border);
}
[data-theme="light"] .lang-btn { color: var(--text-tertiary); }
[data-theme="light"] .lang-btn:hover { color: var(--text-primary); }
[data-theme="light"] .lang-btn.active { background: var(--accent); color: #000; }

/* Guest header lang-switcher dark text in light mode */
[data-theme="light"] .guest-header .lang-switcher {
    background: var(--bg-input); border-color: var(--border);
}
[data-theme="light"] .guest-header .lang-btn { color: var(--text-tertiary); }
[data-theme="light"] .guest-header .lang-btn:hover { color: var(--text-primary); }

/* ============================================================
   GUEST LAYOUT (Login)
   ============================================================ */
.guest-layout {
    min-height: 100vh; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    background:
        radial-gradient(800px 400px at 30% 20%, rgba(255,107,53,0.08), transparent 60%),
        radial-gradient(600px 300px at 70% 80%, rgba(247,147,30,0.06), transparent 60%),
        var(--bg-primary);
}

.guest-header {
    position: fixed; top: 0; left: 0; right: 0;
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 24px; z-index: 10;
}

.guest-main {
    width: 100%; max-width: 420px; padding: 80px 20px 40px;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: 20px;
    margin-bottom: 16px; box-shadow: var(--shadow-sm);
    overflow: hidden; /* prevent children from overflowing card */
    min-width: 0; /* allow flexbox/grid shrinking */
}

.card-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 16px; gap: 12px;
}

/* ============================================================
   STAT CARDS / GRID
   ============================================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px; margin-bottom: 16px;
}

.stat-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: 16px;
    display: flex; flex-direction: column; gap: 4px;
}

.stat-card-label {
    font-size: 12px; color: var(--text-secondary); font-weight: 500;
}

.stat-card-value {
    font-size: 26px; font-weight: 800; color: var(--text-primary);
}

.stat-card-accent .stat-card-value {
    background: var(--accent-gradient);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ============================================================
   FORMS
   ============================================================ */
.form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

.form-full { grid-column: 1 / -1; }
.form-error { font-size: 12px; color: var(--error); margin-top: 2px; }

label {
    display: flex; flex-direction: column; gap: 4px;
    font-size: 13px; font-weight: 500; color: var(--text-secondary);
}

input, textarea, select {
    border-radius: var(--radius-sm); border: 1px solid var(--border);
    background: var(--bg-input); color: var(--text-primary);
    padding: 10px 12px; font-size: 14px; font-family: var(--font);
    transition: border-color 0.2s, box-shadow 0.2s;
    min-height: 42px;
}

input::placeholder, textarea::placeholder { color: var(--text-tertiary); }

input:focus, textarea:focus, select:focus {
    outline: none; border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(255,107,53,0.15);
}

textarea { min-height: 80px; resize: vertical; }

select {
    appearance: none; cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center;
    padding-right: 32px;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 20px; border-radius: var(--radius-sm); border: none;
    font-family: var(--font); font-size: 14px; font-weight: 600;
    cursor: pointer; transition: transform 0.15s, box-shadow 0.2s, opacity 0.2s;
    min-height: 42px; text-decoration: none;
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary {
    background: var(--accent-gradient); color: #000;
    box-shadow: 0 4px 12px rgba(255,107,53,0.25);
}
.btn-primary:hover { box-shadow: 0 6px 16px rgba(255,107,53,0.35); }

.btn-secondary {
    background: var(--bg-input); color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-outline {
    background: transparent; color: var(--accent);
    border: 1px solid var(--accent);
}

.btn-sm { padding: 6px 12px; font-size: 12px; min-height: 32px; }
.btn-block { width: 100%; }

/* Legacy form button compat */
.form button[type="submit"] { composes: btn btn-primary; }
button { font-family: var(--font); }

/* ============================================================
   TABLES
   ============================================================ */
.table-wrap {
    overflow-x: auto; border: 1px solid var(--border);
    border-radius: var(--radius-md); margin-bottom: 16px;
    -webkit-overflow-scrolling: touch;
}

.table {
    width: 100%; border-collapse: collapse; font-size: 13px;
}

.table th, .table td {
    text-align: left; padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.table th {
    background: var(--bg-input); color: var(--text-secondary);
    font-weight: 600; font-size: 12px;
}

.table td { background: var(--bg-card); }

.table tbody tr:hover td {
    background: rgba(255,107,53,0.04);
}

.table code {
    background: var(--bg-input); font-size: 11px;
    color: var(--accent);
}

/* ============================================================
   STATUS BADGES
   ============================================================ */
.badge {
    display: inline-flex; align-items: center; padding: 3px 8px;
    border-radius: 999px; font-size: 11px; font-weight: 600;
    text-transform: uppercase; white-space: nowrap; letter-spacing: 0.2px;
}

.badge-success { background: rgba(16,185,129,0.15); color: var(--success); }
.badge-warning { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-error   { background: rgba(239,68,68,0.15);  color: var(--error); }
.badge-info    { background: rgba(59,130,246,0.15);  color: var(--info); }
.badge-neutral { background: var(--bg-input); color: var(--text-secondary); }

/* Legacy compat aliases */
.status-badge { composes: badge; }
.status-success { composes: badge-success; }
.status-cancel, .status-error { composes: badge-error; }
.status-warning { composes: badge-warning; }
.status-neutral { composes: badge-neutral; }

/* ============================================================
   ALERTS
   ============================================================ */
.alert {
    padding: 12px 16px; border-radius: var(--radius-sm);
    font-size: 13px; margin-bottom: 12px;
}

.alert-error {
    background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.3);
    color: var(--error);
}

.alert-success {
    background: rgba(16,185,129,0.1); border: 1px solid rgba(16,185,129,0.3);
    color: var(--success);
}

.alert-info {
    background: rgba(59,130,246,0.1); border: 1px solid rgba(59,130,246,0.3);
    color: var(--info);
}

/* ============================================================
   META / HINT
   ============================================================ */
.meta { color: var(--text-secondary); font-size: 12px; line-height: 1.5; }
.meta strong { color: var(--text-primary); }
.hint { color: var(--accent-end); font-size: 13px; }

/* ============================================================
   SECTION HEADER ROW
   ============================================================ */
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; margin-bottom: 20px; flex-wrap: wrap;
}

.page-header h1, .page-header h2 { margin: 0; }

.page-subtitle {
    font-size: 13px; color: var(--text-secondary); margin-top: 2px;
}

/* ============================================================
   PERIOD TABS (Today / Week / 30 days / Custom)
   ============================================================ */
.period-tabs {
    display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px;
}

.period-tab {
    padding: 6px 14px; border-radius: 999px; font-size: 12px; font-weight: 600;
    background: var(--bg-input); color: var(--text-secondary); border: 1px solid var(--border);
    cursor: pointer; transition: 0.2s; text-decoration: none;
}

.period-tab:hover, .period-tab.active {
    background: var(--accent); color: #000; border-color: var(--accent);
}

/* ============================================================
   PROMO TOOLS (Dashboard cards with icons)
   ============================================================ */
.promo-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px; margin-bottom: 20px;
}

.promo-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: 16px;
    display: flex; align-items: center; gap: 14px;
    cursor: pointer; transition: border-color 0.2s, box-shadow 0.2s;
    text-decoration: none; color: var(--text-primary);
}

.promo-card:hover {
    border-color: var(--accent); box-shadow: 0 4px 16px rgba(255,107,53,0.12);
}

.promo-card-icon {
    width: 40px; height: 40px; border-radius: var(--radius-sm);
    background: var(--accent-gradient);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

.promo-card-icon svg { width: 20px; height: 20px; color: #000; }

.promo-card-text h3 { font-size: 14px; margin-bottom: 2px; }
.promo-card-text p { font-size: 12px; color: var(--text-secondary); margin: 0; }

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
    text-align: center; padding: 40px 20px;
    color: var(--text-tertiary); font-size: 14px;
}

/* ============================================================
   CHAT MESSAGES
   ============================================================ */
.chat-messages {
    display: flex; flex-direction: column; gap: 8px;
    max-height: 500px; overflow-y: auto; padding: 12px 0;
}

.chat-msg {
    max-width: 75%; padding: 10px 14px;
    border-radius: var(--radius-md); font-size: 13px;
    line-height: 1.5; position: relative;
}

.chat-msg-partner {
    align-self: flex-end;
    background: var(--accent); color: #000;
    border-bottom-right-radius: 4px;
}

.chat-msg-manager {
    align-self: flex-start;
    background: var(--bg-input); color: var(--text-primary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.chat-msg-time {
    font-size: 10px; opacity: 0.6; margin-top: 4px;
}

.chat-input-row {
    display: flex; gap: 8px; margin-top: 12px;
}

.chat-input-row textarea {
    flex: 1; min-height: 42px; resize: none;
}

/* ============================================================
   COPY BUTTON INLINE
   ============================================================ */
.copy-btn {
    background: none; border: 1px solid var(--border); border-radius: var(--radius-sm);
    cursor: pointer; padding: 4px 8px; display: inline-flex; align-items: center; gap: 4px;
    color: var(--text-secondary); font-size: 11px; transition: 0.2s;
}
.copy-btn:hover { border-color: var(--accent); color: var(--accent); }
.copy-btn svg { width: 14px; height: 14px; }

/* ============================================================
   LINK DISPLAY
   ============================================================ */
.link-display {
    display: flex; align-items: center; gap: 8px;
    background: var(--bg-input); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 10px 14px;
    font-size: 13px; color: var(--accent); word-break: break-all;
}

/* ============================================================
   MANAGER CONTACT CARD
   ============================================================ */
.manager-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: 20px;
}

.manager-card h3 { margin-bottom: 12px; }

.manager-card-row {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 0; font-size: 13px; color: var(--text-secondary);
}

/* ============================================================
   PAGE BOOT ANIMATION
   ============================================================ */
body.page-boot .sidebar,
body.page-boot .topbar,
body.page-boot .main-content,
body.page-boot .guest-layout {
    opacity: 0;
}

body.page-ready .sidebar,
body.page-ready .topbar,
body.page-ready .main-content,
body.page-ready .guest-layout {
    opacity: 1;
    transition: opacity 0.5s ease;
}

body.page-boot .guest-main > * {
    opacity: 0; transform: translateY(16px); filter: blur(6px);
}

body.page-ready .guest-main > * {
    opacity: 1; transform: translateY(0); filter: blur(0);
    transition: opacity 0.6s cubic-bezier(0.22,1,0.36,1),
                transform 0.7s cubic-bezier(0.22,1,0.36,1),
                filter 0.7s ease;
}

body.page-boot .content-inner > * {
    opacity: 0; transform: translateY(12px);
}

body.page-ready .content-inner > * {
    opacity: 1; transform: translateY(0);
    transition: opacity 0.4s ease, transform 0.5s cubic-bezier(0.22,1,0.36,1);
}

body.page-ready .content-inner > *:nth-child(1) { transition-delay: 80ms; }
body.page-ready .content-inner > *:nth-child(2) { transition-delay: 140ms; }
body.page-ready .content-inner > *:nth-child(3) { transition-delay: 200ms; }
body.page-ready .content-inner > *:nth-child(4) { transition-delay: 260ms; }
body.page-ready .content-inner > *:nth-child(5) { transition-delay: 320ms; }
body.page-ready .content-inner > *:nth-child(6) { transition-delay: 380ms; }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition-duration: 0s !important;
        animation-duration: 0s !important;
    }
}

/* ============================================================
   SIDEBAR COLLAPSE (class-based, desktop toggle button)
   ============================================================ */

/* Collapse button — fixed, sits on the right edge of the sidebar */
.sidebar-collapse-btn {
    position: fixed;
    top: 24px;
    left: calc(var(--sidebar-width) - 12px);
    z-index: 101; /* above sidebar */
    width: 24px; height: 24px;
    border-radius: 50%;
    background: var(--sidebar-bg);
    border: 1px solid rgba(255,255,255,0.15);
    color: rgba(255,255,255,0.6);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    padding: 0;
    box-shadow: 2px 0 8px rgba(0,0,0,0.3);
    transition: left 0.25s cubic-bezier(0.4,0,0.2,1), transform 0.25s, background 0.2s, color 0.2s;
}
.sidebar-collapse-btn:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
[data-theme="light"] .sidebar-collapse-btn {
    background: #fff;
    border-color: var(--border);
    color: var(--text-secondary);
    box-shadow: 2px 0 8px rgba(0,0,0,0.1);
}
[data-theme="light"] .sidebar-collapse-btn:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* ---- COLLAPSED STATE (desktop only, via body class) ---- */
@media (min-width: 768px) {
    /* Shrink sidebar */
    .sidebar-collapsed .sidebar {
        width: var(--sidebar-collapsed);
    }
    /* Hide text elements */
    .sidebar-collapsed .sidebar-logo-text,
    .sidebar-collapsed .sidebar-label,
    .sidebar-collapsed .sidebar-link-text,
    .sidebar-collapsed .sidebar-badge,
    .sidebar-collapsed .sidebar-id,
    .sidebar-collapsed .sidebar-section-label { display: none; }
    .sidebar-collapsed .sidebar-divider { margin: 4px 8px; }
    /* Center icons */
    .sidebar-collapsed .sidebar-link {
        justify-content: center;
        padding: 12px 0;
    }
    .sidebar-collapsed .sidebar-icon { margin: 0; }
    /* Compact footer */
    .sidebar-collapsed .sidebar-footer {
        justify-content: center;
        padding: 8px 4px;
    }
    /* Compact header */
    .sidebar-collapsed .sidebar-header {
        padding: 14px 8px 8px;
    }
    .sidebar-collapsed .sidebar-header-row {
        justify-content: center;
    }
    .sidebar-collapsed .sidebar-logo { justify-content: center; }
    /* Move collapse button to match narrower sidebar & flip arrow
       Button is a sibling of .sidebar, not a child, so use body class directly */
    body.sidebar-collapsed .sidebar-collapse-btn {
        left: calc(var(--sidebar-collapsed) - 12px);
        transform: rotate(180deg);
    }
    /* Shift topbar and main */
    .sidebar-collapsed .topbar { left: var(--sidebar-collapsed); }
    .sidebar-collapsed .main-content { margin-left: var(--sidebar-collapsed); }
}

/* Hide collapse button on mobile (burger is used instead) */
@media (max-width: 767px) {
    .sidebar-collapse-btn { display: none; }
}

/* ============================================================
   PENDING BANNER
   ============================================================ */
.pending-banner {
    background: linear-gradient(135deg, #f59e0b22, #f59e0b11);
    border-bottom: 1px solid rgba(245, 158, 11, 0.3);
    padding: 12px 20px;
}
.pending-banner-inner {
    display: flex; align-items: flex-start; gap: 12px;
    max-width: 800px; margin: 0 auto;
    color: var(--warning);
}
.pending-banner-icon { flex-shrink: 0; margin-top: 2px; }
.pending-banner strong { display: block; font-size: 14px; }
.pending-banner-text { font-size: 13px; opacity: 0.85; margin-top: 2px; }

/* ============================================================
   FORM VALIDATION ERRORS
   ============================================================ */
.form-error {
    font-size: 12px;
    color: var(--error);
    margin-top: 2px;
}
.alert-success {
    background: rgba(16,185,129,0.1);
    border: 1px solid rgba(16,185,129,0.3);
    color: var(--success);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    margin-bottom: 12px;
    font-size: 14px;
}
.text-center { text-align: center; }
a.link { color: var(--accent); text-decoration: none; }
a.link:hover { text-decoration: underline; }

/* ============================================================
   RESPONSIVE: Tablet landscape (768-1024)
   Auto-collapse sidebar on narrow desktops/tablets
   ============================================================ */
/* (No auto-collapse — user controls via toggle button) */

/* ============================================================
   RESPONSIVE: Tablet portrait & Mobile (< 768px)
   ============================================================ */
@media (max-width: 767px) {
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width);
        box-shadow: 4px 0 24px rgba(0,0,0,0.3);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.open { display: block; }
    .sidebar-logo-text, .sidebar-label, .sidebar-link-text,
    .sidebar-badge, .sidebar-id { display: initial; }
    .sidebar-link { justify-content: flex-start; padding: 10px 12px; }
    .sidebar-footer { justify-content: space-between; }

    .topbar { left: 0; }
    .topbar-burger { display: flex; }
    .topbar-user-name, .topbar-user-role { display: none; }
    .main-content { margin-left: 0; }

    .content-inner { padding: 16px 12px 32px; }

    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .promo-grid { grid-template-columns: 1fr; }
    .form { grid-template-columns: 1fr; }
    .page-header { flex-direction: column; align-items: flex-start; }

    .stat-card-value { font-size: 22px; }

    .table { font-size: 12px; }
    .table th, .table td { padding: 8px 8px; }

    .btn-block-mobile { width: 100%; }

    .chat-msg { max-width: 90%; }
}

/* ============================================================
   RESPONSIVE: Small mobile (< 480px)
   ============================================================ */
@media (max-width: 479px) {
    .stats-grid { grid-template-columns: 1fr; }
    .content-inner { padding: 12px 10px 28px; }
    .stat-card { padding: 12px; }
    .stat-card-value { font-size: 20px; }
    h1 { font-size: 18px; }
}

/* ============================================================
   UTILITY CLASSES
   ============================================================ */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-sm { gap: 8px; }
.gap-md { gap: 12px; }
.gap-lg { gap: 20px; }
.mt-sm { margin-top: 8px; }
.mt-md { margin-top: 16px; }
.mt-lg { margin-top: 24px; }
.mb-sm { margin-bottom: 8px; }
.mb-md { margin-bottom: 16px; }
.text-muted { color: var(--text-secondary); }
.text-sm { font-size: 12px; }
.text-accent { color: var(--accent); }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.w-full { width: 100%; }
/* ============================================================
   SIDEBAR ADMIN SECTION
   ============================================================ */
.sidebar-divider {
    height: 1px;
    background: var(--border);
    margin: 12px 16px;
    opacity: 0.5;
}
.sidebar-section-label {
    display: block;
    padding: 4px 20px 8px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--accent);
    opacity: 0.8;
}
.sidebar-link-admin { opacity: 0.9; }
.sidebar-link-admin.active { opacity: 1; }

/* Button variants */
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-danger { background: #ef4444; color: #fff; border-color: #ef4444; }
.btn-danger:hover { background: #dc2626; }
.checkbox-label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.checkbox-label input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }

.hidden { display: none !important; }

/* ============================================================
   LINK TYPE SELECTOR
   ============================================================ */
.link-type-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-top: 8px;
}
.link-type-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 16px 10px;
    border: 2px solid var(--border);
    border-radius: var(--radius-md, 10px);
    background: var(--bg-card);
    cursor: pointer;
    transition: border-color .2s, box-shadow .2s, background .2s;
    text-align: center;
}
.link-type-option input[type="radio"] { display: none; }
.link-type-option:hover { border-color: var(--accent); }
.link-type-option.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(255,107,53,0.18);
    background: rgba(255,107,53,0.06);
}
.link-type-icon { font-size: 28px; line-height: 1; }
.link-type-name { font-weight: 600; font-size: 14px; color: var(--text-primary); }
.link-type-desc { font-size: 11px; color: var(--text-secondary); line-height: 1.3; }

/* Badge variants */
.badge-info { background: rgba(56,189,248,0.15); color: #38bdf8; }
.badge-primary { background: rgba(255,107,53,0.15); color: var(--accent); }

@media (max-width: 575px) {
    .link-type-grid { grid-template-columns: 1fr; }
}

/* ============================================================
   TRAINING GRID
   ============================================================ */
.training-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
    margin-top: 16px;
}
.training-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* ============================================================
   TABS
   ============================================================ */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border);
    overflow-x: auto;
}
.tab {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.2s, border-color 0.2s;
    white-space: nowrap;
}
.tab:hover { color: var(--text-primary); }
.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* ============================================================
   UTILITY
   ============================================================ */
.mt-xl { margin-top: 40px; }
.mt-lg { margin-top: 24px; }
.mt-md { margin-top: 16px; }
.mt-sm { margin-top: 8px; }
.mb-md { margin-bottom: 16px; }
.mb-lg { margin-bottom: 24px; }
.text-sm { font-size: 13px; }
.text-secondary { color: var(--text-secondary); }
.text-muted { color: var(--text-tertiary); }
.fw-600 { font-weight: 600; }
.badge-error { background: rgba(239,68,68,0.15); color: var(--error); }
.badge-success { background: rgba(16,185,129,0.15); color: var(--success); }
.badge-warning { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-neutral { background: rgba(160,160,160,0.12); color: var(--text-secondary); }
.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover { opacity: 0.9; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ============================================================
   MENU TOGGLE SWITCHES (Admin Settings)
   ============================================================ */
.menu-toggles-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
}
.menu-toggle-item {
    display: flex;
    align-items: center;
}
.toggle-switch-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 10px 14px;
    border-radius: 10px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    width: 100%;
    transition: background 0.2s, border-color 0.2s;
}
.toggle-switch-label:hover {
    border-color: var(--accent);
}
.toggle-switch-input {
    display: none;
}
.toggle-switch-slider {
    position: relative;
    width: 40px;
    height: 22px;
    background: rgba(160,160,160,0.3);
    border-radius: 11px;
    transition: background 0.25s;
    flex-shrink: 0;
}
.toggle-switch-slider::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    transition: transform 0.25s;
}
.toggle-switch-input:checked + .toggle-switch-slider {
    background: var(--accent);
}
.toggle-switch-input:checked + .toggle-switch-slider::after {
    transform: translateX(18px);
}
.toggle-switch-text {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}
.menu-toggle-hint {
    display: inline-block;
    margin-left: 12px;
    font-size: 13px;
    color: var(--text-tertiary);
}

/* === Charts === */
.chart-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}
@media (max-width: 900px) {
    .chart-grid {
        grid-template-columns: 1fr;
    }
}
.chart-box {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 16px;
    border: 1px solid var(--border);
    position: relative;
    height: 320px;
}
.chart-canvas-wrap {
    position: relative;
    width: 100%;
    height: calc(100% - 30px);
}
.chart-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 0 0 12px 0;
}

/* === Filters === */
.filters-form {
    width: 100%;
}
.filters-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
}
.filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 140px;
}
.filter-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.filter-group .input,
.filter-group select.input {
    padding: 7px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
    transition: border-color 0.2s;
}
.filter-group .input:focus,
.filter-group select.input:focus {
    border-color: var(--accent);
    outline: none;
}
.filter-actions {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding-top: 18px;
}
.btn-sm {
    padding: 7px 16px;
    font-size: 13px;
    border-radius: 8px;
}
.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    transition: border-color 0.2s, color 0.2s;
}
.btn-outline:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* === Expandable Rows === */
.table-hover tbody tr.expandable-row:hover {
    background: rgba(230, 138, 46, 0.06);
}
.expand-toggle {
    width: 30px;
    text-align: center;
}
.expand-icon {
    font-size: 10px;
    color: var(--text-tertiary);
    transition: transform 0.2s;
}
.expandable-content td {
    background: var(--bg-secondary, rgba(0,0,0,0.02));
    padding: 16px 20px;
    border-top: none;
}

/* === Detail Grid === */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 24px;
}
@media (max-width: 768px) {
    .detail-grid {
        grid-template-columns: 1fr;
    }
}
.detail-item {
    font-size: 13px;
    line-height: 1.5;
}
.detail-item strong {
    color: var(--text-secondary);
    font-weight: 600;
}
.detail-full {
    grid-column: 1 / -1;
}
.json-block {
    background: rgba(0,0,0,0.1);
    border-radius: 8px;
    padding: 10px 14px;
    margin-top: 4px;
    overflow-x: auto;
    max-height: 200px;
}
.json-block pre {
    margin: 0;
    font-size: 12px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    white-space: pre-wrap;
    word-break: break-all;
    color: var(--text-primary);
}
body[data-theme="light"] .json-block {
    background: rgba(0,0,0,0.04);
}

/* === Pagination === */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}
.pagination-info {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
}

/* === Misc text helpers === */
.text-accent {
    color: var(--accent);
    font-weight: 600;
}
.text-error {
    color: #e55;
}
.text-xs {
    font-size: 11px;
}
.order-id {
    font-size: 11px;
    word-break: break-all;
}
.mb-md { margin-bottom: 20px; }
.mt-md { margin-top: 20px; }

/* === Referral Tree === */
.referral-tree {
    margin: 0;
    padding: 0;
}
.tree-node {
    border-left: 2px solid var(--border);
    padding-left: 16px;
    margin-bottom: 8px;
    position: relative;
}
.tree-node::before {
    content: '';
    position: absolute;
    left: -2px;
    top: 12px;
    width: 14px;
    height: 2px;
    background: var(--border);
}
.tree-node-header {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 8px 12px;
    background: var(--surface);
    border-radius: 6px;
    font-size: 14px;
}
.tree-node-l1 {
    border-left-color: var(--accent);
}
.tree-node-l1::before {
    background: var(--accent);
}
.tree-node-l2 {
    border-left-color: #4e9fff;
}
.tree-node-l2::before {
    background: #4e9fff;
}
.tree-node-l3 {
    border-left-color: #a87fdd;
}
.tree-node-l3::before {
    background: #a87fdd;
}
.tree-children {
    margin-left: 8px;
    margin-top: 4px;
}

/* === Badge variants for levels === */
.badge-secondary {
    background: #4e9fff22;
    color: #4e9fff;
    border: 1px solid #4e9fff33;
}
.badge-muted {
    background: #a87fdd22;
    color: #a87fdd;
    border: 1px solid #a87fdd33;
}

/* === stat-card sub text === */
.stat-card-sub {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* === Commission tree visual === */
.commission-tree-visual {
    border: 1px solid var(--border);
}
