:root {
    --bg: #f5f7fa;
    --card: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #10b981;
    --danger: #ef4444;
    --border: #e5e7eb;
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

header {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 1rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

header h1 {
    margin: 0;
    font-size: 1.25rem;
}

header nav {
    display: flex;
    gap: 1rem;
    align-items: center;
}

header nav a {
    font-weight: 500;
}

header form {
    margin: 0;
}

main {
    max-width: 960px;
    margin: 2rem auto;
    padding: 0 1rem;
}

h2 {
    margin-top: 0;
}

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

a:hover {
    text-decoration: underline;
}

button, .button {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.95rem;
}

button:hover, .button:hover {
    background: var(--primary-hover);
}

button.link {
    background: none;
    color: var(--primary);
    padding: 0;
}

button.link:hover {
    text-decoration: underline;
}

.status {
    display: inline-block;
    width: 0.75rem;
    height: 0.75rem;
    border-radius: 50%;
    margin-right: 0.5rem;
}

.status.online {
    background: var(--success);
}

.status.offline {
    background: var(--danger);
}

.device-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
}

.card h3 {
    margin: 0 0 0.5rem;
    font-size: 1.1rem;
}

.card p {
    margin: 0.25rem 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

th, td {
    text-align: left;
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
}

th {
    font-weight: 600;
    background: #f9fafb;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.metric {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
}

.metric .label {
    font-size: 0.85rem;
    color: var(--muted);
    margin: 0;
}

.metric .value {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0.25rem 0 0;
}

.empty {
    color: var(--muted);
    font-style: italic;
}

input, select {
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    margin-top: 0.25rem;
}

label {
    font-weight: 500;
    font-size: 0.9rem;
}

tr.canceled td {
    color: var(--muted);
    text-decoration: line-through;
}

.actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}

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

.alert.success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.alert.error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.map-page {
    max-width: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 73px);
}

.map-header {
    padding: 1rem 1.5rem;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.map-header h2 {
    margin: 0.5rem 0 0;
}

.map-header p {
    margin: 0;
}

.map-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

.map-sidebar {
    width: 320px;
    flex-shrink: 0;
    background: var(--card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 1000;
}

.map-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1rem 0.75rem;
    border-bottom: 1px solid var(--border);
}

.map-sidebar-header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.map-sidebar-close {
    display: none;
    background: none;
    color: var(--text);
    font-size: 1.5rem;
    line-height: 1;
    padding: 0;
    width: 2rem;
    height: 2rem;
}

.map-sidebar-close:hover {
    background: var(--bg);
}

.map-search-wrapper {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}

.map-search {
    width: 100%;
    margin: 0;
}

.map-device-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0;
}

.map-device-item {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.map-device-item:hover {
    background: #f9fafb;
}

.map-device-item.active {
    background: #eff6ff;
    border-left: 4px solid var(--primary);
    padding-left: calc(1rem - 4px);
}

.map-device-item.offline {
    opacity: 0.7;
}

.map-device-item.no-location {
    cursor: not-allowed;
    background: #f9fafb;
}

.map-device-title {
    display: flex;
    align-items: center;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.map-device-serial {
    font-size: 0.85rem;
    color: var(--muted);
    margin-bottom: 0.25rem;
}

.map-device-location {
    font-size: 0.8rem;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.map-empty {
    padding: 1rem;
    color: var(--muted);
    font-style: italic;
    text-align: center;
}

.map-sidebar-toggle {
    display: none;
    position: absolute;
    top: 1rem;
    left: 1rem;
    z-index: 900;
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
}

.map-sidebar-toggle:hover {
    background: var(--bg);
}

.map-container {
    flex: 1;
    position: relative;
    min-width: 0;
    padding: 0.5rem;
    background: var(--bg);
}

#map {
    width: 100%;
    height: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
}

.map-marker .marker-pin {
    width: 20px;
    height: 20px;
    background: var(--primary);
    border-radius: 50%;
    border: 3px solid white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    transition: all 0.2s ease;
}

.map-marker.active .marker-pin {
    width: 28px;
    height: 28px;
    background: var(--success);
    box-shadow: 0 0 0 6px rgba(16, 185, 129, 0.25);
}

@media (max-width: 768px) {
    .map-page {
        height: calc(100vh - 65px);
    }

    .map-header {
        padding: 0.75rem 1rem;
    }

    .map-sidebar {
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
    }

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

    .map-sidebar-close {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .map-sidebar-toggle {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
    }

    .map-container {
        padding: 0;
    }

    #map {
        border-radius: 0;
        border: none;
    }
}

/* Login page */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.login-container {
    width: 100%;
    max-width: 400px;
}

.login-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0;
    overflow: hidden;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.login-brand {
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    padding: 2rem 2rem 1.5rem;
    text-align: center;
}

.login-logo {
    display: block;
    width: 240px;
    max-width: 80%;
    height: auto;
    margin: 0 auto;
}

.login-brand p {
    margin: 0.5rem 0 0;
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.95rem;
}

.login-body {
    padding: 1.5rem 2rem 2rem;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group input {
    width: 100%;
}

.password-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.password-wrapper input {
    padding-right: 2.5rem;
}

.toggle-password {
    position: absolute;
    right: 0.5rem;
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 0.25rem;
    font-size: 1rem;
    line-height: 1;
}

.toggle-password:hover {
    color: var(--text);
}

.login-button {
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem;
    font-weight: 500;
    margin-top: 0.5rem;
}

.login-card .alert {
    margin-top: 1rem;
    margin-bottom: 0;
}
