/**
 * Varha-R Hankehallinta Demo - Custom Styles
 */

/* General Styles */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: #f8f9fa;
}

.container-fluid {
    max-width: 1400px;
}

/* Prevent horizontal overflow on mobile */
html, body {
    overflow-x: hidden;
    width: 100%;
}

body {
    position: relative;
}

/* Table Styles */
.table th.sortable {
    cursor: pointer;
    user-select: none;
}

.table th.sortable:hover {
    background-color: #e9ecef;
}

.table th.sortable::after {
    content: ' ⇅';
    opacity: 0.3;
}

.table th.sortable.sorted-asc::after {
    content: ' ↑';
    opacity: 1;
}

.table th.sortable.sorted-desc::after {
    content: ' ↓';
    opacity: 1;
}

.table tbody tr {
    cursor: pointer;
}

.table tbody tr:hover {
    background-color: #f8f9fa;
}

/* Form Styles */
.form-label {
    font-weight: 500;
}

.card {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

/* Dynamic List Items */
.list-item {
    position: relative;
    padding: 15px;
    margin-bottom: 10px;
    background-color: #f8f9fa;
    border-radius: 0.375rem;
    border: 1px solid #dee2e6;
}

.list-item .btn-remove {
    position: absolute;
    top: 10px;
    right: 10px;
}

/* ==================== Gantt Chart Styles (From Native Example) ==================== */
.gantt-container {
    position: relative;
    overflow-x: auto;
    min-height: 500px;
    user-select: none;
    border: 1px solid #dee2e6;
    background-color: #fff;
}

.gantt-timeline {
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
    height: 80px;
    display: flex;
    flex-direction: column;
}

.gantt-grid {
    position: relative;
    display: grid;
    grid-template-columns: 250px 1fr;
}

.gantt-labels {
    background-color: #f8f9fa;
    border-right: 1px solid #dee2e6;
    position: sticky;
    left: 0;
    z-index: 5;
    padding-top: 80px;
}

.gantt-chart-area {
    position: relative;
}

.gantt-row {
    display: flex;
    height: 40px;
    border-bottom: 1px solid #e9ecef;
    align-items: center;
}

.gantt-row-label {
    padding: 0 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.gantt-row-content {
    position: relative;
    height: 100%;
    width: 100%;
}

.gantt-timeline-cell {
    display: inline-block;
    text-align: center;
    border-right: 1px solid #dee2e6;
    padding: 5px;
    font-size: 0.85rem;
    box-sizing: border-box;
}

.gantt-grid-cell {
    height: 40px;
    border-right: 1px solid #e9ecef;
    display: inline-block;
    box-sizing: border-box;
}

.gantt-grid-row {
    position: relative;
    height: 40px;
    box-sizing: border-box;
}

.gantt-grid-cell-marker {
    position: absolute;
    top: 0;
    height: 100%;
    border-right: 1px solid #e9ecef;
    box-sizing: border-box;
}

.gantt-grid-cell-marker.bg-light {
    background-color: #f8f9fa;
}

.gantt-task-bar {
    position: absolute;
    height: 20px;
    margin-top: 10px;
    background-color: #0d6efd;
    border-radius: 4px;
    cursor: pointer;
    z-index: 1;
    box-sizing: border-box;
}

.gantt-task-bar.parent-task {
    height: 24px;
    margin-top: 8px;
    background-color: #6c757d;
    z-index: 2;
    border: 1px solid #495057;
}

.gantt-task-bar.parent-task[data-level="0"] {
    height: 28px;
    margin-top: 6px;
    background-color: #495057;
    border: 1px solid #343a40;
    font-weight: bold;
    z-index: 3;
}

.gantt-task-bar.partial-task {
    position: relative;
}

.partial-indicator {
    position: absolute;
    color: white;
    font-size: 12px;
    top: 4px;
    text-shadow: 0 0 2px rgba(0, 0, 0, 0.7);
}

.partial-indicator.left {
    left: 2px;
}

.partial-indicator.right {
    right: 2px;
}

.gantt-task-label {
    position: absolute;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: white;
    padding: 0 5px;
    font-size: 0.85rem;
    pointer-events: none;
    top: 1px;
    left: 0;
    right: 0;
}

.gantt-progress-bar {
    height: 100%;
    background-color: rgba(0, 0, 0, 0.2);
}

.gantt-today-marker {
    position: absolute;
    height: 100%;
    width: 2px;
    background-color: red;
    z-index: 4;
    top: 80px;
}

.gantt-child-marker {
    position: absolute;
    width: 10px;
    height: 10px;
    margin-top: 15px;
    cursor: pointer;
    z-index: 5;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.gantt-child-marker.diamond {
    background-color: #dc3545;
    transform: rotate(45deg);
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.gantt-child-marker.triangle {
    width: 0;
    height: 0;
    background-color: transparent;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 10px solid #fd7e14;
    box-shadow: none;
}

.gantt-child-marker.square {
    background-color: #20c997;
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.gantt-child-marker.circle {
    background-color: #0dcaf0;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.gantt-child-marker:hover {
    transform-origin: center;
    transform: scale(1.2);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
}

.gantt-child-marker.diamond:hover {
    transform: scale(1.2) rotate(45deg);
}

.gantt-task-handle-left,
.gantt-task-handle-right {
    position: absolute;
    width: 5px;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    cursor: col-resize;
    z-index: 6;
}

.gantt-task-handle-left {
    left: 0;
}

.gantt-task-handle-right {
    right: 0;
}

.dragging {
    opacity: 0.7;
}

.time-scale-year .gantt-task-bar {
    height: 18px;
    margin-top: 11px;
    min-width: 3px;
}

.time-scale-year .gantt-task-label {
    font-size: 0.7rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.time-scale-week .gantt-task-bar {
    min-width: 3px;
}

/* Loading State */
.loading {
    text-align: center;
    padding: 40px;
    color: #6c757d;
}

.loading::after {
    content: '...';
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #6c757d;
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

/* Badge Styles */
.badge {
    font-weight: 500;
}

/* Responsive Adjustments */
@media (max-width: 768px) {
    /* Prevent horizontal scroll on mobile */
    .container-fluid {
        max-width: 100vw;
        overflow-x: hidden;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    /* Ensure all view containers fit within viewport */
    .view-container {
        max-width: 100vw;
        overflow-x: auto;
    }

    .gantt-grid {
        grid-template-columns: 180px 1fr;
    }

    .gantt-labels {
        padding-top: 80px;
    }

    .gantt-label {
        padding: 8px;
        font-size: 12px;
    }

    /* Hide low-priority table columns on tablets */
    #projects-table th:nth-child(3),  /* Sijainti */
    #projects-table td:nth-child(3),
    #projects-table th:nth-child(4),  /* Toteuttamistapa */
    #projects-table td:nth-child(4) {
        display: none;
    }

    /* Touch-friendly improvements */
    #projects-table tbody tr {
        cursor: pointer;
        min-height: 44px;  /* iOS minimum touch target */
    }

    #projects-table tbody tr td {
        padding: 0.75rem 0.5rem;
    }

    /* Larger touch targets for buttons */
    .btn {
        min-height: 44px;
        min-width: 44px;
    }

    /* Larger checkbox/radio targets */
    .btn-check + .btn {
        padding: 0.5rem 1rem;
    }

    /* Increase filter dropdown touch area */
    .form-select,
    .form-control {
        min-height: 44px;
        font-size: 1rem;  /* Prevent zoom on iOS */
    }

    /* Touch feedback */
    #projects-table tbody tr:active {
        background-color: #e9ecef;
        transition: background-color 0.1s;
    }

    .btn:active {
        transform: scale(0.98);
        transition: transform 0.1s;
    }

    /* Remove hover effects (not applicable on touch) */
    #projects-table tbody tr:hover {
        background-color: transparent;
    }

    /* Fix header and navigation to prevent overflow */
    header {
        max-width: 100vw;
        overflow-x: hidden;
    }

    h1, h1.h3 {
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    /* Fix tab navigation */
    .nav-tabs {
        flex-wrap: wrap;
    }

    /* Ensure buttons don't cause overflow */
    .mb-3.d-flex {
        max-width: 100%;
    }

    .btn-group {
        flex-wrap: wrap;
    }
}

/* Large phones and small tablets (640px) */
@media (max-width: 640px) {
    .gantt-grid {
        grid-template-columns: 140px 1fr;
    }

    .gantt-timeline {
        height: 60px;
    }

    .gantt-labels {
        padding-top: 60px;
        font-size: 0.85rem;
    }

    .gantt-today-marker {
        top: 60px;
    }

    /* Stack width controls below view buttons */
    .mb-3.d-flex.justify-content-between {
        flex-direction: column;
        align-items: stretch !important;
        gap: 0.5rem;
    }

    #gantt-width-controls-container {
        order: 3;
    }

    .btn-group {
        order: 1;
    }

    button#btn-new-project {
        order: 0;
        width: 100%;
    }
}

/* Standard phones (480px - iPhone 12/13/14, Galaxy S21) */
@media (max-width: 480px) {
    .gantt-grid {
        grid-template-columns: 120px 1fr;
    }

    .gantt-timeline {
        height: 50px;
        font-size: 0.75rem;
    }

    .gantt-labels {
        padding-top: 50px;
        font-size: 0.8rem;
    }

    .gantt-today-marker {
        top: 50px;
    }

    .gantt-timeline-cell {
        font-size: 0.7rem;
        padding: 3px;
    }

    /* Task list row padding */
    .gantt-row-label {
        padding: 0 5px;
        font-size: 0.8rem;
    }

    /* Hide "Avaa/Sulje kaikki" button text, keep icon */
    #toggle-all-tasks-btn {
        font-size: 0;
        padding: 0.375rem 0.5rem;
    }

    #toggle-all-tasks-btn #toggle-all-tasks-icon {
        font-size: 1rem;
    }

    /* Reduce filter card padding */
    .card-body {
        padding: 0.75rem;
    }

    /* Stack filter dropdowns */
    .row.g-3 .col-md-3 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* Hide more table columns on phones */
    #projects-table th:nth-child(2),  /* Palvelualue */
    #projects-table td:nth-child(2),
    #projects-table th:nth-child(7),  /* Keskeiset Päivämäärät */
    #projects-table td:nth-child(7) {
        display: none;
    }

    /* Keep only: Name, Phase, Investment */
    #projects-table {
        font-size: 0.85rem;
    }

    #projects-table th,
    #projects-table td {
        padding: 0.5rem 0.25rem;
    }
}

/* Small phones (375px - iPhone SE, Galaxy S8) */
@media (max-width: 375px) {
    .gantt-grid {
        grid-template-columns: 100px 1fr;
    }

    .gantt-timeline {
        height: 45px;
        font-size: 0.7rem;
    }

    .gantt-labels {
        padding-top: 45px;
        font-size: 0.75rem;
    }

    .gantt-today-marker {
        top: 45px;
    }

    .gantt-timeline-cell {
        font-size: 0.65rem;
        padding: 2px;
    }

    .gantt-row-label {
        padding: 0 3px;
        font-size: 0.75rem;
    }

    /* View toggle buttons smaller */
    .btn-group label {
        font-size: 0.75rem;
        padding: 0.25rem 0.5rem;
    }

    /* Header title smaller */
    h1.h3 {
        font-size: 1.25rem;
    }

    h1.h3 small {
        display: block;
        margin-top: 0.25rem;
    }

    /* Ultra-minimal table on small phones */
    #projects-table {
        font-size: 0.8rem;
    }

    #projects-table th,
    #projects-table td {
        padding: 0.4rem 0.2rem;
    }

    /* Wrap long project names */
    #projects-table td:first-child {
        word-break: break-word;
        white-space: normal;
    }
}

/* Landscape mode on mobile - optimize for horizontal space */
@media (max-width: 768px) and (orientation: landscape) {
    .gantt-grid {
        grid-template-columns: 160px 1fr;
    }

    .gantt-timeline {
        height: 50px;
    }

    .gantt-labels {
        padding-top: 50px;
    }

    .gantt-today-marker {
        top: 50px;
    }

    /* Reduce header size in landscape */
    h1.h3 {
        font-size: 1.25rem;
        margin-bottom: 0.5rem;
    }

    /* Filters can be hidden in landscape to save vertical space */
    .card.mb-3 {
        margin-bottom: 0.5rem !important;
    }
}

/* Print Styles */
@media print {
    .btn, .nav-tabs, .card-header button {
        display: none !important;
    }

    .gantt-container {
        max-height: none;
        overflow: visible;
    }
}

/* Gantt Container Heights */
#task-gantt-container {
    min-height: 600px;
    height: auto;
}

#view-task-gantt-container {
    min-height: 650px;
}

/* ==================== Hankekortti Read View Styles ==================== */

/* Header Card */
.hankekortti-header {
    background: linear-gradient(135deg, #f8f9fa 0%, #fff 100%);
    border-left: 4px solid #0d6efd;
}

.hankekortti-header h3 {
    font-weight: 600;
    color: #212529;
}

/* Metrics Cards */
.hankekortti-metric {
    border: none;
    background: linear-gradient(135deg, #fff 0%, #f8f9fa 100%);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.hankekortti-metric:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.hankekortti-metric .h4 {
    font-weight: 600;
    color: #0d6efd;
}

.hankekortti-metric small {
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 0.7rem;
}

/* Read View Section Styling */
.hankekortti-view-section {
    margin-bottom: 1rem;
}

.hankekortti-view-section .card-header {
    background-color: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
}

.hankekortti-view-section .card-header .btn-link {
    font-weight: 600;
    color: #212529;
    padding: 0;
}

.hankekortti-view-section .card-header .btn-link:hover {
    color: #0d6efd;
    text-decoration: none;
}

/* Field Display */
.hankekortti-field {
    margin-bottom: 0.75rem;
}

.hankekortti-field-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 500;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 0.15rem;
}

.hankekortti-field-value {
    font-size: 0.95rem;
    color: #212529;
}

.hankekortti-field-value.empty {
    color: #adb5bd;
    font-style: italic;
}

/* Subsection Headers */
.hankekortti-subsection-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: #495057;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid #e9ecef;
}

/* List Items in Read View */
.hankekortti-list {
    list-style: none;
    padding-left: 0;
    margin-bottom: 0;
}

.hankekortti-list li {
    padding: 0.5rem 0;
    border-bottom: 1px solid #f1f3f5;
}

.hankekortti-list li:last-child {
    border-bottom: none;
}

/* Schedule Phase Display */
.hankekortti-schedule-phase {
    padding: 0.5rem 0;
    border-bottom: 1px solid #f1f3f5;
}

.hankekortti-schedule-phase:last-child {
    border-bottom: none;
}

.hankekortti-schedule-phase .phase-name {
    font-weight: 500;
    color: #212529;
}

.hankekortti-schedule-phase .phase-dates {
    font-size: 0.85rem;
    color: #6c757d;
}

.hankekortti-schedule-phase .progress {
    height: 6px;
    margin-top: 0.25rem;
}

/* Contact Cards in Read View */
.hankekortti-contact {
    background-color: #f8f9fa;
    border-radius: 0.375rem;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
}

.hankekortti-contact .contact-name {
    font-weight: 600;
    color: #212529;
}

.hankekortti-contact .contact-role {
    font-size: 0.8rem;
    color: #6c757d;
}

.hankekortti-contact .contact-info {
    font-size: 0.85rem;
    color: #495057;
}

/* Decision Document Cards */
.hankekortti-document {
    background-color: #f8f9fa;
    border-radius: 0.375rem;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    border-left: 3px solid #0d6efd;
}

.hankekortti-document .document-name {
    font-weight: 600;
    color: #212529;
}

.hankekortti-document .document-meta {
    font-size: 0.8rem;
    color: #6c757d;
}

/* Links in Read View */
.hankekortti-link {
    color: #0d6efd;
    text-decoration: none;
}

.hankekortti-link:hover {
    text-decoration: underline;
}

/* Empty Section State */
.hankekortti-empty {
    text-align: center;
    padding: 1.5rem;
    color: #6c757d;
    font-style: italic;
}

/* Badge for Phase/Status */
.hankekortti-badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 0.25rem;
    background-color: #e9ecef;
    color: #495057;
}

.hankekortti-badge.phase-rakentaminen {
    background-color: #d4edda;
    color: #155724;
}

.hankekortti-badge.phase-suunnittelu {
    background-color: #cce5ff;
    color: #004085;
}

.hankekortti-badge.phase-kayttoonotto {
    background-color: #fff3cd;
    color: #856404;
}

/* Responsive Adjustments for Read View */
@media (max-width: 768px) {
    .hankekortti-header .d-flex {
        flex-direction: column;
        gap: 1rem;
    }

    .hankekortti-header .d-flex > div:last-child {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .hankekortti-header .d-flex > div:last-child .btn {
        flex: 1 1 auto;
    }

    #view-metrics-row .col-md-4 {
        margin-bottom: 0.5rem;
    }

    .hankekortti-metric .h4 {
        font-size: 1.25rem;
    }
}

@media (max-width: 480px) {
    .hankekortti-field-label {
        font-size: 0.7rem;
    }

    .hankekortti-field-value {
        font-size: 0.9rem;
    }

    .hankekortti-metric .card-body {
        padding: 0.5rem;
    }

    .hankekortti-metric .h4 {
        font-size: 1rem;
    }
}
