/* Reset and Base */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #252525;
    --text-primary: #f5f5f5;
    --text-secondary: #a0a0a0;
    --text-muted: #666;
    --border-color: #333;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --success: #22c55e;
    --success-hover: #16a34a;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --warning: #f59e0b;
    --radius: 6px;
    --radius-lg: 10px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

/* Typography */
h1,
h2,
h3 {
    font-weight: 600;
}

h1 {
    font-size: 1.5rem;
}

h2 {
    font-size: 1.25rem;
}

h3 {
    font-size: 1rem;
}

/* Layout */
#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 2rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

nav {
    display: flex;
    gap: 0.5rem;
}

.nav-link {
    padding: 0.5rem 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius);
    transition: all 0.2s;
}

.nav-link:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.nav-link.active {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

main {
    flex: 1;
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

/* Project Selector */
.project-selector {
    position: relative;
}

.project-selector-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
}

.project-selector-btn:hover {
    background: var(--bg-secondary);
    border-color: var(--accent);
}

.project-selector-btn.no-project {
    color: var(--text-secondary);
    border-style: dashed;
}

.project-selector-btn .project-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.project-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.5rem;
    min-width: 200px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 200;
    overflow: hidden;
}

.project-dropdown-list {
    max-height: 300px;
    overflow-y: auto;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: background 0.15s;
}

.dropdown-item:hover {
    background: var(--bg-tertiary);
}

.dropdown-item.selected {
    background: var(--bg-tertiary);
    border-left: 3px solid var(--accent);
}

.dropdown-item .project-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.dropdown-empty {
    padding: 1rem;
    text-align: center;
    color: var(--text-muted);
}

/* Timer Widget */
.timer-widget {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 1rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-lg);
}

.timer-widget.running {
    background: var(--bg-tertiary);
    border: 1px solid var(--accent);
}

.timer-widget.warning {
    border-color: var(--warning);
}

.timer-display {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

#timer-time {
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    font-size: 1.25rem;
    font-weight: 600;
    min-width: 90px;
}

.timer-controls {
    display: flex;
    gap: 0.5rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

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

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

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

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

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

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

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.btn-outline:hover {
    background: var(--bg-tertiary);
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

label {
    display: block;
    margin-bottom: 0.375rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

input,
select,
textarea {
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 0.9375rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    transition: border-color 0.2s;
}

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

input[type="color"] {
    padding: 0.25rem;
    height: 42px;
    cursor: pointer;
}

/* Cards */
.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

/* Entry List */
.entry-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.entry-item {
    display: grid;
    grid-template-columns: auto 1fr auto auto auto;
    gap: 1rem;
    align-items: center;
    padding: 0.875rem 1rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    transition: background 0.2s;
}

.entry-item:hover {
    background: #2a2a2a;
}

.entry-color {
    width: 4px;
    height: 32px;
    border-radius: 2px;
}

.entry-info {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.entry-project {
    font-weight: 500;
}

.entry-task {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.entry-note {
    font-size: 0.8125rem;
    color: var(--text-muted);
    font-style: italic;
}

.entry-date {
    font-size: 0.8125rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.entry-duration {
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.entry-actions {
    display: flex;
    gap: 0.25rem;
    opacity: 0;
    transition: opacity 0.2s;
}

.entry-item:hover .entry-actions {
    opacity: 1;
}

.entry-actions button {
    padding: 0.375rem 0.5rem;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius);
}

.entry-actions button:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* Daily View */
.daily-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.daily-total {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
}

.daily-total-time {
    font-size: 2rem;
    font-weight: 600;
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
}

.daily-total-label {
    color: var(--text-secondary);
}

/* Start Timer Form */
.start-timer-form {
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
}

.task-input-row {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
}

.task-input-row .form-group {
    min-width: 0;
}

.no-project-message {
    text-align: center;
    padding: 1rem;
    color: var(--text-muted);
}

.start-timer-form.expanded {
    grid-template-columns: 1fr;
}

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

/* Project List */
.project-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.project-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.875rem 1rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s;
}

.project-item:hover {
    background: #2a2a2a;
}

.project-item.archived {
    opacity: 0.5;
    cursor: default;
}

.project-item.selected {
    border: 1px solid var(--accent);
    background: rgba(59, 130, 246, 0.1);
}

.project-color {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    flex-shrink: 0;
}

.project-name {
    flex: 1;
    font-weight: 500;
}

.project-tasks {
    font-size: 0.8125rem;
    color: var(--text-muted);
}

/* Entries Filters */
.filter-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 1.5rem;
    gap: 1rem;
}

.filters {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.filters input,
.filters select {
    width: auto;
    min-width: 150px;
}

/* Inline Summary */
.summary-inline {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.summary-item {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
}

.summary-label {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.summary-value {
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    font-weight: 600;
}

/* Login */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 2rem;
}

.login-card {
    width: 100%;
    max-width: 400px;
}

.login-card h1 {
    text-align: center;
    margin-bottom: 2rem;
}

.login-error {
    color: var(--danger);
    font-size: 0.875rem;
    margin-top: 0.5rem;
}

/* Summary */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.summary-card {
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
}

.summary-card-label {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.summary-card-value {
    font-size: 1.5rem;
    font-weight: 600;
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.5rem;
    line-height: 1;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    padding: 0.875rem 1.25rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.875rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    z-index: 2000;
    opacity: 0;
    transform: translateY(1rem);
    transition: all 0.3s ease;
    max-width: 300px;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast-success {
    border-left: 4px solid var(--success);
}

.toast-error {
    border-left: 4px solid var(--danger);
}

.toast-info {
    border-left: 4px solid var(--accent);
}

@media (max-width: 768px) {
    .toast {
        right: 1rem;
        left: 1rem;
        max-width: none;
    }
}

/* Utilities */
.hidden {
    display: none !important;
}

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

.text-secondary {
    color: var(--text-secondary);
}

.mt-1 {
    margin-top: 0.5rem;
}

.mt-2 {
    margin-top: 1rem;
}

.mb-1 {
    margin-bottom: 0.5rem;
}

.mb-2 {
    margin-bottom: 1rem;
}

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

.empty-state h3 {
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

/* Responsive */
@media (max-width: 768px) {

    /* Header - Clean two-row layout */
    header {
        flex-direction: column;
        gap: 0;
        padding: 0;
    }

    .header-left {
        width: 100%;
        justify-content: space-between;
        padding: 0.75rem 1rem;
        border-bottom: 1px solid var(--border-color);
    }

    .header-left h1 {
        font-size: 1.25rem;
    }

    .header-left nav {
        gap: 0.25rem;
    }

    .nav-link {
        padding: 0.375rem 0.625rem;
        font-size: 0.8125rem;
    }

    .header-right {
        width: 100%;
        justify-content: space-between;
        padding: 0.5rem 1rem;
        background: var(--bg-tertiary);
        gap: 0.75rem;
    }

    /* Timer widget - more compact on mobile */
    .timer-widget {
        padding: 0.375rem 0.75rem;
        gap: 0.5rem;
        flex: 1;
        justify-content: center;
    }

    #timer-time {
        font-size: 1.125rem;
        min-width: 80px;
    }

    .timer-controls .btn {
        padding: 0.25rem 0.625rem;
        font-size: 0.75rem;
    }

    /* Project selector - smaller */
    .project-selector-btn {
        padding: 0.375rem 0.75rem;
        font-size: 0.8125rem;
    }

    .project-selector-btn .project-color {
        width: 10px;
        height: 10px;
    }

    #logout-btn {
        padding: 0.375rem 0.625rem;
        font-size: 0.75rem;
    }

    /* Main content */
    main {
        padding: 1rem;
    }

    /* Daily header */
    .daily-header {
        margin-bottom: 1rem;
    }

    .daily-header h2 {
        font-size: 1.125rem;
    }

    .daily-total-time {
        font-size: 1.5rem;
    }

    /* Start timer form - cleaner card */
    .start-timer-form {
        padding: 1rem;
        margin-bottom: 1rem;
    }

    .task-input-row {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .task-input-row .form-group {
        margin-bottom: 0;
    }

    .task-input-row .btn {
        width: 100%;
        padding: 0.875rem 1.25rem;
        font-size: 1rem;
        font-weight: 600;
    }

    /* Entry cards - redesigned for mobile */
    .entry-list {
        gap: 0.75rem;
    }

    .entry-item {
        display: grid;
        grid-template-columns: 4px 1fr auto;
        grid-template-rows: auto auto;
        gap: 0;
        padding: 0;
        overflow: hidden;
        border-radius: var(--radius-lg);
    }

    .entry-color {
        grid-row: 1 / 3;
        grid-column: 1;
        width: 4px;
        height: auto;
        border-radius: 0;
    }

    .entry-info {
        grid-column: 2 / 4;
        display: flex;
        flex-direction: column;
        gap: 0.25rem;
        padding: 1rem 1rem 0.5rem;
        padding-right: 5.5rem;
        /* Space for duration */
    }

    .entry-project {
        font-size: 1rem;
        font-weight: 600;
    }

    .entry-task {
        font-size: 0.875rem;
        color: var(--text-secondary);
    }

    .entry-date {
        grid-column: 2;
        grid-row: 2;
        font-size: 0.75rem;
        color: var(--text-muted);
        padding: 0 1rem 0.75rem;
    }

    .entry-duration {
        position: absolute;
        top: 1rem;
        right: 1rem;
        font-size: 1.125rem;
        font-weight: 600;
        color: var(--text-primary);
        font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    }

    /* Entry item needs relative positioning for duration */
    .entry-item {
        position: relative;
    }

    .entry-actions {
        grid-column: 1 / -1;
        display: flex;
        gap: 0;
        opacity: 1;
        padding: 0;
        border-top: 1px solid var(--border-color);
    }

    .entry-actions button {
        flex: 1;
        padding: 0.75rem;
        font-size: 0.875rem;
        color: var(--text-secondary);
        text-align: center;
        background: transparent;
    }

    .entry-actions button:first-child {
        border-right: 1px solid var(--border-color);
    }

    .entry-actions button:active {
        background: var(--bg-secondary);
    }

    /* Cards */
    .card {
        padding: 1rem;
        border-radius: var(--radius);
    }

    .card-header {
        margin-bottom: 0.75rem;
    }

    .card-header h2 {
        font-size: 1rem;
    }

    /* Filters */
    .filter-row {
        flex-direction: column;
        align-items: stretch;
    }

    .filters {
        flex-direction: column;
        gap: 0.75rem;
    }

    .filters input,
    .filters select {
        width: 100%;
    }

    .summary-inline {
        justify-content: space-between;
        flex-wrap: wrap;
        gap: 1rem;
    }

    /* Project dropdown - full width mobile */
    .project-dropdown {
        position: fixed;
        left: 0.5rem;
        right: 0.5rem;
        top: auto;
        bottom: 0.5rem;
        max-height: 50vh;
        border-radius: var(--radius-lg);
    }

    .dropdown-item {
        padding: 1rem;
    }

    /* Summary grid */
    .summary-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
    }

    .summary-card {
        padding: 0.875rem;
    }

    .summary-card-value {
        font-size: 1.25rem;
    }

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

    .modal {
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        max-width: 100%;
        max-height: 85vh;
        padding: 1.25rem;
    }

    /* Project list */
    .project-item {
        padding: 1rem;
    }

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

    /* Login */
    .login-container {
        padding: 1rem;
    }

    .login-card {
        padding: 1.25rem;
    }

    .login-card h1 {
        font-size: 1.5rem;
        margin-bottom: 1.5rem;
    }
}

/* Small mobile - extra compact */
@media (max-width: 375px) {
    .header-left {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
    }

    .daily-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }

    .daily-total {
        align-self: flex-end;
    }

    .summary-grid {
        grid-template-columns: 1fr;
    }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {

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

    .btn-sm {
        min-height: 36px;
    }

    input,
    select,
    textarea {
        min-height: 44px;
        font-size: 16px;
        /* Prevents iOS zoom */
    }

    .nav-link {
        min-height: 36px;
        display: flex;
        align-items: center;
    }

    /* Remove hover states on touch devices */
    .entry-item:hover {
        background: var(--bg-tertiary);
    }

    .project-item:hover {
        background: var(--bg-tertiary);
    }

    /* Active states for touch feedback */
    .btn:active {
        transform: scale(0.98);
    }

    .entry-item:active {
        background: #2a2a2a;
    }

    .project-item:active {
        background: #2a2a2a;
    }

    .nav-link:active {
        background: var(--bg-tertiary);
    }
}