/* Google Fonts Import */
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap');

:root {
    /* --- COLOR PALETTE: Green Fiber --- */
    --primary-50: #f0fdf4;
    --primary-100: #dcfce7;
    --primary-200: #bbf7d0;
    --primary-300: #86efac;
    --primary-400: #4ade80;
    --primary-500: #22c55e;
    --primary-600: #16a34a; /* Brand Color */
    --primary-700: #15803d;
    --primary-800: #166534;
    --primary-900: #14532d;

    --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;

    --danger-500: #ef4444;
    --danger-600: #dc2626;
    --warning-500: #f59e0b;
    
    /* --- SEMANTIC --- */
    --bg-body: var(--gray-50);
    --bg-card: #ffffff;
    --text-main: var(--gray-900);
    --text-muted: var(--gray-500);
    --border-color: var(--gray-200);

    /* --- SHADOWS & RADIUS --- */
    --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    
    --radius-md: 0.5rem;   /* 8px */
    --radius-lg: 0.75rem;  /* 12px */
    --radius-xl: 1rem;     /* 16px */
}

/* --- RESET & BASE --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Roboto', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; color: inherit; }
ul { list-style: none; }

/* --- TYPOGRAPHY --- */
h1, h2, h3, h4 {
    font-weight: 700;
    color: var(--gray-900);
    letter-spacing: -0.025em;
}

/* --- LAYOUT UTILITIES --- */
.container-centered {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1.5rem;
    background: radial-gradient(circle at top left, var(--primary-50), transparent 40%);
}

.dashboard-wrapper {
    max-width: 1600px;
    margin: 0 auto;
    padding: 2rem;
}

/* --- COMPONENTS: CARD & CONTAINERS --- */
.card, .user-list, .user-details {
    background: #fff;
    border-radius: var(--radius-xl); /* Increased radius for modern look */
    /* Professional shadow, static and clean */
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03); 
    border: 1px solid var(--gray-200); /* Clean border */
    /* Removed thick top border for cleaner look */
    padding: 3rem; /* More breathing room */
    position: relative;
    overflow: hidden;
}

.card {
    width: 100%;
    max-width: 440px;
    text-align: center;
     /* Removed hover transition for static professional look */
    margin: 0 auto; 
}
/* Removed .card:hover transform */
.card h2 { margin-bottom: 1.5rem; font-size: 1.5rem; }

/* Specific adjustments for dashboard containers */
.chart-container { padding: 1.5rem; margin-bottom: 1.5rem; }
.user-details { min-height: 300px; padding: 2rem; }

/* User List specific overrides */
.user-list {
    padding: 0; /* List needs 0 padding for clean items */
    max-height: calc(100vh - 150px);
    overflow-y: auto;
    border-top: 5px solid var(--primary-600); /* Re-ensure border top */
}
/* Restore title padding inside list since container padding is 0 */
.user-list h3 {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--gray-100);
    margin: 0;
    background: #fff;
}
input, select, textarea {
    display: block;
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    background-color: #fff;
    margin-bottom: 1rem;
    transition: all 0.2s;
    outline: none;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px var(--primary-100);
}

button {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    gap: 0.5rem;
}

button:active { transform: scale(0.98); }

/* Buttons Variants */
button[name="login"], button[name="crea"], button.start, button[type="submit"] {
    background-color: var(--primary-600);
    color: #fff;
}
button[name="login"]:hover, button[name="crea"]:hover, button.start:hover, button[type="submit"]:hover {
    background-color: var(--primary-700);
    box-shadow: 0 4px 12px rgba(22, 163, 74, 0.3);
    transform: translateY(-2px);
}

button.stop {
    background-color: var(--danger-600);
    color: #fff;
}
button.stop:hover {
    background-color: #b91c1c;
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3);
}

/* --- TOPBAR --- */
.topbar {
    height: 70px;
    background: linear-gradient(135deg, var(--primary-600), var(--primary-800));
    color: #fff;
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-md);
}

.topbar .title {
    font-size: 1.25rem;
    font-weight: 800;
    color: #fff; /* White title */
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.topbar .user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.9); /* Lighter white for text */
}

.topbar a.logout-btn {
    color: #fff;
    background: rgba(255, 255, 255, 0.2);
    padding: 0.4rem 0.8rem;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 600;
    border: 1px solid rgba(255, 255, 255, 0.3);
    transition: all 0.2s;
}
.topbar a.logout-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.5);
}

.topbar a.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 50%; /* Circle */
    border: 1px solid rgba(255, 255, 255, 0.3);
    transition: all 0.2s;
}
.topbar a.action-btn:hover {
    background: #fff;
    color: var(--primary-600);
    transform: scale(1.1);
}

/* --- DASHBOARD COMPONENTS --- */
.dashboard-header {
    background: #fff;
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-lg), 0 0 0 1px rgba(0,0,0,0.03); /* Deeper shadow + subtle border ring */
    margin-bottom: 2rem;
    border-top: 5px solid var(--primary-600); /* Accentuation */
    position: relative;
    overflow: hidden;
}

/* Optional: Background decoration */
.dashboard-header::before {
    content: '';
    position: absolute;
    top: 0; right: 0;
    width: 200px; height: 100%;
    background: linear-gradient(to left, var(--primary-50), transparent);
    opacity: 0.5;
    pointer-events: none;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.header-top h2 {
    font-size: 1.75rem;
    color: var(--gray-900);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 800;
    letter-spacing: -0.03em;
}
.header-top h2 .icon-dashboard { font-size: 1.5rem; background: var(--primary-100); padding: 8px; border-radius: 8px; }

.search-box input {
    margin-bottom: 0;
    width: 280px;
    background: var(--gray-50);
    border-color: var(--gray-200);
    padding: 0.6rem 1rem;
    border-radius: 50px; /* Pill shape for search */
    transition: all 0.2s;
}
.search-box input:focus {
    background: #fff;
    width: 320px; /* Expand on focus */
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    border-color: var(--primary-400);
}

.filters {
    display: flex;
    gap: 1.5rem;
    align-items: center;
    padding-top: 1.5rem;
    border-top: 1px solid var(--gray-100);
}

.filters label {
    font-size: 0.7rem;
    color: var(--gray-500);
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.05em;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.filters select {
    margin-bottom: 0;
    padding: 0.5rem 2rem 0.5rem 0.8rem;
    min-width: 140px;
    background-color: var(--gray-50);
    border-color: var(--gray-200);
    font-weight: 600;
    color: var(--gray-700);
    cursor: pointer;
}
.filters select:hover { background-color: var(--gray-100); border-color: var(--gray-300); }

/* Dashboard Grid */
.dashboard-layout {
    display: grid;
    grid-template-columns: 350px 1fr; /* Slightly wider user list */
    gap: 2rem;
    align-items: start;
}

/* User List Setup - Visuals inherited */
.user-list {
    /* background, border-radius, box-shadow handled by grouped rule */
    /* border: none; -> border handled by grouped rule */
    overflow: hidden;
    max-height: calc(100vh - 150px);
    overflow-y: auto;
}

.user-list h3 {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--gray-100);
    background: #fff;
    font-size: 0.95rem;
    color: var(--gray-800);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.user-item {
    padding: 1.2rem 1.5rem; /* Larger touch area */
    border-bottom: 1px solid var(--gray-50);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.user-item:hover {
    background-color: var(--gray-50);
}

.user-item.active {
    background-color: var(--primary-50);
    border-left: 3px solid var(--primary-600);
    padding-left: calc(1.5rem - 3px); /* Compensate border */
}

.user-info-row {
    display: flex;
    align-items: center;
}

/* Status Indicators */
.status-dot {
    height: 10px;
    width: 10px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 0.75rem;
}
.status-dot.online { background-color: var(--primary-500); box-shadow: 0 0 0 2px var(--primary-100); }
.status-dot.offline { background-color: var(--gray-300); }

/* Avatar and Badges */
.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: var(--primary-100);
    color: var(--primary-700);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    margin-right: 0.75rem;
    flex-shrink: 0;
}

.badge {
    padding: 0.25rem 0.6rem;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
.badge.success { background: var(--primary-100); color: var(--primary-700); }
.badge.warning { background: #fef9c3; color: #a16207; }
.badge.danger { background: #fee2e2; color: #b91c1c; }
.badge.neutral { background: var(--gray-100); color: var(--gray-600); }

.badge-working {
    /* Legacy override, map to badge success style eventually or keep distinct */
    font-size: 0.7rem;
    background: var(--primary-100);
    color: var(--primary-700);
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 600;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 4px;
}
.badge-working::before {
    content: '';
    display: inline-block;
    width: 6px; height: 6px;
    background: currentColor;
    border-radius: 50%;
}

/* Embedded Chart in Header */
.header-chart-wrapper {
    margin-top: 2rem; /* Spacing from filters */
    width: 100%;
    border-top: 1px solid var(--gray-100); 
    padding-top: 1.5rem;
}

/* Charts Container - Styles inherited from grouped rule above */
.chart-container {
    margin-bottom: 1.5rem;
}

/* User Details Area - Styles inherited */
.user-details {
    /* min-height set in grouped rule or here */
    min-height: 300px;
}

#placeholder-text {
    text-align: center;
    color: var(--gray-400);
    margin-top: 4rem;
    font-size: 1.1rem;
}

.user-block h3 {
    font-size: 1.75rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--gray-100);
    padding-bottom: 1rem;
}

/* Stats Cards inside User Details */
.user-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--gray-50);
    padding: 1.5rem;
    border-radius: var(--radius-md);
    text-align: center;
    border: 1px solid var(--gray-200);
}

.stat-card strong {
    display: block;
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--gray-500);
    margin-bottom: 0.5rem;
    letter-spacing: 0.05em;
}

/* Tables */
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin-top: 1rem;
}

thead {
    background: linear-gradient(135deg, var(--primary-600), var(--primary-800)); /* Continuous Gradient */
}

th {
    text-align: left;
    padding: 1rem;
    background: transparent; /* Transparent to show thead gradient */
    color: #fff;
    text-transform: uppercase;
    font-size: 0.75rem;
    font-weight: 700;
    /* border-bottom removed for seamless look */
}
th:first-child { border-top-left-radius: var(--radius-md); }
th:last-child { border-top-right-radius: var(--radius-md); }

td {
    padding: 1rem;
    border-bottom: 1px solid var(--gray-100);
    color: var(--gray-700);
    font-size: 0.9rem;
}

tr:last-child td { border-bottom: none; }

tr:hover td {
    background-color: var(--gray-50);
}

.clessidra { animation: spin 2s linear infinite; display: inline-block; }
@keyframes spin { 100% { transform: rotate(360deg); } }

/* Login/Error Messages */
.msg {
    padding: 0.75rem;
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
    font-size: 0.9rem;
    font-weight: 500;
    text-align: center;
}
.msg.error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.msg.success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }

/* --- UTILITIES & TYPOGRAPHY --- */
.card-title {
    color: var(--primary-600);
    margin-bottom: 0.5rem;
    font-size: 2rem;
    letter-spacing: -0.03em;
}

.card-subtitle {
    color: var(--gray-500);
    font-size: 0.95rem;
    margin-bottom: 2rem;
}

.form-group {
    text-align: left;
    margin-bottom: 1.25rem;
}

.form-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 0.5rem;
    display: block;
}

.form-input {
    margin-bottom: 0; /* Override default */
    border-color: var(--gray-300);
    padding: 0.85rem 1rem;
    font-size: 1rem;
}
.form-input:focus {
    border-color: var(--primary-500);
    box-shadow: 0 0 0 4px var(--primary-50);
}

/* --- UTILITIES --- */
.text-danger { color: var(--color-danger) !important; }
.text-danger:hover { color: #b91c1c !important; }

.icon-btn {
    text-decoration: none;
    font-size: 1.1rem;
    padding: 4px;
    border-radius: 4px;
    transition: background 0.2s;
    margin: 0 2px;
}
.icon-btn:hover { background: var(--gray-200); }

/* --- RESPONSIVE --- */
@media (max-width: 1024px) {
    .dashboard-layout { 
        grid-template-columns: 1fr; /* Stack vertically */
    }
    
    .user-list { 
        width: 100%; 
        max-height: 250px; /* Shorter list on tablet/mobile to see details below */
        margin-bottom: 2rem;
    }
}

@media (max-width: 768px) {
    /* Login & User Card Mobile Optimization */
    .container-centered {
        padding: 1rem;
        align-items: flex-start; /* Avoid cut-off on small landscape screens */
        padding-top: 2rem;
        background: var(--bg-body); /* Simplify background on mobile */
    }

    .card {
        padding: 1.5rem;
        box-shadow: var(--shadow-md); /* Softer shadow for mobile */
        border-radius: var(--radius-lg);
    }

    .card h2 { font-size: 1.35rem; }
    
    /* Topbar adjustments */
    .topbar {
        padding: 0 1rem;
        height: auto;
        min-height: 60px;
        flex-wrap: wrap;
        gap: 0.5rem;
        justify-content: center; /* Center content if wraps */
    }
    
    .topbar .title { font-size: 1.1rem; width: 100%; justify-content: center; margin-bottom: 0.5rem; }
    .topbar .user-info { width: 100%; justify-content: center; padding-bottom: 0.5rem; }

    /* Dashboard adjustments */
    .dashboard-wrapper { padding: 1rem; }
    
    .dashboard-header {
        padding: 1.5rem;
        text-align: center;
    }
    
    .header-top { 
        flex-direction: column; 
        align-items: stretch;
        gap: 1rem; 
    }
    
    .header-main-row {
        flex-direction: column-reverse; /* Chart on top or bottom? Let's check. Column reverse filters bottom. */
        flex-direction: column;
        align-items: stretch;
        gap: 1.5rem;
    }

    .header-chart {
        max-width: 100%;
        height: 150px; /* Taller on mobile for visibility */
    }
    
    .header-top h2 { justify-content: center; }
    
    .search-box input { width: 100%; }
    .search-box input:focus { width: 100%; }

    .filters { 
        flex-direction: column; 
        width: 100%; 
        align-items: stretch; 
        gap: 1rem;
    }
    
    .filters label { flex-direction: row; justify-content: space-between; align-items: center; }
    .filters select { flex: 1; margin-left: 1rem; }

    /* Stats Grid */
    .user-stats {
        grid-template-columns: 1fr; /* Stack stats */
        gap: 1rem;
    }
    
    /* Table scroll */
    table { display: block; overflow-x: auto; white-space: nowrap; }
}