:root {
    --bg: #090b0f;
    --surface: #12171d;
    --ink: #f3f6f8;
    --muted: #9aa7b3;
    --line: #2a333d;
    --primary: #0f766e;
    --primary-dark: #0d9488;
    --accent: #f59e0b;
    --blue: #60a5fa;
    --red: #f87171;
    --green-soft: #0f2f2a;
    --amber-soft: #2f2413;
    --blue-soft: #13283f;
    --red-soft: #32191c;
    --shadow: 0 18px 60px rgba(0, 0, 0, 0.42);
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html {
    color-scheme: dark;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
    line-height: 1.5;
}

button,
input,
select,
textarea {
    font: inherit;
    max-width: 100%;
}

.topbar {
    align-items: end;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    display: flex;
    gap: 24px;
    justify-content: space-between;
    padding: 20px clamp(16px, 4vw, 42px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.nav-menu {
    position: relative;
}

.menu-toggle {
    align-items: center;
    background: #1b242c;
    border: 1px solid var(--line);
    border-radius: 7px;
    cursor: pointer;
    display: none;
    gap: 4px;
    height: 42px;
    justify-content: center;
    padding: 0;
    width: 46px;
}

.menu-toggle span {
    background: var(--ink);
    border-radius: 999px;
    display: block;
    height: 2px;
    width: 20px;
}

.eyebrow {
    color: var(--accent);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0;
    margin: 0 0 4px;
    text-transform: uppercase;
}

h1,
h2,
h3 {
    line-height: 1.15;
    margin: 0;
}

h1 {
    font-size: clamp(24px, 3vw, 38px);
}

h2 {
    font-size: clamp(22px, 2.5vw, 32px);
}

h3 {
    font-size: 22px;
}

.tabs {
    background: #151b21;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    overflow: hidden;
}

.tab {
    background: transparent;
    border: 0;
    color: var(--muted);
    cursor: pointer;
    min-height: 44px;
    padding: 0 18px;
    white-space: nowrap;
}

.tab.is-active {
    background: var(--primary);
    color: #fff;
}

.shell {
    margin: 0 auto;
    max-width: 1220px;
    padding: 28px clamp(16px, 4vw, 42px) 48px;
}

.view {
    display: none;
}

.view.is-active {
    display: block;
}

.section-heading {
    align-items: end;
    display: flex;
    gap: 20px;
    justify-content: space-between;
    margin-bottom: 18px;
}

.section-heading p:not(.eyebrow) {
    color: var(--muted);
    margin: 0;
    max-width: 560px;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 22px;
}

.panel,
label,
.stat,
.ticket-card,
.message,
.company-card,
.approval-card,
.client-report {
    min-width: 0;
}

.login-screen {
    display: grid;
    gap: 18px;
    margin: clamp(18px, 6vw, 70px) auto 0;
    max-width: 620px;
}

.login-screen .section-heading {
    align-items: center;
    display: grid;
    gap: 10px;
    justify-content: center;
    margin-bottom: 0;
    text-align: center;
}

.login-screen .section-heading p:not(.eyebrow) {
    max-width: 520px;
}

.auth-form {
    align-items: end;
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(2, minmax(0, 1fr)) auto;
}

.auth-form.login-card {
    align-items: stretch;
    grid-template-columns: 1fr;
    margin: 0 auto;
    max-width: 460px;
    width: 100%;
}

.auth-form output {
    grid-column: 1 / -1;
}

.client-workspace {
    display: grid;
    gap: 18px;
    margin-top: 18px;
}

.portal-bar {
    align-items: center;
    display: flex;
    gap: 18px;
    justify-content: space-between;
}

.portal-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
}

.account-menu {
    position: relative;
}

.account-panel {
    background: #12171d;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    display: grid;
    gap: 12px;
    min-width: 360px;
    padding: 16px;
    position: absolute;
    right: 0;
    top: calc(100% + 10px);
    z-index: 20;
}

.account-meta {
    border-bottom: 1px solid var(--line);
    display: grid;
    gap: 3px;
    padding-bottom: 12px;
}

.account-meta span,
.stat small {
    color: var(--muted);
    font-size: 12px;
}

.button.full {
    width: 100%;
}

.button.small-button {
    font-size: 13px;
    min-height: 34px;
    padding: 0 12px;
}

.client-layout {
    align-items: start;
    display: grid;
    gap: 18px;
    grid-template-columns: minmax(320px, 0.9fr) minmax(360px, 1.1fr);
}

.mini-head {
    margin-bottom: 16px;
}

.mini-head.split {
    align-items: end;
    display: flex;
    gap: 14px;
    justify-content: space-between;
}

.month-filter {
    align-items: end;
    display: flex;
    gap: 10px;
}

.month-filter label {
    min-width: 180px;
}

.ticket-form {
    display: grid;
    gap: 14px;
}

.password-form {
    border-top: 1px solid var(--line);
    display: grid;
    gap: 12px;
    padding-top: 12px;
}

.ticket-list.compact {
    max-height: 560px;
}

.empty-state.small {
    min-height: 160px;
}

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

label {
    color: #d8dee5;
    display: grid;
    font-size: 13px;
    font-weight: 700;
    gap: 7px;
}

input,
select,
textarea {
    background: #0d1117;
    border: 1px solid #303b46;
    border-radius: 7px;
    color: var(--ink);
    min-height: 42px;
    padding: 10px 12px;
    width: 100%;
}

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

select {
    text-overflow: ellipsis;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    outline: 3px solid rgba(20, 184, 166, 0.22);
}

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

.form-actions,
.lookup-bar,
.admin-login,
.filters,
.report-head {
    align-items: end;
    display: flex;
    gap: 14px;
}

.form-actions {
    justify-content: space-between;
}

.lookup-bar,
.filters {
    flex-wrap: wrap;
}

.lookup-bar label,
.admin-login label,
.filters label,
.report-head label {
    min-width: 210px;
}

.button {
    align-items: center;
    background: #1b242c;
    border: 1px solid #33414d;
    border-radius: 7px;
    color: var(--ink);
    cursor: pointer;
    display: inline-flex;
    font-weight: 700;
    justify-content: center;
    min-height: 42px;
    padding: 0 16px;
    text-decoration: none;
}

.button:hover {
    filter: brightness(0.98);
}

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

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

.button.danger {
    background: var(--red-soft);
    border-color: #5b2a31;
    color: var(--red);
}

output,
.notice {
    color: var(--muted);
    font-size: 14px;
}

.filters output {
    align-items: center;
    display: flex;
    min-height: 42px;
}

.notice.success {
    color: var(--primary);
    font-weight: 700;
}

.notice.error {
    color: var(--red);
    font-weight: 700;
}

.ticket-result,
.admin-workspace {
    display: grid;
    gap: 18px;
    margin-top: 18px;
}

.ticket-card,
.message,
.stat,
.client-report {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.ticket-card {
    align-items: start;
    cursor: pointer;
    display: grid;
    gap: 10px;
    padding: 16px;
}

.ticket-card:hover,
.ticket-card.is-selected {
    border-color: var(--primary);
    box-shadow: 0 10px 30px rgba(20, 184, 166, 0.18);
}

.ticket-card strong {
    font-size: 16px;
}

.ticket-card strong,
.ticket-meta,
.timeline-meta,
.message-body,
.company-card strong,
.company-card span,
.company-card small,
.approval-card span,
.approval-card small,
.attachment {
    overflow-wrap: anywhere;
    word-break: break-word;
}

.ticket-meta,
.timeline-meta,
.report-meta {
    color: var(--muted);
    display: flex;
    flex-wrap: wrap;
    font-size: 13px;
    gap: 8px 14px;
}

.status {
    align-items: center;
    align-self: start;
    border-radius: 999px;
    display: inline-flex;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.2;
    padding: 4px 9px;
    width: fit-content;
}

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

.status.en_proceso {
    background: var(--amber-soft);
    color: var(--accent);
}

.status.respondido {
    background: var(--green-soft);
    color: var(--primary);
}

.status.cerrado {
    background: #252c33;
    color: #c4ccd4;
}

.stats-row {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.stat {
    padding: 16px;
}

.summary-controls {
    align-items: center;
    display: flex;
    gap: 16px;
    justify-content: space-between;
}

.summary-controls h3 {
    margin: 0;
}

.summary-controls label {
    min-width: 220px;
}

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

.stat span {
    color: var(--muted);
    display: block;
    font-size: 13px;
}

.stat strong {
    display: block;
    font-size: clamp(18px, 2vw, 26px);
    margin-top: 4px;
}

.admin-layout {
    display: grid;
    gap: 18px;
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
}

.ticket-list {
    display: grid;
    gap: 12px;
    max-height: 720px;
    overflow: auto;
    padding-right: 4px;
}

.approvals-panel {
    box-shadow: none;
}

.approval-list {
    display: grid;
    gap: 10px;
}

.approval-card {
    align-items: center;
    background: #10151b;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: flex;
    gap: 14px;
    justify-content: space-between;
    padding: 14px;
}

.approval-card > div:first-child {
    display: grid;
    gap: 3px;
}

.approval-card span,
.approval-card small {
    color: var(--muted);
    font-size: 13px;
}

.approval-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.company-admin-panel,
.company-form {
    display: grid;
    gap: 14px;
}

.company-grid {
    align-items: end;
    display: grid;
    gap: 12px;
    grid-template-columns: minmax(220px, 1fr) minmax(180px, 260px) auto;
}

.company-list {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.company-card {
    background: #10151b;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: grid;
    gap: 6px;
    padding: 12px;
}

.company-card .button {
    justify-self: start;
    margin-top: 4px;
}

.company-card span,
.company-card small {
    color: var(--muted);
    font-size: 13px;
}

.admin-tools {
    display: grid;
    gap: 18px;
}

.admin-ticket-form,
.admin-password-form {
    display: grid;
    gap: 14px;
}

.admin-ticket-form {
    border-bottom: 1px solid var(--line);
    padding-bottom: 18px;
}

.admin-ticket-grid,
.admin-password-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

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

.admin-password-grid {
    align-items: end;
}

.ticket-detail {
    min-height: 520px;
}

.detail-head {
    border-bottom: 1px solid var(--line);
    display: grid;
    gap: 10px;
    margin: -2px 0 18px;
    padding-bottom: 16px;
}

.detail-title {
    align-items: start;
    display: flex;
    gap: 14px;
    justify-content: space-between;
}

.ticket-edit-form {
    border-bottom: 1px solid var(--line);
    display: grid;
    gap: 14px;
    margin-bottom: 18px;
    padding-bottom: 18px;
}

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

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

.timeline {
    display: grid;
    gap: 12px;
    margin: 16px 0;
}

.message {
    padding: 14px;
}

.message.soporte {
    border-left: 4px solid var(--primary);
}

.message.cliente {
    border-left: 4px solid var(--blue);
}

.message-body {
    margin: 8px 0 0;
    white-space: pre-wrap;
}

.message-edit-form {
    border-top: 1px solid var(--line);
    display: grid;
    gap: 10px;
    margin-top: 14px;
    padding-top: 12px;
}

.message-edit-actions {
    align-items: end;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.message-edit-actions label {
    min-width: 120px;
}

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

.attachment {
    background: #1b242c;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--ink);
    font-size: 12px;
    padding: 5px 10px;
    text-decoration: none;
}

.reply-box,
.support-form {
    border-top: 1px solid var(--line);
    display: grid;
    gap: 12px;
    margin-top: 18px;
    padding-top: 18px;
}

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

.support-grid label:first-child {
    grid-column: span 2;
}

.check-row {
    align-items: center;
    display: flex;
    gap: 8px;
    min-height: 42px;
}

.check-row input {
    min-height: auto;
    width: auto;
}

.empty-state {
    color: var(--muted);
    display: grid;
    min-height: 240px;
    place-items: center;
    text-align: center;
}

.report-panel {
    box-shadow: none;
}

.report-head {
    justify-content: space-between;
    margin-bottom: 16px;
}

.report-summary {
    background: var(--green-soft);
    border: 1px solid #24564d;
    border-radius: 8px;
    color: var(--primary-dark);
    font-weight: 700;
    margin-bottom: 14px;
    padding: 12px 14px;
}

.client-report {
    margin-top: 12px;
    padding: 14px;
}

.client-report h4 {
    margin: 0 0 8px;
}

.report-table {
    border-collapse: collapse;
    width: 100%;
}

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

.report-table th:last-child,
.report-table td:last-child {
    text-align: right;
}

.print-only {
    display: none;
}

@media (max-width: 860px) {
    input,
    select,
    textarea {
        font-size: 16px;
    }

    .shell {
        padding: 18px 12px 36px;
    }

    .panel {
        padding: 16px;
    }

    .topbar,
    .section-heading,
    .detail-title,
    .portal-bar,
    .report-head,
    .summary-controls {
        align-items: stretch;
        flex-direction: column;
    }

    .form-grid,
    .auth-form,
    .client-layout,
    .admin-layout,
    .support-grid,
    .admin-ticket-grid,
    .admin-password-grid,
    .ticket-edit-grid,
    .company-grid {
        grid-template-columns: 1fr;
    }

    .stats-row {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

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

    .span-2,
    .support-grid label:first-child,
    .admin-ticket-grid .span-2,
    .ticket-edit-grid .span-2 {
        grid-column: auto;
    }

    .form-actions,
    .lookup-bar,
    .admin-login,
    .filters {
        align-items: stretch;
        flex-direction: column;
    }

    .lookup-bar label,
    .auth-form label,
    .admin-login label,
    .filters label,
    .report-head label,
    .summary-controls label {
        min-width: 0;
    }

    .topbar {
        align-items: center;
        flex-direction: row;
    }

    .nav-menu {
        align-self: start;
    }

    .menu-toggle {
        display: grid;
    }

    .tabs {
        border-radius: 8px;
        box-shadow: var(--shadow);
        display: none;
        min-width: 210px;
        position: absolute;
        right: 0;
        top: calc(100% + 10px);
        width: min(280px, calc(100vw - 24px));
        z-index: 30;
    }

    .tabs.is-open {
        display: grid;
    }

    .tab {
        justify-content: start;
        padding: 0 10px;
        text-align: left;
    }

    .auth-form output {
        grid-column: auto;
    }

    .portal-actions {
        justify-content: stretch;
    }

    .mini-head.split,
    .month-filter,
    .approval-card,
    .message-edit-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .month-filter label {
        min-width: 0;
    }

    .portal-actions .button,
    .month-filter .button,
    .approval-actions .button,
    .auth-form .button,
    .message-edit-actions .button,
    .company-card .button,
    .company-grid .button {
        width: 100%;
    }

    .company-card .button {
        justify-self: stretch;
    }

    .approval-actions {
        justify-content: stretch;
    }

    .account-menu,
    .account-panel {
        width: 100%;
    }

    .account-panel {
        min-width: 0;
        position: static;
    }

    .ticket-list {
        max-height: none;
        padding-right: 0;
    }

    .report-table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
}

@media (max-width: 520px) {
    .stats-row {
        grid-template-columns: 1fr;
    }

    .topbar {
        align-items: flex-start;
        gap: 10px;
        padding: 14px 12px;
    }

    .panel {
        padding: 14px;
    }

    .section-heading {
        gap: 10px;
    }

    .ticket-card,
    .message,
    .company-card,
    .approval-card {
        padding: 12px;
    }

    .stat.wide {
        grid-column: auto;
    }

    h1 {
        font-size: 21px;
    }

    h2 {
        font-size: 24px;
    }

    h3 {
        font-size: 19px;
    }
}

@media print {
    .topbar,
    .tabs,
    .filters,
    .ticket-list,
    .support-form,
    .admin-login,
    .button,
    .section-heading p,
    .reply-box {
        display: none !important;
    }

    body {
        background: #fff;
    }

    .shell,
    .panel {
        box-shadow: none;
        max-width: none;
        padding: 0;
    }

    .admin-layout {
        display: block;
    }

    .print-only {
        display: block;
    }
}
