:root {
    --bg: #f8fafc;
    --bg-gradient-top: #eff6ff;
    --surface: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #dc2626;
    --success-bg: #ecfdf5;
    --success-text: #047857;
    --error-bg: #fef2f2;
    --error-text: #b91c1c;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
    --radius: 14px;
    --input-bg: #ffffff;
    --nav-active-bg: #eef2ff;
    --topbar-bg: rgba(255, 255, 255, 0.9);
    --table-head-bg: #f8fafc;
    --tag-bg: #e2e8f0;
    --tag-text: #334155;
    --bar-track: #e2e8f0;
    --inline-bg: #f8fafc;
}

[data-theme="dark"] {
    --bg: #0f172a;
    --bg-gradient-top: #1e293b;
    --surface: #1e293b;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --border: #334155;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --danger: #f87171;
    --success-bg: #064e3b;
    --success-text: #6ee7b7;
    --error-bg: #450a0a;
    --error-text: #fca5a5;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    --input-bg: #0f172a;
    --nav-active-bg: #334155;
    --topbar-bg: rgba(15, 23, 42, 0.92);
    --table-head-bg: #0f172a;
    --tag-bg: #334155;
    --tag-text: #e2e8f0;
    --bar-track: #334155;
    --inline-bg: #0f172a;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0f172a;
        --bg-gradient-top: #1e293b;
        --surface: #1e293b;
        --text: #f1f5f9;
        --muted: #94a3b8;
        --border: #334155;
        --primary: #3b82f6;
        --primary-hover: #60a5fa;
        --danger: #f87171;
        --success-bg: #064e3b;
        --success-text: #6ee7b7;
        --error-bg: #450a0a;
        --error-text: #fca5a5;
        --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
        --input-bg: #0f172a;
        --nav-active-bg: #334155;
        --topbar-bg: rgba(15, 23, 42, 0.92);
        --table-head-bg: #0f172a;
        --tag-bg: #334155;
        --tag-text: #e2e8f0;
        --bar-track: #334155;
        --inline-bg: #0f172a;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, sans-serif;
    background: linear-gradient(180deg, var(--bg-gradient-top) 0%, var(--bg) 220px);
    color: var(--text);
    min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
    background: var(--topbar-bg);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand a {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
}

.tagline {
    display: block;
    font-size: 0.8rem;
    color: var(--muted);
}

.nav {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
}

.nav a {
    padding: 0.45rem 0.8rem;
    border-radius: 999px;
    color: var(--text);
    text-decoration: none;
}

.nav a.active,
.nav a.btn {
    background: var(--nav-active-bg);
}

.container {
    width: min(1200px, calc(100% - 2rem));
    margin: 1.5rem auto 3rem;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.page-header h1,
.card h2 {
    margin: 0 0 0.35rem;
}

.muted, .small { color: var(--muted); }
.small { font-size: 0.85rem; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}

.grid-2, .grid-3, .filters-grid, .form-grid {
    display: grid;
    gap: 1rem;
}

.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.filters-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.form-grid .full,
.filters .actions,
.form-grid .actions { grid-column: 1 / -1; }

label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.92rem;
}

input, select, textarea, button {
    font: inherit;
}

input, select, textarea {
    width: 100%;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--input-bg);
    color: var(--text);
}

/* Evita zoom automático en iOS al enfocar campos */
@media (max-width: 768px) {
    input, select, textarea {
        font-size: 16px;
    }
}

textarea { resize: vertical; }

.btn, button.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.65rem 1rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--text);
    cursor: pointer;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.btn-primary:hover { background: var(--primary-hover); }

.btn:disabled, button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-danger, .danger { color: var(--danger); }

.btn-small { padding: 0.35rem 0.7rem; font-size: 0.85rem; }

.actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}

.stats { margin-bottom: 1rem; }

.stat {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.stat-label {
    color: var(--muted);
    font-size: 0.9rem;
}

.stat strong {
    font-size: 1.6rem;
}

.table-wrap { overflow-x: auto; padding: 0; }

.activity-cards {
    display: none;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.activity-card {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.activity-card__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
}

.activity-card__title {
    margin: 0;
    font-size: 1.05rem;
    line-height: 1.35;
    flex: 1;
}

.activity-card__duration {
    text-align: right;
    flex-shrink: 0;
}

.activity-card__duration strong {
    display: block;
    font-size: 1rem;
}

.activity-card__detail {
    margin: 0;
    line-height: 1.45;
}

.activity-card__dates {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
}

.activity-card__dates-sep {
    opacity: 0.6;
}

.activity-card__meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.activity-card__project {
    font-size: 0.88rem;
    color: var(--muted);
}

.activity-card__actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
}

.activity-card__actions .btn {
    width: 100%;
    min-height: 40px;
    font-size: 0.82rem;
    padding: 0.45rem 0.35rem;
}

.btn-danger-outline {
    background: transparent;
    border-color: var(--danger);
    color: var(--danger);
}

.empty-state {
    text-align: center;
    color: var(--muted);
    padding: 2rem 1rem;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

th {
    font-size: 0.85rem;
    color: var(--muted);
    background: var(--table-head-bg);
}

.empty {
    text-align: center;
    color: var(--muted);
    padding: 2rem !important;
}

.row-actions {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    white-space: nowrap;
}

.badge, .tag {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    color: #fff;
    font-size: 0.78rem;
}

.tag {
    background: var(--tag-bg);
    color: var(--tag-text);
    margin-right: 0.25rem;
    margin-top: 0.25rem;
}

.tags { margin-top: 0.35rem; }

.filters { margin-bottom: 1rem; }

.filters-bottom {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 1rem;
    align-items: end;
    margin-top: 1rem;
}

.filters-bottom__actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    padding-bottom: 0.1rem;
}

.pagination {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}

.pagination a {
    min-width: 2.2rem;
    text-align: center;
    padding: 0.45rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--input-bg);
    text-decoration: none;
    color: var(--text);
}

.pagination a.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.alert {
    padding: 0.85rem 1rem;
    border-radius: 10px;
    margin-bottom: 1rem;
}

.alert-success { background: var(--success-bg); color: var(--success-text); }
.alert-error { background: var(--error-bg); color: var(--error-text); }

.bar-list, .simple-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.bar-list li + li,
.simple-list li + li { margin-top: 0.75rem; }

.bar-row, .simple-list li {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    align-items: center;
}

.bar-track {
    height: 8px;
    background: var(--bar-track);
    border-radius: 999px;
    overflow: hidden;
    margin-top: 0.35rem;
}

.bar-fill { height: 100%; border-radius: 999px; }

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 0.35rem;
}

.timer-active { text-align: center; }
.timer-title { font-size: 1.1rem; margin: 0; }
.timer-clock {
    font-size: 2.4rem;
    font-weight: 700;
    margin: 0.5rem 0;
}

.timer-form {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.timer-form label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.92rem;
}

.timer-form__actions {
    margin-top: 0.25rem;
}

.timer-form__actions .btn-primary {
    width: 100%;
}

.inline-filters {
    display: flex;
    gap: 0.5rem;
    align-items: end;
    flex-wrap: wrap;
}

.inline-form {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.inline-form input[type="text"] { min-width: 160px; }
.inline-form input[type="color"] { width: 42px; padding: 0.2rem; }

.duration-preview {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--table-head-bg);
}

.card-inline {
    padding: 0.85rem 1rem;
    border: 1px dashed var(--border);
    border-radius: 10px;
}

.footer {
    text-align: center;
    color: var(--muted);
    padding: 1rem;
    font-size: 0.9rem;
}

.install-page {
    display: grid;
    place-items: center;
    min-height: 100vh;
}

.install-card { width: min(520px, calc(100% - 2rem)); }

.auth-page {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 1rem;
}

.auth-card {
    width: min(420px, 100%);
}

.auth-card h1 {
    margin-top: 0;
}

.btn-icon {
    min-width: 2.4rem;
    padding: 0.45rem 0.6rem;
}

.theme-icon-dark { display: none; }

[data-theme="dark"] .theme-icon-light { display: none; }
[data-theme="dark"] .theme-icon-dark { display: inline; }

.form-divider {
    grid-column: 1 / -1;
    border: none;
    border-top: 1px solid var(--border);
    margin: 0.25rem 0;
}

.settings-info li {
    padding: 0.35rem 0;
}

.settings-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
    padding: 0.35rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.settings-nav a {
    flex: 1;
    min-width: 7rem;
    text-align: center;
    padding: 0.6rem 0.85rem;
    border-radius: 8px;
    color: var(--text);
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 500;
}

.settings-nav a:hover {
    background: var(--nav-active-bg);
    text-decoration: none;
}

.settings-nav a.active {
    background: var(--primary);
    color: #fff;
}

.restore-confirm {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
}

.restore-confirm input[type="checkbox"] {
    width: auto;
}

.theme-picker {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.theme-picker label {
    cursor: pointer;
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 1rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.theme-picker input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.theme-picker label:has(input:checked) {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent);
}

.theme-picker__title {
    font-weight: 600;
    margin-bottom: 0.35rem;
}

.theme-picker__preview {
    height: 56px;
    border-radius: 8px;
    margin-top: 0.65rem;
    border: 1px solid var(--border);
}

.theme-picker__preview--default {
    background: linear-gradient(180deg, var(--bg-gradient-top) 0%, var(--bg) 100%);
}

.theme-picker__preview--adminlte {
    background: linear-gradient(90deg, #343a40 35%, #f4f6f9 35%);
}

/* —— Tablet —— */
@media (max-width: 900px) {
    .grid-2, .grid-3, .form-grid {
        grid-template-columns: 1fr;
    }

    .filters-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .filters-bottom {
        grid-template-columns: 1fr 1fr;
    }

    .filters-bottom__actions {
        grid-column: 1 / -1;
        justify-content: flex-start;
    }

    .topbar {
        flex-direction: column;
        align-items: stretch;
        padding: 0.85rem 1rem;
    }

    .nav {
        gap: 0.5rem;
    }
}

/* —— Móvil —— */
@media (max-width: 640px) {
    .container {
        width: calc(100% - 1rem);
        margin: 1rem auto 2rem;
    }

    .card {
        padding: 1rem;
        border-radius: 12px;
    }

    .page-header {
        flex-direction: column;
        align-items: stretch;
    }

    .page-header .actions {
        flex-direction: column;
        align-items: stretch;
    }

    .page-header .actions .btn {
        width: 100%;
        min-height: 44px;
    }

    .filters-grid,
    .filters-bottom {
        grid-template-columns: 1fr;
    }

    .filters-bottom__actions {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
    }

    .filters-bottom__actions .btn {
        width: 100%;
        min-height: 44px;
    }

    .btn, button.btn {
        min-height: 44px;
    }

    .nav {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
    }

    .nav a,
    .nav .btn-icon {
        justify-content: center;
        text-align: center;
        min-height: 44px;
    }

    .nav a.btn-small,
    .nav a[href*="logout"] {
        grid-column: 1 / -1;
    }

    .nav .btn-icon {
        width: 100%;
    }

    .settings-nav {
        flex-direction: column;
    }

    .settings-nav a {
        min-width: 0;
    }

    .theme-picker {
        grid-template-columns: 1fr;
    }

    th, td {
        padding: 0.65rem 0.75rem;
        font-size: 0.9rem;
    }

    .activity-cards {
        display: flex;
    }

    .table-desktop {
        display: none;
    }

    .row-actions {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .inline-form {
        flex-direction: column;
        align-items: stretch;
    }

    .inline-form input[type="text"] {
        min-width: 0;
        width: 100%;
    }

    .inline-form .btn {
        width: 100%;
    }

    .pagination a {
        min-width: 2.75rem;
        min-height: 2.75rem;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .auth-card,
    .install-card {
        padding: 0.25rem;
    }
}
