/* === wMBus Frontend — Design System === */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --bg: #f5f7fa;
    --bg-card: #ffffff;
    --bg-hover: #f0f4ff;
    --text: #1e293b;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    --border: #e2e8f0;
    --accent: #06245c;
    --accent-light: #dbeafe;
    --accent-dark: #03153a;
    --success: #22c55e;
    --success-light: #dcfce7;
    --warn: #f59e0b;
    --warn-light: #fef3c7;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.05), 0 2px 4px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.08);
    --transition: 0.2s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* === LAYOUT === */

.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.navbar {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 20px;
    font-weight: 700;
    font-size: 30px;
    color: rgb(7, 14, 75);
    cursor: pointer;
    overflow: hidden;
}

.navbar-brand img {
    height: 36px;
    max-height: 36px;
    width: auto;
    display: block;
}

.navbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.navbar-user {
    font-size: 14px;
    color: var(--text-muted);
}

.main-content {
    flex: 1;
    padding: 24px;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
}

/* === BUTTONS === */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-hover);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
}

.btn-ghost:hover {
    color: var(--text);
    background: var(--bg);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

/* === LOGIN === */

.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #f0f4ff 0%, #e8f0fe 50%, #f5f7fa 100%);
}

.login-card {
    background: var(--bg-card);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    padding: 48px 40px;
    width: 100%;
    max-width: 420px;
    text-align: center;
}

.login-logo {
    margin-bottom: 16px;
}

.login-logo img {
    height: auto;
    width: 200px;
}

.login-title {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 4px;
    color: var(--text);
}

.login-subtitle {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 32px;
}

.form-group {
    margin-bottom: 16px;
    text-align: left;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 15px;
    transition: border-color var(--transition);
    outline: none;
}

.form-group input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.login-btn {
    width: 100%;
    padding: 12px;
    margin-top: 8px;
    font-size: 15px;
    font-weight: 600;
}

.login-error {
    background: var(--danger-light);
    color: var(--danger);
    padding: 10px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-top: 12px;
    display: none;
}

/* === DASHBOARD === */

.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px 24px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 16px;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
}

.stat-icon.blue {
    background: var(--accent-light);
}

.stat-icon.green {
    background: var(--success-light);
}

.stat-icon.orange {
    background: var(--warn-light);
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
}

.stat-label {
    font-size: 13px;
    color: var(--text-muted);
}

/* Pie chart */
.chart-section {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 24px;
    margin-bottom: 32px;
}

.chart-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.chart-card h3 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text);
}

.chart-canvas-wrap {
    width: 200px;
    height: 200px;
}

/* Route tiles */
.section-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text);
}

.routes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.route-tile {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px 24px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: all var(--transition);
    border: 2px solid transparent;
}

.route-tile:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.route-tile-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.route-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

.route-name-input {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    border: 1px solid var(--accent);
    border-radius: 4px;
    padding: 2px 6px;
    font-family: inherit;
    outline: none;
    width: 180px;
}

.route-badge {
    font-size: 12px;
    padding: 3px 10px;
    border-radius: 20px;
    font-weight: 600;
}

.route-badge.complete {
    background: var(--success-light);
    color: #15803d;
}

.route-badge.partial {
    background: var(--accent-light);
    color: var(--accent-dark);
}

.route-badge.empty {
    background: var(--bg);
    color: var(--text-muted);
}

.route-stats {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.route-progress-bar {
    height: 8px;
    background: var(--bg);
    border-radius: 4px;
    overflow: hidden;
}

.route-progress-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;
    background: linear-gradient(90deg, var(--accent) 0%, var(--success) 100%);
}

.route-last-reading {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 8px;
}

/* === READINGS TABLE === */

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.page-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.search-input {
    padding: 8px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    width: 260px;
    outline: none;
    transition: border-color var(--transition);
}

.search-input:focus {
    border-color: var(--accent);
}

.table-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.table-scroll {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    white-space: nowrap;
}

.data-table thead th {
    background: var(--bg);
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--border);
    cursor: pointer;
    user-select: none;
    position: sticky;
    top: 0;
}

.data-table thead th:hover {
    color: var(--accent-dark);
}

.data-table thead th .sort-icon {
    display: inline-block;
    margin-left: 4px;
    opacity: 0.3;
    font-size: 10px;
}

.data-table thead th.sorted .sort-icon {
    opacity: 1;
    color: var(--accent);
}

.data-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background var(--transition);
}

.data-table tbody tr:hover {
    background: var(--bg-hover);
}

.data-table tbody tr.row-read {}

.data-table tbody tr.row-unread {
    background: var(--warn-light);
}

.data-table tbody td {
    padding: 10px 14px;
    color: var(--text);
}

.data-table tbody td.no-data {
    color: var(--text-light);
    font-style: italic;
}

.table-footer {
    display: flex;
    justify-content: space-between;
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-muted);
}

/* === BREADCRUMB === */

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.breadcrumb a {
    color: var(--accent);
    text-decoration: none;
    cursor: pointer;
}

.breadcrumb a:hover {
    text-decoration: underline;
}

.breadcrumb .sep {
    color: var(--text-light);
}

/* === LOADING === */

.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 60px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* === EDIT NAME ICON === */

.edit-icon {
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--transition);
    font-size: 14px;
    color: var(--text-light);
    margin-left: 6px;
}

.route-tile:hover .edit-icon {
    opacity: 1;
}

.edit-icon:hover {
    color: var(--accent);
}

/* === MODAL === */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 200;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.modal-overlay.visible {
    opacity: 1;
}

.modal-card {
    background: var(--bg-card);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    padding: 32px;
    width: 100%;
    max-width: 640px;
    max-height: 85vh;
    overflow-y: auto;
    transform: translateY(20px);
    transition: transform 0.2s ease;
}

.modal-overlay.visible .modal-card {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px 8px;
    border-radius: 6px;
    transition: all var(--transition);
}

.modal-close:hover {
    background: var(--bg);
    color: var(--text);
}

/* === DROPZONE === */

.dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    background: var(--bg);
}

.dropzone:hover,
.dropzone.drag-over {
    border-color: var(--accent);
    background: var(--accent-light);
}

.dropzone-icon {
    font-size: 36px;
    margin-bottom: 8px;
}

.dropzone-text {
    font-size: 14px;
    color: var(--text-muted);
}

.dropzone-text strong {
    color: var(--accent);
}

.dropzone-file {
    margin-top: 12px;
    font-size: 13px;
    color: var(--success);
    font-weight: 500;
}

/* === PREVIEW TABLE === */

.preview-section {
    margin-top: 20px;
}

.preview-section h4 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-muted);
}

.preview-table-wrap {
    max-height: 200px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.preview-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    white-space: nowrap;
}

.preview-table th {
    background: var(--bg);
    padding: 6px 10px;
    text-align: left;
    font-weight: 600;
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    position: sticky;
    top: 0;
    border-bottom: 1px solid var(--border);
}

.preview-table td {
    padding: 5px 10px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}

/* === IMPORT RESULT === */

.import-result {
    margin-top: 20px;
    padding: 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
}

.import-result.success {
    background: var(--success-light);
    color: #15803d;
}

.import-result.has-errors {
    background: var(--warn-light);
    color: #92400e;
}

.import-result-stats {
    display: flex;
    gap: 20px;
    font-weight: 600;
    margin-bottom: 8px;
}

.import-errors {
    font-size: 12px;
    margin-top: 8px;
    max-height: 100px;
    overflow-y: auto;
}

.import-errors div {
    padding: 2px 0;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
}

/* === RESPONSIVE === */

@media (max-width: 768px) {
    .chart-section {
        grid-template-columns: 1fr;
    }

    .search-input {
        width: 100%;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .main-content {
        padding: 16px;
    }

    .modal-card {
        margin: 16px;
        max-width: calc(100% - 32px);
    }
}