:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --sidebar-width: 280px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB',
                 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    line-height: 1.6;
    color: var(--gray-800);
    background: var(--gray-50);
    overflow-x: hidden;
}

/* App Layout */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: white;
    border-right: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 2rem 1.5rem;
    border-bottom: 1px solid var(--gray-200);
}

.logo {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 0.3rem;
}

.subtitle {
    font-size: 0.9rem;
    color: var(--gray-500);
}

.sidebar-nav {
    padding: 1rem;
}

.nav-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.8rem 1rem;
    margin-bottom: 0.3rem;
    border: none;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.95rem;
    color: var(--gray-700);
    text-align: left;
}

.nav-btn:hover {
    background: var(--gray-100);
}

.nav-btn.active {
    background: var(--primary);
    color: white;
}

.nav-icon {
    font-size: 1.2rem;
    flex-shrink: 0;
}

.badge {
    margin-left: auto;
    padding: 0.2rem 0.5rem;
    background: white;
    color: var(--primary);
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 600;
    flex-shrink: 0;
}

.nav-btn.active .badge {
    background: rgba(255,255,255,0.2);
    color: white;
}

.badge-gray { background: var(--gray-200); color: var(--gray-700); }
.badge-blue { background: var(--info); color: white; }
.badge-green { background: var(--success); color: white; }

.sidebar-section {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--gray-200);
}

.section-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.8rem;
}

.category-list button {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--gray-700);
    width: 100%;
    border: none;
    background: transparent;
    text-align: left;
    transition: color 0.2s;
}

.category-list button:hover {
    color: var(--primary);
}

.filter-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--gray-700);
}

.filter-item input {
    margin-right: 0.3rem;
    cursor: pointer;
}

.priority-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.priority-dot.critical { background: #dc2626; }
.priority-dot.high { background: #ea580c; }
.priority-dot.medium { background: #f59e0b; }
.priority-dot.low { background: #84cc16; }

.sidebar-footer {
    margin-top: auto;
    padding: 1.5rem;
    border-top: 1px solid var(--gray-200);
}

.btn-export {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid var(--gray-300);
    background: white;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--gray-700);
    transition: all 0.2s;
}

.btn-export:hover {
    background: var(--gray-50);
    border-color: var(--primary);
    color: var(--primary);
}

.update-time {
    margin-top: 1rem;
    font-size: 0.8rem;
    color: var(--gray-500);
    text-align: center;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.main-header {
    background: white;
    padding: 1.5rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1;
    min-width: 0;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
    white-space: nowrap;
}

.search-box {
    position: relative;
    flex: 1;
    max-width: 400px;
    min-width: 0;
}

.search-box input {
    width: 100%;
    padding: 0.7rem 2.5rem 0.7rem 1rem;
    border: 1px solid var(--gray-300);
    border-radius: 8px;
    font-size: 0.95rem;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary);
}

.search-icon {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
}

.btn {
    padding: 0.7rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}

.btn-secondary:hover {
    background: var(--gray-300);
}

/* Stats */
.stats-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    padding: 1.5rem;
    background: var(--gray-50);
}

.stat-card {
    background: white;
    padding: 1.2rem;
    border-radius: 12px;
    border: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-icon {
    font-size: 1.8rem;
    width: 45px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gray-100);
    border-radius: 10px;
    flex-shrink: 0;
}

.stat-info {
    flex: 1;
    min-width: 0;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--gray-500);
    margin-bottom: 0.2rem;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
}

/* Todo List */
.todo-list {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    -webkit-overflow-scrolling: touch;
}

.todo-item {
    background: white;
    padding: 1.2rem;
    margin-bottom: 1rem;
    border-radius: 12px;
    border: 1px solid var(--gray-200);
    transition: all 0.2s;
    cursor: pointer;
}

.todo-item:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.todo-item:active {
    transform: scale(0.98);
}

.todo-header {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 0.8rem;
}

.todo-checkbox {
    margin-top: 0.2rem;
    width: 20px;
    height: 20px;
    cursor: pointer;
    flex-shrink: 0;
}

.todo-main {
    flex: 1;
    min-width: 0;
}

.todo-title-row {
    display: flex;
    align-items: flex-start;
    gap: 0.8rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.todo-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-900);
    flex: 1;
    min-width: 0;
    word-wrap: break-word;
}

.priority-badge {
    padding: 0.3rem 0.8rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}

.priority-critical {
    background: #fee2e2;
    color: #dc2626;
}

.priority-high {
    background: #fed7aa;
    color: #ea580c;
}

.priority-medium {
    background: #fef3c7;
    color: #f59e0b;
}

.priority-low {
    background: #d9f99d;
    color: #65a30d;
}

.status-badge {
    padding: 0.3rem 0.8rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}

.status-pending {
    background: var(--gray-200);
    color: var(--gray-700);
}

.status-in_progress {
    background: #dbeafe;
    color: #2563eb;
}

.status-blocked {
    background: #fee2e2;
    color: #dc2626;
}

.status-completed {
    background: #d1fae5;
    color: #059669;
}

.status-cancelled {
    background: var(--gray-200);
    color: var(--gray-500);
}

.todo-description {
    color: var(--gray-600);
    font-size: 0.9rem;
    margin-bottom: 0.8rem;
    word-wrap: break-word;
}

.todo-meta {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    font-size: 0.85rem;
    color: var(--gray-500);
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    white-space: nowrap;
}

.todo-tags {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.tag {
    padding: 0.2rem 0.6rem;
    background: var(--gray-100);
    border-radius: 6px;
    font-size: 0.75rem;
    color: var(--gray-700);
    white-space: nowrap;
}

.todo-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.8rem;
    flex-wrap: wrap;
}

.action-btn {
    padding: 0.5rem 0.8rem;
    border: 1px solid var(--gray-300);
    background: white;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
    white-space: nowrap;
}

.action-btn:hover {
    background: var(--gray-50);
    border-color: var(--primary);
    color: var(--primary);
}

.action-btn:active {
    transform: scale(0.95);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--gray-500);
}

.empty-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.empty-state h3 {
    font-size: 1.3rem;
    margin-bottom: 0.5rem;
    color: var(--gray-700);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    padding: 0;
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
}

.modal-content {
    position: relative;
    background: white;
    border-radius: 16px;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    margin: 1rem;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    -webkit-overflow-scrolling: touch;
}

.modal-detail {
    max-width: 800px;
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    background: white;
    z-index: 10;
}

.modal-header h3 {
    font-size: 1.3rem;
    color: var(--gray-900);
}

.modal-close {
    border: none;
    background: transparent;
    font-size: 1.5rem;
    color: var(--gray-500);
    cursor: pointer;
    padding: 0.5rem;
    line-height: 1;
    flex-shrink: 0;
}

.modal-close:hover {
    color: var(--gray-900);
}

form {
    padding: 1.5rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--gray-700);
    font-size: 0.95rem;
}

input[type="text"],
input[type="url"],
input[type="date"],
textarea,
select {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid var(--gray-300);
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
}

textarea {
    resize: vertical;
    min-height: 100px;
}

.modal-footer {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    padding-top: 1rem;
    flex-wrap: wrap;
}

.modal-footer .btn {
    flex: 1;
    min-width: 100px;
}

/* Detail Modal */
.detail-content {
    padding: 1.5rem;
}

.detail-section {
    margin-bottom: 2rem;
}

.detail-section h4 {
    font-size: 0.9rem;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.8rem;
}

.detail-value {
    font-size: 1.1rem;
    color: var(--gray-900);
    word-wrap: break-word;
}

/* Mobile Menu Toggle */
.mobile-menu-toggle {
    display: none;
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 1001;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    border: none;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
    cursor: pointer;
    transition: all 0.3s;
}

.mobile-menu-toggle:active {
    transform: scale(0.95);
}

.hamburger {
    position: relative;
    display: block;
    width: 24px;
    height: 2px;
    background: white;
    margin: auto;
}

.hamburger::before,
.hamburger::after {
    content: '';
    position: absolute;
    width: 24px;
    height: 2px;
    background: white;
    transition: all 0.3s;
}

.hamburger::before {
    top: -8px;
}

.hamburger::after {
    top: 8px;
}

.mobile-menu-toggle.active .hamburger {
    background: transparent;
}

.mobile-menu-toggle.active .hamburger::before {
    transform: rotate(45deg);
    top: 0;
}

.mobile-menu-toggle.active .hamburger::after {
    transform: rotate(-45deg);
    top: 0;
}

/* Mobile Optimizations */
@media (max-width: 768px) {
    .mobile-menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .app-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        max-height: none;
        height: 100vh;
        border-right: none;
        border-bottom: 1px solid var(--gray-200);
        position: fixed;
        top: 0;
        left: 0;
        z-index: 999;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        overflow-y: auto;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .sidebar-header {
        padding: 1.5rem 1rem;
    }

    .logo {
        font-size: 1.3rem;
    }

    .sidebar-nav {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
        padding: 1rem;
    }

    .nav-btn {
        padding: 0.7rem 0.8rem;
        font-size: 0.9rem;
    }

    .nav-icon {
        font-size: 1rem;
    }

    .sidebar-section {
        padding: 1rem;
    }

    .sidebar-footer {
        padding: 1rem;
    }

    .main-header {
        padding: 1rem;
        flex-direction: column;
        align-items: stretch;
    }

    .header-left {
        flex-direction: column;
        align-items: stretch;
        gap: 0.8rem;
    }

    .page-title {
        font-size: 1.3rem;
    }

    .search-box {
        max-width: none;
    }

    .btn {
        width: 100%;
        justify-content: center;
    }

    .stats-container {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.8rem;
        padding: 1rem;
    }

    .stat-card {
        padding: 1rem;
    }

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

    .stat-value {
        font-size: 1.3rem;
    }

    .todo-list {
        padding: 1rem;
    }

    .todo-item {
        padding: 1rem;
    }

    .todo-header {
        gap: 0.8rem;
    }

    .todo-title {
        font-size: 0.95rem;
    }

    .todo-title-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .priority-badge,
    .status-badge {
        font-size: 0.7rem;
        padding: 0.25rem 0.6rem;
    }

    .todo-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .todo-actions {
        gap: 0.5rem;
    }

    .action-btn {
        flex: 1;
        font-size: 0.8rem;
        padding: 0.5rem 0.6rem;
        justify-content: center;
        min-width: 0;
    }

    .modal-content {
        border-radius: 16px 16px 0 0;
        max-height: 85vh;
        margin: 0;
        align-self: flex-end;
        width: 100%;
    }

    .modal-header {
        padding: 1rem;
    }

    .modal-header h3 {
        font-size: 1.2rem;
    }

    form {
        padding: 1rem;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .modal-footer {
        position: sticky;
        bottom: 0;
        background: white;
        padding: 1rem;
        margin: -1rem;
        margin-top: 1rem;
        border-top: 1px solid var(--gray-200);
    }

    .modal-footer .btn {
        flex: 1;
    }

    .detail-content {
        padding: 1rem;
    }

    .empty-state {
        padding: 2rem 1rem;
    }

    .empty-icon {
        font-size: 2.5rem;
    }

    .empty-state h3 {
        font-size: 1.1rem;
    }
}

/* Small Mobile */
@media (max-width: 480px) {
    .stats-container {
        grid-template-columns: 1fr;
    }

    .sidebar-nav {
        grid-template-columns: 1fr;
    }

    .page-title {
        font-size: 1.2rem;
    }

    .stat-value {
        font-size: 1.2rem;
    }
}

/* Landscape Mobile */
@media (max-width: 900px) and (orientation: landscape) {
    .sidebar {
        max-height: 30vh;
    }

    .stats-container {
        grid-template-columns: repeat(5, 1fr);
    }
}

/* Touch Device Improvements */
@media (hover: none) and (pointer: coarse) {
    .btn,
    .action-btn,
    .nav-btn,
    .modal-close {
        min-height: 44px;
        min-width: 44px;
    }

    .todo-checkbox {
        width: 24px;
        height: 24px;
    }

    input,
    textarea,
    select {
        font-size: 16px; /* Prevent zoom on iOS */
    }
}
