/* Reset podstawowych stylów */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    height: 100vh;
    overflow: hidden;
}

/* Główny kontener aplikacji */
#app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Nagłówek */
#app-header {
    background: #2c3e50;
    color: white;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

#app-header h1 {
    font-size: 1.5rem;
    font-weight: 500;
}

#app-logo {
    height: 55px;
    width: auto;
    display: block;
}

#coords-display {
    font-size: 0.9rem;
    opacity: 0.9;
}

/* Główna zawartość - layout 3-kolumnowy */
#main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Panele boczne */
#sidebar-container {
    width: 250px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-right: none;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

#tools-panel {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

#results-panel {
    width: 300px;
    min-width: 200px;
    max-width: 600px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-left: none;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    flex-shrink: 0;
}

/* Resize handles (both left and right) */
#left-resize-handle,
#right-resize-handle {
    width: 4px;
    background: #dee2e6;
    cursor: ew-resize;
    position: relative;
    flex-shrink: 0;
    transition: background-color 0.2s;
}

#left-resize-handle:hover,
#right-resize-handle:hover {
    background: #007bff;
}

#left-resize-handle::before,
#right-resize-handle::before {
    content: '';
    position: absolute;
    top: 0;
    left: -2px;
    right: -2px;
    bottom: 0;
    background: transparent;
}

/* Resizing state styles */
body.panel-resizing {
    cursor: ew-resize !important;
    user-select: none !important;
}

body.panel-resizing * {
    cursor: ew-resize !important;
    user-select: none !important;
}

/* Visual indicator for resize handles */
#left-resize-handle::after,
#right-resize-handle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2px;
    height: 20px;
    background: rgba(0, 123, 255, 0.3);
    border-radius: 1px;
    opacity: 0;
    transition: opacity 0.2s;
}

#left-resize-handle:hover::after,
#right-resize-handle:hover::after {
    opacity: 1;
}

/* Sekcje w panelach */
.panel-section {
    padding: 1rem;
    border-bottom: 1px solid #dee2e6;
}

/* Special layout for chat section - keep it at bottom */
.panel-section:has(#geochat-panel) {
    margin-top: auto;
    border-bottom: none;
}

/* Fallback for browsers that don't support :has() */
.panel-section:last-child {
    margin-top: auto;
    border-bottom: none;
}

.panel-section h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
    color: #495057;
}

/* Hide export section - functionality preserved in geometry popups */
.panel-section:has(#export-btn) {
    display: none;
}

/* Kontener mapy */
#map-container {
    flex: 1;
    position: relative;
}

#map {
    width: 100%;
    height: 100%;
}

/* Przyciski */
button:not(.geochat-send) {
    background: #ffffff;
    color: rgb(0, 0, 0);
    border: rgb(0, 0, 0);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s;
}

button:not(.geochat-send):hover:not(:disabled) {
    background: #ffffff;
}

button:not(.geochat-send):disabled {
    background: #ffffff;
    cursor: not-allowed;
    opacity: 0.6;
}

/* Licznik działek */
#parcels-count {
    background: #e9ecef;
    padding: 0.5rem;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

/* Responsywność - ukryj panele na małych ekranach */
@media (max-width: 1024px) {
    #tools-panel, #results-panel {
        width: 250px;
    }
}

@media (max-width: 768px) {
    #main-content {
        position: relative;
    }
    
    #tools-panel, #results-panel {
        position: absolute;
        z-index: 1000;
        height: 100%;
        display: none; /* Domyślnie ukryte na mobile */
    }
}
/* Dodatkowe style dla etapu 2 */

/* Współrzędne - więcej miejsca na 2 linie */
#coords-display {
    font-size: 0.8rem;
    line-height: 1.4;
    text-align: right;
    min-width: 400px;
}

#current-coords {
    white-space: pre-line;  /* Preserve line breaks from \n */
    display: inline-block;
    vertical-align: top;
}

/* Panel warstw */
#layers-control h4 {
    font-size: 0.9rem;
    font-weight: 600;
    color: #2c3e50;
    margin-top: 0;
}

#layers-control label {
    font-size: 0.9rem;
    padding: 0.25rem 0;
}

#layers-control label:hover {
    background: #e9ecef;
    padding-left: 0.5rem;
    margin-left: -0.5rem;
    margin-right: -0.5rem;
    padding-right: 0.5rem;
}

#layers-control hr {
    border: none;
    border-top: 1px solid #dee2e6;
}

/* Kontrolki Leaflet - dopasowanie do naszego stylu */
.leaflet-control-zoom a {
    color: #2c3e50 !important;
}

.leaflet-control-scale {
    font-size: 11px;
}

/* Ukryj domyślną kontrolkę warstw Leaflet */
.leaflet-control-layers {
    display: none;
}

/* Animacja przy zmianie warstw */
.leaflet-tile-container {
    transition: opacity 0.3s;
}
/* Style dla narzędzi rysowania - Etap 3 */

/* Przyciski narzędzi */
.tool-button {
    display: block;
    width: 100%;
    margin-bottom: 0.5rem;
    padding: 0.75rem;
    font-size: 0.9rem;
    text-align: left;
    border: 1px solid #dee2e6;
    background: white;
    transition: all 0.2s;
}

.tool-button:hover:not(:disabled) {
    background: #e9ecef;
    border-color: #007bff;
    transform: translateX(2px);
}

.tool-button.active {
    background: #007bff;
    color: white;
    border-color: #007bff;
}

.tool-button.danger {
    color: #dc3545;
}

.tool-button.danger:hover:not(:disabled) {
    background: #dc3545;
    color: white;
    border-color: #dc3545;
}

/* Informacja o powierzchni */
.area-info {
    margin-top: 1rem;
    padding: 0.75rem;
    background: #e8f4f8;
    border: 1px solid #b8e0e8;
    border-radius: 4px;
    font-size: 0.9rem;
    text-align: center;
}

.area-info span {
    font-weight: 600;
    color: #0c5460;
}

/* Popup poligonu */
.polygon-popup {
    min-width: 150px;
}

.polygon-popup strong {
    color: #2c3e50;
}

.polygon-popup small {
    color: #6c757d;
}

/* Kursor podczas rysowania */
.leaflet-container.drawing-cursor {
    cursor: crosshair !important;
}

/* Style dla kontrolek Leaflet.draw */
.leaflet-draw-toolbar a {
    background-color: white;
}

.leaflet-draw-actions {
    top: 0;
    right: 0;
    margin-top: 0;
}

.leaflet-draw-actions a {
    background-color: white;
    border: 1px solid #ccc;
    color: #333;
}

/* Tooltip podczas rysowania */
.leaflet-draw-tooltip {
    background: rgba(0, 0, 0, 0.8);
    border: none;
    color: white;
    font-size: 12px;
    padding: 4px 8px;
    white-space: nowrap;
}

/* Ukryj domyślną kontrolkę draw */
.leaflet-draw {
    display: none;
}

/* Responsywność panelu narzędzi */
@media (max-width: 1024px) {
    .tool-button {
        font-size: 0.85rem;
        padding: 0.5rem;
    }
}
/* Popup z danymi poligonu - draggable window */
.data-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    /* Transparent background to see map */
    background: transparent;
    pointer-events: none;
    z-index: 2000;
}

.data-popup {
    position: absolute;
    top: 60px;
    right: 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    width: 450px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    pointer-events: auto;
    resize: both;
    overflow: auto;
    min-width: 350px;
    min-height: 300px;
}

.popup-header {
    padding: 1rem;
    border-bottom: 1px solid #dee2e6;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: move;
    background: #f8f9fa;
    user-select: none;
}

.popup-header:hover {
    background: #e9ecef;
}

.popup-header h3 {
    margin: 0;
    color: #2c3e50;
}

.popup-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6c757d;
}

.popup-close:hover {
    color: #dc3545;
}

.popup-content {
    padding: 1rem;
    overflow-y: auto;
    flex: 1;
}

.data-section {
    margin-bottom: 1.5rem;
}

.data-section h4 {
    margin: 0 0 0.5rem 0;
    color: #495057;
    font-size: 1rem;
}

.data-section p {
    margin: 0.25rem 0;
    font-size: 0.9rem;
}

.vertices-textarea, .uldk-response {
    width: 100%;
    min-height: 100px;
    padding: 0.5rem;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.85rem;
    resize: vertical;
}

.uldk-response {
    min-height: 150px;
}

.link-container {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.uldk-link {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.85rem;
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
}

.info-text {
    font-size: 0.85rem;
    color: #6c757d;
    font-style: italic;
}

.popup-footer {
    padding: 1rem;
    border-top: 1px solid #dee2e6;
    text-align: right;
}

.btn-primary {
    background: #007bff;
    color: white;
    border: none;
    padding: 0.5rem 1.5rem;
    border-radius: 4px;
    cursor: pointer;
}

.btn-primary:hover {
    background: #0056b3;
}

.btn-secondary {
    background: #6c757d;
    color: white;
    border: none;
    padding: 0.5rem 1.5rem;
    border-radius: 4px;
    cursor: pointer;
    margin-right: 0.5rem;
}

.btn-secondary:hover {
    background: #5a6268;
}

/* Tabela ULDK */
.uldk-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.uldk-table th {
    background: #f8f9fa;
    padding: 0.5rem;
    text-align: left;
    border: 1px solid #dee2e6;
    font-weight: 600;
}

.uldk-table td {
    padding: 0.5rem;
    border: 1px solid #dee2e6;
}

.uldk-table tr:hover {
    background: #f8f9fa;
}
/* Poprawki dla KIEG i WMS */
.leaflet-tile {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

/* Informacja o zoom dla użytkownika */
.zoom-warning {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.9);
    padding: 20px;
    border-radius: 5px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    z-index: 1000;
    display: none;
}

.zoom-warning.show {
    display: block;
}

/* =================================
   Old GeoChat styles removed - using new geochat-new.js
   ================================= */

/* Removed old chat styles - now using modern implementation in geochat-new.js */

/*
#geochat-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 350px;
    height: 450px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: all 0.3s ease;
}

#geochat-container.minimized {
    height: 50px;
}

#geochat-container.minimized .geochat-messages,
#geochat-container.minimized .geochat-input-container {
    display: none;
}

/* Header czatu */
.geochat-header {
    background: #0066cc;
    color: white;
    padding: 12px 15px;
    border-radius: 12px 12px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.geochat-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

#geochat-toggle {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 0;
    transition: background 0.2s;
}

#geochat-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Kontener wiadomości */
.geochat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    background: #f8f9fa;
}

.geochat-messages::-webkit-scrollbar {
    width: 6px;
}

.geochat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.geochat-messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

/* Wiadomości */
.geochat-message {
    margin-bottom: 12px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

.user-message {
    text-align: right;
}

.user-message .message-content {
    background: #0066cc;
    color: white;
    display: inline-block;
    padding: 8px 12px;
    border-radius: 12px 12px 4px 12px;
    max-width: 80%;
    word-wrap: break-word;
}

.bot-message .message-content {
    background: white;
    color: #333;
    display: inline-block;
    padding: 8px 12px;
    border-radius: 12px 12px 12px 4px;
    max-width: 80%;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.message-time {
    font-size: 11px;
    color: #999;
    margin-top: 4px;
}

/* Wskaźnik pisania */
.typing-indicator {
    display: inline-flex;
    align-items: center;
    padding: 8px 12px;
}

.typing-indicator span {
    height: 8px;
    width: 8px;
    background: #999;
    border-radius: 50%;
    display: inline-block;
    margin: 0 2px;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Input */
.geochat-input-container {
    padding: 12px;
    border-top: 1px solid #e9ecef;
    display: flex;
    gap: 8px;
}

#geochat-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 20px;
    outline: none;
    font-size: 14px;
    transition: border-color 0.2s;
}

#geochat-input:focus {
    border-color: #0066cc;
}

#geochat-send {
    background: #0066cc;
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: background 0.2s;
}

#geochat-send:hover:not(:disabled) {
    background: #0052a3;
}

#geochat-send:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Responsywność */
@media (max-width: 768px) {
    #geochat-container {
        width: calc(100% - 20px);
        right: 10px;
        left: 10px;
        bottom: 10px;
        height: 400px;
    }
}

/* === GeoChat – zmienne kolorów (łatwo dopasować do portalu) === */
:root {
  --geochat-bg: #2c3e50;         /* tło panelu (np. granat jak tailwind slate-900) */
  --geochat-surface: #2c3e50;    /* karty/bąbelki */
  --geochat-accent: #22c55e;     /* akcent (np. zielony) */
  --geochat-text: #e5e7eb;       /* tekst jasny */
  --geochat-muted: #9ca3af;      /* tekst drugorzędny */
  --geochat-user: #2c3e50;       /* bąbelek użytkownika */
  --geochat-bot: #0b5;           /* pasek typing dots (dziedziczy akcent) */
}

/* Kontener */
#geochat-container {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: 360px;
  max-height: 60vh;
  display: flex;
  flex-direction: column;
  background: var(--geochat-bg);
  color: var(--geochat-text);
  border-radius: 12px;
  box-shadow: 0 10px 40px #2c3e50;
  overflow: hidden;
  z-index: 10000;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

#geochat-container.minimized {
  height: 44px;
  max-height: 44px;
}

#geochat-container .geochat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(90deg, #2c3e50, transparent);
  padding: 10px 12px;
  border-bottom: 1px solid #2c3e50;
}

#geochat-container .geochat-header h3 {
  margin: 0;
  font-size: 15px;
  letter-spacing: .2px;
}

#geochat-toggle {
  background: transparent;
  color: var(--geochat-text);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  width: 28px;
  height: 28px;
  cursor: pointer;
}

.geochat-messages {
  padding: 12px;
  overflow-y: auto;
  gap: 8px;
  display: flex;
  flex-direction: column;
}

.geochat-message {
  max-width: 85%;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--geochat-surface);
  line-height: 1.35;
  word-wrap: break-word;
}

.geochat-message.user-message {
  align-self: flex-end;
  background: var(--geochat-user);
}

.geochat-message .message-time {
  font-size: 11px;
  color: var(--geochat-muted);
  margin-top: 6px;
  text-align: right;
}

.geochat-input-container {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid #2c3e50;
  background: #2c3e50;
}

#geochat-input {
  flex: 1;
  background: #2c3e50;
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--geochat-text);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}

#geochat-send {
  background: var(--geochat-accent);
  border: none;
  color: #2c3e50;
  border-radius: 10px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 700;
}

/* Typing dots */
.typing .typing-indicator {
  display: flex;
  gap: 5px;
}
.typing .typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--geochat-accent);
  display: inline-block;
  animation: geochat-bounce 1.2s infinite ease-in-out;
}
.typing .typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing .typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes geochat-bounce {
  0%, 80%, 100% { transform: scale(0.8); opacity: .6; }
  40% { transform: scale(1); opacity: 1; }
}

/* Opcje wyboru */
#geochat-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 10px 8px 10px;
}
.geochat-option {
  text-align: left;
  background: rgba(34,197,94,0.12);
  color: var(--geochat-text);
  border: 1px solid rgba(34,197,94,0.35);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
}
.geochat-option:hover {
  background: rgba(34,197,94,0.2);
}
*/

/* ========================================
   Buffer Controls in Popup (Buffer Enhancement)
   ======================================== */

/* Buffer controls container in popup */
.buffer-controls {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #e0e0e0;
}

.buffer-controls label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 6px;
  color: #555;
}

.buffer-input {
  width: 100%;
  padding: 6px 8px;
  margin-bottom: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 14px;
  box-sizing: border-box;
}

.buffer-input:focus {
  outline: none;
  border-color: #2196F3;
  box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.1);
}

.popup-action-btn {
  width: 100%;
  padding: 8px 12px;
  margin-top: 6px;
  background: #2196F3;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.2s;
}

.popup-action-btn:hover {
  background: #1976D2;
}

.popup-action-btn.secondary {
  background: #4CAF50;
}

.popup-action-btn.secondary:hover {
  background: #388E3C;
}

.popup-actions {
  margin-top: 6px;
}

/* Leaflet popup adjustments for buffer controls */
.leaflet-popup-content {
  min-width: 200px;
}

.geometry-popup {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.geometry-popup h4 {
  margin: 0 0 8px 0;
  font-size: 16px;
  color: #333;
}

.geometry-popup p {
  margin: 4px 0;
  font-size: 13px;
  color: #666;
}
