:root {
    --bg: #f5f7fb;
    --surface: #ffffff;
    --line: #dfe5ef;
    --text: #1d2433;
    --muted: #687386;
    --primary: #246bfe;
    --primary-dark: #174dc2;
    --green: #16a05d;
    --green-bg: #eaf8f0;
    --blue: #246bfe;
    --blue-bg: #eaf1ff;
    --purple: #7b4ed8;
    --purple-bg: #f0eafa;
    --red: #cc3a3a;
    --red-bg: #fdecec;
    --gray-bg: #eef2f7;
    --gray: #596579;
    --shadow: 0 12px 30px rgba(29, 36, 51, .08);
}

html {
    color-scheme: light;
}

html[data-theme="dark"] {
    color-scheme: dark;
    --bg: #10141d;
    --surface: #181e29;
    --line: #30394a;
    --text: #edf2fa;
    --muted: #a5b0c2;
    --primary: #6d9cff;
    --primary-dark: #91b4ff;
    --green: #55d590;
    --green-bg: #173b2a;
    --blue: #82aaff;
    --blue-bg: #1c3158;
    --purple: #bb98ff;
    --purple-bg: #342650;
    --red: #ff8585;
    --red-bg: #4a2328;
    --gray-bg: #293140;
    --gray: #c0cada;
    --shadow: 0 12px 30px rgba(0, 0, 0, .28);
}

.priority-select {
    min-width: 112px;
    min-height: 30px;
    border: 0 !important;
    border-radius: 999px;
    padding: 4px 30px 4px 11px;
    font-size: 12px;
    font-weight: 750;
    cursor: pointer;
}

.priority-baja {
    background-color: #dce9ff !important;
    color: #1456c4 !important;
}

.priority-media {
    background-color: #ffe89a !important;
    color: #6f5100 !important;
}

.priority-alta {
    background-color: #ffd7d7 !important;
    color: #b42323 !important;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    font-size: 13px;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    font-size: 24px;
    line-height: 1.2;
}

h2 {
    font-size: 15px;
    line-height: 1.3;
}

code {
    background: var(--gray-bg);
    border-radius: 5px;
    padding: 2px 5px;
}

.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        linear-gradient(135deg, rgba(36, 107, 254, .16), rgba(22, 160, 93, .12)),
        var(--bg);
}

.login-panel {
    width: min(430px, 100%);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 28px;
}

.install-panel {
    width: min(520px, 100%);
}

.login-brand,
.app-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.login-brand {
    margin-bottom: 24px;
}

.login-brand p,
.muted {
    color: var(--muted);
}

.small {
    font-size: 12px;
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    font-weight: 800;
    letter-spacing: 0;
}

.brand-logo {
    display: block;
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    border-radius: 9px;
    object-fit: contain;
}

.demo-users {
    display: grid;
    gap: 6px;
    margin-top: 18px;
    color: var(--muted);
    font-size: 12px;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 18px;
    min-height: 54px;
    padding: 8px 18px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.app-brand {
    color: var(--text);
    font-weight: 800;
    white-space: nowrap;
}

.main-nav {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    overflow-x: auto;
}

.main-nav a {
    color: var(--muted);
    padding: 7px 11px;
    border-radius: 7px;
    white-space: nowrap;
}

.main-nav a.active,
.main-nav a:hover {
    background: var(--blue-bg);
    color: var(--primary);
}

.user-menu {
    display: grid;
    grid-template-columns: auto auto;
    gap: 1px;
    column-gap: 8px;
    justify-items: end;
    align-items: center;
    color: var(--text);
    white-space: nowrap;
}

.theme-toggle {
    grid-row: 1 / span 3;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--gray-bg);
    color: var(--text);
    padding: 4px 9px;
    font: inherit;
    font-size: 11px;
    font-weight: 750;
    cursor: pointer;
}

.theme-toggle:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.theme-toggle-dark {
    display: none;
}

html[data-theme="dark"] .theme-toggle-light {
    display: none;
}

html[data-theme="dark"] .theme-toggle-dark {
    display: inline;
}

.user-menu small {
    color: var(--muted);
}

.logout-link {
    font-size: 11px;
}

.page {
    width: min(1220px, calc(100% - 32px));
    margin: 0 auto;
    padding: 24px 0 34px;
}

.page-title-row,
.panel-heading,
.form-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.page-title-row {
    margin-bottom: 18px;
}

.header-actions,
.selection-actions {
    display: flex;
    align-items: center;
    gap: 9px;
}

.selection-actions {
    flex-wrap: wrap;
}

.select-column {
    width: 58px;
    min-width: 58px;
    text-align: center !important;
}

.select-column input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin: 0 auto;
    accent-color: var(--primary);
    cursor: pointer;
}

.selected-task-list {
    display: grid;
    gap: 7px;
    margin-top: 10px;
}

.selected-task-list > div {
    display: grid;
    gap: 2px;
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fafbfe;
}

.selected-task-list small {
    color: var(--muted);
}

.sprint-metrics {
    grid-template-columns: repeat(4, minmax(150px, 1fr));
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.metric,
.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(29, 36, 51, .04);
}

.metric {
    padding: 13px;
    display: grid;
    gap: 6px;
}

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

.metric strong {
    font-size: 24px;
    line-height: 1;
}

.content-grid {
    display: grid;
    gap: 14px;
}

.dashboard-stack {
    margin-bottom: 14px;
}

.dashboard-list {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.two-columns {
    grid-template-columns: minmax(0, 1.2fr) minmax(360px, .8fr);
}

.narrow-form {
    grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
    align-items: start;
}

.panel {
    padding: 14px;
}

.panel-heading {
    margin-bottom: 12px;
}

.panel-heading .table-live-search {
    max-width: 260px;
}

.project-list,
.compact-list,
.stack-form {
    display: grid;
    gap: 10px;
}

.project-progress,
.compact-item {
    display: grid;
    gap: 8px;
    color: var(--text);
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcff;
}

.project-progress:hover,
.compact-item:hover {
    border-color: #b9c8e8;
}

.project-link {
    color: var(--primary);
    font-weight: 800;
}

.project-progress {
    grid-template-columns: minmax(0, 1fr) minmax(180px, 260px);
    align-items: center;
}

.project-progress small,
.compact-item small,
.data-table small {
    display: block;
    color: var(--muted);
    margin-top: 4px;
}

.progress-wrap {
    display: grid;
    gap: 6px;
    min-width: 120px;
}

.progress-wrap span {
    color: var(--muted);
    font-size: 12px;
    text-align: right;
}

.progress-wrap.compact {
    min-width: 130px;
}

.progress-track {
    height: 8px;
    background: var(--gray-bg);
    border-radius: 999px;
    overflow: hidden;
}

.progress-track div {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--green));
}

.filters-bar {
    display: grid;
    grid-template-columns: minmax(190px, 250px) minmax(170px, 220px) minmax(160px, 190px) minmax(160px, 190px) minmax(170px, 1fr);
    gap: 10px;
    align-items: end;
    margin-bottom: 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
}

label {
    display: grid;
    gap: 5px;
    color: var(--muted);
    font-weight: 650;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid #cfd8e6;
    border-radius: 7px;
    background: #fff;
    color: var(--text);
    font: inherit;
    padding: 8px 9px;
    outline: none;
}

textarea {
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(36, 107, 254, .12);
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 9px;
    color: var(--text);
}

.checkbox-row input {
    width: auto;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    border: 1px solid transparent;
    border-radius: 7px;
    padding: 8px 13px;
    font-weight: 750;
    cursor: pointer;
    white-space: nowrap;
}

.btn:hover,
.app-brand:hover,
.main-nav a:hover,
.project-progress:hover,
.compact-item:hover {
    text-decoration: none;
}

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

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

.btn-light {
    background: #fff;
    color: var(--text);
    border-color: var(--line);
}

.btn-light:hover {
    border-color: #b9c8e8;
    color: var(--primary);
}

.btn-full {
    width: 100%;
}

.wide-form {
    max-width: 980px;
}

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

.span-2 {
    grid-column: span 2;
}

.table-scroll {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    min-width: 850px;
}

.monday-table {
    min-width: 1500px;
}

.data-table th,
.data-table td {
    text-align: left;
    vertical-align: top;
    padding: 9px 8px;
    border-bottom: 1px solid var(--line);
}

.data-table th {
    color: var(--muted);
    font-size: 11px;
    background: #fafbfe;
    position: sticky;
    top: 0;
}

.resizable-table th {
    position: relative;
}

.resizable-table td {
    overflow: hidden;
}

.resizable-table td input,
.resizable-table td select,
.resizable-table td textarea,
.resizable-table td .select2-container {
    min-width: 0 !important;
    max-width: 100%;
}

.column-resizer {
    position: absolute;
    top: 0;
    right: -5px;
    width: 10px;
    height: 100%;
    cursor: col-resize;
    user-select: none;
    z-index: 2;
}

.column-resizer::after {
    content: "";
    position: absolute;
    top: 20%;
    bottom: 20%;
    left: 4px;
    width: 2px;
    border-radius: 999px;
    background: #aebbd0;
    transition: top .12s ease, bottom .12s ease, width .12s ease, background .12s ease;
}

.column-resizer:hover::after,
.resizing-column .column-resizer:hover::after {
    top: 5%;
    bottom: 5%;
    width: 3px;
    background: var(--primary);
}

.resizable-table th:hover .column-resizer::after {
    background: #7899d2;
}

.resizing-column,
.resizing-column * {
    cursor: col-resize !important;
    user-select: none !important;
}

.data-table tr:last-child td {
    border-bottom: 0;
}

.text-cell {
    max-width: 260px;
    white-space: normal;
}

.activity-cell {
    min-width: 300px;
    max-width: 380px;
    line-height: 1.4;
}

.expandable-text-content {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow-wrap: anywhere;
}

.expandable-text.is-expanded .expandable-text-content {
    display: block;
    overflow: visible;
    -webkit-line-clamp: unset;
    line-clamp: unset;
}

.text-expand-button {
    display: inline-flex;
    margin-top: 3px;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--primary);
    font: inherit;
    font-size: 11px;
    font-weight: 750;
    cursor: pointer;
}

.text-expand-button:hover {
    text-decoration: underline;
}

.area-cell {
    min-width: 175px;
}

.responsible-cell {
    min-width: 190px;
}

.actions-cell {
    text-align: right;
}

.inline-actions {
    display: table-cell;
    vertical-align: middle !important;
    white-space: nowrap;
}

.btn-compact {
    min-height: 28px;
    padding: 5px 9px;
    font-size: 11px;
}

.table-control,
.table-number,
.table-date,
.status-select {
    min-height: 30px;
    border-radius: 6px;
    padding: 6px 7px;
    font-size: 12px;
}

.table-control {
    min-width: 165px;
}

.table-number {
    max-width: 76px;
}

.table-date {
    min-width: 130px;
}

.progress-editor {
    display: grid;
    min-width: 170px;
}

.progress-controls {
    display: grid;
    grid-template-columns: minmax(104px, 1fr) 54px;
    gap: 7px;
    align-items: center;
}

.progress-range {
    --progress-value: 0%;
    appearance: none;
    -webkit-appearance: none;
    height: 8px;
    padding: 0;
    border: 0;
    border-radius: 999px;
    box-shadow: none;
    background: linear-gradient(90deg, var(--primary) 0 var(--progress-value), var(--gray-bg) var(--progress-value) 100%);
    cursor: pointer;
}

.progress-range:focus {
    box-shadow: none;
}

.progress-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border: 3px solid #fff;
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 1px 5px rgba(29, 36, 51, .28);
}

.progress-range::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border: 3px solid #fff;
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 1px 5px rgba(29, 36, 51, .28);
}

.progress-range::-moz-range-track {
    height: 8px;
    border-radius: 999px;
    background: transparent;
}

.progress-number {
    max-width: 54px;
}

.percent-input {
    position: relative;
    display: block;
}

.percent-input::after {
    content: "%";
    position: absolute;
    top: 50%;
    right: 10px;
    color: var(--muted);
    font-weight: 750;
    pointer-events: none;
    transform: translateY(-50%);
}

.percent-input input {
    padding-right: 27px;
    appearance: textfield;
    -moz-appearance: textfield;
}

.percent-input input::-webkit-inner-spin-button,
.percent-input input::-webkit-outer-spin-button {
    margin: 0;
    -webkit-appearance: none;
}

.percent-input-table {
    width: 58px;
}

.percent-input-table::after {
    right: 7px;
    font-size: 11px;
}

.percent-input-table .progress-number {
    width: 58px;
    max-width: 58px;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 26px;
    border-radius: 999px;
    padding: 4px 10px;
    font-weight: 750;
    font-size: 12px;
    white-space: nowrap;
}

.status-select {
    border: 0;
    font-weight: 750;
    min-width: 112px;
}

.ticket-status-select {
    min-height: 30px;
    min-width: 118px;
    border: 0;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 750;
}

.save-state {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 66px;
    min-height: 22px;
    border-radius: 999px;
    padding: 3px 8px;
    font-size: 11px;
    font-weight: 750;
}

.save-state-saved {
    background: var(--green-bg);
    color: var(--green);
}

.save-state-saving,
.save-state-dirty {
    background: var(--blue-bg);
    color: var(--blue);
}

.save-state-error {
    background: var(--red-bg);
    color: var(--red);
}

.select2-container {
    max-width: 100%;
}

.select2-container .select2-selection--single {
    min-height: 30px;
    border-color: #cfd8e6;
    border-radius: 6px;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    color: var(--text);
    line-height: 28px;
    padding-left: 8px;
    padding-right: 24px;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    min-height: 28px;
}

.data-table .select2-container {
    min-width: 165px;
}

.status-gray {
    background: var(--gray-bg);
    color: var(--gray);
}

.status-blue {
    background: var(--blue-bg);
    color: var(--blue);
}

.status-purple {
    background: var(--purple-bg);
    color: var(--purple);
}

.status-green {
    background: var(--green-bg);
    color: var(--green);
}

.status-red {
    background: var(--red-bg);
    color: var(--red);
}

.alert {
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 16px;
    border: 1px solid transparent;
}

.alert-error {
    background: var(--red-bg);
    border-color: #f2b8b8;
    color: var(--red);
}

.alert-success {
    background: var(--green-bg);
    border-color: #a9e7c6;
    color: var(--green);
}

.empty,
.empty-state {
    color: var(--muted);
    text-align: center;
    padding: 26px;
}

.empty-state {
    display: grid;
    justify-items: center;
    gap: 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.detail-panel {
    align-self: start;
}

.detail-list {
    display: grid;
    grid-template-columns: 170px minmax(0, 1fr);
    gap: 12px;
    margin: 0;
}

.detail-list dt {
    color: var(--muted);
    font-weight: 750;
}

.detail-list dd {
    margin: 0;
}

.preserve-lines {
    white-space: pre-wrap;
}

html[data-theme="dark"] body,
html[data-theme="dark"] .login-body {
    background-color: var(--bg);
}

html[data-theme="dark"] .login-body {
    background:
        linear-gradient(135deg, rgba(109, 156, 255, .12), rgba(85, 213, 144, .08)),
        var(--bg);
}

html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea,
html[data-theme="dark"] .btn-light,
html[data-theme="dark"] .select2-container--default .select2-selection--single,
html[data-theme="dark"] .select2-dropdown,
html[data-theme="dark"] .select2-search__field {
    background: #202735;
    color: var(--text);
    border-color: var(--line);
}

html[data-theme="dark"] .select2-container--default .select2-selection--single .select2-selection__rendered,
html[data-theme="dark"] .select2-container--default .select2-results__option[aria-selected="true"] {
    color: var(--text);
}

html[data-theme="dark"] .select2-container--default .select2-results__option[aria-selected="true"] {
    background: #30394a;
}

html[data-theme="dark"] .select2-container--default .select2-results__option--highlighted[aria-selected] {
    background: var(--primary);
    color: #10141d;
}

html[data-theme="dark"] .data-table th,
html[data-theme="dark"] .compact-item,
html[data-theme="dark"] .project-progress,
html[data-theme="dark"] .selected-task-list > div {
    background: #1d2431;
}

html[data-theme="dark"] .btn-primary {
    color: #10141d;
}

html[data-theme="dark"] .priority-baja {
    background: #243f70 !important;
    color: #a9c6ff !important;
}

html[data-theme="dark"] .priority-media {
    background: #584817 !important;
    color: #ffe48a !important;
}

html[data-theme="dark"] .priority-alta {
    background: #57272c !important;
    color: #ffaaaa !important;
}

@media (max-width: 1080px) {
    .metric-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .two-columns,
    .narrow-form {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 760px) {
    .topbar {
        position: static;
        grid-template-columns: 1fr;
        align-items: start;
    }

    .user-menu {
        justify-items: start;
    }

    .page {
        padding: 18px 14px 34px;
    }

    .page-title-row,
    .panel-heading,
    .form-actions,
    .project-progress {
        align-items: stretch;
        flex-direction: column;
        grid-template-columns: 1fr;
    }

    .filters-bar,
    .form-grid,
    .metric-grid {
        grid-template-columns: 1fr;
    }

    .span-2 {
        grid-column: span 1;
    }

    .detail-list {
        grid-template-columns: 1fr;
    }
}
