:root {
    --bg: #f4f6f8;
    --panel: #ffffff;
    --text: #17202a;
    --muted: #6b7280;
    --line: #d9dee7;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --danger-dark: #b91c1c;
    --success: #15803d;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.12);
}

* {
    box-sizing: border-box;
}

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

a {
    color: inherit;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

input,
textarea,
select,
button {
    font: inherit;
}

input,
textarea,
select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
    background: #fff;
}

textarea {
    resize: vertical;
}

select[multiple] {
    min-height: 120px;
}

input[type="color"] {
    min-height: 40px;
    padding: 4px;
}

input[type="checkbox"] {
    width: auto;
}

.compact-form {
    gap: 8px;
}

.master-form {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 8px;
    align-items: center;
}

.master-form input[type="hidden"] {
    display: none;
}

.master-form input[type="color"] {
    width: 48px;
}

.master-form input[type="number"] {
    width: 76px;
}

.master-form .btn {
    white-space: nowrap;
}

.null-type-color-form {
    margin-top: 12px;
}

.master-form-label {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.master-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
}

.master-list-item {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    gap: 8px;
    align-items: center;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
}

#groupList .master-list-item {
    grid-template-columns: 1fr auto auto;
}

.color-dot {
    width: 18px;
    height: 18px;
    border-radius: 999px;
    border: 1px solid rgba(15, 23, 42, 0.24);
}


button {
    cursor: pointer;
}

.app-header {
    height: 58px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 18px;
    color: #fff;
    background: #111827;
}

.brand {
    font-weight: 800;
    letter-spacing: 0.02em;
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 14px;
}

.user-name {
    color: #d1d5db;
}

.app-layout {
    height: calc(100vh - 58px);
    display: grid;
    grid-template-columns: 360px 1fr;
    min-height: 560px;
}

.sidebar {
    overflow: auto;
    padding: 14px;
    border-right: 1px solid var(--line);
    background: #eef2f7;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 14px;
    margin-bottom: 14px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.panel h2 {
    margin: 0 0 10px;
    font-size: 16px;
}

.panel-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}

.panel-title-row h2 {
    margin: 0;
}

.help-text,
.empty-text {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.6;
}

.map-wrap {
    position: relative;
    min-width: 0;
}

#map {
    width: 100%;
    height: 100%;
}

.map-load-error {
    position: absolute;
    inset: 24px;
    z-index: 930;
    max-width: 640px;
    height: fit-content;
    margin: auto;
    padding: 20px;
    border: 1px solid #fecaca;
    border-radius: 18px;
    color: #7f1d1d;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: var(--shadow);
    line-height: 1.7;
}

.map-load-error[hidden] {
    display: none;
}

.map-load-error h2 {
    margin: 0 0 8px;
    font-size: 20px;
}

.map-load-error p {
    margin: 0 0 10px;
    font-weight: 700;
}

.map-load-error ul {
    margin: 0;
    padding-left: 1.25em;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 10px;
    padding: 10px 14px;
    min-height: 40px;
    color: #111827;
    background: #e5e7eb;
    font-weight: 700;
    text-decoration: none;
    transition: transform 0.08s ease, background 0.15s ease;
}

.btn:hover {
    text-decoration: none;
    transform: translateY(-1px);
}

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

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

.btn-secondary {
    background: #e5e7eb;
}

.btn-danger {
    color: #fff;
    background: var(--danger);
}

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

.btn-block {
    width: 100%;
}

.btn-small {
    min-height: 32px;
    padding: 6px 10px;
    font-size: 13px;
}

.is-active {
    background: var(--danger);
}

.is-active:hover {
    background: var(--danger-dark);
}

.pin-list-toolbar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin-bottom: 10px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.pin-list-toolbar select {
    min-height: 32px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 4px 8px;
    background: #fff;
}

.pin-list-pagination {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
}

.pin-list-page-summary {
    color: var(--muted);
    font-size: 13px;
    text-align: center;
}

.pin-list-page-controls {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
}

.pin-list-page-controls .btn[disabled] {
    cursor: not-allowed;
    opacity: 0.5;
    transform: none;
}

.pin-list-page-controls .is-current {
    color: #fff;
    background: var(--primary);
}

.pin-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.pin-list-item {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: start;
    text-align: left;
    border: 1px solid var(--line);
    border-left: 6px solid var(--pin-color, var(--line));
    border-radius: 12px;
    padding: 10px;
    background: #fff;
}

.pin-list-item:hover {
    border-color: var(--primary);
    background: #f8fbff;
}

.pin-list-main {
    min-width: 0;
}

.pin-list-item strong,
.pin-list-item span,
.pin-list-item small {
    display: block;
}

.pin-list-item span {
    margin-top: 4px;
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pin-list-item small {
    margin-top: 4px;
    color: #9ca3af;
    font-size: 12px;
}

.pin-list-thumb {
    display: grid;
    place-items: center;
    width: 58px;
    height: 58px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 10px;
    color: #9ca3af;
    background: #f3f4f6;
    font-size: 10px;
    font-weight: 800;
    text-align: center;
}

.pin-list-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.pin-list-thumb.is-empty {
    padding: 6px;
}


.form-stack {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.form-stack label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-weight: 700;
    font-size: 14px;
}

.field-help {
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
}

.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
}

.modal.is-open {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px;
}

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
}

.modal-card {
    position: relative;
    width: min(560px, 100%);
    max-height: calc(100dvh - 28px);
    overflow: auto;
    margin: 0;
    background: #fff;
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 18px;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

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

.modal-header h2 {
    margin: 0;
    font-size: 20px;
}

.icon-btn {
    border: 0;
    width: 36px;
    height: 36px;
    border-radius: 999px;
    background: #e5e7eb;
    font-size: 22px;
}


.pin-photo-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #f8fafc;
}

.photo-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
    gap: 10px;
}

.photo-gallery .empty-text {
    grid-column: 1 / -1;
    margin: 0;
}

.photo-thumb {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
}

.photo-thumb a {
    display: block;
    aspect-ratio: 1 / 1;
}

.photo-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.photo-delete-btn {
    position: absolute;
    right: 6px;
    bottom: 6px;
    border: 0;
    border-radius: 999px;
    padding: 4px 8px;
    color: #fff;
    background: rgba(220, 38, 38, 0.92);
    font-size: 11px;
    font-weight: 800;
}

.photo-delete-btn:hover {
    background: var(--danger-dark);
}

.pin-id-box,
.latlng-box {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 10px;
    background: #f3f4f6;
    border-radius: 12px;
    color: var(--muted);
    font-size: 13px;
}

.pin-id-box {
    align-items: center;
}

.pin-id-box strong {
    color: var(--text);
    font-size: 15px;
    text-align: right;
}

.modal-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.spacer {
    flex: 1;
}

/* Google Maps Advanced Marker用：虫ピン風マーカー */
.bug-pin {
    position: relative;
    width: 46px;
    height: 76px;
    transform: translateY(-24px) rotate(-12deg);
    filter: drop-shadow(0 4px 4px rgba(0,0,0,0.28));
}

.bug-pin-id {
    position: absolute;
    left: 50%;
    top: 0;
    z-index: 2;
    max-width: 64px;
    padding: 2px 6px;
    color: #111827;
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid rgba(17, 24, 39, 0.24);
    border-radius: 999px;
    font-size: 11px;
    font-weight: 800;
    line-height: 1.2;
    white-space: nowrap;
    transform: translateX(-50%) rotate(12deg);
}

.bug-pin-head {
    position: absolute;
    left: 14px;
    top: 22px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #ffffff 0 18%, var(--pin-color, #ef4444) 19% 72%, #111827 73% 100%);
    border: 2px solid #111827;
}

.bug-pin-needle {
    position: absolute;
    left: 24px;
    top: 42px;
    width: 3px;
    height: 34px;
    border-radius: 999px;
    background: linear-gradient(to bottom, #9ca3af, #111827);
}

.bug-pin-needle::after {
    content: "";
    position: absolute;
    left: -3px;
    bottom: -5px;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 8px solid #111827;
}

.toast {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 2000;
    max-width: min(420px, calc(100vw - 36px));
    padding: 12px 14px;
    border-radius: 12px;
    color: #fff;
    box-shadow: var(--shadow);
    font-weight: 700;
}

.toast-success {
    background: var(--success);
}

.toast-error {
    background: var(--danger);
}

.import-result {
    margin-top: 8px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.6;
}

.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 18px;
    background: radial-gradient(circle at top, #374151, #111827);
}

.login-card {
    width: min(420px, 100%);
    padding: 26px;
    background: #fff;
    border-radius: 20px;
    box-shadow: var(--shadow);
}

.login-card h1 {
    margin: 0 0 8px;
}

.login-lead {
    margin: 0 0 18px;
    color: var(--muted);
}

.alert {
    margin: 0 0 16px;
    padding: 12px 14px;
    border-radius: 12px;
    font-weight: 700;
}

.alert-error {
    color: #7f1d1d;
    background: #fee2e2;
}

.alert-success {
    color: #14532d;
    background: #dcfce7;
}

.admin-wrap {
    max-width: 1180px;
    margin: 0 auto;
    padding: 24px 16px 60px;
}

.admin-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 18px;
    margin-top: 18px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.user-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr auto auto;
    gap: 12px;
    align-items: end;
}

.user-form-grid label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-weight: 700;
    font-size: 14px;
}

.check-label {
    display: inline-flex !important;
    align-items: center;
    flex-direction: row !important;
    gap: 6px;
    white-space: nowrap;
}

.check-label input {
    width: auto;
}

.table-scroll {
    overflow: auto;
}

.user-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 900px;
}

.user-table th,
.user-table td {
    border-bottom: 1px solid var(--line);
    padding: 10px;
    text-align: left;
    vertical-align: middle;
}

.user-table th {
    background: #f3f4f6;
}

.action-cell {
    white-space: nowrap;
}

.mobile-menu-toggle {
    display: none;
}

@media (max-width: 900px) {
    .app-layout {
        display: block;
        position: relative;
        height: calc(100dvh - 58px);
        min-height: 0;
        overflow: hidden;
    }

    .map-wrap {
        height: 100%;
        min-height: 0;
    }

    .sidebar {
        position: fixed;
        right: 10px;
        bottom: 0;
        left: 10px;
        z-index: 950;
        max-height: min(78dvh, calc(100dvh - 92px));
        overflow: auto;
        padding: 34px 14px 18px;
        border: 1px solid var(--line);
        border-bottom: 0;
        border-radius: 22px 22px 0 0;
        background: #eef2f7;
        box-shadow: var(--shadow);
        transform: translateY(calc(100% + 18px));
        transition: transform 0.24s ease;
        overscroll-behavior: contain;
    }

    .mobile-menu-open .sidebar {
        transform: translateY(0);
    }

    .mobile-menu-toggle {
        position: fixed;
        right: auto;
        bottom: 16px;
        left: 50%;
        z-index: 960;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        min-width: 124px;
        min-height: 48px;
        border: 0;
        border-radius: 999px;
        padding: 10px 18px;
        color: #fff;
        background: var(--primary);
        box-shadow: 0 12px 26px rgba(37, 99, 235, 0.34);
        font-weight: 800;
        transform: translateX(-50%);
        transition: bottom 0.24s ease, transform 0.24s ease, background 0.15s ease;
    }

    .mobile-menu-toggle:hover {
        background: var(--primary-dark);
        text-decoration: none;
    }

    .mobile-menu-open .mobile-menu-toggle {
        bottom: min(78dvh, calc(100dvh - 92px));
        background: #111827;
        transform: translate(-50%, 50%);
    }

    .mobile-menu-arrow {
        font-size: 22px;
        line-height: 1;
    }

    .mobile-menu-label {
        font-size: 14px;
    }

    .mobile-menu-open {
        overflow: hidden;
    }

    .user-form-grid,
    .master-form {
        grid-template-columns: 1fr;
    }

    .master-form input[type="color"],
    .master-form input[type="number"] {
        width: 100%;
    }

    .master-list-item,
    #groupList .master-list-item {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 560px) {
    .app-header {
        height: auto;
        min-height: 58px;
        align-items: flex-start;
        flex-direction: column;
        gap: 8px;
        padding: 12px 14px;
    }

    .app-layout {
        height: calc(100dvh - 92px);
    }

    .header-nav {
        flex-wrap: wrap;
        gap: 10px;
    }

    .pin-id-box,
    .latlng-box {
        grid-template-columns: 1fr;
    }

    .pin-id-box strong {
        text-align: left;
    }

    .modal.is-open {
        align-items: flex-start;
        padding-top: max(10px, env(safe-area-inset-top));
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    .modal-card {
        max-height: calc(100dvh - max(10px, env(safe-area-inset-top)) - max(10px, env(safe-area-inset-bottom)));
        padding: 14px;
    }

    .modal-actions {
        position: sticky;
        bottom: -14px;
        z-index: 1;
        flex-wrap: wrap;
        margin: 0 -14px -14px;
        padding: 10px 14px 14px;
        border-top: 1px solid var(--line);
        background: #fff;
    }

    .modal-actions .btn {
        flex: 0 0 auto;
        white-space: nowrap;
    }
}

.location-search-panel {
    border-color: rgba(37, 99, 235, 0.22);
}

.location-search-form {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: center;
}

.location-search-map-host {
    display: none;
}

.account-wrap {
    max-width: 720px;
}

.account-card {
    max-width: 560px;
}

@media (max-width: 900px) {
    .location-search-map-host {
        position: absolute;
        top: 12px;
        right: 12px;
        left: 12px;
        z-index: 940;
        display: block;
        pointer-events: none;
    }

    .location-search-map-host .location-search-panel {
        margin: 0;
        padding: 10px;
        border-radius: 16px;
        box-shadow: var(--shadow);
        pointer-events: auto;
    }

    .location-search-map-host .location-search-panel h2,
    .location-search-map-host .location-search-panel .help-text {
        display: none;
    }

    .location-search-form {
        grid-template-columns: 1fr auto;
    }
}

@media (max-width: 560px) {
    .location-search-map-host {
        top: 8px;
        right: 8px;
        left: 8px;
    }

    .location-search-map-host .location-search-panel {
        padding: 8px;
    }

    .location-search-form .btn {
        padding-inline: 10px;
    }
}

.audit-wrap {
    max-width: 1320px;
}

.audit-filter-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(150px, 1fr)) auto;
    gap: 12px;
    align-items: end;
}

.audit-filter-grid label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-weight: 700;
    font-size: 14px;
}

.audit-filter-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.audit-table {
    min-width: 1180px;
}

.audit-table td {
    vertical-align: top;
}

.audit-details {
    max-width: 360px;
    max-height: 220px;
    overflow: auto;
    margin: 8px 0 0;
    padding: 10px;
    border-radius: 10px;
    background: #111827;
    color: #e5e7eb;
    font-size: 12px;
    line-height: 1.5;
    white-space: pre-wrap;
}

@media (max-width: 900px) {
    .audit-filter-grid {
        grid-template-columns: 1fr;
    }

    .audit-filter-actions {
        flex-wrap: wrap;
    }
}
