:root {
    --kpa-bg: #f4f7fb;
    --kpa-surface: #ffffff;
    --kpa-text: #1f2937;
    --kpa-muted: #6b7280;
    --kpa-line: #d9e2ec;
    --kpa-blue: #2b6cb0;
    --kpa-green: #276749;
    --kpa-yellow: #975a16;
    --kpa-red: #c53030;
}

* { box-sizing: border-box; }
.kpa-body { margin: 0; background: var(--kpa-bg); color: var(--kpa-text); font-family: Inter, Segoe UI, Arial, sans-serif; }
.kpa-page { max-width: 1220px; margin: 0 auto; padding: 22px; }
.kpa-topbar { height: 56px; display: flex; align-items: center; gap: 24px; padding: 0 22px; background: #162033; color: white; position: sticky; top: 0; z-index: 20; }
.kpa-brand { color: white; text-decoration: none; font-weight: 700; }
.kpa-nav { display: flex; gap: 14px; flex-wrap: wrap; }
.kpa-nav a { color: rgba(255,255,255,0.84); text-decoration: none; font-size: 14px; }
.kpa-nav a:hover { color: white; }

.kpa-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; margin-bottom: 18px; }
.kpa-header h1 { margin: 0; font-size: 26px; line-height: 1.2; letter-spacing: 0; }
.kpa-subtitle { margin: 5px 0 0; color: var(--kpa-muted); font-size: 14px; }
.kpa-header-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.kpa-btn { padding: 8px 13px; border-radius: 6px; font-size: 13px; font-weight: 650; cursor: pointer; border: none; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; line-height: 1.2; }
.kpa-btn-primary { background: var(--kpa-blue); color: white; }
.kpa-btn-secondary { background: #e7edf5; color: #24364c; }
.kpa-btn-danger { background: #c53030; color: white; }
.kpa-btn:hover { filter: brightness(0.97); }

.kpa-stats-grid { display: grid; grid-template-columns: repeat(5, minmax(130px, 1fr)); gap: 12px; margin: 16px 0 20px; }
.kpa-stat-card { background: var(--kpa-surface); border: 1px solid var(--kpa-line); border-radius: 8px; padding: 14px; min-height: 92px; display: flex; flex-direction: column; justify-content: center; box-shadow: 0 1px 3px rgba(15,23,42,0.05); }
.kpa-stat-number { font-size: 30px; font-weight: 760; line-height: 1; }
.kpa-stat-label { color: var(--kpa-muted); margin-top: 8px; font-size: 13px; }
.kpa-stat-ok { border-top: 4px solid #38a169; }
.kpa-stat-warning { border-top: 4px solid #d69e2e; }
.kpa-stat-critical { border-top: 4px solid #e53e3e; }
.kpa-stat-expired { border-top: 4px solid #742a2a; }
.kpa-stat-total { border-top: 4px solid #2b6cb0; }

.kpa-section { background: var(--kpa-surface); border: 1px solid var(--kpa-line); border-radius: 8px; padding: 16px; margin: 16px 0; box-shadow: 0 1px 3px rgba(15,23,42,0.05); }
.kpa-section h2 { margin: 0 0 12px; font-size: 18px; letter-spacing: 0; }
.kpa-section-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.kpa-section-head a { color: var(--kpa-blue); text-decoration: none; font-size: 13px; font-weight: 650; }

.kpa-table-header { display: flex; justify-content: space-between; gap: 14px; align-items: center; margin-bottom: 12px; }
.kpa-table-header h2 { margin: 0; }
.kpa-table-filters { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.kpa-table-filters select, .kpa-table-filters input, .kpa-form input, .kpa-form select, .kpa-form textarea { border: 1px solid #cbd5e1; border-radius: 6px; padding: 8px 10px; font: inherit; background: white; color: var(--kpa-text); min-height: 38px; }
.kpa-table-wrap { overflow-x: auto; }
.kpa-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.kpa-table th { text-align: left; color: #526174; border-bottom: 1px solid var(--kpa-line); padding: 10px 8px; white-space: nowrap; }
.kpa-table td { border-bottom: 1px solid #eef2f7; padding: 10px 8px; vertical-align: middle; }
.kpa-table td:first-child { display: flex; gap: 8px; align-items: center; min-width: 190px; }
.kpa-table small { display: block; color: var(--kpa-muted); margin-top: 2px; }
.kpa-item-icon { width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; background: #eef2f7; flex: 0 0 auto; }
.kpa-actions { white-space: nowrap; }
.kpa-actions a { text-decoration: none; display: inline-flex; width: 28px; height: 28px; align-items: center; justify-content: center; border-radius: 6px; }
.kpa-actions a:hover { background: #eef2f7; }
.kpa-pagination { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-top: 12px; color: var(--kpa-muted); font-size: 13px; }
.kpa-pagination button { border: 1px solid var(--kpa-line); background: white; border-radius: 6px; padding: 6px 10px; cursor: pointer; }

.kpa-days-badge { margin-left: 5px; border-radius: 10px; padding: 1px 6px; font-size: 11px; font-weight: 700; background: #edf2f7; color: #4a5568; }
.kpa-days-warning { background: #fefcbf; color: #744210; }
.kpa-days-critical { background: #fed7d7; color: #742a2a; }
.kpa-days-expired { background: #742a2a; color: white; }

.kpa-marker {
    width: 40px; height: 40px;
    background: white;
    border: 3px solid #38a169;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.kpa-marker:hover { transform: scale(1.15); box-shadow: 0 4px 16px rgba(0,0,0,0.4); }
.kpa-marker-icon { font-size: 18px; line-height: 1; }
.kpa-marker-dot { position: absolute; bottom: -4px; right: -4px; width: 12px; height: 12px; border-radius: 50%; border: 2px solid white; }
.kpa-pulse { animation: kpaPulse 1.5s ease-in-out infinite; }
@keyframes kpaPulse {
    0%, 100% { box-shadow: 0 2px 8px rgba(0,0,0,0.3), 0 0 0 0 rgba(229,62,62,0.4); }
    50% { box-shadow: 0 2px 8px rgba(0,0,0,0.3), 0 0 0 12px rgba(229,62,62,0); }
}

.kpa-popup-container .leaflet-popup-content-wrapper { padding: 0; border-radius: 12px; overflow: hidden; min-width: 280px; }
.kpa-popup-container .leaflet-popup-content { margin: 0; }
.kpa-popup-header { display: flex; gap: 10px; align-items: center; padding: 12px 14px; color: white; }
.kpa-popup-icon { font-size: 28px; }
.kpa-popup-header strong { display: block; font-size: 14px; font-weight: 700; }
.kpa-popup-header small { font-size: 11px; opacity: 0.85; }
.kpa-popup-body { padding: 10px 14px; }
.kpa-status-badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 700; margin-bottom: 8px; }
.kpa-status-ok { background: #c6f6d5; color: #276749; }
.kpa-status-warning { background: #fefcbf; color: #744210; }
.kpa-status-critical { background: #fed7d7; color: #742a2a; }
.kpa-status-expired { background: #742a2a; color: #fff5f5; }
.kpa-popup-table { width: 100%; font-size: 12px; border-collapse: collapse; }
.kpa-popup-table td { padding: 3px 4px; }
.kpa-popup-table td:first-child { color: #718096; font-weight: 600; width: 45%; }
.kpa-popup-notes { font-size: 12px; color: #718096; margin-top: 6px; font-style: italic; }
.kpa-popup-actions { display: flex; gap: 6px; padding: 10px 14px; background: #f7fafc; border-top: 1px solid #e2e8f0; }

#kpa-filter-panel {
    position: absolute; top: 70px; right: -310px; z-index: 1000;
    width: 290px; background: rgba(15, 17, 21, 0.96); color: #f8fafc; border-radius: 8px;
    border: 1px solid rgba(148,163,184,0.2);
    box-shadow: 0 8px 32px rgba(0,0,0,0.32);
    transition: right 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    max-height: calc(100vh - 120px); overflow-y: auto;
}
#kpa-filter-panel.kpa-panel-open { right: 12px; }
#kpa-filter-panel hr { border: 0; border-top: 1px solid rgba(148,163,184,0.24); }
.kpa-filter-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid rgba(148,163,184,0.24); font-weight: 700; font-size: 14px; color: #f8fafc; position: sticky; top: 0; background: rgba(15, 17, 21, 0.98); z-index: 1; }
.kpa-filter-close { background: none; border: none; font-size: 20px; cursor: pointer; color: #94a3b8; }
.kpa-filter-body { padding: 8px 0; }
.kpa-filter-item { display: flex; align-items: center; gap: 8px; padding: 8px 14px; cursor: pointer; font-size: 13px; transition: background 0.15s; }
.kpa-filter-item:hover, .kpa-filter-item.active { background: rgba(255,255,255,0.06); }
.kpa-filter-item input { accent-color: #2b6cb0; width: 14px; height: 14px; }
.kpa-filter-item span:nth-child(2) { flex: 1; }
.kpa-filter-count { background: rgba(148,163,184,0.16); color: #cbd5e1; padding: 1px 7px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.kpa-filter-alerts { padding: 8px 14px; }
.kpa-filter-alerts strong { display: block; font-size: 12px; color: #94a3b8; margin-bottom: 6px; }
.kpa-alert-btn { display: inline-block; margin: 2px; padding: 5px 9px; border-radius: 6px; font-size: 12px; cursor: pointer; border: 1px solid transparent; font-weight: 650; background: #edf2f7; color: #334155; }
.kpa-alert-btn.active { outline: 2px solid #2b6cb0; outline-offset: 1px; border-color: rgba(43,108,176,0.45); }
.kpa-alert-critical { background: #fed7d7; color: #742a2a; }
.kpa-alert-warning { background: #fefcbf; color: #744210; }
.kpa-alert-expired { background: #742a2a; color: white; }

#kpa-fab { position: absolute; bottom: 152px; right: 14px; z-index: 999; }
.kpa-fab-btn { width: 52px; height: 52px; border-radius: 50%; background: #2b6cb0; color: white; border: none; font-size: 22px; cursor: pointer; position: relative; box-shadow: 0 4px 16px rgba(43,108,176,0.4); transition: transform 0.2s, box-shadow 0.2s; display: flex; align-items: center; justify-content: center; }
.kpa-fab-btn:hover { transform: scale(1.08); box-shadow: 0 6px 20px rgba(43,108,176,0.5); }
.kpa-badge { position: absolute; top: -4px; right: -4px; background: #e53e3e; color: white; min-width: 20px; height: 20px; border-radius: 10px; font-size: 11px; font-weight: 800; display: flex; align-items: center; justify-content: center; border: 2px solid white; animation: kpaPulse 1.5s infinite; }

#kpa-add-banner { display: none; position: absolute; top: 64px; left: 50%; transform: translateX(-50%); z-index: 1001; background: #2b6cb0; color: white; padding: 10px 20px; border-radius: 8px; font-size: 14px; box-shadow: 0 4px 16px rgba(0,0,0,0.2); }
#kpa-add-banner button { margin-left: 12px; background: rgba(255,255,255,0.2); color: white; border: 1px solid rgba(255,255,255,0.4); border-radius: 4px; padding: 3px 10px; cursor: pointer; }

#kpa-map-control {
    position: absolute;
    top: 12px;
    left: 58px;
    z-index: 998;
    display: flex;
    align-items: center;
    gap: 7px;
    max-width: min(760px, calc(100% - 360px));
    padding: 7px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.88);
    border: 1px solid rgba(148, 163, 184, 0.25);
    box-shadow: 0 10px 30px rgba(15,23,42,0.28);
    backdrop-filter: blur(8px);
}
.kpa-control-chip {
    height: 34px;
    display: inline-flex;
    align-items: center;
    padding: 0 11px;
    border-radius: 999px;
    background: rgba(255,255,255,0.08);
    color: #e2e8f0;
    font-size: 12px;
    font-weight: 850;
    letter-spacing: 0;
    flex: 0 0 auto;
}
.kpa-category-dock {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: thin;
}
.kpa-category-icon-btn {
    width: 34px;
    height: 34px;
    border: 1px solid rgba(255,255,255,0.14);
    border-radius: 50%;
    background: rgba(255,255,255,0.1);
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 34px;
    box-shadow: 0 3px 10px rgba(0,0,0,0.18);
    transition: transform .15s ease, background .15s ease, box-shadow .15s ease;
}
.kpa-category-icon-btn span { font-size: 17px; line-height: 1; }
.kpa-category-icon-btn:hover {
    transform: translateY(-1px);
    background: rgba(59,130,246,0.55);
}
.kpa-category-icon-btn.active {
    background: #2563eb;
    border-color: rgba(255,255,255,0.45);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.28), 0 6px 18px rgba(37,99,235,0.35);
}
.kpa-mode-toggle { display: inline-flex; border: 1px solid #cbd5e1; border-radius: 7px; overflow: hidden; flex-shrink: 0; }
.kpa-mode-toggle button,
.kpa-filter-toggle-btn {
    min-height: 34px;
    border: 1px solid rgba(255,255,255,0.14);
    background: rgba(255,255,255,0.1);
    color: #e2e8f0;
    border-radius: 999px;
    padding: 0 12px;
    font-size: 12px;
    font-weight: 750;
    cursor: pointer;
    white-space: nowrap;
}
.kpa-mode-toggle button + button { border-left: 1px solid #cbd5e1; }
.kpa-mode-toggle button.active,
.kpa-filter-toggle-btn:hover,
.kpa-filter-toggle-btn.active {
    background: #2b6cb0;
    color: white;
}
#kpa-map-control.kpa-register-active {
    border-color: rgba(229,62,62,0.42);
    box-shadow: 0 4px 16px rgba(229,62,62,0.22);
}
#kpa-map-control.kpa-register-active .kpa-mode-toggle button.active {
    background: #e53e3e;
    color: white;
}
#kpa-add-category-select {
    min-height: 34px;
    min-width: 210px;
    max-width: 280px;
    border: 1px solid #cbd5e1;
    border-radius: 7px;
    background: white;
    color: #1e293b;
    padding: 0 10px;
    font-size: 12px;
    font-weight: 650;
}
#kpa-add-category-select:disabled { opacity: .55; }

.kpa-map-page { max-width: none; }
.kpa-map-header { margin-bottom: 12px; }
.kpa-map-frame { height: calc(100vh - 140px); min-height: 520px; position: relative; overflow: hidden; border: 1px solid var(--kpa-line); border-radius: 8px; background: #dbeafe; }
#kpaMap { width: 100%; height: 100%; }
.kpa-map-add-toolbar { position: absolute; top: 12px; left: 12px; z-index: 900; display: flex; flex-wrap: wrap; gap: 6px; max-width: min(560px, calc(100% - 90px)); }
.kpa-map-add-toolbar button { width: 36px; height: 36px; border-radius: 6px; border: 1px solid rgba(15,23,42,0.14); background: white; cursor: pointer; box-shadow: 0 2px 7px rgba(15,23,42,0.15); font-size: 18px; }
.kpa-map-add-toolbar button:hover { background: #f8fafc; transform: translateY(-1px); }

.kpa-alert-card { border-left: 4px solid; border-radius: 8px; padding: 12px 16px; margin-bottom: 8px; background: white; display: flex; gap: 12px; align-items: flex-start; box-shadow: 0 1px 4px rgba(0,0,0,0.06); transition: transform 0.15s; }
.kpa-alert-card:hover { transform: translateX(3px); }
.kpa-alert-card.critical { border-color: #e53e3e; }
.kpa-alert-card.warning { border-color: #d69e2e; }
.kpa-alert-card.expired { border-color: #742a2a; background: #fff5f5; }
.kpa-alert-icon { font-size: 28px; }
.kpa-alert-content { flex: 1; min-width: 0; }
.kpa-alert-title { font-weight: 700; font-size: 14px; color: #2d3748; }
.kpa-alert-meta { font-size: 12px; color: #718096; margin-top: 2px; line-height: 1.45; }
.kpa-alert-action { align-self: center; }
.kpa-inspect-btn { padding: 6px 14px; background: #2b6cb0; color: white; border: none; border-radius: 6px; font-size: 12px; cursor: pointer; text-decoration: none; }

.kpa-modal { position: fixed; inset: 0; z-index: 3000; background: rgba(15,23,42,0.48); align-items: center; justify-content: center; padding: 18px; }
.kpa-modal-content { width: min(760px, 100%); max-height: calc(100vh - 48px); overflow: auto; background: white; border-radius: 8px; padding: 18px; box-shadow: 0 16px 48px rgba(15,23,42,0.2); }
.kpa-modal-content h3 { margin-top: 0; }
.kpa-category-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpa-category-card { border: 1px solid var(--kpa-line); border-radius: 8px; min-height: 86px; background: #fbfdff; cursor: pointer; display: flex; flex-direction: column; gap: 7px; align-items: center; justify-content: center; padding: 10px; text-align: center; color: var(--kpa-text); }
.kpa-category-card:hover { border-color: #2b6cb0; background: #eff6ff; }
.kpa-cat-icon { font-size: 26px; }

.kpa-form-page, .kpa-detail-page, .kpa-report { max-width: 1040px; margin: 0 auto; }
.kpa-form { background: white; border: 1px solid var(--kpa-line); border-radius: 8px; padding: 16px; display: grid; gap: 14px; }
.kpa-form.compact { padding: 0; border: 0; }
.kpa-form-grid { display: grid; grid-template-columns: repeat(2, minmax(220px, 1fr)); gap: 14px; }
.kpa-form label { display: grid; gap: 6px; font-size: 13px; font-weight: 650; color: #344256; }
.kpa-form textarea { resize: vertical; min-height: 90px; }
.kpa-form-actions { display: flex; gap: 8px; justify-content: flex-end; }
.kpa-form-message { min-height: 20px; margin-top: 10px; color: var(--kpa-muted); }
.kpa-form-message.error { color: #c53030; font-weight: 700; }
.kpa-detail-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr); gap: 16px; align-items: start; }
.kpa-detail-list { display: grid; grid-template-columns: 150px 1fr; gap: 10px 14px; margin: 0; }
.kpa-detail-list dt { color: var(--kpa-muted); font-size: 13px; }
.kpa-detail-list dd { margin: 0; font-size: 14px; }
.kpa-empty { border: 1px dashed #cbd5e1; border-radius: 8px; padding: 18px; color: var(--kpa-muted); background: #f8fafc; }

@media (max-width: 860px) {
    .kpa-page { padding: 14px; }
    .kpa-header, .kpa-table-header { flex-direction: column; align-items: stretch; }
    .kpa-header-actions, .kpa-table-filters { justify-content: flex-start; }
    .kpa-stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .kpa-form-grid, .kpa-detail-grid { grid-template-columns: 1fr; }
    .kpa-map-frame { height: calc(100vh - 190px); min-height: 430px; }
    #kpa-filter-panel { top: 58px; width: min(290px, calc(100% - 24px)); }
    #kpa-map-control {
        top: 58px;
        left: 10px;
        right: 10px;
        max-width: none;
        align-items: center;
        flex-direction: row;
        border-radius: 18px;
    }
    .kpa-category-dock { flex: 1 1 auto; }
    #kpa-add-category-select { min-width: 0; max-width: none; width: 100%; }
    #kpa-fab { bottom: 152px; right: 14px; }
}

@media print {
    .kpa-topbar, .kpa-print-hide, .kpa-header-actions { display: none !important; }
    .kpa-body { background: white; }
    .kpa-page { max-width: none; padding: 0; }
    .kpa-section, .kpa-stat-card { box-shadow: none; break-inside: avoid; }
}
