/* D3 Radar - Enterprise App Styles */

:root {
    /* Color Palette */
    --primary-color: #1976d2; /* Material Blue 700 */
    --primary-dark: #115293;
    --success-color: #388e3c; /* Material Green 700 */
    --danger-color: #d32f2f;  /* Material Red 700 */
    --warning-color: #f57c00;
    
    --bg-color: #f4f6f8;
    --surface-color: #ffffff;
    --text-primary: #333333;
    --text-secondary: #666666;
    --border-color: #e0e0e0;
    
    --sidebar-width: 250px;
    --sidebar-mini-width: 68px;
    --header-height: 64px;
    
    --border-radius-sm: 4px;
    --border-radius-md: 8px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
}

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

html, body {
    height: 100%;
    overflow: hidden; /* No scroll on body — we scroll inside .page-content */
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.5;
}

/* Layout */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar — Fixed */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--surface-color);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100;
    overflow-y: auto;
    overflow-x: hidden;
    transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1), transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid var(--border-color);
    color: var(--primary-color);
    flex-shrink: 0;
    transition: padding 0.25s ease;
}

.sidebar-header h2 {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.2rem;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    padding: 12px 0;
    flex: 1;
}

.nav-item {
    padding: 11px 20px;
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 500;
    border-left: 4px solid transparent;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
    transition: background-color 0.15s, color 0.15s;
}

.nav-item i {
    width: 20px;
    text-align: center;
    font-size: 1rem;
    color: var(--text-secondary);
    transition: color 0.15s;
}

.nav-item:hover {
    background-color: #f0f4ff;
}

.nav-item:hover i {
    color: var(--primary-color);
}

.nav-item.active {
    background-color: #e3f2fd;
    color: var(--primary-color);
    border-left-color: var(--primary-color);
}

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

/* Sidebar Nav Submenu */
.nav-group-toggle {
    cursor: pointer;
    user-select: none;
}
.nav-group .nav-arrow {
    transition: transform 0.2s ease;
    margin-left: auto;
    font-size: 0.75rem !important;
    width: auto !important;
}
.nav-group.open .nav-arrow {
    transform: rotate(180deg);
}
.nav-submenu {
    display: none;
    background: #f8fafc;
    border-left: 3px solid #e2e8f0;
    margin-left: 20px;
    padding: 4px 0;
}
.nav-group.open .nav-submenu {
    display: flex;
    flex-direction: column;
}
.nav-subitem {
    padding: 8px 16px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    transition: all 0.15s ease;
}
.nav-subitem i {
    width: 16px;
    text-align: center;
    font-size: 0.85rem;
}
.nav-subitem:hover {
    color: var(--primary-color);
    background: #f1f5f9;
}
.nav-subitem.active {
    color: var(--primary-color);
    font-weight: 600;
    background: #e3f2fd;
    border-left: 3px solid var(--primary-color);
}

/* Main Content — offset by sidebar width */
.main-wrapper {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    margin-left: var(--sidebar-width);
    height: 100vh;
    overflow: hidden;
    min-width: 0;
    transition: margin-left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.app-header {
    height: var(--header-height);
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 24px;
    flex-shrink: 0;
}

.header-content {
    display: flex;
    justify-content: space-between;
    width: 100%;
    align-items: center;
}

.header-content h1 {
    font-size: 1.25rem;
    font-weight: 500;
    margin: 0;
}

.sidebar-toggle-btn,
.mobile-menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    border-radius: 6px;
    width: 36px;
    height: 36px;
    font-size: 1.15rem;
    cursor: pointer;
    margin-right: 14px;
    color: var(--text-secondary);
    transition: background-color 0.15s, color 0.15s;
    flex-shrink: 0;
}

.sidebar-toggle-btn:hover,
.mobile-menu-toggle:hover {
    background-color: #f1f5f9;
    color: var(--primary-color);
}

.submenu-header {
    display: none;
}

/* Scrollable Content Area */
.page-content {
    padding: 24px;
    flex-grow: 1;
    overflow-y: auto;
    overflow-x: hidden; /* No horizontal scroll */
}

/* Components */
.card {
    background: var(--surface-color);
    border-radius: var(--border-radius-md);
    box-shadow: var(--shadow-sm);
    padding: 24px;
    margin-bottom: 24px;
    border: 1px solid var(--border-color);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--border-radius-sm);
    font-weight: 500;
    text-align: center;
    cursor: pointer;
    border: 1px solid transparent;
    text-decoration: none;
    font-size: 0.875rem;
    transition: background-color 0.15s;
}

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

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

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

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

/* Action Icon Buttons */
.action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    text-decoration: none;
    transition: all 0.2s ease;
}

.action-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(0,0,0,0.15);
}

.action-view {
    background: #0284c7;
    color: #ffffff;
}
.action-view:hover {
    background: #0369a1;
    color: #ffffff;
}

.action-edit {
    background: #ea580c;
    color: #ffffff;
}
.action-edit:hover {
    background: #c2410c;
    color: #ffffff;
}

.action-delete {
    background: #dc2626;
    color: #ffffff;
}
.action-delete:hover {
    background: #b91c1c;
    color: #ffffff;
}

/* Badges & Tags */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    line-height: 1.2;
}
.badge-success {
    background: #16a34a;
    color: #ffffff;
}
.badge-danger {
    background: #dc2626;
    color: #ffffff;
}
.badge-warning {
    background: #ea580c;
    color: #ffffff;
}
.badge-info {
    background: #0284c7;
    color: #ffffff;
}
.badge-secondary {
    background: #e2e8f0;
    color: #475569;
}

/* Tables */
.table-responsive {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th, .table td {
    padding: 12px 16px;
    text-align: left;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-color);
}

.table th {
    background-color: #fafafa;
    font-weight: 600;
    color: var(--text-secondary);
}

/* Forms */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
}

.form-control {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    font-size: 1rem;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(25, 118, 210, 0.2);
}

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: var(--border-radius-sm);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.alert-success {
    background-color: #e8f5e9;
    color: #2e7d32;
    border: 1px solid #c8e6c9;
}

.alert-danger {
    background-color: #ffebee;
    color: #c62828;
    border: 1px solid #ffcdd2;
}

/* ============================================================ */
/* Desktop Mini-Sidebar (Collapsed Mode)                         */
/* ============================================================ */
@media (min-width: 769px) {
    body.sidebar-collapsed .sidebar {
        width: var(--sidebar-mini-width);
        overflow: visible;
    }

    body.sidebar-collapsed .main-wrapper {
        margin-left: var(--sidebar-mini-width);
    }

    body.sidebar-collapsed .sidebar-header {
        padding: 0;
        justify-content: center;
    }

    body.sidebar-collapsed .sidebar-header h2 {
        justify-content: center;
    }

    body.sidebar-collapsed .sidebar-header .brand-text {
        display: none;
    }

    body.sidebar-collapsed .nav-item {
        padding: 12px 0;
        justify-content: center;
        position: relative;
        border-left: 3px solid transparent;
    }

    body.sidebar-collapsed .nav-item i {
        margin: 0;
        width: auto;
        font-size: 1.15rem;
    }

    body.sidebar-collapsed .nav-item .nav-text,
    body.sidebar-collapsed .nav-item .nav-arrow {
        display: none;
    }

    body.sidebar-collapsed .nav-item.active {
        border-left-color: var(--primary-color);
        background-color: #e3f2fd;
    }

    /* Floating Tooltip for Simple Nav Items */
    body.sidebar-collapsed .nav-item:not(.nav-group-toggle)[data-tooltip]:hover::after {
        content: attr(data-tooltip);
        position: absolute;
        left: calc(var(--sidebar-mini-width) + 8px);
        top: 50%;
        transform: translateY(-50%);
        background: #1e293b;
        color: #ffffff;
        padding: 6px 12px;
        border-radius: 6px;
        font-size: 0.82rem;
        font-weight: 500;
        white-space: nowrap;
        pointer-events: none;
        box-shadow: 0 4px 12px rgba(0,0,0,0.18);
        z-index: 1000;
        opacity: 0;
        animation: miniTooltipFade 0.15s ease forwards;
    }

    /* Floating Flyout Submenu for Nav Group */
    body.sidebar-collapsed .nav-group {
        position: relative;
    }

    body.sidebar-collapsed .nav-group .nav-submenu {
        display: none !important;
        position: absolute;
        left: var(--sidebar-mini-width);
        top: 0;
        min-width: 200px;
        background: #ffffff;
        border: 1px solid var(--border-color);
        border-radius: 0 8px 8px 8px;
        box-shadow: 0 8px 24px rgba(0,0,0,0.14);
        padding: 6px 0;
        margin-left: 0;
        z-index: 1000;
    }

    body.sidebar-collapsed .nav-group:hover .nav-submenu {
        display: flex !important;
        flex-direction: column;
        animation: miniTooltipFade 0.15s ease forwards;
    }

    body.sidebar-collapsed .submenu-header {
        display: block;
        padding: 8px 16px 6px;
        font-size: 0.72rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: #94a3b8;
        border-bottom: 1px solid #f1f5f9;
        margin-bottom: 4px;
    }

    body.sidebar-collapsed .nav-subitem {
        padding: 9px 18px;
        font-size: 0.88rem;
    }

    @keyframes miniTooltipFade {
        from { opacity: 0; transform: translateY(-50%) translateX(-4px); }
        to { opacity: 1; transform: translateY(-50%) translateX(0); }
    }
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0,0,0,0.15);
    }

    .main-wrapper {
        margin-left: 0;
    }

    .mobile-menu-toggle {
        display: block;
    }

    /* Header adjustments */
    .app-header {
        padding: 0 12px;
        height: 52px;
    }

    .header-content h1 {
        font-size: 1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 140px;
    }

    .user-profile {
        gap: 6px !important;
    }

    .user-profile span[style*="font-weight: 500"] {
        display: none; /* Hide username text on small screens */
    }

    /* Page content */
    .page-content {
        padding: 12px;
    }

    /* Card */
    .card {
        padding: 14px;
        margin-bottom: 14px;
    }

    .card h2 {
        font-size: 1.1rem;
    }

    /* Table — stack cells on mobile */
    .table th, .table td {
        padding: 8px 10px;
        font-size: 0.82rem;
    }

    /* Table columns on tablet/mobile: hide ID, Status, Created; keep Title, URL, Domain, Actions */
    .table th:nth-child(1), .table td:nth-child(1),
    .table th:nth-child(5), .table td:nth-child(5),
    .table th:nth-child(6), .table td:nth-child(6) {
        display: none;
    }

    /* Buttons */
    .btn {
        padding: 6px 10px;
        font-size: 0.8rem;
    }

    /* Forms */
    .form-control {
        padding: 8px;
        font-size: 0.9rem;
    }

    /* Alerts */
    .alert {
        padding: 10px 12px;
        font-size: 0.85rem;
    }
}

@media (max-width: 480px) {
    .header-content h1 {
        font-size: 0.9rem;
        max-width: 120px;
    }

    .page-content {
        padding: 10px;
    }

    .card {
        padding: 12px;
        border-radius: 6px;
    }

    .card h2 {
        font-size: 1rem;
    }

    /* Stack heading + button vertically */
    .card > div[style*="justify-content: space-between"] {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 10px;
    }

    /* Table on tiny screens: also hide Domain, keep Title, URL, Actions */
    .table th:nth-child(4), .table td:nth-child(4) {
        display: none;
    }

    .table th, .table td {
        padding: 6px 8px;
        font-size: 0.78rem;
    }

    .btn {
        padding: 5px 8px;
        font-size: 0.75rem;
    }
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.35);
    z-index: 99;
}

.sidebar-overlay.show {
    display: block;
}
