/*
 * ======================
 * AREA TABLE COMPONENT
 * ======================
 * Styling for the main area detail table with street data.
 */
.area-table {
    width: 100%;
    border-collapse: collapse;
    border: 2px solid #333; /* Fixed border color, unaffected by theme */
    border-spacing: 0;
    max-width: 768px;
    margin: 0 auto;
    background-color: #ffffff; /* Always white background */
    color: #333; /* Always dark text */
}

.area-header {
    font-size: 20px;
    font-weight: 800;
}

.area-header td {
    padding: 6px 12px; /* Add padding all around */
}

.card-number {
    text-align: right;
}

.table-header {
    font-size: 18px;
    font-weight: 600;
    background-color: #f0f0f0;
    border-left: 1px solid #333;
    border-right: 1px solid #333;
}

.table-header td {
    padding: 3px 12px; /* Add padding all around */
}

.even-row {
    background-color: #f2f2f2 !important;
    border-left: 1px solid #333 !important;
    border-right: 1px solid #333 !important;
}


/*
 * ======================
 * STREET NUMBER PADDING
 * ======================
 * Add proper spacing to street number cells in the area table.
 */

/* Target second td in any row that has "row" in its class name */
tr[class*="row"] > td:nth-child(2) {
    padding-left: 15px; /* Add padding to the left side */
    padding-right: 6px; /* Add padding to the right side as well */
    max-width: 270px;
}

/* Ensure proper vertical padding too for better spacing */
tr[class*="row"] > td {
    padding-top: 1px;
    padding-bottom: 1px;
}




/*
 * ======================
 * EXPORT FUNCTIONALITY
 * ======================
 * Styling related to the capture and export of area maps.
 */
#capture-area {
    width: 100%;
    max-width: 768px;
    margin: 0 auto;
    /* Export card is theme-independent: always light (PNG parity). */
    border: 2px solid #333;
    background: #ffffff;
    box-sizing: border-box;
}

/* .exporting is set on #capture-area during html2canvas capture. It must
   NOT resize anything — the export is a raster downscale of the live view
   exactly as composed (WYSIWYG), and any live resize/reframe here reloads
   tiles and shifts panes mid-capture (seams, gray patches, wrong framing).
   The fixed PNG width comes from the html2canvas scale factor instead. */

/* Map container styling (inside the theme-independent export card). */
.map-container {
    width: 100%;
    margin: 0 auto;
    border-top: 2px solid #333;
    border-bottom: 2px solid #333;
    height: 300px; /* Default height for small screens */
    position: relative;
    overflow: hidden;
}

/* Responsive map heights */
@media (min-width: 768px) {
    .map-container {
        height: 350px;
    }
}

@media (min-width: 992px) {
    .map-container {
        height: 400px;
    }
}

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

/*
 * ======================
 * MAP COMPONENT STYLING
 * ======================
 * Leaflet map customizations specific to the area detail view.
 */
/* Hide attribution */
.leaflet-attribution-flag {
    display: none !important;
}

/* Control visibility for export mode */
.hide-leaflet-controls .leaflet-control-container {
    display: none;
}

.hide-leaflet-controls .leaflet-control-attribution { display: none; }
.hide-leaflet-controls .leaflet-marker-icon { display: none; }
.hide-leaflet-controls .custom-text-marker { display: block; }

/*
 * ======================
 * MAP MARKERS
 * ======================
 * Styling for address markers on the map with grouping by street.
 */
.marker-address {
    /* Set fixed dimensions for a perfect circle */
    width: 25px !important;
    height: 25px !important;

    /* Center the content inside the circle */
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    text-align: center;

    /* Keep the circle shape */
    border-radius: 50% !important;

    /* Other styling */
    font-weight: 900 !important;
    font-size: 16px !important;
    text-shadow: 0px 0px 2px white, 0px 0px 1px white !important;
    color: #333 !important; /* Ensure text color is dark */
    border: 4px solid #333 !important;
    background-color: rgba(218, 210, 185, 0.6) !important;
}

/* Street group marker colors */
.marker-group-1 {
    border-color: #ff7f00 !important; /* Orange */
}

.marker-group-2 {
    border-color: #377eb8 !important; /* Blue */
}

.marker-group-3 {
    border-color: #4daf4a !important; /* Green */
}

.marker-group-4 {
    border-color: #984ea3 !important; /* Purple */
}

.marker-group-5 {
    border-color: #e41a1c !important; /* Red */
}

.marker-group-6 {
    border-color: #ffff33 !important; /* Yellow */
}

/*
 * ======================
 * STREET GROUP STYLING
 * ======================
 * Visual indicators for street groups in the table rows.
 */
/* Street group colors for table cells */
tr[class*="street-group"] > td:first-child {
    padding-left: 12px !important;
    background-image: linear-gradient(to right, transparent 0%, transparent 100%);
    background-position: left center;
    background-repeat: no-repeat;
    background-size: 6px 80%;
}

tr.street-group-1 > td:first-child {
    background-image: linear-gradient(to right, #ff7f00 0%, #ff7f00 100%); /* Orange */
}

tr.street-group-2 > td:first-child {
    background-image: linear-gradient(to right, #377eb8 0%, #377eb8 100%); /* Blue */
}

tr.street-group-3 > td:first-child {
    background-image: linear-gradient(to right, #4daf4a 0%, #4daf4a 100%); /* Green */
}

tr.street-group-4 > td:first-child {
    background-image: linear-gradient(to right, #984ea3 0%, #984ea3 100%); /* Purple */
}

tr.street-group-5 > td:first-child {
    background-image: linear-gradient(to right, #e41a1c 0%, #e41a1c 100%); /* Red */
}

tr.street-group-6 > td:first-child {
    background-image: linear-gradient(to right, #ffff33 0%, #ffff33 100%); /* Yellow */
}

/*
 * ======================
 * TABULATOR INTEGRATION
 * ======================
 * Custom styling for the Tabulator table component.
 */

.address-table-container {
    margin: 1px 0;
    background-color: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 5px;
    padding: 15px;
    box-shadow: 0 1px 3px rgb(0 0 0 / 44%);
}


/* Dark theme for the vendored Tabulator grid (edit mode).
   tabulator.min.css ships light-only; these overrides re-skin it with the
   surface tokens. Two surface groups, selectors merged with :is().
   NOTE :is() takes the specificity of its MOST specific member — that's why
   .tabulator-row-even and .tabulator-selected stay as standalone rules
   below: folded into the :is() groups they'd outrank each other in the
   wrong order (row-even would beat selected). */
html[data-theme="dark"] :is(
    .tabulator,
    .tabulator .tabulator-tableholder,
    .tabulator .tabulator-tableholder .tabulator-table) {
    background-color: var(--surface);
    color: var(--text-color);
    border-color: var(--border-color);
}
/* .tabulator-row stays OUT of the group above for the same reason as the
   even/selected rules: the :is() group's (0,3,0) specificity would beat
   them and kill the striping and selection highlight. */
html[data-theme="dark"] .tabulator-row {
    background-color: var(--surface);
    color: var(--text-color);
    border-color: var(--border-color);
}
html[data-theme="dark"] :is(
    .tabulator .tabulator-header,
    .tabulator .tabulator-header .tabulator-col,
    .tabulator .tabulator-header .tabulator-col .tabulator-col-content,
    .tabulator .tabulator-footer,
    .tabulator-group,
    .tabulator-edit-select-list,
    .tabulator-row .tabulator-cell.tabulator-editing input,
    .tabulator-row .tabulator-cell.tabulator-editing select) {
    background-color: var(--surface-2);
    color: var(--text-color);
    border-color: var(--border-color);
}
html[data-theme="dark"] .tabulator-row .tabulator-cell {
    border-color: var(--border-color);
}
html[data-theme="dark"] .tabulator-row.tabulator-row-even {
    background-color: var(--surface-2);
}
html[data-theme="dark"] .tabulator-row.tabulator-selected {
    background-color: #1c4a6e;
}

/* Group styling in Tabulator */
.tabulator-group.street-group-1 {
    border-left: 4px solid #ff7f00 !important;
    background-color: rgba(255, 127, 0, 0.1) !important;
}

.tabulator-group.street-group-2 {
    border-left: 4px solid #377eb8 !important;
    background-color: rgba(55, 126, 184, 0.1) !important;
}

.tabulator-group.street-group-3 {
    border-left: 4px solid #4daf4a !important;
    background-color: rgba(77, 175, 74, 0.1) !important;
}

.tabulator-group.street-group-4 {
    border-left: 4px solid #984ea3 !important;
    background-color: rgba(152, 78, 163, 0.1) !important;
}

.tabulator-group.street-group-5 {
    border-left: 4px solid #e41a1c !important;
    background-color: rgba(228, 26, 28, 0.1) !important;
}

.tabulator-group.street-group-6 {
    border-left: 4px solid #ffff33 !important;
    background-color: rgba(255, 255, 51, 0.1) !important;
}

/*
 * ======================
 * AREA STATISTICS
 * ======================
 * Styling for the area statistics and status panels.
 */
.area-stats-container,
.area-check-container,
.area-loan-container {
    margin: 1px 0;
    background-color: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 5px;
    padding: 15px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.area-stats-table {
    width: 100%;
    border-collapse: collapse;
}

.area-stats-table td,
.check-status {
    padding: 8px;
}

.area-stats-table tr:last-child td {
    border-bottom: none;
}

.area-stats-table td:first-child,
.check-status .status-indicator {
    font-weight: bold;
    color: var(--text-color, #495057);
}

.area-check-container h3 {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.area-stats-table td:last-child {
    text-align: right;
    color: var(--text-color, #212529);
}

/*
 * ======================
 * EDIT MODE
 * ======================
 * Editing controls (save/delete-version/alignment/add-remove street+house)
 * only matter to someone actively editing — showing them all the time to
 * every editor cluttered the page. They're marked .edit-control in the
 * template and hidden until #edit-mode-switch is checked, which toggles
 * .edit-mode on the page container (area-edit.js).
 */
.edit-control {
    display: none;
}
.edit-mode .edit-control {
    display: inline-block;
}
.edit-mode .edit-control.edit-control-flex {
    display: flex;
}
.edit-mode .edit-control.edit-control-block {
    display: block;
}

/* Two mutually-exclusive sub-modes (area-edit.js): editing the boundary
   polygon and editing streets/buildings show unrelated map content, so each
   hides what the other needs. Boundary mode's red editable-polygon overlay
   is added/removed by JS directly (it's a raw Leaflet layer, not something
   CSS can reach); building markers ARE plain DOM icons, so hiding them here
   is simpler than threading visibility through Leaflet layer state. */
body.submode-boundary .marker-address {
    /* .marker-address itself sets display:flex !important (below) — has
       to be matched here or this rule silently loses regardless of
       selector specificity. */
    display: none !important;
}

.edit-mode-toggle {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
.edit-mode-toggle .edit-mode-label {
    font-weight: 600;
}

/*
 * ======================
 * VERSION SELECTOR
 * ======================
 * Area version selection component.
 */
.version-selector {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    width: 100%;
}

.version-selector label {
    margin-right: 10px;
    color: var(--text-color, #333);
}

.version-selector select {
    padding: 5px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background-color: var(--surface-2);
    color: var(--text-color);
}

/*
 * ======================
 * AREA NOTES COMPONENT
 * ======================
 * Styling for the notes section, cards, and editing functionality.
 */
.notes-section {
    padding: 15px;
    background-color: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgb(0 0 0 / 44%);
    margin-bottom: 15px;
}

.notes-container {
    margin-bottom: 15px;
    max-height: 500px;
    overflow-y: auto;
}

.note-card {
    background-color: var(--surface-2);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.note-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.9em;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

.note-author {
    font-weight: bold;
    color: var(--text-color);
}

.note-date {
    color: var(--muted-text);
}

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

.note-content {
    white-space: pre-wrap;
    color: var(--text-color);
}

.edit-note-textarea {
    width: 100%;
    min-height: 80px;
    padding: 8px;
    margin-bottom: 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--surface);
    color: var(--text-color);
}

.edit-note-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.no-notes {
    font-style: italic;
    color: var(--muted-text);
}

.add-note-container {
    margin-top: 15px;
}

#new-note-text {
    width: 100%;
    min-height: 80px;
    padding: 8px;
    margin-bottom: 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--surface-2);
    color: var(--text-color);
}

/* Note button styling */
.edit-note-btn, .delete-note-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--muted-text);
    padding: 3px;
}

.edit-note-btn:hover {
    color: var(--primary-color, #007bff);
}

.delete-note-btn:hover {
    color: var(--danger-color);
}

/*
 * ======================
 * ALIGNMENT TOOLS
 * ======================
 * Styling for the marker alignment feature components.
 */
.alignment-line {
    stroke: #ff6b6b;
    stroke-width: 3;
    stroke-dasharray: 5,5;
    pointer-events: all;
    cursor: crosshair;
}

.alignment-handle {
    fill: #ff4757;
    cursor: move;
    stroke: white;
    stroke-width: 2;
}

.alignment-control-point {
    fill: var(--primary-color, #3498db);
    cursor: move;
    stroke: white;
    stroke-width: 2;
}

.marker-selected {
    border: 3px solid #ff6348 !important;
    box-shadow: 0 0 8px rgba(255, 99, 72, 0.8);
    z-index: 1000 !important;
}

/* Tooltip style for alignment instructions */
.alignment-tooltip {
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    pointer-events: none;
}

/*
 * ======================
 * LAYOUT STRUCTURE
 * ======================
 * Area-specific layout structure with responsive behavior.
 */
/* Main content area for two-column layout */
.main-content {
    display: flex;
    flex-direction: column;
    width: 100%;
}

/* Left column: export card + loan ledger stacked under it. */
.left-column-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
}

/* Right side container for stats and controls */
.right-column-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
}

/* For wider screens, use a two-column layout for top content */
@media (min-width: 1100px) {
    .main-content {
        flex-direction: row;
        align-items: flex-start;
        gap: 20px;
    }

    .left-column-container {
        flex: 0 0 auto;
        width: 65%;
        max-width: 768px;
        margin-right: 20px;
        margin-bottom: 0;
    }

    .right-column-container {
        flex: 1;
        min-width: 300px;
    }

    /* Keep notes section and address table full width below */
    .notes-section,
    #address-table,
    .table-controls,
    .alignment-tools {
        width: 100%;
    }
}

/* "Working on: <street> <house #>" indicator under the table toolbar.
   Block with reserved height: text appearing on row-select must not shift
   the table below mid-interaction (it broke double-click-to-edit). */
.table-selection-hint {
    display: block;
    /* Fixed, not min-: a min-height below the line height still grew 4 px
       and the table re-render closed the cell editor (2026-11-21). */
    height: 1.6em;
    line-height: 1.6em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 0.35em;
    font-size: 0.85rem;
    color: var(--muted-text);
}

/* Full-width container for elements below the two columns */
.full-width-container {
    width: 100%;
    margin-top: 20px;
}

/*
 * ======================
 * MOBILE RESPONSIVENESS
 * ======================
 * Specific adjustments for smaller screens.
 */
@media (max-width: 850px) {
    .area-header {
        font-size: 18px;
    }

    .street-cell {
        min-width: auto;
    }
}

/*
 * ======================
 * SVG AREA BOUNDARY
 * ======================
 * Styling for the area boundary on maps.
 */
.area-boundary,
.svg-boundary {
    stroke: red;
    stroke-width: 4;
    fill: red;
    fill-opacity: 0;
    vector-effect: non-scaling-stroke; /* Maintains stroke width regardless of scaling */
}

.leaflet-overlay-pane {
    z-index: 410 !important; /* Ensure overlay pane is above other elements */
}

.leaflet-overlay-pane path[stroke="red"],
.leaflet-overlay-pane path[stroke="#ff0000"] {
    stroke-linecap: round;
    stroke-linejoin: round;
    vector-effect: non-scaling-stroke;
}

/*
 * ======================
 * AREAS LIST COMPONENTS
 * ======================
 * Styling for the areas listing page elements.
 */
/* .area-stats / .stat-box / .stat-label moved to core styles.css — the loan
   dashboard and home page use them too and don't load this file. */

.filter-controls {
    margin: 20px 0;
    padding: 10px;
    background-color: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 5px;
}

.filter-controls label {
    margin-right: 15px;
}

/* .area-item is a JS/data hook on the areas-list table rows (delete button
   finds its row via .closest('.area-item')) — the rows are styled by the
   shared .area-table-list rules in core styles.css. The old card styling
   that used to live here predated the table layout and no longer applied
   meaningfully to a <tr>.
   .area-actions (page-header button row) is the shared component in core
   styles.css — don't redefine it here. */

/* .delete-btn is a JS hook only (areas.html row delete) — its look comes
   from the shared .btn .btn-sm .btn-danger classes; don't re-style it here. */

/* .status-badge itself is the shared component in core styles.css — see the
   comment there. This page only adds the count/margin utility for its
   inline placement next to the "Area Status" heading. */
.status-badge {
    margin-left: auto;
}

.admin-badge {
    font-size: 16px;
    margin-left: 5px;
    opacity: 0.7;
}

/* @mention highlight in area notes. */
.note-content .mention {
    color: var(--primary-color);
    font-weight: 600;
    background: rgba(52, 152, 219, 0.12);
    border-radius: 3px;
    padding: 0 2px;
}

/* Building/address enrichment status — shown while process_area_data_background
   (Overpass + Mapy.cz) runs after a boundary is drawn or edited, so the user
   isn't left guessing whether a still-empty map means "working" or "broken". */
.enrichment-status-banner[hidden] {
    display: none;
}

.enrichment-status-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    margin: 10px 0;
    border-radius: var(--radius);
    font-size: 14px;
    border: 1px solid transparent;
}

.enrichment-status-banner[data-state="pending"] {
    background: var(--info-bg);
    color: var(--info-text);
    border-color: var(--info-color);
}

.enrichment-status-banner[data-state="ready"] {
    background: var(--success-bg);
    color: var(--success-text);
    border-color: var(--success-color);
}

.enrichment-status-banner[data-state="error"] {
    background: var(--danger-bg);
    color: var(--danger-text);
    border-color: var(--danger-color);
}

/* GeoJSON viewer syntax highlighting (render_geojson_html fragment). */
.json-key { color: #a31515; }
.json-str { color: #0451a5; }
.json-num { color: #098658; }
.json-lit { color: #0000ff; }

[data-theme="dark"] .json-key { color: #e06c75; }
[data-theme="dark"] .json-str { color: #61afef; }
[data-theme="dark"] .json-num { color: #98c379; }
[data-theme="dark"] .json-lit { color: #c678dd; }

/* Phase 24 — mask-labels editor (area-mask-editor.js). Fullscreen: the
 * editor takes the whole viewport in one go (no window-in-window shuffling);
 * the zoom buttons rescale only the inner image inside the scrollable
 * viewport. Above the sticky navbar (z-index 1001). */
.mask-editor-modal {
    z-index: 1002;
}

.mask-editor-content {
    position: fixed;
    inset: 0;
    max-width: none;
    width: auto;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    padding: 10px 14px;
    overflow: hidden;
}

/* Single top bar: title, hint, zoom + overlay buttons, close. */
.mask-editor-header {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}
.mask-editor-header h3 {
    margin: 0;
}

.mask-hint {
    font-size: 0.85em;
    color: var(--text-color);
    opacity: 0.8;
    margin: 0;
    flex: 1;
    min-width: 180px;
}

.mask-zoom-bar {
    display: flex;
    gap: 6px;
}

.mask-viewport {
    flex: 1 1 auto;
    overflow: auto;
    border: 1px solid var(--border-color);
    background: var(--surface);
}

/* Boundary + building circles; pointer-events off so drawing and color
 * sampling always hit the tile canvas underneath. */
.mask-overlay-canvas {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
}

/* Sized (via JS) to the display-rotated grid's bounding box, so the
 * scrollable viewport actually has room for the rotated corners of .mask-stage
 * instead of clipping them. */
.mask-rotate-wrapper {
    position: relative;
}

/* Centered inside .mask-rotate-wrapper and rotated there (JS sets
 * transform: translate(-50%,-50%) rotate(deg)) — canvas + patch overlay
 * rotate together as one rigid unit, matching the bearing the area was
 * being edited at when this version was saved. */
.mask-stage {
    position: absolute;
    top: 50%;
    left: 50%;
    transform-origin: center center;
}
.mask-stage-canvas {
    display: block;
    cursor: crosshair;
    user-select: none;
    -webkit-user-drag: none;
}

/* Sits over the canvas but only its children opt back into pointer events
 * (the delete button) — everywhere else, mouse events pass through to the
 * canvas underneath so drawing works even where it overlaps an existing
 * patch. */
.mask-patch-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.mask-patch-rect,
.mask-draft-rect {
    position: absolute;
    top: 0;
    left: 0;
    box-sizing: border-box;
    border: 1px dashed rgba(0, 0, 0, 0.5);
    transform-origin: 0 0;
    pointer-events: none;
}
.mask-draft-rect {
    background: rgba(255, 0, 0, 0.25);
}

.mask-patch-delete {
    position: absolute;
    top: -10px;
    right: -10px;
    width: 18px;
    height: 18px;
    line-height: 16px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--surface);
    color: var(--danger-color);
    cursor: pointer;
    font-size: 12px;
    pointer-events: auto;
}

/* Positioned via inline left/top (JS) at the click point, in plain unrotated
 * canvas coordinates — a sibling of .mask-draft-rect, not nested inside it,
 * so it never inherits the draft rectangle's rotation. */
.mask-save-form {
    position: absolute;
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 4px;
    white-space: nowrap;
    z-index: 1;
    pointer-events: auto;
}

/* Note on an address, in the marker popup (area-map.js buildMarkerPopup). */
.address-note {
    margin: 0.25rem 0;
    padding: 0.25rem 0.4rem;
    border-left: 3px solid var(--primary-color);
    background: var(--hover-color);
    white-space: pre-wrap;
}
