html,
body {
    height: 100%;
}

:root {
    --map-tab-offset: 160px;
    --map-tab-offset-mobile: 190px;
}

body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 16px;
    background-color: #f8f9fa;
    color: #1f2937;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

.tab {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    border-bottom: 1px solid #d1d5db;
    gap: 8px;
    margin-bottom: 8px;
}

.tab button {
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 12px 16px;
    font-size: 16px;
    color: #374151;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.tab button:hover {
    background-color: #e5e7eb;
}

.tab button.active {
    background-color: #2563eb;
    color: #ffffff;
}

.tabcontent {
    display: none;
    background-color: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 16px;
    flex: 1 1 auto;
    min-height: 0;
}

.tabcontent.active {
    display: block;
}

#Map.tabcontent.active {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - var(--map-tab-offset));
}

#map {
    width: 100%;
    height: auto;
    flex: 1 1 auto;
    min-height: 500px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
}

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

#sessionInfo {
    font-size: 14px;
    color: #4b5563;
}

.logout-btn {
    display: none;
}

.login-form {
    max-width: 360px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.login-form input {
    padding: 8px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
}

.login-form button {
    margin-top: 4px;
    padding: 10px 12px;
    border: none;
    border-radius: 4px;
    background: #2563eb;
    color: #fff;
    cursor: pointer;
}

.form-message {
    min-height: 20px;
    margin: 0;
    color: #374151;
}

.form-message.error {
    color: #b91c1c;
}

.admin-toolbar,
.section-header,
.section-actions,
.admin-tabs,
.modal-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.section-header {
    justify-content: space-between;
}

.device-data-panel {
    margin-top: 12px;
    border-top: 1px solid #e5e7eb;
    padding-top: 10px;
}

.marker-config-panel {
    margin-top: 12px;
    border-top: 1px solid #e5e7eb;
    padding-top: 10px;
}

.marker-config-panel h5 {
    margin: 0 0 8px 0;
}

.marker-config-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 10px;
}

.marker-config-item {
    display: grid;
    gap: 6px;
}

.marker-config-item select {
    padding: 8px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
}

.marker-config-item img {
    width: 50px;
    height: 50px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    object-fit: contain;
    background: #fff;
}

.device-data-panel h5 {
    margin: 0 0 8px 0;
}

.device-data-panel input[type="datetime-local"] {
    padding: 8px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
}

.admin-toolbar {
    margin-bottom: 8px;
}

.admin-tabs {
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: 12px;
}

.admin-tab-btn {
    border: 1px solid #d1d5db;
    background: #f9fafb;
    border-radius: 4px 4px 0 0;
    padding: 8px 12px;
    cursor: pointer;
}

.admin-tab-btn.active {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
}

.admin-tab-panel {
    display: none;
}

.admin-tab-panel.active {
    display: block;
}

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

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

th,
td {
    padding: 8px;
    border-bottom: 1px solid #e5e7eb;
    text-align: left;
    vertical-align: top;
}

button.danger {
    background: #dc2626;
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 6px 10px;
    cursor: pointer;
}

.assignment-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 8px;
    margin-bottom: 10px;
}

.assignment-form label {
    font-size: 13px;
    color: #374151;
}

.assignment-form select,
.assignment-form button,
.modal-fields input,
.modal-fields select {
    padding: 8px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
}

.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.55);
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 16px;
}

.modal.open {
    display: flex;
}

.modal-content {
    background: #fff;
    border-radius: 8px;
    width: min(520px, 100%);
    padding: 16px;
    box-shadow: 0 16px 30px rgba(0, 0, 0, 0.18);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.modal-fields {
    display: grid;
    gap: 6px;
}

.modal-actions {
    justify-content: flex-end;
    margin-top: 10px;
}

.ghost-btn {
    background: #f3f4f6;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    padding: 8px 10px;
    cursor: pointer;
}

@media (max-width: 768px) {
    #Map.tabcontent.active {
        min-height: calc(100vh - var(--map-tab-offset-mobile));
    }

    #map {
        min-height: 320px;
    }

    .modal-content {
        width: 100%;
    }
}
