/**
 * Modern Layout System - Contab-AI
 * Sistema de design moderno com sidebar, topbar e componentes reutilizáveis
 */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ========================================
   CSS VARIABLES - Sistema de Design
   ======================================== */
:root {
    /* Colors - Modern Blue/Purple Palette */
    --primary-gradient: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
    --primary-color: #007bff;
    --primary-dark: #0056b3;
    --primary-light: #3395ff;
    --accent-color: #6C63FF;
    --accent-gradient: linear-gradient(135deg, #6C63FF 0%, #5850d4 100%);
    --golden-color: #F5A623;

    /* Semantic Colors */
    --success-color: #10b981;
    --success-light: #d1fae5;
    --warning-color: #f59e0b;
    --warning-light: #fef3c7;
    --danger-color: #ef4444;
    --danger-light: #fee2e2;
    --info-color: #3b82f6;
    --info-light: #dbeafe;

    /* Neutrals - Light Theme */
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --bg-sidebar: #2c3e50;
    --bg-sidebar-hover: #34495e;
    --bg-topbar: #ffffff;
    --bg-input-light: #e7f3ff;

    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --text-white: #ffffff;
    --text-sidebar: #e2e8f0;

    --border-color: #e2e8f0;
    --border-color-light: #f1f5f9;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    --shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.25);

    /* Layout */
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 70px;
    --topbar-height: 64px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 200ms ease;
    --transition-slow: 300ms ease;

    /* Z-index */
    --z-dropdown: 1000;
    --z-sticky: 1020;
    --z-fixed: 1030;
    --z-modal-backdrop: 1040;
    --z-modal: 1050;
    --z-popover: 1060;
    --z-tooltip: 1070;
}

/* ========================================
   BASE RESET & UTILITIES
   ======================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ========================================
   LAYOUT STRUCTURE
   ======================================== */
.app-layout {
    display: flex;
    min-height: 100vh;
    position: relative;
}

/* ========================================
   TOP BAR
   ======================================== */
.top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-height);
    background: var(--bg-topbar);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-xl);
    z-index: var(--z-fixed);
    box-shadow: var(--shadow-sm);
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
    flex: 1;
}

.logo-link {
    display: flex;
    align-items: center;
    text-decoration: none;
    flex-shrink: 0;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    text-decoration: none;
}

.logo {
    height: 40px;
    width: auto;
    object-fit: contain;
    /* Logo no top-bar mantém cores originais */
}

.company-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    justify-content: center;
    align-self: center;
    margin-left: calc(-40px - var(--space-lg));
    padding-left: calc(40px + var(--space-lg));
}

.company-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.2;
}

.company-nif {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1;
}

/* Search Bar */
.search-bar {
    position: relative;
    width: 400px;
}

.search-bar input {
    width: 100%;
    padding: 10px 16px 10px 42px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 14px;
    transition: all var(--transition-base);
    background: var(--bg-main);
    font-family: inherit;
}

.search-bar input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
    background: var(--bg-card);
}

.search-bar input::placeholder {
    color: var(--text-muted);
}

.search-bar i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

/* Top Bar Right */
.top-bar-right {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

/* Language Toggle */
.language-toggle {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: var(--bg-main);
    border-radius: var(--radius-md);
}

.language-toggle a {
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.language-toggle a.active {
    background: var(--primary-color);
    color: var(--text-white);
}

.language-toggle a:hover:not(.active) {
    background: var(--border-color);
    color: var(--text-primary);
}

/* Notification Badge */
.notification-badge {
    position: relative;
    cursor: pointer;
    padding: var(--space-sm);
    border-radius: var(--radius-md);
    transition: background var(--transition-base);
}

.notification-badge:hover {
    background: var(--bg-main);
}

.notification-badge i {
    font-size: 18px;
    color: var(--text-secondary);
}

.badge-count {
    position: absolute;
    top: 4px;
    right: 4px;
    background: var(--danger-color);
    color: white;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 5px;
    border-radius: var(--radius-full);
    min-width: 18px;
    text-align: center;
    line-height: 1.2;
}

/* User Menu */
.user-menu {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition-base);
}

.user-menu:hover {
    background: var(--bg-main);
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}

.user-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.user-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1.2;
}

.user-role {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1;
}

.user-role-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.user-role-badge.admin {
    background: var(--accent-gradient);
    color: white;
}

.user-role-badge.owner {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
}

.user-role-badge.accountant {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
}

.user-role-badge.viewer {
    background: var(--bg-main);
    color: var(--text-secondary);
}

/* ========================================
   SIDEBAR
   ======================================== */
.sidebar {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--topbar-height));
    background: var(--bg-sidebar);
    padding: var(--space-lg) 0;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: var(--z-sticky);
    transition: transform var(--transition-slow);
}

/* Custom Scrollbar */
.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Sidebar Header */
.sidebar-header {
    padding: 0 var(--space-lg) var(--space-lg) var(--space-lg);
    margin-bottom: var(--space-md);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header .logo-link {
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-logo {
    height: 50px;
    width: auto;
    object-fit: contain;
    /* Logo mantém cores originais - sem filtro */
}

/* Sidebar Company Info */
.sidebar-company-info {
    padding: 18px var(--space-lg);
    background: var(--accent-gradient);
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    margin-bottom: var(--space-md);
    display: flex;
    flex-direction: column;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(108, 99, 255, 0.2);
    min-height: 70px;
}

.sidebar-company-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
    backdrop-filter: blur(10px);
}

.sidebar-company-details {
    flex: 1;
    min-width: 0;
}

.sidebar-company-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-white);
    margin-bottom: 6px;
    line-height: 1.3;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.sidebar-company-nif {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.85);
    font-weight: 500;
}

/* Sidebar Section */
.sidebar-section {
    margin-bottom: var(--space-lg);
}

/* First sidebar section (NAVIGATION) with accent/purple background */
.sidebar-section:first-child {
    background: var(--accent-gradient);
    padding: var(--space-md) 0;
    margin: 0 0 var(--space-lg) 0;
    border-radius: var(--radius-md);
}

.sidebar-section:first-child .sidebar-section-title {
    color: rgba(255, 255, 255, 0.95);
}

.sidebar-section:first-child .sidebar-nav-link {
    color: rgba(255, 255, 255, 0.9);
}

.sidebar-section:first-child .sidebar-nav-link:hover,
.sidebar-section:first-child .sidebar-nav-link.active {
    background: rgba(255, 255, 255, 0.15);
    color: white;
}

.sidebar-section-title {
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0 var(--space-lg);
    margin-bottom: var(--space-sm);
}

.sidebar-nav {
    list-style: none;
}

.sidebar-nav-item {
    margin-bottom: 4px;
}

.sidebar-nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px var(--space-lg);
    color: var(--text-sidebar);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all var(--transition-base);
    position: relative;
}

.sidebar-nav-link:hover {
    background: var(--bg-sidebar-hover);
    color: var(--text-white);
}

.sidebar-nav-link.active {
    background: var(--bg-sidebar-hover);
    color: var(--text-white);
}

.sidebar-nav-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--primary-color);
}

.sidebar-nav-link i {
    width: 20px;
    text-align: center;
    font-size: 16px;
    flex-shrink: 0;
}

.sidebar-nav-badge {
    margin-left: auto;
    background: var(--danger-color);
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: var(--radius-full);
    min-width: 20px;
    text-align: center;
}

/* Mobile Toggle */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: calc(var(--topbar-height) + var(--space-md));
    left: var(--space-md);
    width: 40px;
    height: 40px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: calc(var(--z-fixed) + 1);
    box-shadow: var(--shadow-md);
}

.sidebar-toggle i {
    font-size: 18px;
    color: var(--text-primary);
}

/* ========================================
   MAIN CONTENT
   ======================================== */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    margin-top: var(--topbar-height);
    padding: var(--space-xl);
    min-height: calc(100vh - var(--topbar-height));
}

/* Breadcrumbs */
.breadcrumbs {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-lg);
    padding-left: 0;
    font-size: 14px;
    color: var(--text-secondary);
}

.breadcrumbs a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color var(--transition-base);
}

.breadcrumbs a:hover {
    color: var(--primary-color);
}

.breadcrumbs .current {
    color: var(--text-primary);
    font-weight: 500;
}

.breadcrumbs i {
    font-size: 10px;
}

/* Page Header */
.page-header {
    margin-bottom: var(--space-xl);
}

.page-header h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--space-sm);
}

.page-header p {
    font-size: 15px;
    color: var(--text-secondary);
}

/* ========================================
   CARDS & COMPONENTS
   ======================================== */

/* Base Card */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    padding: var(--space-lg);
    box-shadow: var(--shadow-sm);
    transition: all var(--transition-slow);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card.full-width {
    grid-column: 1 / -1;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--space-lg);
    margin-bottom: var(--space-xl);
}

.stat-card {
    background: var(--bg-card);
    padding: var(--space-lg);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    transition: all var(--transition-slow);
    cursor: pointer;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-color);
}

.stat-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-md);
}

.stat-card-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
}

.stat-card-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.stat-card-icon.blue {
    background: var(--info-light);
    color: var(--info-color);
}

.stat-card-icon.green {
    background: var(--success-light);
    color: var(--success-color);
}

.stat-card-icon.purple {
    background: rgba(102, 126, 234, 0.1);
    color: var(--primary-color);
}

.stat-card-icon.orange {
    background: var(--warning-light);
    color: var(--warning-color);
}

.stat-card-icon.red {
    background: var(--danger-light);
    color: var(--danger-color);
}

.stat-card-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--space-sm);
    line-height: 1.2;
}

.stat-card-change {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
}

.stat-card-change.positive {
    color: var(--success-color);
}

.stat-card-change.negative {
    color: var(--danger-color);
}

/* Feature Grid */
.feature-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: var(--space-lg);
    margin-bottom: var(--space-xl);
}

.feature-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    overflow: hidden;
    transition: all var(--transition-slow);
    cursor: pointer;
}

.feature-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-xl);
    border-color: var(--primary-color);
}

.feature-card-header {
    padding: var(--space-lg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
}

.feature-card-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    background: var(--accent-gradient);
    color: white;
    flex-shrink: 0;
}

.feature-card-title {
    flex: 1;
}

.feature-card-title h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.feature-card-title p {
    font-size: 13px;
    color: var(--text-secondary);
}

.feature-card-body {
    padding: var(--space-lg);
}

.feature-card-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.feature-action-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    text-decoration: none;
    transition: all var(--transition-base);
}

.feature-action-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    transform: translateX(4px);
}

.feature-action-btn i {
    width: 16px;
    text-align: center;
    flex-shrink: 0;
}

/* ========================================
   BUTTONS
   ======================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-base);
    text-decoration: none;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
}

.btn-secondary {
    background: var(--bg-main);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-card);
    border-color: var(--primary-color);
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */
@media (max-width: 1024px) {
    .search-bar {
        width: 300px;
    }
}

@media (max-width: 768px) {
    /* Sidebar becomes overlay on mobile */
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .sidebar-toggle {
        display: flex;
    }

    .main-content {
        margin-left: 0;
        padding: var(--space-lg);
    }

    .search-bar {
        display: none;
    }

    .top-bar {
        padding: 0 var(--space-md);
    }

    .user-info {
        display: none;
    }

    .company-info {
        display: none;
    }

    .feature-grid {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .page-header h1 {
        font-size: 24px;
    }
}

@media (max-width: 480px) {
    .main-content {
        padding: var(--space-md);
    }

    .language-toggle {
        display: none;
    }
}

/* ========================================
   UTILITIES
   ======================================== */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: var(--space-sm) !important; }
.mb-2 { margin-bottom: var(--space-md) !important; }
.mb-3 { margin-bottom: var(--space-lg) !important; }
.mb-4 { margin-bottom: var(--space-xl) !important; }

.mt-0 { margin-top: 0 !important; }
.mt-1 { margin-top: var(--space-sm) !important; }
.mt-2 { margin-top: var(--space-md) !important; }
.mt-3 { margin-top: var(--space-lg) !important; }
.mt-4 { margin-top: var(--space-xl) !important; }

/* ========================================
   DROPDOWN MENUS
   ======================================== */
.dropdown-menu {
    position: fixed;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    padding: var(--space-sm) 0;
    min-width: 220px;
    z-index: var(--z-dropdown);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all var(--transition-base);
}

.dropdown-menu.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: 10px var(--space-md);
    color: var(--text-primary);
    text-decoration: none;
    font-size: 14px;
    transition: all var(--transition-fast);
}

.dropdown-item:hover {
    background: var(--bg-main);
    color: var(--primary-color);
}

.dropdown-item i {
    width: 16px;
    text-align: center;
    font-size: 14px;
}

.dropdown-divider {
    height: 1px;
    background: var(--border-color);
    margin: var(--space-sm) 0;
}

/* Useful Links Grid - Equal Size Cards */
.useful-links-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

@media (max-width: 1200px) {
    .useful-links-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .useful-links-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .useful-links-grid {
        grid-template-columns: 1fr;
    }
}
