@font-face {
    font-family: "Space Grotesk";
    src: url("SpaceGrotesk-VariableFont_wght.ttf") format("truetype");
    font-display: swap;
}

:root {
    --bg: #f0eeee;
    --surface: #ffffff;
    --surface-soft: #faf8fb;
    --surface-strong: #f4eff7;
    --text: #250044;
    --muted: #766d7d;
    --line: #e6dfe8;
    --primary: #ff0045;
    --primary-dark: #d9003d;
    --primary-soft: #fff0f4;
    --purple: #2b0050;
    --purple-2: #560078;
    --danger: #b00030;
    --success: #18a874;
    --focus: #ff7aa4;
    --shadow: 0 18px 46px rgba(37, 0, 68, 0.09);
    --shadow-soft: 0 10px 26px rgba(37, 0, 68, 0.07);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at 100% 0, rgba(255, 0, 69, 0.09), transparent 34rem),
        var(--bg);
    color: var(--text);
    font-family: "Space Grotesk", "Segoe UI", Arial, Helvetica, sans-serif;
    font-size: 12px;
}

.topbar {
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    gap: 32px;
    min-height: 154px;
    padding: 28px max(20px, calc((100vw - 1540px) / 2 + 20px));
    border-bottom: 0;
    background:
        radial-gradient(circle at 86% 22%, rgba(255, 0, 69, 0.44) 0 2px, transparent 3px),
        linear-gradient(112deg, #2b0050 0%, #3c0061 48%, #7c003e 100%);
    color: #fff;
}

.topbar::after {
    position: absolute;
    right: -9rem;
    top: -17rem;
    width: 36rem;
    height: 36rem;
    border-radius: 50%;
    background: repeating-conic-gradient(from 0deg, rgba(255, 255, 255, 0.19) 0deg 1deg, transparent 1deg 6deg);
    content: "";
    opacity: 0.75;
    pointer-events: none;
}

.topbar h1,
.topbar p,
.content h2,
.panel h2 {
    margin: 0;
}

.topbar h1 {
    font-size: clamp(28px, 4vw, 50px);
    font-weight: 700;
    letter-spacing: 0;
}

.topbar p {
    margin-top: 8px;
    color: rgba(255, 255, 255, 0.84);
    font-size: 16px;
}

.brand-lockup,
.topbar-title,
.user-bar {
    position: relative;
    z-index: 1;
}

.brand-lockup {
    flex: 0 0 auto;
}

.brand-logo-card {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 190px;
    height: 102px;
    border-radius: 18px;
    background: #fff;
    box-shadow: var(--shadow-soft);
}

.brand-logo-card img {
    display: block;
    width: 154px;
    height: auto;
}

.topbar-title {
    min-width: 0;
    flex: 1 1 auto;
}

.eyebrow {
    display: inline-block;
    margin-bottom: 8px;
    color: var(--primary);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.status-badge {
    padding: 8px 12px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    font-weight: 700;
    backdrop-filter: blur(12px);
}

.status-badge-danger {
    border-color: rgba(180, 35, 24, 0.28);
    background: #ffe3df;
    color: var(--danger);
}

.status-badge-success {
    border-color: rgba(19, 121, 91, 0.28);
    background: #e5f6ef;
    color: var(--success);
}

.sidebar .status-badge,
.content .status-badge,
.wo-panel .status-badge,
.wo-current .status-badge {
    border-color: rgba(43, 0, 80, 0.12);
    background: var(--surface-strong);
    color: var(--text);
}

.user-bar {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logout-link {
    color: #fff;
    font-weight: 700;
    text-decoration: none;
}

.logout-link:hover {
    text-decoration: underline;
}

.app-shell {
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr);
    gap: 18px;
    width: min(1540px, calc(100% - 40px));
    min-height: calc(100vh - 154px);
    margin: -18px auto 0;
    padding-bottom: 18px;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 0;
    border-right: 0;
    background: transparent;
}

.module {
    display: grid;
    gap: 10px;
    padding: 22px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: var(--shadow-soft);
}

.search-module {
    background: var(--surface);
}

.operation-module {
    border-color: rgba(255, 0, 69, 0.16);
    background: linear-gradient(180deg, #fff 0%, #fff8fa 100%);
}

.module h2,
.content h2 {
    color: var(--text);
    font-size: 22px;
}

label {
    color: var(--muted);
    font-weight: 700;
    font-size: 11px;
    text-transform: uppercase;
}

select,
input[type="search"],
input[type="text"],
input[type="password"],
input[type="date"],
input[type="number"],
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    color: var(--text);
    padding: 0 14px;
    font: inherit;
}

input[type="search"],
input[type="text"],
input[type="password"],
input[type="date"],
input[type="number"],
select {
    height: 42px;
}

textarea {
    min-height: 74px;
    padding-top: 10px;
    resize: vertical;
}

.login-page {
    display: grid;
    place-items: center;
    min-height: 100vh;
    background:
        radial-gradient(circle at 78% 12%, rgba(255, 0, 69, 0.18), transparent 22rem),
        linear-gradient(125deg, #2b0050 0%, #4a0067 52%, #7c003e 100%);
}

.login-shell {
    width: min(440px, calc(100vw - 24px));
}

.login-panel {
    display: grid;
    gap: 12px;
    padding: 28px;
    border: 1px solid var(--line);
    border-radius: 22px;
    background: var(--surface);
    box-shadow: 0 28px 80px rgba(0, 0, 0, 0.24);
}

.login-panel h1,
.login-panel p {
    margin: 0;
}

.login-panel h1 {
    color: var(--text);
    font-size: 30px;
}

.login-panel p {
    color: var(--muted);
    font-size: 14px;
    line-height: 1.45;
}

.login-logo {
    width: 188px;
    height: 96px;
    margin-bottom: 8px;
}

.selector-page {
    min-height: 100vh;
}

.selector-shell {
    display: grid;
    align-items: start;
    min-height: calc(100vh - 154px);
    padding: 34px 20px;
}

.tool-choice {
    display: grid;
    grid-template-columns: repeat(2, minmax(240px, 1fr));
    gap: 18px;
    width: min(980px, 100%);
    margin: 0 auto;
}

.tool-card {
    position: relative;
    overflow: hidden;
    display: grid;
    gap: 12px;
    min-height: 232px;
    padding: 26px;
    border: 1px solid var(--line);
    border-radius: 22px;
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
    box-shadow: var(--shadow-soft);
}

.tool-card::after {
    position: absolute;
    right: -94px;
    bottom: -110px;
    width: 220px;
    height: 220px;
    border-radius: 50%;
    background: repeating-conic-gradient(from -25deg, rgba(255, 0, 69, 0.13) 0deg 2deg, transparent 2deg 8deg);
    content: "";
    pointer-events: none;
}

.tool-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow);
    transform: translateY(-1px);
}

.tool-card.is-new {
    border-color: rgba(255, 0, 69, 0.16);
    background: linear-gradient(180deg, #fff 0%, #fff5f8 100%);
}

.tool-card-kicker {
    color: var(--primary);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.tool-card strong {
    font-size: 28px;
}

.tool-card span {
    line-height: 1.45;
}

.tool-card-action {
    align-self: end;
    justify-self: start;
    padding: 10px 16px;
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    box-shadow: 0 14px 26px rgba(255, 0, 69, 0.22);
}

/* Gestión masiva: zona operativa y tabla. */
#ownerOperationFields,
#centerOperationFields,
#deactivateOperationFields,
#meatOwnerOperationFields,
#maleGroupOperationFields,
#publicSaleOperationFields,
#internalSaleOperationFields,
#productionDateOperationFields {
    display: grid;
    gap: 5px;
}

#ownerOperationFields[hidden],
#centerOperationFields[hidden],
#deactivateOperationFields[hidden],
#meatOwnerOperationFields[hidden],
#maleGroupOperationFields[hidden],
#publicSaleOperationFields[hidden],
#internalSaleOperationFields[hidden],
#productionDateOperationFields[hidden] {
    display: none;
}

select:focus,
input:focus,
button:focus {
    outline: 3px solid rgba(255, 122, 164, 0.38);
    outline-offset: 1px;
}

button {
    min-height: 42px;
    border: 1px solid transparent;
    border-radius: 999px;
    padding: 0 16px;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
}

button:disabled,
select:disabled,
input:disabled,
textarea:disabled {
    cursor: not-allowed;
    opacity: 0.58;
}

.primary-button {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 14px 26px rgba(255, 0, 69, 0.2);
}

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

.secondary-button {
    border-color: var(--line);
    background: var(--surface-strong);
    color: var(--text);
}

.counter {
    display: flex;
    align-items: baseline;
    gap: 5px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
}

.counter span:first-child {
    color: var(--primary);
    font-size: 26px;
    font-weight: 700;
}

.message {
    display: none;
    padding: 10px 12px;
    border-radius: 10px;
    line-height: 1.4;
}

.message.is-visible { display: block; }

.message.is-error {
    border: 1px solid rgba(176, 0, 48, 0.35);
    background: #fff1ef;
    color: var(--danger);
}

.message.is-success {
    border: 1px solid rgba(19, 121, 91, 0.35);
    background: #edf8f4;
    color: var(--success);
}

.content {
    min-width: 0;
    padding: 22px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: var(--shadow-soft);
}

.table-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}

.table-toolbar p {
    margin: 4px 0 0;
    color: var(--muted);
}

.inactive-toggle {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    color: var(--text);
    font-weight: 700;
    white-space: nowrap;
}

.inactive-toggle input,
input[type="checkbox"] {
    width: 18px;
    height: 18px;
}

.horizontal-scroll-top {
    overflow-x: auto;
    overflow-y: hidden;
    height: 14px;
    margin-bottom: 3px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
}

.horizontal-scroll-top div { height: 1px; }

.table-wrap {
    overflow: auto;
    max-height: calc(100vh - 252px);
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
}

table {
    width: 100%;
    min-width: 1550px;
    border-collapse: collapse;
}

th,
td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
    white-space: nowrap;
}

th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--surface-strong);
    color: var(--text);
    font-size: 12px;
    text-transform: uppercase;
}

.filter-row th {
    top: 39px;
    padding: 5px;
    background: #fbf8fc;
}

.filter-row input {
    width: 100%;
    height: 32px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0 8px;
    font-size: 12px;
    text-transform: none;
}

.sort-button {
    width: 100%;
    min-height: 26px;
    border: 0;
    padding: 0;
    border-radius: 0;
    background: transparent;
    color: inherit;
    text-align: left;
    text-transform: uppercase;
    font-size: 12px;
}

th.check-col,
td.check-col {
    position: sticky;
    left: 0;
    z-index: 2;
    width: 42px;
    min-width: 42px;
    background: inherit;
    text-align: center;
}

th.sticky-number,
td.sticky-number {
    position: sticky;
    left: 42px;
    z-index: 2;
    min-width: 130px;
    background: inherit;
    border-right: 1px solid var(--line);
    box-shadow: 5px 0 12px rgba(33, 0, 76, 0.07);
}

thead th.check-col,
thead th.sticky-number { z-index: 4; background: var(--surface-strong); }
thead .filter-row th.check-col,
thead .filter-row th.sticky-number { background: #fbf8fc; }

.sort-button.is-active::after { content: " ▲"; }
.sort-button.is-desc::after { content: " ▼"; }

tbody tr:hover { background: #fff7fa; }
tbody td.check-col,
tbody td.sticky-number { background: #fff; }
tbody tr:hover td.check-col,
tbody tr:hover td.sticky-number { background: #fff7fa; }

.empty-state {
    height: 120px;
    color: var(--muted);
    text-align: center;
}

.owner-cell {
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sql-preview {
    margin-top: 18px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--surface);
    overflow: hidden;
}

.sql-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px;
    border-bottom: 1px solid var(--line);
    background: var(--surface-strong);
}

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

.sql-preview-header p { margin: 4px 0 0; color: var(--muted); }

#sqlPreviewText {
    display: block;
    width: 100%;
    min-height: 260px;
    border: 0;
    padding: 12px;
    resize: vertical;
    color: #21004c;
    font-family: Consolas, "Courier New", monospace;
    font-size: 13px;
    line-height: 1.45;
}

@media (max-width: 760px) {
    .topbar,
    .table-toolbar { align-items: flex-start; flex-direction: column; }
    .topbar { min-height: 0; padding: 20px 16px 46px; }
    .topbar h1 { font-size: 32px; }
    .topbar p { font-size: 14px; }
    .app-shell { grid-template-columns: 1fr; width: calc(100% - 24px); margin-top: -26px; }
    .sidebar { border-bottom: 1px solid var(--line); }
    .table-wrap { max-height: 62vh; }
}
