:root {
    --primary-color: #007356;
    --secondary-color: #e6f1ef;
    --border-color: #ddd;
    --font-color: #333;
}
html {
    scroll-behavior: smooth;
}
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    background-color: #f4f4f9;
    color: var(--font-color);
    line-height: 1.6;
}

header {
    background-color: #fff;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}
.logo-title {
    display: flex;
    align-items: center;
    gap: 15px;
}
.header-icon {
    width: 60px;
    height: 60px;
}
header h1 {
    margin: 0;
    font-size: 1.8rem;
    color: var(--primary-color);
}
/* MODIFIED: Align lang-selector buttons to the right */
.lang-selector {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}
header h1 { margin: 0; line-height: 1; /* Adjust for subtitle */ }
.subtitle {
    margin: 0;
    font-size: 0.9em;
    font-weight: 400;
    color: #555;
}

.user-area {
    display: flex;
    align-items: center;
    gap: 1rem;
}
.lang-toggle-group {
    font-size: 0.8em;
    font-weight: bold;
    color: #888;
}
.lang-toggle-group span {
    cursor: pointer;
    padding: 0 4px;
    transition: color 0.2s;
}
.lang-toggle-group span:hover {
    color: var(--primary-color);
}
.lang-toggle-group span.active-lang {
    color: var(--primary-color);
    text-decoration: underline;
}
#user-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.username-input {
    padding: 5px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}
#update-username-btn {
    padding: 5px 10px;
    font-size: 0.9em;
}
/* ADDED: Click-to-edit username style */
#username-display.clickable {
    cursor: pointer;
    font-weight: 500;
    border-bottom: 2px dashed var(--border-color);
}
nav {
    background-color: var(--primary-color);
}
nav ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
}
nav ul li a {
    display: block;
    color: white;
    text-align: center;
    padding: 14px 20px;
    text-decoration: none;
    transition: background-color 0.3s;
}
nav ul li a:hover {
    background-color: #005a41;
}

main {
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}
.card {
    background-color: #fff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.card h2 {
    margin-top: 0;
    color: var(--primary-color);
    border-bottom: 2px solid var(--secondary-color);
    padding-bottom: 0.5rem;
}
button {
    background-color: var(--primary-color);
    color: white;
    cursor: pointer;
    border: none;
    padding: 10px 15px;
    border-radius: 4px;
    transition: background-color 0.3s;
}
button:hover {
    background-color: #005a41;
}
button:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}
.button-group {
    display: flex;
    gap: 10px;
    margin-top: 1rem;
}
.delete-button {
    background-color: #d93025;
}
.delete-button:hover {
    background-color: #a50e0e;
}

footer {
    text-align: center;
    padding: 1rem;
    background-color: #333;
    color: white;
    margin-top: 2rem;
}

/* Instructions */
.instructions-list {
    padding-left: 20px;
    margin: 0;
}
.instructions-list li {
    margin-bottom: 0.75rem;
}

/* Add Record Form Layout */
.form-layout {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.form-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}
.form-row label {
    font-weight: bold;
}
.form-row select,
.form-row input {
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
}
#route-select {
    max-width: 100%;
}
.form-row .select2-container {
    flex-grow: 1;
}
#date-input {
    max-width: 180px;
}

/* Details Window and Legend */
.add-record-body {
    display: flex;
    align-items: stretch;
    gap: 5px; /* MODIFIED: Reduced gap */
}
.details-window {
    flex-grow: 1;
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 40px;
    align-items: center;
    padding: 15px;
    padding-bottom: 25px;
    border: 1px solid var(--border-color);
    background-color: #fafafa;
    min-height: 120px;
    border-radius: 4px;
}
.radio-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    position: relative;
    width: 90px;
    flex-shrink: 0;
    padding: 10px 5px;
    background-color: #ffffff;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.vertex-name {
    font-size: 12px;
    font-weight: 500;
    text-align: center;
    word-wrap: break-word;
    padding: 5px 0;
    color: #333;
}
.radio-top, .radio-bottom {
    -webkit-appearance: none;
    appearance: none;
    background-color: #fff;
    margin: 0;
    width: 1.15em;
    height: 1.15em;
    border: 0.15em solid currentColor;
    border-radius: 50%;
    display: grid;
    place-content: center;
    cursor: pointer;
}
.radio-top::before, .radio-bottom::before {
    content: "";
    width: 0.65em;
    height: 0.65em;
    border-radius: 50%;
    transform: scale(0);
    transition: 120ms transform ease-in-out;
    box-shadow: inset 1em 1em var(--primary-color);
}
.radio-top:checked::before, .radio-bottom:checked::before {
    transform: scale(1);
}
.radio-item.has-connector:not(:last-child)::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 100%;
    transform: translateY(-50%);
    width: 40px;
    height: 2px;
    background-color: #ccc;
}
.radio-item.path-selected.has-connector:not(:last-child)::after {
    background-color: var(--primary-color);
    height: 3px;
}
.legend-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    width: 60px;  /* MODIFIED: Reduced width */
    flex-shrink: 0;
    padding: 5px;   /* MODIFIED: Reduced padding */
    background-color: #e9ecef;
    border: 1px dashed #adb5bd;
    border-radius: 8px;
    font-weight: bold;
    color: #495057;
    text-align: center;
}
.legend-item .vertex-name {
    font-size: 14px;
    font-weight: 600;
}
.dummy-radio {
    width: 1.15em;
    height: 1.15em;
    border: 0.15em solid currentColor;
    border-radius: 50%;
    background-color: #fff;
}

/* Summary Bar */
.summary-bar {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}
#selection-summary {
    font-size: 0.9em;
    font-weight: 500;
    color: #555;
}
#selection-summary.warning {
    color: #d93025;
}

/* Show Record Table */
.table-container {
    overflow-x: auto;
    margin-top: 1rem;
}
.table-window {
    border: 1px solid var(--border-color);
    height: 300px;
    overflow: auto;
    background-color: #fafafa;
}
table {
    width: 100%;
    border-collapse: collapse;
}
th, td {
    border: 1px solid var(--border-color);
    padding: 8px;
    text-align: left;
    white-space: nowrap;
}
th {
    background-color: var(--secondary-color);
    position: sticky;
    top: 0;
}
table thead th {
    cursor: pointer;
    position: relative;
}
table thead th:hover {
    background-color: #e2eef7;
}
table thead th::after {
    content: '';
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    border: 4px solid transparent;
    opacity: 0.3;
}
table thead th.sort-asc::after {
    border-bottom-color: #333;
    opacity: 1;
}
table thead th.sort-desc::after {
    border-top-color: #333;
    opacity: 1;
}

/* Map Section */
.map-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    gap: 1rem;
}
.map-controls, .control-group {
    display: flex;
    align-items: center;
    gap: 1rem;
}
.control-group label {
    font-weight: 500;
    font-size: 0.9em;
}
#map {
    height: 500px;
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: #fcfcfc;
}
.map-style-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
}
.map-style-table th, .map-style-table td {
    border: 1px solid var(--border-color);
    padding: 8px;
    text-align: left;
}
.map-style-table th {
    background-color: var(--secondary-color);
}
.map-style-table td:first-child {
    font-weight: bold;
    background-color: #f8f9fa;
}
.map-style-table select, .map-style-table input[type="color"] {
    width: 100%;
    border: 1px solid #ccc;
    background-color: #fff;
    padding: 5px;
    box-sizing: border-box;
}
.segment-info-box {
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--secondary-color);
    margin-bottom: 1rem;
    font-size: 0.9em;
}
.segment-info-box .close-btn {
    float: right;
    cursor: pointer;
    font-weight: bold;
}
.segment-info-box a {
    color: var(--primary-color);
    cursor: pointer;
    text-decoration: underline;
    margin: 0 5px;
}

/* Collapsible Sections */
details.card > summary {
    display: block;
    cursor: pointer;
    list-style: none;
}
details.card > summary::-webkit-details-marker {
    display: none;
}
details.card > summary h2 {
    display: inline-block;
    margin: 0;
}
details.card > summary::before {
    content: '▼';
    font-size: 0.8em;
    margin-right: 0.75rem;
    transition: transform 0.2s ease-in-out;
}
details[open] > summary::before {
    transform: rotate(180deg);
}
details.card > summary h2 {
    border-bottom: none;
    padding-bottom: 0;
}
details[open].card {
    padding-bottom: 1.5rem;
}
.cta-button {
    display: inline-block;
    background-color: var(--primary-color);
    color: white !important;
    padding: 10px 20px;
    border-radius: 4px;
    text-decoration: none;
    font-weight: 500;
    transition: background-color 0.3s;
}
.cta-button:hover {
    background-color: #005a41;
}

/* ADDED: Styles for card header and relocated delete button */
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem; /* Replaces margin on h2 */
}
.card-header h2 {
    margin: 0;
    padding: 0;
    border: none;
}
.delete-button-small {
    background-color: #d93025;
    padding: 4px 10px;
    font-size: 0.8em;
}
.delete-button-small:hover {
    background-color: #a50e0e;
}

/* --- Responsive Styles for Mobile Devices --- */
@media (max-width: 768px) {
    main {
        padding: 1rem 0.5rem;
    }
    .card {
        padding: 1rem;
    }
    .form-layout .form-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    .form-row #route-select, .form-row input {
        width: 100%;
        box-sizing: border-box;
    }
    .add-record-body {
        gap: 5px;
    }
    .details-window {
        padding: 10px;
        gap: 10px; /* MODIFIED: Reduced gap */
    }
    .radio-item {
        width: 60px; /* MODIFIED: Reduced width */
        padding: 4px; /* MODIFIED: Reduced padding */
    }
    .radio-item.has-connector:not(:last-child)::after {
        width: 10px; /* MODIFIED: Shortened connector */
    }
}