/* =========================================
   MASTER UNIVERSAL CSS (API Hub)
   Handles: Login, Dashboard, Tables, Forms, Mobile
========================================= */

/* ---------- 1. CORE VARIABLES ---------- */
:root {
    --bg: #fafbfc;
    --surface: #ffffff;
    --border: #eef1f5;
    --border-strong: #e2e8f0;
    --text: #0f172a;
    --text-muted: #64748b;
    --text-soft: #94a3b8;
    --radius: 12px;
    --radius-sm: 8px;
    --primary: #0f172a;
    --primary-hover: #1e293b;
    --success: #027a48;
    --danger: #b42318;
}

/* ---------- 2. BASE RESET ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
a { text-decoration: none; }

/* ---------- 3. MAIN DASHBOARD LAYOUT ---------- */
.app-container { display: flex; min-height: 100vh; }
.main-wrapper { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.main-content { flex: 1; padding: 32px 40px; max-width: 1200px; width: 100%; margin: 0 auto; }

/* ---------- 4. SIDEBAR & TOPBAR (Desktop) ---------- */
.sidebar { width: 250px; background: var(--surface); border-right: 1px solid var(--border); padding: 24px 16px; flex-shrink: 0; }
.sidebar a { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 500; color: var(--text-muted); transition: 0.15s; margin-bottom: 5px; }
.sidebar a:hover { background: #f1f5f9; color: var(--text); }
.sidebar .logo h2 { margin: 0 0 20px 0; font-size: 20px; color: var(--text); }

.topbar { height: 64px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 32px; }
.topbar-right { display: flex; align-items: center; gap: 24px; }
.topbar-wallet { display: flex; gap: 8px; background: var(--bg); padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); }
.wallet-label { color: var(--text-muted); font-size: 13px; font-weight: 500; }
.wallet-amount { font-weight: 600; color: var(--success); }

/* Profile Dropdown */
.profile-menu { position: relative; display: inline-block; }
.profile-btn { background: none; border: none; display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 4px; border-radius: var(--radius-sm); }
.profile-btn:hover { background: var(--bg); }
.avatar { width: 32px; height: 32px; background: var(--primary); color: white; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 600; }
.username { font-weight: 500; color: var(--text); font-size: 14px; }
.caret { font-size: 10px; color: var(--text-muted); }
.dropdown-content { display: none; position: absolute; right: 0; top: 100%; margin-top: 8px; background-color: var(--surface); min-width: 200px; box-shadow: 0 10px 25px -5px rgba(0,0,0,0.1); border-radius: var(--radius); border: 1px solid var(--border); z-index: 100; }
.profile-menu:hover .dropdown-content, .profile-menu:focus-within .dropdown-content { display: block; }
.dropdown-header { padding: 16px; line-height: 1.4; }
.dropdown-content hr { margin: 0; border: none; border-top: 1px solid var(--border); }
.dropdown-content a { color: var(--text); padding: 12px 16px; display: flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 500; transition: background 0.2s; }
.dropdown-content a:hover { background-color: var(--bg); }

/* ---------- 5. UI COMPONENTS (Headers, Cards, Stats) ---------- */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 28px; }
.page-header h1 { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; margin: 0 0 4px; color: var(--text); }
.page-header .sub { font-size: 13.5px; color: var(--text-muted); margin: 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px 40px; margin-bottom: 24px; overflow-x: auto; }
.card-title { font-size: 15px; font-weight: 600; margin: 0 0 16px; color: var(--text); border-bottom: 1px solid var(--border); padding-bottom: 12px; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 24px; }
.stat-label { font-size: 13px; font-weight: 500; color: var(--text-muted); margin: 0 0 8px; }
.stat-value { font-size: 24px; font-weight: 600; color: var(--text); margin: 0; }

dl.profile-list { margin: 0; padding: 0; }
.profile-row { display: flex; align-items: center; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.profile-row:last-child { border-bottom: none; padding-bottom: 0; }
.profile-row:first-child { padding-top: 0; }
.profile-row dt { flex: 0 0 140px; font-size: 13.5px; font-weight: 500; color: var(--text-muted); }
.profile-row dd { margin: 0; font-size: 14px; color: var(--text); font-weight: 500; word-break: break-word; }

/* ---------- 6. BADGES ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600; padding: 4px 10px; border-radius: 999px; white-space: nowrap; letter-spacing: 0.02em; }
.badge-cr, .badge-active, .badge-success { color: var(--success); background: #ecfdf3; border: 1px solid #d1fadf; } 
.badge-dr, .badge-inactive, .badge-failed { color: var(--danger); background: #fef3f2; border: 1px solid #fee4e2; } 
.badge-admin { color: #004085; background: #cce5ff; border: 1px solid #b8daff; }
.badge-user { color: #383d41; background: #e2e3e5; border: 1px solid #d6d8db; }
.badge-success::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #12b76a; }

/* ---------- 7. DATA TABLES ---------- */
.data-table, .txn-table { width: 100%; border-collapse: collapse; font-size: 13.5px; text-align: left; min-width: 800px; }
.data-table th, .data-table td, .txn-table th, .txn-table td { padding: 14px 20px; border-bottom: 1px solid var(--border); }
.data-table th, .txn-table th { background: #f8fafc; font-weight: 500; color: var(--text-muted); white-space: nowrap; font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.05em; }
.data-table tr:hover td, .txn-table tr:hover td { background-color: #f8fafc; }
.status-success { color: var(--success); font-weight: 500; }
.status-failed { color: var(--danger); font-weight: 500; }
.status-pending { color: #b54708; font-weight: 500; }
.amount-text { font-weight: 600; color: var(--text); }
.text-muted { color: var(--text-muted); font-size: 12.5px; }
.text-stack { display: flex; flex-direction: column; gap: 2px; }

/* ---------- 8. FORMS & GRID (Settings, Profile, Filters) ---------- */
.form-section { margin-bottom: 40px; }
.form-section:last-of-type { margin-bottom: 0; }
.form-section-title { font-size: 16px; font-weight: 600; color: var(--text); margin: 0 0 20px 0; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.settings-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; align-items: flex-start; }
.form-group { margin-bottom: 16px; } 
.form-group label { display: block; font-weight: 600; margin-bottom: 4px; color: var(--text); font-size: 13.5px; }
.form-text { display: block; font-size: 12px; color: var(--text-soft); margin-bottom: 8px; line-height: 1.3; min-height: 16px; } 
.form-group input, .form-group select, .readonly-input { width: 100%; padding: 10px 14px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font-size: 14px; background: var(--surface); color: var(--text); transition: all 0.2s ease; outline: none;}
.form-group input:focus, .form-group select:focus { border-color: var(--text-soft); box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.15); }
.readonly-input { background: #f1f5f9; color: var(--text-muted); cursor: default; }

/* Filter Section (Joined Inputs) */
.filter-container { display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 24px; padding: 20px; background: var(--surface); border-radius: var(--radius-sm); border-top: 3px solid var(--primary); }
.filter-col { display: flex; flex-direction: column; gap: 8px; }
.filter-label { font-size: 13px; font-weight: 600; color: var(--text); }
.input-group-joined { display: flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--bg); height: 40px; }
.input-group-joined input, .input-group-joined select { border: none; padding: 0 14px; outline: none; background: transparent; color: var(--text); font-size: 14px; }
.input-group-joined select { border-right: 1px solid var(--border); cursor: pointer; }
.input-group-joined .icon-box { padding: 0 14px; background: var(--surface); border-left: 1px solid var(--border); display: flex; align-items: center; color: var(--text-muted); }

.api-box { background: #f8fafc; border: 1px dashed var(--border-strong); padding: 16px; border-radius: var(--radius-sm); margin-bottom: 16px; }
.api-key-text { font-family: monospace; font-size: 15px; color: var(--success); word-break: break-all; margin: 0;}

/* Buttons */
.btn-update, .btn-primary, .btn { background: var(--primary); color: white; border: none; padding: 10px 24px; font-size: 14px; font-weight: 500; border-radius: var(--radius-sm); cursor: pointer; transition: 0.2s; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn-update:hover, .btn-primary:hover, .btn:hover { background: var(--primary-hover); }
.btn-update:disabled, .btn:disabled { opacity: 0.7; cursor: not-allowed; }
.btn-edit { background: var(--surface); border: 1px solid var(--border-strong); padding: 6px 12px; border-radius: var(--radius-sm); font-size: 12.5px; font-weight: 600; color: var(--text); cursor: pointer; transition: 0.2s; }
.btn-edit:hover { background: #f1f5f9; }
.btn-filter { background: #ff7f50; color: white; border: none; padding: 0 20px; border-radius: var(--radius-sm); height: 40px; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-weight: 500; transition: 0.2s; }
.btn-filter:hover { background: #e06c40; }
.btn-export { background: #10b981; color: white; border: none; padding: 0 20px; border-radius: var(--radius-sm); height: 40px; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-weight: 500; transition: 0.2s; }
.btn-export:hover { background: #059669; }

.alert-box, .error-msg { padding: 10px 16px; border-radius: var(--radius-sm); display: none; background: #ecfdf3; border: 1px solid #d1fadf; color: var(--success); font-size: 13.5px; font-weight: 500; margin-top: 16px; }
.error-msg { background: #fef3f2; border-color: #fee4e2; color: var(--danger); display: flex; align-items: center; gap: 8px; margin-bottom:20px; margin-top:0;}
.error-msg::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--danger); flex-shrink: 0; }
.error-container { background: #fef3f2; border: 1px solid #fee4e2; border-left: 4px solid var(--danger); padding: 30px; border-radius: var(--radius-sm); margin-top: 30px; text-align: center; }
.error-container h2 { color: var(--danger); margin: 0 0 10px 0; font-size: 20px; }
.error-container p { color: var(--text-muted); font-size: 14px; margin-bottom: 20px; }

/* ---------- 9. LOGIN PAGE SPECIFIC ---------- */
.login-page { display: grid; grid-template-columns: 1fr 1fr; min-height: 100vh; }
.login-panel { display: flex; align-items: center; justify-content: center; padding: 48px 32px; }
.login-inner { width: 100%; max-width: 352px; }
.login-inner .brand { display: inline-flex; align-items: center; gap: 9px; font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 40px; }
.login-inner .brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--primary); display: grid; place-items: center; }
.label-row { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 6px; }
.forgot { font-size: 12.5px; color: var(--text-muted); transition: 0.15s; }
.forgot:hover { color: var(--text); }
.side-panel { background: var(--bg); border-left: 1px solid var(--border); display: flex; align-items: center; justify-content: center; padding: 56px 48px; position: relative; overflow: hidden; }
.side-panel::before { content: ""; position: absolute; top: -160px; right: -160px; width: 420px; height: 420px; border-radius: 50%; background: radial-gradient(circle, rgba(15, 23, 42, .045), transparent 68%); pointer-events: none; }
.side-inner { position: relative; width: 100%; max-width: 384px; }
.side-inner .eyebrow { font-size: 11.5px; font-weight: 500; letter-spacing: 0.09em; text-transform: uppercase; color: var(--text-soft); margin: 0 0 12px; }
.side-inner h2 { font-size: 19px; font-weight: 600; line-height: 1.4; margin: 0 0 32px; color: var(--text); }
.login-menu { border-top: 1px solid #e8ecf1; }
.login-menu a { display: flex; align-items: center; gap: 14px; padding: 15px 2px; border-bottom: 1px solid #e8ecf1; transition: padding-left .18s ease; }
.login-menu a:hover { padding-left: 8px; }
.login-menu-icon { width: 30px; height: 30px; border-radius: 8px; background: var(--surface); border: 1px solid #e8ecf1; display: grid; place-items: center; color: var(--text-muted); transition: 0.18s; }
.login-menu a:hover .login-menu-icon { border-color: #cbd5e1; color: var(--text); }
.login-menu-title { font-size: 13.5px; font-weight: 500; color: var(--text); display: block;}
.login-menu-desc { font-size: 12.5px; color: var(--text-soft); }
.status-indicator { display: inline-flex; align-items: center; gap: 8px; margin-top: 28px; font-size: 12.5px; color: var(--text-muted); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #12b76a; box-shadow: 0 0 0 3px rgba(18, 183, 106, .13); }

/* ---------- 10. MOBILE RESPONSIVE & HAMBURGER ---------- */
.mobile-header, .close-btn, .sidebar-overlay { display: none; }

@media (max-width: 992px) {
    .settings-grid { grid-template-columns: repeat(2, 1fr); } 
    .login-page { grid-template-columns: 1fr; }
    .side-panel { display: none; }
    .login-panel { padding: 40px 24px; min-height: 100vh; }
}

@media (max-width: 768px) {
    .app-container { flex-direction: column; }
    .main-content { padding: 20px 16px; }
    .card { padding: 20px 16px; }
    .settings-grid { grid-template-columns: 1fr; } 
    .form-text { min-height: auto; }
    
    .mobile-header { display: flex; justify-content: space-between; align-items: center; background: var(--surface); padding: 15px 20px; border-bottom: 1px solid var(--border); }
    .mobile-header h2 { margin: 0; font-size: 20px; color: var(--primary); font-weight: 700; }
    .hamburger { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--text); padding: 5px; }
    .topbar { display: none !important; }

    .sidebar { position: fixed; top: 0; left: 0; height: 100vh; width: 260px; z-index: 1000; transform: translateX(-100%); transition: transform 0.3s ease-in-out; box-shadow: 2px 0 15px rgba(0,0,0,0.2); }
    .sidebar.active { transform: translateX(0); }

    .close-btn { display: block; background: none; border: none; font-size: 18px; position: absolute; top: 20px; right: 20px; cursor: pointer; color: var(--text-muted); }
    .sidebar-overlay { display: block; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0,0,0,0.5); z-index: 999; opacity: 0; visibility: hidden; transition: 0.3s; }
    .sidebar-overlay.active { opacity: 1; visibility: visible; }
}