/* Console Factures: internal tool, server-rendered, no framework. */

:root {
    --bg: #F6F6F3;
    --surface: #FFFFFF;
    --text: #1B1B19;
    --text-muted: #5C5C56;
    --border: #E2E2DC;
    --accent: #2457C5;
    --accent-hover: #1C469F;

    --green-bg: #E3F1E7;
    --green-fg: #1D5733;
    --amber-bg: #FBEFD9;
    --amber-fg: #6B4205;
    --grey-bg: #ECECE7;
    --grey-fg: #45453F;
    --red-bg: #F8E2DF;
    --red-fg: #82231A;

    --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
    --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
    --radius: 6px;
    --target: 40px;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 400 15px/1.5 var(--font);
}

a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.25; }
code, .mono { font-family: var(--mono); font-size: 0.92em; }
.muted { color: var(--text-muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.visually-hidden {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* --- Layout --------------------------------------------------------------------------------- */

.layout {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}
.sidebar__title { font-size: 20px; }
.sidebar__title a { color: var(--text); text-decoration: none; }
.sidebar__meta { margin: 4px 0 0; font-size: 13px; color: var(--text-muted); }
.sidebar__heading {
    font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
    color: var(--text-muted); margin-bottom: 6px;
}
.sidebar__foot { margin-top: auto; display: grid; gap: 8px; }

.nav { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.nav__link {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    min-height: var(--target); padding: 8px 10px; border-radius: var(--radius);
    color: var(--text); text-decoration: none; overflow-wrap: anywhere;
}
.nav__link:hover { background: var(--bg); color: var(--text); }
.nav__link.is-active { background: #E8EEFA; color: var(--accent-hover); font-weight: 500; }
.nav__count { font-family: var(--mono); font-size: 13px; color: var(--text-muted); }

.main { padding: 20px 24px 40px; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.main__head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.main__heading { flex: 1 1 220px; }
.main__heading p { margin: 2px 0 0; }
.main__title { font-size: 22px; }

.search { display: flex; gap: 8px; flex: 1 1 320px; max-width: 520px; }
.search .input { flex: 1; min-width: 0; }

.workspace { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
.workspace.has-detail { grid-template-columns: minmax(0, 1fr) 340px; }
/* The mailbox is repeated in the detail panel: give its column to the status. */
.workspace.has-detail .col-mailbox { display: none; }

/* --- Controls ------------------------------------------------------------------------------- */

.button {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: var(--target); padding: 8px 14px;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface); color: var(--text);
    font: 500 14px/1.2 var(--font); text-decoration: none; cursor: pointer;
}
.button:hover { border-color: #C9C9C1; color: var(--text); }
.button--primary { background: var(--accent); border-color: var(--accent); color: #FFFFFF; }
.button--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #FFFFFF; }
.button--ghost { background: transparent; }
.button--block { width: 100%; }

.label { display: block; font-size: 13px; font-weight: 500; color: var(--text-muted); margin-bottom: 4px; }
.input {
    min-height: var(--target); padding: 8px 10px;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface); color: var(--text); font: 400 15px/1.3 var(--font);
}
.input:focus { border-color: var(--accent); }
.inline { display: flex; gap: 8px; }
.inline .input { flex: 1; min-width: 0; }

.check { display: flex; align-items: center; gap: 8px; min-height: var(--target); cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
.check.is-disabled { color: var(--text-muted); cursor: not-allowed; }
.fieldset { border: 0; margin: 0; padding: 0; }

.alert { margin: 0; padding: 10px 12px; border-radius: var(--radius); }
.alert--error { background: var(--red-bg); color: var(--red-fg); }
.alert--success { background: var(--green-bg); color: var(--green-fg); }

/* --- Status pills --------------------------------------------------------------------------- */

.pill {
    display: inline-block; padding: 2px 10px; border-radius: 999px;
    font-size: 13px; font-weight: 500; white-space: nowrap;
}
.pill--green { background: var(--green-bg); color: var(--green-fg); }
.pill--amber { background: var(--amber-bg); color: var(--amber-fg); }
.pill--grey { background: var(--grey-bg); color: var(--grey-fg); }
.pill--red { background: var(--red-bg); color: var(--red-fg); }

/* --- Table ---------------------------------------------------------------------------------- */

.table-wrap {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
    text-align: left; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
    color: var(--text-muted); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #FAFAF8; }
.table tr.is-selected { background: #EEF2FB; }
.table .subject { min-width: 180px; }
.table .subject a {
    display: flex; align-items: center; min-height: var(--target);
    color: var(--text); font-weight: 500; text-decoration: none;
}
.table .subject a:hover { color: var(--accent); text-decoration: underline; }
.table .truncate { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table .empty { text-align: center; color: var(--text-muted); padding: 32px 12px; }
.table--runs td { vertical-align: top; }
/* Longer labels (Spanish) wrap instead of pushing the status out of view. */
.table .pill { white-space: normal; max-width: 180px; border-radius: 12px; }

.pagination { display: flex; align-items: center; gap: 12px; margin-top: 12px; }

/* --- Detail panel --------------------------------------------------------------------------- */

.detail {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; position: sticky; top: 16px;
    max-height: calc(100vh - 32px); overflow-y: auto;
}
.detail__title { font-size: 17px; overflow-wrap: anywhere; }
.detail > .pill { justify-self: start; max-width: 100%; white-space: normal; }
.detail select.input { width: 100%; text-overflow: ellipsis; }
.detail > .muted { margin: -8px 0 0; font-size: 14px; overflow-wrap: anywhere; }
.detail__label { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 4px; }
.detail__block p { margin: 0; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; margin: 0; }
.grid dt { font-size: 12px; color: var(--text-muted); }
.grid dd { margin: 0; overflow-wrap: anywhere; }
.grid .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.path { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; overflow-wrap: anywhere; }
.note { margin: 0; background: var(--amber-bg); color: var(--amber-fg); border-radius: var(--radius); padding: 10px 12px; font-size: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.reclassify .small { margin: 6px 0 0; }

.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: 14px; }
.history li { display: grid; grid-template-columns: auto 1fr; gap: 10px; }
.history time { color: var(--text-muted); font-size: 12px; padding-top: 2px; white-space: nowrap; }
.history span { overflow-wrap: anywhere; }

/* --- Backfill panel ------------------------------------------------------------------------- */

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.panel__summary {
    display: flex; align-items: center; min-height: var(--target); padding: 8px 16px;
    font-weight: 600; cursor: pointer;
}
.panel[open] { padding-bottom: 16px; }
.panel[open] > :not(summary) { margin-left: 16px; margin-right: 16px; }
.panel__subtitle { font-size: 15px; margin-top: 20px; margin-bottom: 8px; }
.backfill { display: grid; gap: 12px; max-width: 560px; }
.backfill__dates { display: flex; flex-wrap: wrap; gap: 12px; }
.backfill__mode { margin: 0; padding: 10px 12px; border-radius: var(--radius); font-size: 14px; }
.backfill__mode.is-on { background: var(--green-bg); color: var(--green-fg); }
.backfill__mode.is-off { background: var(--grey-bg); color: var(--grey-fg); }

/* --- Login ---------------------------------------------------------------------------------- */

.login {
    max-width: 360px; margin: 12vh auto 0; padding: 28px 24px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    display: grid; gap: 14px;
}
.login__title { font-size: 24px; }
.login__hint { margin: 0; color: var(--text-muted); }
.login__form { display: grid; gap: 10px; }
.input--code { font-family: var(--mono); font-size: 22px; letter-spacing: .3em; text-align: center; }

/* --- Responsive ----------------------------------------------------------------------------- */

@media (max-width: 1100px) {
    .workspace.has-detail { grid-template-columns: minmax(0, 1fr); }
    .workspace.has-detail .col-mailbox { display: table-cell; }
    .detail { position: static; max-height: none; }
}

@media (max-width: 760px) {
    .layout { grid-template-columns: 1fr; }
    .sidebar { border-right: 0; border-bottom: 1px solid var(--border); gap: 16px; }
    .sidebar__foot { margin-top: 0; }
    .main { padding: 16px; }
    .search { max-width: none; }
    .main__head > .button { width: 100%; }
    .grid { grid-template-columns: 1fr; }
    .login { margin: 8vh 16px 0; }
}

/* --- Filters ------------------------------------------------------------------------------- */

.filters {
    display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 12px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px;
}
.filters__field { display: flex; flex-direction: column; flex: 1 1 170px; min-width: 0; }
.filters__field--wide { flex: 2 1 240px; }
.filters__field--amount { flex: 0 1 120px; }
.filters__field .label { margin-bottom: 4px; }
.filters__field .input { width: 100%; }
.filters__actions { display: flex; gap: 8px; }

/* --- Brand -------------------------------------------------------------------------------- */

.brand { display: inline-flex; align-self: flex-start; border-radius: var(--radius); }
.brand__logo { display: block; width: 168px; height: auto; }
.sidebar__title { font-size: 15px; font-weight: 600; color: var(--text-muted); margin-top: 10px; letter-spacing: .02em; }

/* --- Language switcher (segmented control) -------------------------------------------------- */

.lang {
    display: inline-flex; align-self: flex-start; padding: 3px; gap: 2px;
    background: var(--bg); border: 1px solid var(--border); border-radius: 999px;
}
.lang__option {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 44px; min-height: 34px; padding: 0 12px; border-radius: 999px;
    color: var(--text-muted); font: 600 12px/1 var(--font); letter-spacing: .08em; text-decoration: none;
    transition: background-color .15s ease, color .15s ease;
}
.lang__option:hover { color: var(--text); background: var(--surface); }
.sidebar__foot .lang { justify-self: start; }
.lang__option.is-active { background: var(--accent); color: #FFFFFF; box-shadow: 0 1px 2px rgba(27, 27, 25, .18); }
.lang__option:focus-visible { outline-offset: 1px; }

.login__top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.login__top .brand__logo { width: 140px; }

/* --- Runs ----------------------------------------------------------------------------------- */

.table tr.is-link { cursor: pointer; position: relative; }
.table .row-link { font-weight: 600; text-decoration: none; }
/* The run number link covers the whole row: one target, still a real <a>. */
.table .row-link::after { content: ""; position: absolute; inset: 0; }
.table tr.is-link a:not(.row-link) { position: relative; z-index: 1; }

.panel--run { padding: 16px; display: grid; gap: 14px; }
.run__head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.grid--run { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid--run > div:last-child { grid-column: span 2; }
@media (max-width: 760px) { .grid--run > div:last-child { grid-column: auto; } }
