:root {
    --bg: #0f1419;
    --bg-elevated: #1a222d;
    --bg-muted: #243042;
    --border: #2d3b52;
    --text: #e8eef7;
    --muted: #94a3b8;
    --accent: #38bdf8;
    --accent-2: #a78bfa;
    --danger: #f87171;
    --success: #4ade80;
    --warning: #fbbf24;
    --radius: 12px;
    --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

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

body {
    margin: 0;
    background: radial-gradient(1200px 600px at 10% -10%, rgba(56, 189, 248, 0.12), transparent),
        radial-gradient(900px 500px at 100% 0%, rgba(167, 139, 250, 0.1), transparent),
        var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* App: solo el panel principal hace scroll; la barra lateral queda fija. */
body.is-app {
    height: 100vh;
    overflow: hidden;
}

html:has(body.is-app) {
    height: 100%;
}

body.is-login {
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-screen {
    width: min(440px, 100%);
}

.login-card {
    padding: 28px;
}

.card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.brand {
    display: flex;
    gap: 16px;
    align-items: center;
    margin-bottom: 24px;
}

.brand-mark {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    background: linear-gradient(135deg, rgba(56, 189, 248, 0.25), rgba(167, 139, 250, 0.25));
    border: 1px solid var(--border);
    display: grid;
    place-items: center;
    font-size: 1.4rem;
    color: var(--accent);
}

.brand h1 {
    margin: 0;
    font-size: 1.35rem;
}

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

.tiny {
    font-size: 0.78rem;
}

#k-sync-state {
    display: none !important;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
}

.field span {
    font-size: 0.85rem;
    color: var(--muted);
}

input[type="text"],
input[type="password"],
input[type="date"],
select,
textarea {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 12px;
    border-radius: 10px;
    outline: none;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.35);
}

.password-wrap {
    position: relative;
    display: block;
}

.password-wrap input {
    width: 100%;
    padding-right: 44px;
}

.password-wrap .icon-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 999px;
    background: transparent;
}

.password-wrap .icon-btn:hover {
    transform: translateY(-50%);
    background: rgba(56, 189, 248, 0.12);
}

.btn {
    border: 1px solid var(--border);
    background: var(--bg-muted);
    color: var(--text);
    padding: 10px 14px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: transform 0.08s ease, background 0.15s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn.primary {
    background: linear-gradient(135deg, #38bdf8, #6366f1);
    border-color: transparent;
    color: #0b1220;
}

.btn.secondary {
    background: rgba(56, 189, 248, 0.12);
    border-color: rgba(56, 189, 248, 0.35);
    color: var(--text);
}

.btn.ghost {
    background: transparent;
}

.btn.small {
    padding: 8px 10px;
    font-size: 0.85rem;
}

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

.icon-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 10px;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: grid;
    place-items: center;
}

.icon-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.form-error {
    color: var(--danger);
    font-size: 0.88rem;
}

.layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    height: 100%;
    min-height: 0;
    max-height: 100vh;
    overflow: hidden;
}

.sidebar {
    background: rgba(26, 34, 45, 0.92);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(10px);
    height: 100%;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-brand {
    padding: 22px 18px;
    font-weight: 700;
    display: flex;
    gap: 10px;
    align-items: center;
    border-bottom: 1px solid var(--border);
    color: var(--accent);
}

.nav {
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
}

.nav-item {
    text-align: left;
    padding: 12px 12px;
    border-radius: 10px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    display: flex;
    gap: 10px;
    align-items: center;
    font-size: 0.95rem;
}

.nav-item:hover {
    background: rgba(56, 189, 248, 0.08);
}

.nav-item.active {
    border-color: rgba(56, 189, 248, 0.35);
    background: rgba(56, 189, 248, 0.12);
}

.hidden {
    display: none !important;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
}

.user-block {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 12px;
}

.avatar {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: var(--bg-muted);
    display: grid;
    place-items: center;
    border: 1px solid var(--border);
}

.user-name {
    font-weight: 600;
}

.pill {
    display: inline-block;
    margin-top: 4px;
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(167, 139, 250, 0.15);
    border: 1px solid rgba(167, 139, 250, 0.35);
    color: #ddd6fe;
}

.footer-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.main {
    padding: 20px 26px 32px;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
    flex-shrink: 0;
}

.topbar h2 {
    margin: 0;
    font-size: 1.25rem;
}

.panel {
    display: none;
    flex: 1;
    min-height: 0;
    flex-direction: column;
}

.panel.active {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}

#panel-kanban.active {
    overflow: hidden;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
    margin-bottom: 16px;
    flex-shrink: 0;
}

.inline {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.85rem;
    color: var(--muted);
}

.kanban {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    flex: 1;
    min-height: 0;
    align-content: stretch;
}

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

    body.is-app {
        height: auto;
        min-height: 100vh;
        overflow: auto;
    }

    .layout {
        grid-template-columns: 1fr;
        height: auto;
        max-height: none;
        min-height: min-content;
        overflow: visible;
    }

    .sidebar {
        flex-direction: row;
        flex-wrap: wrap;
        height: auto;
        position: sticky;
        top: 0;
        z-index: 40;
    }

    .main {
        min-height: 0;
        overflow-x: hidden;
        overflow-y: visible;
    }

    #panel-kanban.active {
        overflow: visible;
    }

    .kanban {
        flex: none;
        min-height: auto;
    }

    .kan-col {
        max-height: min(75vh, 560px);
        min-height: 200px;
    }

    #panel-users.active {
        overflow: visible;
    }

    #panel-users .users-tables-card {
        flex: none;
        min-height: auto;
        overflow-x: auto;
        overflow-y: visible;
    }
}

.kan-col {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    min-height: 0;
    display: flex;
    flex-direction: column;
    max-height: 100%;
}

.kan-col h3 {
    margin: 0 0 12px;
    font-size: 0.95rem;
    color: var(--muted);
    flex-shrink: 0;
}

.kan-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
}

.kan-list.drag-over {
    outline: 2px dashed rgba(56, 189, 248, 0.45);
    border-radius: 10px;
}

.task-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    cursor: grab;
}

.task-card.dragging {
    opacity: 0.65;
}

.task-card h4 {
    margin: 0 0 8px;
    font-size: 0.98rem;
}

.task-meta {
    font-size: 0.78rem;
    color: var(--muted);
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tag {
    padding: 2px 8px;
    border-radius: 999px;
    border: 1px solid var(--border);
    font-size: 0.72rem;
}

.task-actions {
    margin-top: 10px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.task-progress {
    margin-top: 8px;
}

.task-progress-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.76rem;
    color: var(--muted);
    margin-bottom: 5px;
}

.task-progress-label strong {
    color: #dbeafe;
    font-size: 0.8rem;
}

.task-progress-track {
    height: 8px;
    width: 100%;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.18);
    border: 1px solid rgba(148, 163, 184, 0.25);
    overflow: hidden;
}

.task-progress-fill {
    height: 100%;
    width: 0;
    border-radius: 999px;
    background: linear-gradient(90deg, #38bdf8, #22c55e);
    transition: width 0.25s ease;
}

.status-pendiente {
    border-left: 3px solid var(--warning);
}

.status-en_proceso {
    border-left: 3px solid var(--accent);
}

.status-completado {
    border-left: 3px solid var(--success);
}

.gantt-wrap {
    padding: 16px;
    overflow-x: hidden;
}

.gantt-head {
    display: grid;
    grid-template-columns: 220px 1fr 54px;
    gap: 12px;
    margin-bottom: 10px;
    font-size: 0.85rem;
    color: var(--muted);
}

.gantt-row {
    display: grid;
    grid-template-columns: 220px 1fr 54px;
    gap: 12px;
    align-items: center;
    margin-bottom: 10px;
}

.gantt-bar-track {
    position: relative;
    height: 36px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.gantt-bar {
    position: absolute;
    top: 4px;
    bottom: 4px;
    border-radius: 8px;
    background: linear-gradient(90deg, rgba(56, 189, 248, 0.35), rgba(99, 102, 241, 0.45));
    border: 1px solid rgba(56, 189, 248, 0.45);
    display: flex;
    align-items: center;
    padding: 0 8px;
    font-size: 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gantt-status-dot {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    box-shadow: 0 0 0 1px rgba(2, 6, 23, 0.45);
}

.gantt-dot-head {
    text-align: center;
}

.gantt-dot-cell {
    display: flex;
    justify-content: center;
    align-items: center;
}

.gantt-status-dot.dot-pendiente {
    background: #FF1300;
}

.gantt-status-dot.dot-en_proceso {
    background: #FFBD44;
}

.gantt-status-dot.dot-completado {
    background: #00CA4E;
}

.table-card {
    overflow: auto;
}

.users-tables-card {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: auto;
    overflow-y: auto;
    padding: 18px 20px 22px;
}

#panel-users.active {
    overflow: hidden;
    gap: 18px;
}

#panel-users > .form-inline,
#panel-users > .users-filters-card {
    flex-shrink: 0;
}

#panel-users > .form-inline {
    margin-bottom: 0;
}

.users-filters-card {
    padding: 22px 22px 24px;
    margin-top: 2px;
}

.users-section-title {
    margin: 0 auto 14px;
    width: fit-content;
    padding: 6px 12px;
    border-radius: 999px;
    text-align: center;
    letter-spacing: 0.03em;
    font-size: 1.02rem;
    font-weight: 700;
    color: #dbeafe;
    background: rgba(56, 189, 248, 0.12);
    border: 1px solid rgba(56, 189, 248, 0.35);
}

.users-section-title.muted {
    color: #cbd5e1;
    background: rgba(148, 163, 184, 0.14);
    border-color: rgba(148, 163, 184, 0.32);
}

.users-filters {
    display: grid;
    grid-template-columns: minmax(320px, 1fr) 260px;
    gap: 14px;
    margin: 0;
    padding: 6px 8px 2px;
}

.users-filters .field {
    margin-bottom: 0;
}

.users-search-wrap {
    position: relative;
    width: 100%;
}

.users-search-wrap input {
    width: 100%;
    padding-right: 38px;
}

.users-search-clear {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    border: 0;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #60a5fa;
    background: transparent;
}

.users-search-clear:hover {
    background: rgba(96, 165, 250, 0.12);
}

.users-inactive-block {
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}

.data-table-muted tbody tr {
    opacity: 0.88;
}

.areas-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 14px;
}

.area-card {
    padding: 18px 16px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-height: 88px;
    border-left: 4px solid var(--accent);
    transition: box-shadow 0.15s ease, transform 0.08s ease;
}

.area-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
}

.area-card-icon {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: rgba(56, 189, 248, 0.12);
    border: 1px solid rgba(56, 189, 248, 0.25);
    display: grid;
    place-items: center;
    color: var(--accent);
    font-size: 1.1rem;
}

.field-color input[type='color'] {
    width: 100%;
    height: 44px;
    padding: 4px;
    cursor: pointer;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg);
}

.area-card-name {
    font-weight: 600;
    font-size: 0.98rem;
    line-height: 1.35;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

.data-table th,
.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

.data-table th {
    color: var(--muted);
    font-weight: 600;
}

.form-inline {
    padding: 18px;
    margin-bottom: 16px;
}

.form-inline h3 {
    margin-top: 0;
}

.subtasks-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
}

.subtask-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.subtask-row .subtask-input {
    flex: 1;
}

.subtask-row .btn-subtask-done {
    flex-shrink: 0;
    min-width: 130px;
    justify-content: center;
}

.subtask-row.is-done .subtask-input {
    text-decoration: line-through;
    opacity: 0.8;
}

.subtask-row .btn-remove-subtask {
    flex-shrink: 0;
    width: 38px;
    height: 38px;
}

.assign-self-wrap {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
}

.assign-self-wrap #t-assignee {
    min-width: 0;
    width: 100%;
    max-width: 100%;
}

.assign-self-wrap #t-assign-self {
    flex-shrink: 0;
    white-space: nowrap;
}

.grid-2 .t-area-field,
.grid-2 .t-assignee-field,
.grid-2 .t-multi-assignee-field {
    grid-column: 1 / -1;
}

.inline-check {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
}

.inline-check input[type='checkbox'] {
    width: 16px;
    height: 16px;
}

.assignees-checklist {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    min-height: 112px;
    max-height: 180px;
    overflow-y: auto;
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.assignee-item {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    color: var(--text);
}

.assignee-item input[type='checkbox'] {
    width: 15px;
    height: 15px;
    margin: 0;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

@media (max-width: 900px) {
    .grid-2,
    .grid-3 {
        grid-template-columns: 1fr;
    }

    .users-filters {
        grid-template-columns: 1fr;
    }
}

.modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

.modal.show {
    display: flex;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(6, 10, 16, 0.72);
    backdrop-filter: blur(4px);
}

.modal-card {
    position: relative;
    z-index: 1;
    width: min(560px, 94vw);
    padding: 20px;
    max-height: 92vh;
    overflow: hidden;
}

.modal-card.small {
    width: min(420px, 94vw);
}

.modal-card header h3 {
    margin: 0 0 12px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 12px;
}

#modal-task .modal-card {
    display: flex;
    flex-direction: column;
}

#modal-task #form-task {
    overflow-y: auto;
    padding-right: 4px;
}

#modal-task .modal-actions {
    position: sticky;
    bottom: 0;
    padding-top: 12px;
    background: linear-gradient(180deg, rgba(15, 23, 42, 0), rgba(15, 23, 42, 0.95) 28%);
}

.ranking-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    flex: 1 1 auto;
    min-height: 0;
}

.ranking-grid > .card {
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.ranking-grid > .card h3 {
    margin: 0 0 14px;
    flex-shrink: 0;
}

#panel-ranking.active {
    overflow: hidden;
}

#panel-ranking .toolbar {
    flex-shrink: 0;
}

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

.rank-list {
    margin: 0;
    padding-left: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
    overflow-y: auto;
    padding-right: 4px;
}

.rank-item {
    display: grid;
    grid-template-columns: 42px 1fr auto auto;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.95), rgba(2, 10, 23, 0.95));
}

.rank-item-empty {
    grid-template-columns: 1fr;
    color: var(--muted);
    text-align: center;
}

.rank-position {
    width: 30px;
    height: 30px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #bfdbfe;
    background: rgba(56, 189, 248, 0.16);
    border: 1px solid rgba(56, 189, 248, 0.35);
}

.rank-item.top-1 {
    border-color: rgba(251, 191, 36, 0.5);
    box-shadow: 0 0 0 1px rgba(251, 191, 36, 0.15) inset;
}

.rank-item.top-1 .rank-position {
    color: #f59e0b;
    background: rgba(251, 191, 36, 0.16);
    border-color: rgba(251, 191, 36, 0.45);
}

.rank-item.top-2 {
    border-color: rgba(148, 163, 184, 0.55);
}

.rank-item.top-2 .rank-position {
    color: #cbd5e1;
    background: rgba(148, 163, 184, 0.16);
    border-color: rgba(148, 163, 184, 0.45);
}

.rank-item.top-3 {
    border-color: rgba(251, 146, 60, 0.5);
}

.rank-item.top-3 .rank-position {
    color: #fb923c;
    background: rgba(251, 146, 60, 0.16);
    border-color: rgba(251, 146, 60, 0.45);
}

.rank-user {
    font-weight: 700;
    letter-spacing: 0.01em;
}

.rank-role {
    font-size: 0.76rem;
    padding: 4px 8px;
    border-radius: 999px;
    color: #bfdbfe;
    border: 1px solid rgba(56, 189, 248, 0.35);
    background: rgba(56, 189, 248, 0.1);
}

.rank-xp {
    font-weight: 700;
    color: #86efac;
    font-variant-numeric: tabular-nums;
}

@media (max-width: 700px) {
    .rank-item {
        grid-template-columns: 34px 1fr auto;
        row-gap: 6px;
    }

    .rank-role {
        grid-column: 2 / 4;
        width: fit-content;
    }
}

.toast-host {
    position: fixed;
    right: 18px;
    bottom: 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 60;
}

.toast {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    padding: 12px 14px;
    border-radius: 10px;
    box-shadow: var(--shadow);
    min-width: 240px;
    font-size: 0.9rem;
}

.toast.err {
    border-color: rgba(248, 113, 113, 0.45);
}

.toast.ok {
    border-color: rgba(74, 222, 128, 0.35);
}
