/* Modern Dashboard CSS */
:root {
    --primary-color: #2563eb;
    --primary-dark: #1e40af;
    --secondary-color: #10b981;
    --danger-color: #ef4444;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-tertiary: #f3f4f6;
    --border-color: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius: 0.5rem;
}

/* Dark mode */
[data-theme="dark"] {
    --text-primary: #f9fafb;
    --text-secondary: #d1d5db;
    --bg-primary: #1f2937;
    --bg-secondary: #111827;
    --bg-tertiary: #374151;
    --border-color: #4b5563;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.4), 0 2px 4px -2px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4), 0 4px 6px -4px rgb(0 0 0 / 0.3);
}

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

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

/* Navigation */
.navbar {
    background-color: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    position: relative;
}

.nav-brand h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary-color);
    white-space: nowrap;
}

.nav-links {
    display: flex;
    gap: 1.5rem;
    align-items: center;
    flex-wrap: wrap;
}

/* Mobile menu toggle button */
.mobile-menu-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    z-index: 101;
    flex-direction: column;
    justify-content: space-around;
    width: 2rem;
    height: 2rem;
}

.hamburger-icon {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    width: 100%;
    height: 100%;
}

.hamburger-icon span {
    width: 100%;
    height: 3px;
    background-color: var(--text-primary);
    border-radius: 2px;
    transition: all 0.3s ease;
    transform-origin: center;
}

.mobile-menu-toggle.active .hamburger-icon span:nth-child(1) {
    transform: rotate(45deg) translate(8px, 8px);
}

.mobile-menu-toggle.active .hamburger-icon span:nth-child(2) {
    opacity: 0;
}

.mobile-menu-toggle.active .hamburger-icon span:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -7px);
}

.theme-toggle {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}

.theme-toggle:hover {
    background-color: var(--bg-tertiary);
}

.nav-link {
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 500;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    transition: all 0.2s;
    white-space: nowrap;
}

.nav-link:hover {
    background-color: var(--bg-tertiary);
}

.logout-form {
    margin: 0;
}

.coordinate-selector {
    display: flex;
    align-items: center;
}

.coordinate-form {
    margin: 0;
}

.coordinate-select {
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 150px;
}

.coordinate-select:hover {
    background-color: var(--bg-tertiary);
    border-color: var(--primary-color);
}

.coordinate-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.logout-btn {
    background: none;
    border: none;
    cursor: pointer;
}

.main-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

/* Dashboard Header */
.dashboard-header {
    margin-bottom: 2rem;
}

.dashboard-header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* Controls */
.controls {
    display: flex;
    gap: 2rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    align-items: flex-end;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.control-group label {
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.control-select {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.control-select:hover {
    border-color: var(--primary-color);
}

.control-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.date-filter-form {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

.date-filter-form input[type="date"] {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-size: 1rem;
}

.date-filter-form input[type="date"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* KPI Grid */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.kpi-card {
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s;
}

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

.kpi-card h3 {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.kpi-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
}

.kpi-unit {
    font-size: 1rem;
    font-weight: 400;
    color: var(--text-secondary);
}

/* Latest Activities */
.latest-activities {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.latest-card {
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.latest-card h3 {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.latest-value {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.days-ago {
    font-size: 0.875rem;
    font-weight: 400;
    color: var(--text-secondary);
}

/* Charts Grid */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 2rem;
    margin-bottom: 2rem;
}

.chart-card {
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.chart-card h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.chart-container {
    height: 300px;
    position: relative;
}

.chart-container-large {
    height: 400px;
    position: relative;
}

/* Data Table */
.data-table-container {
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    overflow-x: auto;
}

.data-table-container h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

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

.data-table thead {
    background-color: var(--bg-tertiary);
}

.data-table th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border-color);
}

.data-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.data-table tbody tr:hover {
    background-color: var(--bg-tertiary);
}

.data-table tfoot {
    background-color: var(--bg-tertiary);
    font-weight: 600;
}

.data-table tfoot td {
    color: var(--text-primary);
    border-top: 2px solid var(--border-color);
}

/* Login Styles */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 80vh;
    padding: 2rem;
}

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

.login-card h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    text-align: center;
}

.login-card h2 {
    font-size: 1.25rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 2rem;
    text-align: center;
}

.form-group {
    margin-bottom: 1.5rem;
}

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

.form-input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-size: 1rem;
    transition: all 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

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

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

.btn-block {
    width: 100%;
}

.alert {
    padding: 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
}

.alert-danger {
    background-color: #fee2e2;
    color: var(--danger-color);
    border: 1px solid #fecaca;
}

.alert-success {
    background-color: #d1fae5;
    color: var(--secondary-color);
    border: 1px solid #a7f3d0;
}

/* Responsive Design */
@media (max-width: 768px) {
    .main-content {
        padding: 1rem;
    }

    .nav-container {
        padding: 1rem;
    }

    .nav-brand h1 {
        font-size: 1.25rem;
    }

    /* Mobile menu toggle */
    .mobile-menu-toggle {
        display: flex;
    }

    .nav-links {
        position: fixed;
        top: 0;
        right: -100%;
        height: 100vh;
        width: 80%;
        max-width: 300px;
        background-color: var(--bg-primary);
        border-left: 1px solid var(--border-color);
        box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
        flex-direction: column;
        align-items: stretch;
        padding: 4rem 1.5rem 2rem;
        gap: 0;
        transition: right 0.3s ease;
        z-index: 100;
        overflow-y: auto;
    }

    .nav-links.active {
        right: 0;
    }

    .nav-links .nav-link,
    .nav-links .theme-toggle,
    .nav-links .coordinate-selector {
        width: 100%;
        padding: 1rem;
        border-bottom: 1px solid var(--border-color);
        border-radius: 0;
        text-align: left;
        margin: 0;
    }

    .nav-links .coordinate-selector .coordinate-form {
        width: 100%;
    }

    .nav-links .coordinate-select {
        width: 100%;
    }

    .nav-links .theme-toggle {
        margin-top: 1rem;
        border-top: 1px solid var(--border-color);
        border-bottom: 1px solid var(--border-color);
    }

    .nav-links .logout-form {
        width: 100%;
        margin-top: 1rem;
    }

    .nav-links .logout-btn {
        width: 100%;
        text-align: left;
        padding: 1rem;
        border-bottom: 1px solid var(--border-color);
        border-radius: 0;
    }

    /* Overlay when menu is open */
    .nav-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 99;
    }

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

    #themeText {
        display: inline;
    }

    .dashboard-header h1 {
        font-size: 1.5rem;
    }

    .controls {
        flex-direction: column;
        gap: 1rem;
    }

    .date-filter-form {
        flex-direction: column;
        align-items: stretch;
    }

    .kpi-grid {
        grid-template-columns: 1fr;
    }

    .latest-activities {
        grid-template-columns: 1fr;
    }

    .charts-grid {
        grid-template-columns: 1fr;
    }

    .chart-container,
    .chart-container-large {
        height: 250px;
    }

    .data-table {
        font-size: 0.75rem;
    }

    .data-table th,
    .data-table td {
        padding: 0.5rem;
    }
}

@media (max-width: 480px) {
    .nav-container {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }

    .nav-links {
        width: 85%;
        max-width: 280px;
    }
}

/* Form Styles */
.form-container {
    background: var(--bg-primary);
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    max-width: 600px;
    margin: 0 auto;
}

.modern-form {
    width: 100%;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.checkbox-item {
    display: flex;
    align-items: stretch;
}

.checkbox-label-large {
    display: flex;
    width: 100%;
    cursor: pointer;
    padding: 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    background-color: var(--bg-primary);
    transition: all 0.2s;
    position: relative;
}

.checkbox-label-large:hover {
    border-color: var(--primary-color);
    background-color: var(--bg-tertiary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.checkbox-label-large input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.checkbox-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
}

.checkbox-icon {
    font-size: 2rem;
    line-height: 1;
}

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

.checkbox-label-large input[type="checkbox"]:checked + .checkbox-content {
    color: var(--primary-color);
}

.checkbox-label-large input[type="checkbox"]:checked + .checkbox-content .checkbox-text {
    color: var(--primary-color);
}

.checkbox-label-large:has(input[type="checkbox"]:checked),
.checkbox-label-large.checkbox-checked {
    border-color: var(--primary-color);
    background-color: rgba(37, 99, 235, 0.1);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.checkbox-label-large:has(input[type="checkbox"]:checked) .checkbox-text,
.checkbox-label-large.checkbox-checked .checkbox-text {
    color: var(--primary-color);
}

.checkbox-group {
    display: flex;
    align-items: center;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-primary);
}

.checkbox-label input[type="checkbox"] {
    width: 1.25rem;
    height: 1.25rem;
    cursor: pointer;
    accent-color: var(--primary-color);
}

.form-actions {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
}

.btn-secondary {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background-color: var(--border-color);
}

.alert-info {
    background-color: #eff6ff;
    color: var(--primary-color);
    border: 1px solid #bfdbfe;
}

[data-theme="dark"] .alert-danger {
    background-color: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.3);
}

[data-theme="dark"] .alert-info {
    background-color: rgba(37, 99, 235, 0.1);
    border-color: rgba(37, 99, 235, 0.3);
}

.text-danger {
    color: var(--danger-color);
    font-size: 0.875rem;
    margin-top: 0.25rem;
    display: block;
}

/* Hover-based delete buttons - make them work on touch devices */
.data-table tbody tr {
    position: relative;
}

/* Delete button that appears on hover - general support for any hidden button */
.data-table tbody tr .delete-btn,
.data-table tbody tr .btn-delete,
.data-table tbody tr .remove-btn,
.data-table tbody tr [class*="delete"],
.data-table tbody tr [class*="remove"],
.data-table tbody tr button[style*="opacity: 0"],
.data-table tbody tr button[style*="display: none"],
.data-table tbody tr a[style*="opacity: 0"],
.data-table tbody tr a[style*="display: none"] {
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
}

.data-table tbody tr:hover .delete-btn,
.data-table tbody tr:hover .btn-delete,
.data-table tbody tr:hover .remove-btn,
.data-table tbody tr:hover [class*="delete"],
.data-table tbody tr:hover [class*="remove"],
.data-table tbody tr:hover button[style*="opacity: 0"],
.data-table tbody tr:hover button[style*="display: none"],
.data-table tbody tr:hover a[style*="opacity: 0"],
.data-table tbody tr:hover a[style*="display: none"] {
    opacity: 1;
    pointer-events: auto;
}

/* On touch devices, make delete buttons always visible or show on tap */
@media (hover: none) and (pointer: coarse) {
    .data-table tbody tr .delete-btn,
    .data-table tbody tr .btn-delete,
    .data-table tbody tr .remove-btn,
    .data-table tbody tr [class*="delete"],
    .data-table tbody tr [class*="remove"],
    .data-table tbody tr button[style*="opacity: 0"],
    .data-table tbody tr button[style*="display: none"],
    .data-table tbody tr a[style*="opacity: 0"],
    .data-table tbody tr a[style*="display: none"] {
        opacity: 1 !important;
        display: inline-block !important;
        pointer-events: auto;
    }
}

/* Alternative: Show delete buttons when row is touched/focused */
.data-table tbody tr.touch-active .delete-btn,
.data-table tbody tr.touch-active .btn-delete,
.data-table tbody tr.touch-active .remove-btn,
.data-table tbody tr.touch-active [class*="delete"],
.data-table tbody tr.touch-active [class*="remove"],
.data-table tbody tr.touch-active button[style*="opacity: 0"],
.data-table tbody tr.touch-active button[style*="display: none"],
.data-table tbody tr.touch-active a[style*="opacity: 0"],
.data-table tbody tr.touch-active a[style*="display: none"],
.data-table tbody tr:focus-within .delete-btn,
.data-table tbody tr:focus-within .btn-delete,
.data-table tbody tr:focus-within .remove-btn,
.data-table tbody tr:focus-within [class*="delete"],
.data-table tbody tr:focus-within [class*="remove"],
.data-table tbody tr:focus-within button[style*="opacity: 0"],
.data-table tbody tr:focus-within button[style*="display: none"],
.data-table tbody tr:focus-within a[style*="opacity: 0"],
.data-table tbody tr:focus-within a[style*="display: none"] {
    opacity: 1 !important;
    display: inline-block !important;
    pointer-events: auto;
}
