:root {
    --sidebar-width: 280px;
    --sidebar-bg: #1e293b;
    --sidebar-hover: #334155;
    --primary-color: #3b82f6;
    --header-bg: #ffffff;
    --content-bg: #f1f5f9;
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--content-bg);
    margin: 0;
    overflow-x: hidden;
}

/* Layout */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: #e2e8f0;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    z-index: 1000;
    overflow: hidden;
}

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.top-header {
    background: var(--header-bg);
    border-bottom: 1px solid #e2e8f0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
}

.header-title-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.header-username {
    font-size: 0.875rem;
    white-space: nowrap;
}

@media (min-width: 576px) {
    .header-inner {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        padding: 0.875rem 1.25rem;
    }

    .header-actions {
        flex-wrap: nowrap;
        justify-content: flex-end;
        gap: 0.5rem;
    }
}

@media (min-width: 768px) {
    .header-inner {
        padding: 1rem 1.5rem;
    }

    .h4-md {
        font-size: 1.5rem;
    }
}

.content-area {
    flex: 1;
    padding: 1rem;
}

@media (min-width: 768px) {
    .content-area {
        padding: 1.5rem;
    }
}

@media (min-width: 992px) {
    .content-area {
        padding: 1.5rem 1.75rem;
    }
}

/* Sidebar */
.sidebar-brand {
    padding: 1.25rem 1.5rem;
    font-size: 1.1rem;
    font-weight: 700;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-nav {
    padding: 1rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 1.5rem;
    color: #94a3b8;
    text-decoration: none;
    transition: all 0.2s;
}

.sidebar-link:hover,
.sidebar-link.active {
    background: var(--sidebar-hover);
    color: #fff;
}

.sidebar-heading {
    padding: 0.75rem 1.5rem 0.5rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #64748b;
    margin: 0;
}

.sidebar-projects {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.sidebar-project-list {
    overflow-y: auto;
    flex: 1;
    padding-bottom: 1rem;
}

.sidebar-project-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 1rem 0.4rem 1.25rem;
    color: #cbd5e1;
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: all 0.2s;
}

.sidebar-project-item:hover,
.sidebar-project-item.active {
    background: var(--sidebar-hover);
    color: #fff;
}

.sidebar-project-item.active {
    border-left-color: var(--primary-color);
}

.sidebar-project-item.overdue {
    border-left-color: #ef4444;
}

.sidebar-project-item.overdue .project-item-name {
    color: #fca5a5;
}

.project-item-number {
    flex-shrink: 0;
    min-width: 1.375rem;
    height: 1.375rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6875rem;
    font-weight: 700;
    line-height: 1;
    color: #94a3b8;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 0.25rem;
    cursor: pointer;
}

.sidebar-project-item:hover .project-item-number,
.sidebar-project-item.active .project-item-number {
    color: #fff;
    background: rgba(255, 255, 255, 0.18);
}

.sidebar-project-item.overdue .project-item-number {
    color: #fca5a5;
    background: rgba(239, 68, 68, 0.2);
}

.project-item-name {
    flex: 1;
    min-width: 0;
    font-weight: 500;
    font-size: 0.8125rem;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Dashboard Stats */
.stat-card {
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.1) !important;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

/* Login Page */
.login-page {
    background: linear-gradient(135deg, #1e293b 0%, #3b82f6 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-container {
    width: 100%;
    max-width: 420px;
    padding: 1rem;
}

.login-card {
    border-radius: 16px;
    border: none;
}

/* Files */
.file-card {
    border: 1px solid #e2e8f0;
    transition: box-shadow 0.2s;
}

.file-card:hover {
    box-shadow: 0 0.25rem 0.75rem rgba(0, 0, 0, 0.1);
}

.img-preview {
    max-height: 120px;
    max-width: 100%;
    object-fit: cover;
    border-radius: 8px;
}

/* Notes */
.note-item {
    background: #f8fafc;
    padding: 0.75rem;
    border-radius: 0 8px 8px 0;
}

/* Keyboard hint */
kbd.shortcut-hint,
.shortcut-hint kbd {
    font-size: 0.7rem;
    padding: 0.15rem 0.35rem;
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    color: #64748b;
}

#searchModal .modal-header {
    flex-direction: column;
    align-items: stretch;
}

#searchModal .btn-close {
    position: absolute;
    right: 1rem;
    top: 1rem;
}

.task-completed-row {
    opacity: 0.85;
}

/* Project tabs */
.project-tabs-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-left: -0.25rem;
    margin-right: -0.25rem;
    padding: 0 0.25rem;
}

.project-tabs {
    flex-wrap: nowrap;
    white-space: nowrap;
    border-bottom: 1px solid #dee2e6;
}

.project-tabs .nav-item {
    flex-shrink: 0;
}

.project-tabs .nav-link {
    color: #64748b;
    font-weight: 500;
    padding: 0.65rem 0.85rem;
    font-size: 0.875rem;
}

.project-tabs .nav-link.active {
    color: var(--primary-color);
    font-weight: 600;
}

.project-tabs .nav-link .shortcut-hint {
    font-size: 0.65rem;
    vertical-align: middle;
}

.matrix-box {
    transition: transform 0.2s;
}

.matrix-box:hover {
    transform: translateY(-2px);
}

/* Sidebar overlay (mobile) */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

.sidebar-overlay.show {
    display: block;
}

/* Mobile */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        width: min(var(--sidebar-width), 88vw);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
        width: 100%;
    }

    .page-title {
        max-width: calc(100vw - 5rem);
    }

    .page-actions {
        width: 100%;
    }

    .page-actions .btn {
        flex: 1 1 auto;
    }

    .project-form-actions {
        flex-direction: column;
    }

    .project-form-actions .btn {
        width: 100%;
    }

    .card-header {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .card-header .btn {
        width: 100%;
    }

    .card-header.d-flex .btn,
    .card-header.d-flex .btn-sm {
        width: auto;
    }
}

@media (max-width: 767.98px) {
    /* Tables as stacked cards */
    .table-mobile-cards thead {
        display: none;
    }

    .table-mobile-cards tbody tr {
        display: block;
        margin: 0.65rem;
        padding: 0.75rem;
        background: #fff;
        border: 1px solid #e2e8f0 !important;
        border-radius: 0.5rem;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    }

    .table-mobile-cards tbody tr.table-danger {
        border-color: #fecaca !important;
        background: #fff5f5;
    }

    .table-mobile-cards tbody tr.task-completed-row {
        background: #f8fafc;
    }

    .table-mobile-cards td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 0.75rem;
        padding: 0.35rem 0;
        border: none;
        text-align: right;
    }

    .table-mobile-cards td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 0.75rem;
        color: #64748b;
        text-align: left;
        flex-shrink: 0;
        padding-right: 0.5rem;
    }

    .table-mobile-cards td[data-label=""]::before,
    .table-mobile-cards td:not([data-label])::before {
        display: none;
    }

    .table-mobile-cards td.td-primary {
        display: block;
        text-align: left;
        padding-bottom: 0.5rem;
        margin-bottom: 0.25rem;
        border-bottom: 1px solid #f1f5f9;
    }

    .table-mobile-cards td.td-primary::before {
        display: none;
    }

    .table-mobile-cards td.td-check {
        display: flex;
        justify-content: flex-end;
        padding-bottom: 0;
        margin-bottom: 0.25rem;
        border-bottom: 1px solid #f1f5f9;
    }

    .table-mobile-cards td.td-actions {
        justify-content: flex-end;
        flex-wrap: wrap;
        gap: 0.35rem;
        padding-top: 0.5rem;
        margin-top: 0.25rem;
        border-top: 1px solid #f1f5f9;
    }

    .table-mobile-cards td.td-actions::before {
        display: none;
    }

    .table-mobile-cards .form-select-sm {
        min-width: 8rem;
    }

    .table-responsive-mobile {
        overflow: visible;
    }

    /* Touch-friendly controls */
    .touch-target,
    .btn-sm {
        min-height: 2.25rem;
        min-width: 2.25rem;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .btn-group .btn-sm {
        min-width: auto;
        padding-left: 0.65rem;
        padding-right: 0.65rem;
    }

    /* Horizontal scroll filters */
    .filter-scroll {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 0.25rem;
    }

    /* File upload */
    #fileUploadForm .input-group {
        flex-direction: column;
        gap: 0.5rem;
    }

    #fileUploadForm .input-group > * {
        width: 100%;
        border-radius: 0.375rem !important;
    }

    #fileUploadForm .btn {
        width: 100%;
    }

    /* Rich text toolbar wrap */
    .rich-text-editor .ql-toolbar.ql-snow {
        display: flex;
        flex-wrap: wrap;
    }

    .rich-text-editor .ql-toolbar.ql-snow .ql-formats {
        margin-bottom: 0.25rem;
    }

    /* Modals */
    .modal-footer {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .modal-footer .btn {
        flex: 1 1 auto;
        min-width: calc(50% - 0.25rem);
    }

    /* Dashboard list items */
    .list-group-item .d-flex {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.5rem;
    }

    .list-group-item .text-end {
        text-align: left !important;
    }

    /* Stat cards */
    .stat-card .card-body {
        padding: 0.875rem;
    }

    .stat-card h3 {
        font-size: 1.35rem;
    }

    .stat-icon {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }

    /* Login */
    .login-card .card-body {
        padding: 2rem 1.25rem !important;
    }

    /* Toast */
    .toast-container {
        left: 0.75rem;
        right: 0.75rem;
        top: auto;
        bottom: 1rem;
    }

    .toast-container .toast {
        width: 100%;
    }
}

@media (max-width: 575.98px) {
    .header-actions .btn {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    .matrix-box {
        padding: 0.75rem !important;
    }

    .matrix-box h3 {
        font-size: 1.25rem;
    }
}

/* Toast notifications */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
}

/* Rich text editor & content */
.rich-text-editor {
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    min-height: 180px;
}

.rich-text-editor .ql-toolbar {
    border-top-left-radius: 0.375rem;
    border-top-right-radius: 0.375rem;
}

.rich-text-editor .ql-container {
    border-bottom-left-radius: 0.375rem;
    border-bottom-right-radius: 0.375rem;
    min-height: 140px;
    font-size: 0.95rem;
}

.rich-text-content h1,
.rich-text-content h2,
.rich-text-content h3 {
    margin-top: 0.75rem;
    margin-bottom: 0.5rem;
}

.rich-text-content h1 { font-size: 1.5rem; }
.rich-text-content h2 { font-size: 1.25rem; }
.rich-text-content h3 { font-size: 1.1rem; }

.rich-text-content p,
.rich-text-content ul,
.rich-text-content ol,
.rich-text-content blockquote {
    margin-bottom: 0.75rem;
}

.rich-text-content blockquote {
    border-left: 4px solid #0d6efd;
    padding-left: 0.75rem;
    color: #475569;
    background: #f8fafc;
}

.rich-text-content a {
    word-break: break-word;
}

#fileSelectionInfo {
    min-height: 1.25rem;
}

.project-form-actions {
    position: sticky;
    bottom: 0;
    z-index: 20;
    background: #fff;
    padding-bottom: 0.5rem;
    margin-bottom: -0.5rem;
}
