/**
 * Base styles + Theme variables injection point
 * Sistem Affiliate Hybrid
 */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* Fallback (Ocean) — akan di-override oleh theme CSS vars */
    --primary: #0ea5e9;
    --primary-dark: #0284c7;
    --primary-light: #e0f2fe;
    --secondary: #0369a1;
    --accent: #06b6d4;
    --accent-soft: #cffafe;
    --bg: #f0f9ff;
    --bg-card: #ffffff;
    --bg-sidebar: #0c4a6e;
    --bg-sidebar-hover: #075985;
    --bg-header: #ffffff;
    --bg-muted: #e0f2fe;
    --text: #0f172a;
    --text-muted: #64748b;
    --text-inverse: #f8fafc;
    --text-sidebar: #e0f2fe;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    --border: #bae6fd;
    --border-strong: #7dd3fc;
    --shadow: 0 4px 6px -1px rgb(14 165 233 / 0.08);
    --radius: 12px;
    --radius-sm: 8px;
    --font: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    --sidebar-width: 260px;
    --header-height: 64px;
}

html { font-size: 15px; scroll-behavior: smooth; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

img { max-width: 100%; display: block; }

/* ========== Layout ========== */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    color: var(--text-sidebar);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 40;
    display: flex;
    flex-direction: column;
    transition: transform 0.25s ease;
}

.sidebar-brand {
    padding: 20px 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-brand .logo {
    width: 36px;
    height: 36px;
    background: var(--primary);
    border-radius: 10px;
    display: grid;
    place-items: center;
    font-weight: 800;
    color: white;
    font-size: 1rem;
}

.sidebar-brand h1 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-inverse);
    line-height: 1.2;
}
.sidebar-brand small {
    font-size: 0.7rem;
    opacity: 0.7;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 12px 10px;
}

.nav-section {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    opacity: 0.5;
    padding: 12px 12px 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-sidebar);
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
    margin-bottom: 2px;
}
.nav-item:hover {
    background: var(--bg-sidebar-hover);
    color: white;
}
.nav-item.active {
    background: var(--primary);
    color: white;
}
.nav-item .icon {
    width: 28px;
    height: 28px;
    min-width: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 1.15rem;
    line-height: 1;
    opacity: 0.95;
    border-radius: 8px;
    flex-shrink: 0;
}
.nav-item.active .icon {
    background: rgba(255,255,255,0.18);
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid rgba(255,255,255,0.08);
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    height: var(--header-height);
    background: var(--bg-header);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 30;
    box-shadow: var(--shadow);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}
.topbar-title {
    font-size: 1.1rem;
    font-weight: 650;
    color: var(--text);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.page-body {
    flex: 1;
    padding: 24px;
}

/* ========== Cards ========== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.card-title {
    font-size: 1rem;
    font-weight: 650;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
}
.stat-card .label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.stat-card .value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
}
.stat-card .trend {
    font-size: 0.75rem;
    margin-top: 4px;
}
.stat-card.primary { border-left: 4px solid var(--primary); }
.stat-card.success { border-left: 4px solid var(--success); }
.stat-card.warning { border-left: 4px solid var(--warning); }
.stat-card.danger  { border-left: 4px solid var(--danger); }

/* ========== Buttons ========== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    line-height: 1.3;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

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

.btn-secondary {
    background: var(--bg-muted);
    color: var(--secondary);
}
.btn-secondary:hover { background: var(--border); }

.btn-outline {
    background: transparent;
    border: 1.5px solid var(--border-strong);
    color: var(--text);
}
.btn-outline:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-success { background: var(--success); color: white; }
.btn-danger  { background: var(--danger); color: white; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-lg { padding: 12px 22px; font-size: 1rem; }

/* ========== Forms ========== */
.form-group { margin-bottom: 16px; }
.form-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text);
}
.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    background: var(--bg-card);
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.form-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }

/* ========== Tables ========== */
.table-wrap {
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}
table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
table.data-table th {
    background: var(--bg-muted);
    text-align: left;
    padding: 12px 14px;
    font-weight: 650;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border);
}
table.data-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
table.data-table tr:last-child td { border-bottom: none; }
table.data-table tr:hover td { background: var(--bg-muted); }

/* ========== Badges ========== */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 650;
    letter-spacing: 0.02em;
}
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-info    { background: #dbeafe; color: #1e40af; }
.badge-primary { background: var(--primary-light); color: var(--secondary); }
.badge-muted   { background: #f1f5f9; color: #475569; }

/* ========== Alerts ========== */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 0.9rem;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
.alert-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-error   { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.alert-info    { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* ========== Theme Picker ========== */
.theme-picker {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}
.theme-option {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    border: 3px solid transparent;
    cursor: pointer;
    position: relative;
    transition: transform 0.15s, border-color 0.15s;
    box-shadow: 0 2px 6px rgba(0,0,0,0.12);
}
.theme-option:hover { transform: scale(1.08); }
.theme-option.active {
    border-color: var(--text);
    box-shadow: 0 0 0 2px white, 0 0 0 4px var(--text);
}
.theme-option .check {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: white;
    font-weight: 800;
    font-size: 1.1rem;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

/* ========== Auth pages ========== */
.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, var(--bg-sidebar) 0%, var(--primary-dark) 100%);
    padding: 24px;
}
.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-card);
    border-radius: 16px;
    padding: 32px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.2);
}
.auth-card h2 {
    font-size: 1.4rem;
    margin-bottom: 6px;
}
.auth-card .subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 24px;
}

/* ========== Utilities ========== */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.85rem; }
.text-xs { font-size: 0.75rem; }
.font-bold { font-weight: 700; }
.w-full { width: 100%; }
.hidden { display: none !important; }

/* Mobile */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--text);
}

@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main-content {
        margin-left: 0;
    }
    .menu-toggle {
        display: block;
    }
    .page-body {
        padding: 16px;
    }
    .stat-grid {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 520px) {
    .stat-grid {
        grid-template-columns: 1fr;
    }
}

/* ========== Mobile-first refinements ========== */
@media (max-width: 900px) {
    :root {
        --sidebar-width: 280px;
    }
    .topbar {
        padding: 0 12px;
        height: 56px;
    }
    .page-body {
        padding: 12px;
    }
    .card {
        padding: 14px;
        border-radius: 10px;
    }
    .stat-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
    .stat-card .value {
        font-size: 1.25rem;
    }
    .table-wrap {
        margin: 0 -4px;
        border-radius: 8px;
    }
    table.data-table th,
    table.data-table td {
        padding: 10px 8px;
        font-size: 0.8rem;
    }
    .btn {
        padding: 10px 14px;
        min-height: 42px; /* touch target */
    }
    .btn-sm {
        min-height: 36px;
        padding: 6px 10px;
    }
    .form-control {
        padding: 12px 14px;
        font-size: 16px; /* prevent iOS zoom */
        min-height: 44px;
    }
    .auth-card {
        padding: 24px 18px;
        border-radius: 14px;
    }
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.45);
        z-index: 35;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
    .sidebar.open ~ .sidebar-overlay,
    body.sidebar-open .sidebar-overlay {
        display: block;
    }
    body.sidebar-open {
        overflow: hidden; /* prevent background scroll while menu open */
    }
    .menu-toggle {
        min-width: 44px;
        min-height: 44px;
        display: grid;
        place-items: center;
        padding: 0;
        border-radius: 8px;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
    .menu-toggle:active {
        background: var(--bg-muted);
    }
}

@media (max-width: 520px) {
    .stat-grid {
        grid-template-columns: 1fr;
    }
    .topbar-title {
        font-size: 0.95rem;
    }
    .flex.gap-4 {
        gap: 12px;
    }
}

@media (min-width: 901px) {
    .page-body {
        padding: 24px 28px;
    }
}

/* Safe area for notched phones */
@supports (padding: max(0px)) {
    .sidebar {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
    .page-body {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
}


/* ========== Bottom icon nav (mobile app style) ========== */
.bottom-nav {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 90;
    box-sizing: border-box;
    min-height: 72px;
    padding: 8px 8px calc(10px + env(safe-area-inset-bottom, 0px));
    background: #ffffff;
    border-top: 1px solid rgba(15, 23, 42, 0.08);
    box-shadow: 0 -8px 32px rgba(15, 23, 42, 0.1);
    justify-content: space-between;
    align-items: flex-end;
    gap: 4px;
}
.bottom-nav a,
.bottom-nav button {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 0;
    min-height: 56px;
    margin: 0;
    padding: 6px 4px 4px;
    border: 0;
    background: transparent;
    color: #94a3b8;
    text-decoration: none;
    font-size: 0.68rem;
    font-weight: 600;
    line-height: 1.15;
    cursor: pointer;
    border-radius: 16px;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.15s ease, transform 0.12s ease;
}
.bottom-nav a:active,
.bottom-nav button:active {
    transform: scale(0.92);
}
.bottom-nav a:focus-visible,
.bottom-nav button:focus-visible {
    outline: 2px solid var(--primary, #2563eb);
    outline-offset: 2px;
}
/* Lingkaran ikon — selalu terlihat */
.bottom-nav .bn-icon {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    font-size: 1.55rem;
    line-height: 1;
    border-radius: 16px;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.06);
    transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease, color 0.15s ease;
}
.bottom-nav .bn-label {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 2px;
    font-size: 0.68rem;
    letter-spacing: 0.01em;
}
/* Active: seperti app — ikon terangkat + warna primary */
.bottom-nav a.active,
.bottom-nav button.active {
    color: var(--primary, #ea580c);
}
.bottom-nav a.active .bn-icon,
.bottom-nav button.active .bn-icon {
    background: #fff7ed;
    border: 2px solid var(--primary, #ea580c);
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.12);
    transform: translateY(-5px) scale(1.05);
}
.bottom-nav a:not(.active):hover .bn-icon,
.bottom-nav button:not(.active):hover .bn-icon {
    background: #e2e8f0;
    border-color: #cbd5e1;
}
.bottom-nav-more .bn-icon {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

@media (max-width: 900px) {
    .bottom-nav {
        display: flex !important;
    }
    .app-shell {
        padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    }
    .main-content {
        padding-bottom: 12px;
    }
    .sidebar {
        z-index: 100;
        padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px));
    }
    .nav-item {
        min-height: 52px;
        padding: 12px 14px;
        font-size: 0.95rem;
        gap: 12px;
        border-radius: 12px;
    }
    .nav-item .icon {
        width: 40px;
        height: 40px;
        min-width: 40px;
        font-size: 1.3rem;
        border-radius: 12px;
        background: rgba(255,255,255,0.1);
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    .nav-item.active .icon {
        background: rgba(255,255,255,0.25);
    }
}

@media (min-width: 901px) {
    .bottom-nav {
        display: none !important;
    }
}

/* ========== Icon controls (hamburger / topbar) — mobile app feel ========== */
.menu-toggle {
    display: none;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 12px;
    background: var(--card-bg, #fff);
    color: var(--text, #0f172a);
    font-size: 1.35rem;
    line-height: 1;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(15,23,42,0.06);
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
}
.menu-toggle:active {
    transform: scale(0.96);
    background: var(--bg-muted, #f1f5f9);
}
@media (max-width: 900px) {
    .menu-toggle {
        display: inline-flex !important;
    }
}
@media (min-width: 901px) {
    .menu-toggle {
        display: none !important;
    }
}

/* Tombol aksi kecil di tabel / card: area sentuh cukup */
@media (max-width: 900px) {
    .btn-sm {
        min-height: 40px;
        min-width: 40px;
        padding: 8px 12px;
    }
    .topbar-left {
        gap: 10px;
    }
}

