/* ============================================
   Garnacha Dashboard - Design System
   ============================================ */

:root {
    --primary: #6d28d9;
    --primary-light: #8b5cf6;
    --primary-dark: #5b21b6;
    --primary-bg: #f5f3ff;

    --success: #059669;
    --success-light: #d1fae5;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --info: #2563eb;
    --info-light: #dbeafe;
    --danger: #dc2626;
    --danger-light: #fee2e2;

    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;

    --sidebar-width: 250px;
    --sidebar-collapsed: 60px;
    --top-bar-height: 60px;
    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 14px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
    --transition: all 0.2s ease;
}

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

html { font-size: 14px; scroll-behavior: smooth; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: var(--gray-800);
    background: var(--gray-50);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

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

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

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--gray-900);
    color: white;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: var(--transition);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    width: 34px;
    height: 34px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.logo-text {
    font-weight: 700;
    font-size: 17px;
    letter-spacing: -0.3px;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--gray-400);
    cursor: pointer;
    padding: 4px;
    font-size: 14px;
    display: none;
}

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

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    color: var(--gray-400);
    font-size: 14px;
    font-weight: 500;
    transition: var(--transition);
}

.nav-item:hover {
    background: rgba(255,255,255,0.06);
    color: white;
}

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

.nav-item i { width: 20px; text-align: center; font-size: 15px; }

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

.lang-switcher {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--gray-500);
    font-size: 13px;
}

.lang-btn {
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    color: var(--gray-400);
    transition: var(--transition);
}

.lang-btn:hover { background: rgba(255,255,255,0.08); color: white; }

.lang-btn.active {
    background: var(--primary);
    color: white;
}

/* Main content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: var(--transition);
}

.top-bar {
    height: var(--top-bar-height);
    background: white;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    padding: 0 28px;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.page-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--gray-900);
    flex: 1;
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    font-size: 18px;
    color: var(--gray-600);
    cursor: pointer;
}

.top-bar-actions { display: flex; gap: 8px; }

.content-area {
    padding: 24px 28px;
    max-width: 1400px;
}

/* ============================================
   Components
   ============================================ */

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11px; }

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

.btn-outline {
    background: transparent;
    border: 1px solid var(--gray-300);
    color: var(--gray-700);
}
.btn-outline:hover { background: var(--gray-100); border-color: var(--gray-400); }

.btn-ghost { background: transparent; color: var(--gray-600); }
.btn-ghost:hover { background: var(--gray-100); color: var(--gray-800); }

/* Cards */
.card {
    background: white;
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
    overflow: hidden;
    margin-bottom: 16px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--gray-100);
}

.card-header h3 {
    font-size: 15px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--gray-800);
}

.card-header h3 i { color: var(--gray-400); font-size: 14px; }

.card-body { padding: 20px; }

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: white;
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: var(--transition);
}

.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

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

.stat-info-text { display: flex; flex-direction: column; }

.stat-value {
    font-size: 28px;
    font-weight: 700;
    line-height: 1.1;
    color: var(--gray-900);
}

.stat-label {
    font-size: 13px;
    color: var(--gray-500);
    font-weight: 500;
}

/* Dashboard */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.big-stat { text-align: center; padding: 20px 0 10px; }

.big-stat-value {
    font-size: 36px;
    font-weight: 700;
    color: var(--primary);
}

.big-stat-label {
    display: block;
    font-size: 14px;
    color: var(--gray-500);
    margin-top: 4px;
}

.task-summary-row {
    display: flex;
    gap: 20px;
    justify-content: center;
    padding: 10px 0;
}

.task-summary-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--gray-600);
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}

.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-info { background: var(--info-light); color: var(--info); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-neutral { background: var(--gray-100); color: var(--gray-600); }

/* Status badges */
.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}

.status-done { background: #d1fae5; color: #065f46; }
.status-working { background: #fef3c7; color: #92400e; }
.status-requested { background: #e0e7ff; color: #3730a3; }

/* Filters */
.filters-bar {
    background: white;
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
    padding: 14px 20px;
    margin-bottom: 16px;
}

.filters-form {
    display: flex;
    align-items: flex-end;
    gap: 16px;
    flex-wrap: wrap;
}

.filter-group { display: flex; flex-direction: column; gap: 4px; }

.filter-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--gray-500);
    display: flex;
    align-items: center;
    gap: 4px;
}

.filter-group select {
    padding: 7px 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 13px;
    background: white;
    color: var(--gray-800);
    min-width: 180px;
    cursor: pointer;
}

.filter-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(109,40,217,0.1);
}

.filter-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-left: auto;
}

/* Grand total */
.grand-total-bar {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
    padding: 14px 24px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.grand-total-label { font-size: 15px; font-weight: 600; }
.grand-total-value { font-size: 24px; font-weight: 700; }

/* Client groups */
.client-group {
    background: white;
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
    margin-bottom: 12px;
    overflow: hidden;
}

.client-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
}

.client-header:hover { background: var(--gray-50); }

.client-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.group-arrow {
    color: var(--gray-400);
    font-size: 12px;
    transition: transform 0.2s;
}

.client-group.collapsed .group-arrow { transform: rotate(-90deg); }
.client-group.collapsed .client-body { display: none; }

.client-name { font-size: 15px; font-weight: 600; color: var(--gray-800); }

.client-total { font-size: 18px; font-weight: 700; color: var(--primary); }

.client-body { border-top: 1px solid var(--gray-100); }

.period-section { border-bottom: 1px solid var(--gray-50); }
.period-section:last-child { border-bottom: none; }

.period-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-100);
}

.period-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-600);
    display: flex;
    align-items: center;
    gap: 6px;
}

.period-total { font-size: 14px; font-weight: 700; color: var(--gray-700); }

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

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

.data-table th {
    text-align: left;
    padding: 10px 16px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--gray-500);
    border-bottom: 1px solid var(--gray-100);
    white-space: nowrap;
}

.data-table td {
    padding: 10px 16px;
    font-size: 13px;
    border-bottom: 1px solid var(--gray-50);
    vertical-align: middle;
}

.data-table tbody tr:hover { background: var(--gray-50); }
.data-table tbody tr:last-child td { border-bottom: none; }

.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--gray-400); }

.task-name { font-weight: 500; color: var(--gray-800); }

.client-badge {
    display: inline-flex;
    padding: 2px 8px;
    background: var(--primary-bg);
    color: var(--primary);
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

.assignee-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: var(--gray-100);
    border-radius: 20px;
    font-size: 12px;
    color: var(--gray-700);
    margin: 1px 2px;
}

.assignee-chip i { font-size: 10px; color: var(--gray-400); }

/* Cost editing */
.cost-cell { white-space: nowrap; }

.cost-display {
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: var(--transition);
    font-weight: 600;
    color: var(--gray-800);
}

.cost-display:hover { background: var(--primary-bg); color: var(--primary); }

.cost-edit {
    display: flex;
    align-items: center;
    gap: 4px;
}

.cost-input {
    width: 90px;
    padding: 4px 8px;
    border: 1px solid var(--primary);
    border-radius: 4px;
    font-size: 13px;
    text-align: right;
    outline: none;
    box-shadow: 0 0 0 3px rgba(109,40,217,0.1);
}

.cost-add-btn {
    font-size: 11px !important;
}

/* Task stats row */
.task-stats-row {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.task-stat-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: var(--radius);
    font-size: 14px;
}

.task-stat-chip.working { background: var(--warning-light); color: #92400e; }
.task-stat-chip.requested { background: var(--info-light); color: #1e40af; }
.task-stat-chip strong { font-weight: 700; }

.task-section { margin-bottom: 16px; }

/* Empty states */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--gray-400);
}

.empty-state i { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 15px; }

.empty-state-sm {
    text-align: center;
    padding: 24px;
    color: var(--gray-400);
}

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

.alert-error {
    background: var(--danger-light);
    color: var(--danger);
    border: 1px solid #fca5a5;
}

/* Toast */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--gray-900);
    color: white;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
    max-width: 360px;
}

.toast.toast-success { border-left: 3px solid var(--success); }
.toast.toast-error { border-left: 3px solid var(--danger); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Sync info */
.sync-info {
    text-align: center;
    padding: 16px;
    color: var(--gray-400);
}

.page-subtitle {
    color: var(--gray-500);
    font-size: 14px;
    margin-bottom: 16px;
}

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

    .sidebar.open { transform: translateX(0); }

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

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

    .content-area { padding: 16px; }
}

@media (max-width: 768px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .dashboard-grid { grid-template-columns: 1fr; }

    .filters-form { flex-direction: column; align-items: stretch; }
    .filter-group select { min-width: 100%; }
    .filter-actions { margin-left: 0; }

    .grand-total-bar { flex-direction: column; text-align: center; gap: 4px; }

    .client-header { flex-direction: column; align-items: flex-start; gap: 6px; }

    .task-stats-row { flex-direction: column; }

    .data-table th, .data-table td { padding: 8px 10px; font-size: 12px; }
}

@media (max-width: 480px) {
    html { font-size: 13px; }
    .stats-grid { grid-template-columns: 1fr; }
    .stat-card { padding: 14px; }
    .stat-value { font-size: 22px; }
}

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

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

/* Loading overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255,255,255,0.85);
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: var(--primary);
    font-size: 16px;
}

.loading-spinner i { font-size: 32px; }

/* Inline loading */
.loading-inline {
    text-align: center;
    padding: 40px 20px;
    color: var(--gray-400);
    font-size: 15px;
}

.loading-inline i { margin-right: 8px; }

/* Sync bar */
.sync-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    margin-top: 16px;
}

.sync-bar-left { color: var(--gray-400); }
.sync-bar-right { display: flex; gap: 8px; }

/* Monday link */
.monday-link {
    color: var(--gray-400) !important;
    font-size: 14px !important;
    padding: 4px 6px !important;
}

.monday-link:hover {
    color: var(--primary) !important;
    background: var(--primary-bg) !important;
}

/* Monday link icon */
.monday-link .monday-icon {
    display: inline-block;
    width: 14px;
    height: 14px;
    background: var(--gray-400);
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M2 7.5a2.5 2.5 0 1 1 5 0v9a2.5 2.5 0 1 1-5 0v-9zm8-1a2.5 2.5 0 1 1 5 0v9a2.5 2.5 0 1 1-5 0v-9zm10.5 9a2.5 2.5 0 1 1-5 0V7.5a2.5 2.5 0 1 1 5 0v8z'/%3E%3C/svg%3E") center/contain no-repeat;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M2 7.5a2.5 2.5 0 1 1 5 0v9a2.5 2.5 0 1 1-5 0v-9zm8-1a2.5 2.5 0 1 1 5 0v9a2.5 2.5 0 1 1-5 0v-9zm10.5 9a2.5 2.5 0 1 1-5 0V7.5a2.5 2.5 0 1 1 5 0v8z'/%3E%3C/svg%3E") center/contain no-repeat;
    vertical-align: middle;
}

.monday-link:hover .monday-icon { background: var(--primary); }
