/* Responsive */

/* Global safety */
*,
*::before,
*::after {
    box-sizing: border-box;
}

/* Remove tap highlight on interactive elements globally */
button,
[role="button"],
a,
.nav-item,
.btn-primary,
.btn-secondary,
.btn-danger,
.btn-icon,
.btn-sm {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* 1400px */

@media (max-width: 1400px) {
    .dashboard-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* 1180px: tablet landscape */

@media (max-width: 1180px) {
    .dashboard-grid,
    .dash-bottom-row,
    .projects-grid,
    .notes-grid,
    .prompts-grid-layout,
    .instr-admin-grid,
    .instr-grid {
        grid-template-columns: 1fr;
    }

    .calendar-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .month-grid,
    .month-header-row {
        grid-template-columns: 30px repeat(7, minmax(0, 1fr));
        gap: 4px;
    }

    .dtp-layout {
        grid-template-columns: 1fr;
    }

    .dtp-visual {
        flex-direction: row;
        align-items: center;
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .admin-stat-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* 980px: tablet */

@media (max-width: 980px) {
    html,
    body {
        min-height: 100%;
        height: auto;
        overflow-x: hidden;
        overflow-y: auto;
    }

    .app-shell {
        display: flex;
        flex-direction: column;
        min-height: 100dvh;
        height: auto;
    }

    .main-content {
        flex: 1;
        min-height: 0;
        overflow-x: clip;
        overflow-y: visible;
        padding: 20px;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
    }

    .sidebar {
        position: relative;
        z-index: 20;
        flex-shrink: 0;
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 12px;
        height: 56px;
        padding: 0 16px;
        border-right: none;
        border-bottom: 1px solid var(--sidebar-border);
        box-shadow:
            0 1px 0 rgba(255, 255, 255, 0.04),
            0 4px 16px rgba(0, 0, 0, 0.22);
    }

    .sidebar::after,
    .nav-divider,
    .sidebar-toggle-btn {
        display: none;
    }

    .logo-section {
        flex-shrink: 0;
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 0;
        margin: 0;
        border: none;
    }

    .logo-mark {
        width: 34px;
        height: 34px;
        font-size: 14px;
        border-radius: 10px;
        box-shadow: none;
    }

    .logo-copy h1 {
        margin: 0;
        font-size: 14px;
        white-space: nowrap;
    }

    .logo-copy p {
        display: none;
    }

    .nav-menu {
        flex: 1;
        min-width: 0;
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: center;
        justify-content: flex-start;
        gap: 3px;
        padding: 0 4px;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        /* Fade edges to hint at horizontal scrollability */
        -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 16px, #000 calc(100% - 16px), transparent 100%);
        mask-image: linear-gradient(90deg, transparent 0, #000 16px, #000 calc(100% - 16px), transparent 100%);
    }

    .nav-menu::-webkit-scrollbar {
        display: none;
    }

    .nav-item {
        flex: 0 0 auto;
        width: auto;
        height: 36px;
        display: flex;
        align-items: center;
        padding: 7px 12px;
        font-size: 13px;
        white-space: nowrap;
        border-radius: 10px;
    }

    /* Reset the vertical-nav hover transform for horizontal layout */
    .nav-item:hover {
        transform: none;
    }

    .nav-icon {
        width: 22px;
        height: 22px;
        margin-right: 7px;
        border-radius: 7px;
        font-size: 11px;
    }

    .sidebar-footer {
        flex-shrink: 0;
        margin-top: 0;
        padding-top: 0;
        border-top: none;
    }

    .sidebar-user-row {
        gap: 4px;
        flex-shrink: 0;
    }

    /* Controls row in horizontal topbar: inline, auto-width */
    .nav-controls-row {
        flex-shrink: 0;
        width: auto;
        gap: 3px;
    }

    .nav-controls-row .nav-theme-row,
    .nav-controls-row .nav-lang-row {
        flex: 0 0 auto;
        width: auto;
        height: 36px;
        padding: 6px 10px;
        font-size: 13px;
        border-radius: 10px;
        margin-top: 0;
    }

    .nav-controls-row .nav-theme-row .nav-label,
    .nav-controls-row .nav-lang-row .nav-label {
        display: none;
    }

    .nav-controls-row .nav-theme-row .nav-icon,
    .nav-controls-row .nav-lang-row .nav-icon {
        width: 22px;
        height: 22px;
        margin-right: 0;
        border-radius: 7px;
        font-size: 11px;
    }

    .status-pill {
        min-height: 30px;
        padding: 4px 10px;
        font-size: 11px;
        white-space: nowrap;
        border-radius: 10px;
    }

    .calendar-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .board-container {
        overflow-x: auto;
        padding-bottom: 16px;
        -webkit-overflow-scrolling: touch;
    }
}

/* 768px: large phone / small tablet */

@media (max-width: 768px) {
    /* Shrink logo in compact top bar */
    .logo-img {
        width: 110px;
    }

    .panel {
        padding: 18px;
    }

    .topbar {
        margin-bottom: 22px;
        gap: 12px;
    }

    .topbar h2 {
        font-size: 26px;
    }

    .form-group input,
    .form-group select,
    .form-group textarea,
    .flow-step-textarea,
    .prompt-note-input,
    .backlog-input,
    .auth-form input {
        font-size: 16px;
    }

    .btn-icon {
        width: 40px;
        height: 40px;
    }

    .btn-sm {
        height: 38px;
        padding: 0 14px;
    }

    .color-dot {
        width: 34px;
        height: 34px;
    }

    .stat-cards,
    .admin-stat-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dash-hero-top,
    .panel-header {
        flex-wrap: wrap;
    }

    .dash-hero {
        padding: 18px;
    }

    .dash-hero-top {
        flex-direction: column;
        align-items: stretch;
    }

    .dash-hero-actions {
        width: 100%;
        justify-content: stretch;
    }

    .admin-tabs {
        width: 100%;
        justify-content: stretch;
    }

    .admin-tab {
        flex: 1;
        padding: 9px 12px;
        text-align: center;
        font-size: 13px;
    }

    .admin-user-row {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .admin-user-meta,
    .admin-user-actions {
        flex-wrap: wrap;
    }
}

/* 680px */

@media (max-width: 680px) {
    .plc-cs-row,
    .proj-detail-cs {
        flex-direction: column;
    }

    /* Wochenvorschau: nur Mo-Fr zeigen, kein horizontales Scrollen */
    .forecast-scroll-wrap {
        overflow-x: visible;
    }

    .forecast-grid {
        grid-template-columns: repeat(5, minmax(0, 1fr));
        gap: 8px;
    }

    .forecast-day:nth-child(n+6) {
        display: none;
    }

    .forecast-card {
        min-height: 132px;
    }

    .forecast-day.non-work .forecast-card {
        min-height: 84px;
    }

    .topbar {
        flex-direction: column;
        align-items: stretch;
    }

    .topbar h2 {
        font-size: 23px;
    }

    .main-content {
        padding: 14px;
    }

    .calendar-grid,
    .prompts-grid-layout,
    .notes-grid {
        grid-template-columns: 1fr;
    }

    .board-container {
        display: flex;
        flex-direction: column;
    }

    .board-column {
        width: 100%;
    }

    .panel,
    .section-block,
    .modal {
        border-radius: 18px;
    }

    .panel {
        padding: 16px;
    }

    .day-type-controls {
        width: 100%;
    }

    .day-type-btn {
        flex: 1;
        height: 40px;
        text-align: center;
    }

    .day-budget {
        gap: 12px;
        padding: 14px 16px;
    }

    .topbar .btn-primary,
    .topbar .btn-secondary {
        width: 100%;
        justify-content: center;
    }

    .dtp-metrics {
        grid-template-columns: 1fr;
    }

    .admin-stat-grid {
        gap: 10px;
    }

    .admin-stat-card {
        padding: 16px 10px;
    }

    .admin-stat-value {
        font-size: 22px;
    }

    .instr-filter-row {
        gap: 6px;
    }

    .instr-filter-btn {
        padding: 6px 12px;
        font-size: 12px;
    }
}

/* 480px: phone with bottom navigation */

@media (max-width: 480px) {
    html,
    body {
        min-height: 100%;
        height: auto;
        overflow-x: hidden;
        overflow-y: auto;
    }

    .app-shell {
        display: block;
        min-height: 100dvh;
        height: auto;
    }

    .main-content {
        min-height: 100dvh;
        overflow-x: clip;
        overflow-y: visible;
        padding: 12px 12px calc(88px + env(safe-area-inset-bottom, 8px));
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
    }

    .logo-section,
    .sidebar-footer,
    .nav-divider {
        display: none;
    }

    .sidebar {
        position: fixed;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 50;
        display: flex;
        flex-direction: row;
        align-items: stretch;
        gap: 0;
        height: auto;
        padding: 4px 6px env(safe-area-inset-bottom, 4px);
        border-top: 1px solid var(--sidebar-border);
        border-bottom: none;
        box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.28);
        backdrop-filter: blur(18px);
        -webkit-backdrop-filter: blur(18px);
        background:
            linear-gradient(180deg, rgba(255, 255, 255, 0.03) 0%, rgba(255, 255, 255, 0.01) 100%),
            linear-gradient(180deg, var(--sidebar-2) 0%, var(--sidebar) 100%);
    }

    .nav-menu {
        flex: 1;
        min-width: 0;
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: stretch;
        justify-content: flex-start;
        gap: 2px;
        padding: 2px 0;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        /* Fade edges to hint at horizontal scrollability */
        -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 12px), transparent 100%);
        mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 12px), transparent 100%);
    }

    .nav-menu::-webkit-scrollbar {
        display: none;
    }

    .nav-item {
        flex: 1 1 0;
        min-width: 58px;
        max-width: 88px;
        min-height: 52px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        padding: 7px 4px 6px;
        font-size: 9.5px;
        letter-spacing: 0;
        white-space: nowrap;
        overflow: hidden;
        border: none;
        border-radius: 10px;
        transform: translateZ(0);
        /* Improve tap responsiveness on mobile */
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        transition:
            background 0.14s ease,
            color 0.14s ease,
            opacity 0.14s ease;
    }

    .nav-icon {
        width: 26px;
        height: 26px;
        margin-right: 0;
        border-radius: 8px;
        font-size: 12px;
        background: rgba(255, 255, 255, 0.05);
        border: 1px solid transparent;
        transition:
            background 0.14s ease,
            border-color 0.14s ease,
            box-shadow 0.14s ease,
            color 0.14s ease;
    }

    .nav-label {
        overflow: hidden;
        max-width: 100%;
        text-overflow: ellipsis;
    }

    .nav-item:hover,
    .nav-item:active {
        transform: none;
    }

    .nav-item:active .nav-icon {
        background: rgba(255, 255, 255, 0.12);
    }

    .nav-item.active {
        background: rgba(249, 115, 22, 0.12);
        border-color: transparent;
        box-shadow: none;
        color: #FCD9BD;
    }

    .nav-item.active .nav-icon {
        background: rgba(249, 115, 22, 0.22);
        border-color: rgba(249, 115, 22, 0.28);
        box-shadow: 0 0 8px rgba(249, 115, 22, 0.18);
        color: var(--accent);
    }

    .nav-item.active::before {
        display: none;
    }

    /* Theme-Toggle im mobilen Bottomnav: kompakt wie ein nav-item, aber dezenter */
    .nav-theme-row {
        flex: 1 1 0;
        min-width: 58px;
        max-width: 88px;
        min-height: 52px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        padding: 7px 4px 6px;
        font-size: 9.5px;
        letter-spacing: 0;
        white-space: nowrap;
        overflow: hidden;
        border: none;
        border-radius: 10px;
        background: transparent;
        color: var(--sidebar-text-muted);
        opacity: 0.9;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        transition:
            background 0.14s ease,
            color 0.14s ease,
            opacity 0.14s ease;
    }

    .nav-theme-row:hover,
    .nav-theme-row:active {
        background: rgba(255, 255, 255, 0.05);
        color: var(--sidebar-text);
        opacity: 1;
    }

    .nav-theme-row .nav-icon {
        width: 26px;
        height: 26px;
        margin-right: 0;
        border-radius: 8px;
        font-size: 12px;
        background: rgba(255, 255, 255, 0.05);
        border: 1px solid rgba(255, 255, 255, 0.06);
        color: var(--sidebar-text-muted);
        box-shadow: none;
        transition:
            background 0.14s ease,
            border-color 0.14s ease,
            color 0.14s ease;
    }

    .nav-theme-row:active .nav-icon {
        background: rgba(255, 255, 255, 0.1);
        border-color: rgba(255, 255, 255, 0.1);
        color: var(--sidebar-text);
    }

    .nav-theme-row .nav-label {
        overflow: hidden;
        max-width: 100%;
        text-overflow: ellipsis;
        font-size: 9.5px;
        color: inherit;
    }

    /* Pill-Switch im Bottom-Nav verstecken, zu breit */
    .nav-theme-pill {
        display: none;
    }

    /* Controls row in mobile bottom nav: two compact icon tabs side by side */
    .nav-controls-row {
        flex: 2 1 0;
        min-width: 116px;
        max-width: 176px;
        min-height: 52px;
        gap: 2px;
        align-items: stretch;
        padding: 2px 0;
    }

    .nav-controls-row .nav-theme-row,
    .nav-controls-row .nav-lang-row {
        flex: 1 1 0;
        min-width: 50px;
        max-width: 88px;
        min-height: 48px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        padding: 7px 4px 6px;
        font-size: 9.5px;
        letter-spacing: 0;
        white-space: nowrap;
        overflow: hidden;
        border: none;
        border-radius: 10px;
        margin-top: 0;
        background: transparent;
        color: var(--sidebar-text-muted);
        opacity: 0.9;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        transition:
            background 0.14s ease,
            color 0.14s ease,
            opacity 0.14s ease;
    }

    .nav-controls-row .nav-theme-row .nav-label,
    .nav-controls-row .nav-lang-row .nav-label {
        display: block;
        overflow: hidden;
        max-width: 100%;
        text-overflow: ellipsis;
        font-size: 9.5px;
        color: inherit;
    }

    .nav-controls-row .nav-theme-row .nav-icon,
    .nav-controls-row .nav-lang-row .nav-icon {
        width: 26px;
        height: 26px;
        margin-right: 0;
        border-radius: 8px;
        font-size: 12px;
        background: rgba(255, 255, 255, 0.05);
        border: 1px solid rgba(255, 255, 255, 0.06);
        color: var(--sidebar-text-muted);
        transition:
            background 0.14s ease,
            border-color 0.14s ease,
            color 0.14s ease;
    }

    .nav-controls-row .nav-theme-pill,
    .nav-controls-row .nav-lang-pill {
        display: none;
    }

    .nav-controls-row .nav-theme-row:hover,
    .nav-controls-row .nav-lang-row:hover,
    .nav-controls-row .nav-theme-row:active,
    .nav-controls-row .nav-lang-row:active {
        background: rgba(255, 255, 255, 0.05);
        color: var(--sidebar-text);
        opacity: 1;
    }

    .nav-controls-row .nav-theme-row:active .nav-icon,
    .nav-controls-row .nav-lang-row:active .nav-icon {
        background: rgba(255, 255, 255, 0.12);
    }

    .topbar {
        margin-bottom: 14px;
        gap: 10px;
        flex-direction: column;
        align-items: stretch;
    }

    .topbar h2 {
        margin-bottom: 6px;
        font-size: 20px;
        letter-spacing: -0.03em;
    }

    .topbar p {
        font-size: 13px;
    }

    .panel {
        padding: 14px;
        border-radius: 16px;
    }

    .panel-header {
        margin-bottom: 14px;
    }

    .section-block {
        border-radius: 16px;
    }

    .btn-primary,
    .btn-secondary,
    .btn-danger {
        height: 48px;
        padding: 0 16px;
    }

    .btn-icon {
        width: 44px;
        height: 44px;
        border-radius: 12px;
    }

    .btn-sm,
    .copy-btn,
    .cat-filter-btn {
        height: 40px;
        padding: 0 14px;
        font-size: 13px;
    }

    .modal-overlay {
        align-items: flex-end;
        padding: 0;
    }

    .modal {
        width: 100%;
        max-width: 100%;
        max-height: 92svh;
        overflow-y: auto;
        padding: 24px 20px calc(16px + env(safe-area-inset-bottom, 0px));
        border-radius: 26px 26px 0 0;
    }

    .modal-wide {
        max-height: 96svh;
    }

    .form-actions,
    .modal-footer,
    .prompt-actions {
        flex-wrap: wrap;
        gap: 8px;
    }

    .form-actions .btn-primary,
    .form-actions .btn-secondary,
    .form-actions .btn-danger,
    .modal-footer .btn-primary,
    .modal-footer .btn-secondary,
    .modal-footer .btn-danger {
        flex: 1;
        min-width: 0;
    }

    .stat-cards {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .board-container {
        display: flex;
        flex-direction: column;
    }

    .board-column {
        width: 100%;
    }

    .calendar-grid,
    .prompts-grid-layout,
    .notes-grid {
        grid-template-columns: 1fr;
    }

    .day-budget {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding: 14px;
    }

    .budget-info {
        gap: 12px;
        font-size: 12.5px;
    }

    .budget-bar {
        width: 100%;
        min-width: unset;
    }

    .month-grid,
    .month-header-row {
        grid-template-columns: 24px repeat(7, minmax(0, 1fr));
        gap: 2px;
    }

    .month-cell {
        min-height: 36px;
        padding: 3px;
        border-radius: 6px;
    }

    .month-kw-cell {
        font-size: 8px;
    }

    .admin-stat-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .admin-user-actions .btn-xs {
        height: 36px;
        padding: 0 12px;
        font-size: 13px;
    }

    .instr-card {
        padding: 14px 16px;
        border-radius: 14px;
    }

    .dashboard-grid,
    .dash-bottom-row,
    .dtp-layout,
    .dtp-metrics {
        grid-template-columns: 1fr;
    }
}

/* 360px: very small phones */

@media (max-width: 360px) {
    .nav-item,
    .nav-theme-row {
        min-width: 52px;
        padding: 6px 2px;
        font-size: 9px;
    }

    .nav-controls-row .nav-theme-row,
    .nav-controls-row .nav-lang-row {
        min-width: 44px;
        padding: 6px 2px;
        font-size: 9px;
    }

    .main-content {
        padding: 10px 10px calc(88px + env(safe-area-inset-bottom, 8px));
    }

    .stat-cards,
    .admin-stat-grid {
        grid-template-columns: 1fr;
    }

    .topbar h2 {
        font-size: 18px;
    }

    .panel {
        padding: 12px;
    }
}

