/* ============================================================
   eSaran SEO Dashboard — style.css v2
   Modern SaaS UI
   ============================================================ */

/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary:        #4F46E5;
    --primary-dark:   #4338CA;
    --primary-light:  #EEF2FF;
    --primary-mid:    #C7D2FE;
    --success:        #10B981;
    --success-light:  #D1FAE5;
    --danger:         #EF4444;
    --danger-light:   #FEE2E2;
    --warning:        #F59E0B;
    --warning-light:  #FEF3C7;
    --info:           #3B82F6;
    --info-light:     #DBEAFE;
    --text-primary:   #111827;
    --text-secondary: #6B7280;
    --text-muted:     #9CA3AF;
    --bg:             #F9FAFB;
    --bg-card:        #FFFFFF;
    --border:         #E5E7EB;
    --border-light:   #F3F4F6;
    --sidebar-w:      240px;
    --radius:         12px;
    --radius-sm:      8px;
    --shadow-sm:      0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
    --shadow:         0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -2px rgba(0,0,0,.05);
    --shadow-md:      0 10px 15px -3px rgba(0,0,0,.08), 0 4px 6px -4px rgba(0,0,0,.05);
    --font:           -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Roboto, Arial, sans-serif;
    --transition:     .15s ease;
}

html { font-size: 14px; -webkit-font-smoothing: antialiased; }
body { font-family: var(--font); background: var(--bg); color: var(--text-primary); line-height: 1.6; }
a { text-decoration: none; color: var(--primary); }
a:hover { color: var(--primary-dark); }
img { max-width: 100%; }

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

/* Sidebar: fixed di kiri */
.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    z-index: 100;
    overflow-y: auto;
}

/* Main content: offset sidebar */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow-x: hidden;
}

.page-content {
    flex: 1;
    padding: 2rem 2.25rem;
    max-width: 1200px;
    width: 100%;
}

/* ============================================================
   SIDEBAR INTERNALS
   ============================================================ */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}

.sidebar-logo {
    width: 36px;
    height: 36px;
    background: var(--primary);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-logo span {
    color: #fff;
    font-weight: 700;
    font-size: 1.1rem;
    font-style: italic;
}

.sidebar-brand-text strong {
    display: block;
    font-size: .9rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.2;
}

.sidebar-brand-text small {
    font-size: .7rem;
    color: var(--text-muted);
}

.sidebar-nav {
    flex: 1;
    padding: 1rem .75rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-section-label {
    font-size: .65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-muted);
    padding: .75rem .5rem .35rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .55rem .75rem;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: .82rem;
    font-weight: 500;
    transition: background var(--transition), color var(--transition);
}

.nav-item:hover {
    background: var(--border-light);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--primary-light);
    color: var(--primary);
}

.nav-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    opacity: .8;
}

.nav-item.active .nav-icon { opacity: 1; }

.sidebar-footer {
    padding: 1rem .75rem;
    border-top: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-shrink: 0;
}

.sidebar-user {
    flex: 1;
    display: flex;
    align-items: center;
    gap: .6rem;
    min-width: 0;
}

.sidebar-avatar {
    width: 32px;
    height: 32px;
    background: var(--primary);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .75rem;
    font-weight: 600;
    flex-shrink: 0;
}

.sidebar-user-info { min-width: 0; }

.sidebar-user-info strong {
    display: block;
    font-size: .78rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-info small {
    font-size: .68rem;
    color: var(--text-muted);
}

.btn-logout {
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    transition: background var(--transition), color var(--transition);
}

.btn-logout:hover { background: var(--danger-light); color: var(--danger); }

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
    padding: 1.1rem 2rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 50;
    flex-shrink: 0;
}

.topbar-title-wrap { flex: 1; min-width: 0; }

.topbar-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.topbar-subtitle {
    font-size: .75rem;
    color: var(--text-muted);
    margin-top: 1px;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: .75rem;
    flex-shrink: 0;
}

.badge-role {
    padding: .25rem .65rem;
    border-radius: 20px;
    font-size: .7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.badge-role.admin  { background: var(--primary-light); color: var(--primary); }
.badge-role.client { background: var(--success-light); color: #065F46; }

/* ============================================================
   CARDS
   ============================================================ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.card-header {
    padding: 1.1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.card-title {
    font-size: .9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.card-body { padding: 1.5rem; }

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.75rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: .35rem;
}

.stat-label {
    font-size: .72rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
}

.stat-value {
    font-size: 1.7rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.2;
}

.stat-hint { font-size: .72rem; color: var(--text-muted); }

.stat-card.primary { border-left: 3px solid var(--primary); }
.stat-card.success { border-left: 3px solid var(--success); }
.stat-card.warning { border-left: 3px solid var(--warning); }
.stat-card.danger  { border-left: 3px solid var(--danger); }

.stat-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: .5rem;
}

.stat-icon.primary { background: var(--primary-light); color: var(--primary); }
.stat-icon.success { background: var(--success-light); color: var(--success); }
.stat-icon.warning { background: var(--warning-light); color: var(--warning); }
.stat-icon.danger  { background: var(--danger-light);  color: var(--danger); }

/* ============================================================
   TABLE
   ============================================================ */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }

table { width: 100%; border-collapse: collapse; font-size: .82rem; }

thead tr { background: var(--border-light); }

thead th {
    padding: .7rem 1rem;
    text-align: left;
    font-weight: 600;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tbody tr { border-bottom: 1px solid var(--border-light); transition: background var(--transition); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #FAFAFA; }

tbody td { padding: .8rem 1rem; color: var(--text-primary); vertical-align: middle; }

.td-muted { color: var(--text-muted); }

/* ============================================================
   FORMS
   ============================================================ */
.form-group { margin-bottom: 1.25rem; }

.form-label {
    display: block;
    font-size: .8rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: .4rem;
}

.form-control {
    display: block;
    width: 100%;
    padding: .6rem .9rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: .85rem;
    color: var(--text-primary);
    background: var(--bg-card);
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
    -webkit-appearance: none;
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,.1);
}

textarea.form-control { resize: vertical; min-height: 90px; }
.form-hint { font-size: .72rem; color: var(--text-muted); margin-top: .3rem; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .5rem 1rem;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: .82rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all var(--transition);
    white-space: nowrap;
    line-height: 1.4;
    text-decoration: none;
}

.btn:active { transform: translateY(1px); }

.btn-primary  { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }

.btn-secondary { background: transparent; color: var(--text-secondary); border-color: var(--border); }
.btn-secondary:hover { background: var(--border-light); color: var(--text-primary); }

.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover { background: #059669; border-color: #059669; color: #fff; }

.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-info { background: var(--info-light); color: var(--info); border-color: var(--info-light); }
.btn-info:hover { background: var(--info); color: #fff; }

.btn-sm { padding: .3rem .7rem; font-size: .75rem; }
.btn-lg { padding: .7rem 1.5rem; font-size: .9rem; }
.btn-block { width: 100%; justify-content: center; }

.btn-group { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* ============================================================
   BADGES
   ============================================================ */
.badge {
    display: inline-flex;
    align-items: center;
    gap: .2rem;
    padding: .2rem .55rem;
    border-radius: 20px;
    font-size: .72rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-up      { background: var(--success-light); color: #065F46; }
.badge-down    { background: var(--danger-light);  color: #991B1B; }
.badge-same    { background: var(--border-light);  color: var(--text-muted); }
.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-success { background: var(--success-light); color: #065F46; }
.badge-warning { background: var(--warning-light); color: #92400E; }
.badge-danger  { background: var(--danger-light);  color: #991B1B; }

/* ============================================================
   ALERTS
   ============================================================ */
.alert {
    padding: .85rem 1.1rem;
    border-radius: var(--radius-sm);
    font-size: .83rem;
    font-weight: 500;
    margin-bottom: 1.25rem;
    border: 1px solid transparent;
}

.alert-success { background: var(--success-light); color: #065F46; border-color: #A7F3D0; }
.alert-error   { background: var(--danger-light);  color: #991B1B; border-color: #FECACA; }
.alert-warning { background: var(--warning-light); color: #92400E; border-color: #FDE68A; }
.alert-info    { background: var(--info-light);    color: #1E40AF; border-color: #BFDBFE; }

/* ============================================================
   PAGE HEADERS
   ============================================================ */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.75rem;
    flex-wrap: wrap;
}

.page-header-text h1 {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-primary);
}

.page-header-text p {
    font-size: .82rem;
    color: var(--text-muted);
    margin-top: .2rem;
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: .3rem;
    font-size: .75rem;
    color: var(--text-muted);
    margin-bottom: .4rem;
    flex-wrap: wrap;
}

.breadcrumb a { color: var(--primary); }

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    padding: 1.5rem;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
}

.login-brand { text-align: center; margin-bottom: 2rem; }

.login-logo {
    width: 52px;
    height: 52px;
    background: var(--primary);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto .75rem;
}

.login-logo span { color: #fff; font-size: 1.5rem; font-weight: 700; font-style: italic; }

.login-brand h1 { font-size: 1.1rem; font-weight: 700; color: var(--text-primary); }
.login-brand p  { font-size: .8rem; color: var(--text-muted); margin-top: .2rem; }

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--text-muted);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    stroke: var(--border);
    margin-bottom: 1rem;
}

.empty-state p { font-size: .9rem; margin-bottom: 1rem; }

/* ============================================================
   BACKLINK
   ============================================================ */
.backlink-card {
    background: var(--primary-light);
    border: 1px solid var(--primary-mid);
    border-radius: var(--radius);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.backlink-info h3 {
    font-size: .9rem;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: .3rem;
}

.backlink-info p { font-size: .78rem; color: var(--text-muted); }

/* ============================================================
   IFRAME
   ============================================================ */
.iframe-wrapper {
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
    margin-top: 1rem;
}

.iframe-wrapper iframe { display: block; width: 100%; height: 500px; border: none; }

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.35);
    z-index: 999;
    align-items: center;
    justify-content: center;
}

.modal-overlay.show { display: flex; }

.modal-box {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 2rem;
    width: 90%;
    max-width: 380px;
    text-align: center;
}

.modal-box h3 { font-size: .95rem; margin-bottom: .5rem; }
.modal-box p  { font-size: .82rem; color: var(--text-muted); margin-bottom: 1.5rem; }

.modal-icon {
    width: 48px;
    height: 48px;
    background: var(--danger-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto .75rem;
    color: var(--danger);
}

/* ============================================================
   UTILITIES
   ============================================================ */
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

.text-muted   { color: var(--text-muted); font-size: .82rem; }
.text-danger  { color: var(--danger); }
.text-success { color: var(--success); }
.text-primary { color: var(--primary); }
.fw-600       { font-weight: 600; }
.d-flex       { display: flex; }
.align-center { align-items: center; }

.divider { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform .25s ease;
        width: 240px;
        z-index: 200;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow-md);
    }

    .main-content { margin-left: 0; }
    .topbar { padding: 1rem 1.25rem; }
    .page-content { padding: 1.25rem; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .page-header { flex-direction: column; align-items: flex-start; }
    .topbar-title-wrap { flex: 1; }

    .hamburger {
        display: flex;
        align-items: center;
        background: none;
        border: none;
        cursor: pointer;
        color: var(--text-secondary);
        padding: .3rem;
        border-radius: var(--radius-sm);
        flex-shrink: 0;
    }

    .hamburger:hover { background: var(--border-light); color: var(--text-primary); }
}

@media (min-width: 769px) {
    .hamburger { display: none; }
}

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

/* ============================================================
   ANALYTICS RESPONSIVE HELPERS
   ============================================================ */
.stats-grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stats-grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.analytics-two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.chart-wrap {
    position: relative;
    width: 100%;
    height: 200px;
    margin-bottom: 1.5rem;
}

/* Paksa page-content tidak overflow */
.page-content {
    overflow-x: hidden;
}

@media (max-width: 768px) {
    .stats-grid-4 { grid-template-columns: 1fr 1fr; }
    .stats-grid-3 { grid-template-columns: 1fr 1fr; }
    .analytics-two-col { grid-template-columns: 1fr; }
    .chart-wrap { height: 160px; }
}

@media (max-width: 480px) {
    .stats-grid-4 { grid-template-columns: 1fr 1fr; }
    .stats-grid-3 { grid-template-columns: 1fr; }
}
