/* Back office (/mng). Minimum font size is 15px everywhere. */
:root {
    --bg: #ffffff;
    --rail: #f3f3f3;
    --panel: #f7f7f7;
    --line: #e4e4e4;
    --ink: #111111;
    --muted: #55585f;
    --active: #e9e9e9;
    --accent: #4f46e5;
    /* Secondary colour = the red of the Paten project (its --color-highlight). */
    --secondary: #b80000;
    --secondary-dark: #8f0000;      /* hover / pressed */
    --secondary-soft: #fdeaea;      /* tinted background (notices) */
    --secondary-line: #f1c0c0;      /* tinted border */
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
    font: 16px/1.4 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--ink);
    background: var(--bg);
}
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- Login ---------- */
.mng-login { display: grid; place-items: center; background: var(--rail); padding: 16px; }
.login-card {
    width: 100%; max-width: 420px; background: #fff; border: 1px solid var(--line);
    border-radius: 16px; padding: 32px; box-shadow: 0 8px 30px rgba(0, 0, 0, .06);
}
.login-card h1 { margin: 0; font-size: 26px; }
.login-sub { margin: 4px 0 20px; color: var(--muted); }
.login-card label { display: block; margin: 14px 0 6px; font-weight: 600; }
.login-card input {
    width: 100%; padding: 11px 12px; font-size: 16px; border: 1px solid #c9c9c9; border-radius: 10px;
}
.login-card input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.captcha-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.captcha-row img { border: 1px solid var(--line); border-radius: 10px; max-width: 100%; height: auto; }
.captcha-refresh {
    display: grid; place-items: center; width: 40px; height: 40px; flex: none;
    border: 1px solid var(--line); border-radius: 10px; color: var(--muted);
}
.captcha-refresh:hover { background: var(--active); color: var(--ink); }
.captcha-input { text-transform: uppercase; letter-spacing: 3px; font-family: ui-monospace, Menlo, monospace; }
.login-card button[type=submit] {
    width: 100%; margin-top: 20px; padding: 12px; border: 0; border-radius: 10px;
    background: var(--ink); color: #fff; font-weight: 600;
}
.login-card button[type=submit]:hover { background: #2b2b2b; }
.login-error {
    margin: 0 0 8px; padding: 10px 12px; border-radius: 10px;
    background: var(--secondary-soft); color: var(--secondary); border: 1px solid var(--secondary-line);
}

/* ---------- App shell: rail | panel | content ---------- */
.shell { display: grid; grid-template-columns: 76px 300px minmax(0, 1fr); min-height: 100vh; }
.shell.panel-closed { grid-template-columns: 76px 0 minmax(0, 1fr); }
.shell.panel-closed .panel { visibility: hidden; border: 0; padding: 0; overflow: hidden; }

/* Column 1 — icon rail */
.rail {
    background: var(--rail); border-right: 1px solid var(--line);
    display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 20px 0;
}
.rail-logo {
    width: 40px; height: 40px; border-radius: 12px; background: var(--accent); color: #fff;
    display: grid; place-items: center; font-weight: 800; font-size: 20px; margin-bottom: 14px;
}
.rail a, .rail button {
    display: grid; place-items: center; width: 48px; height: 48px; border-radius: 12px;
    border: 0; background: none; color: var(--ink);
}
.rail a:hover, .rail button:hover { background: var(--active); }
.rail a.active, .rail .rail-btn.active { background: var(--active); }
.rail hr { width: 40px; margin: 6px 0; }

/* Column 2 — text menu */
.panel {
    position: relative; background: var(--panel); border-right: 1px solid var(--line);
    padding: 24px 20px; overflow-y: auto;
}
.panel h2 { margin: 0 0 18px; font-size: 22px; }
.panel-toggle {
    position: absolute; top: 20px; right: 12px; width: 34px; height: 34px; border-radius: 50%;
    border: 1px solid var(--line); background: #fff; display: grid; place-items: center;
}
.menu { list-style: none; margin: 0; padding: 0; }
.menu a {
    display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 10px; color: var(--muted);
}
.menu a:hover { background: var(--active); color: var(--ink); }
.menu a.active { background: var(--active); color: var(--ink); font-weight: 600; }
.panel hr { margin: 14px 0; }

.group > summary, .group-head {
    display: flex; align-items: center; gap: 8px; font-weight: 700; padding: 6px 10px; margin-bottom: 4px;
    cursor: pointer; list-style: none;
}
.group > summary::-webkit-details-marker { display: none; }
.group > summary svg { margin-left: auto; transition: transform .15s; }
.group:not([open]) > summary svg { transform: rotate(-90deg); }
.group-head { cursor: default; }
.group-head .add {
    margin-left: auto; width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line);
    background: #fff; display: grid; place-items: center;
}
.badge {
    background: #e2e2e2; color: var(--muted); border-radius: 6px; padding: 0 7px;
    font-size: 15px; font-weight: 600;
}
/* Coloured chips (favourites) and dots (projects) */
.chip { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; color: #fff; flex: none; }
.dot { width: 12px; height: 12px; border-radius: 3px; flex: none; margin: 0 8px; }
.c-blue { background: #3b9ae1; } .c-teal { background: #2a8a7d; }
.c-violet { background: #5b4be0; } .c-pink { background: #ec6fb3; }

/* Column 3 — content */
.content { padding: 28px 32px; }
.content-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 24px; }
.content-head h1 { margin: 0; font-size: 26px; }
/* Dashboard rule: two columns at most, half the width each. */
.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.card { border: 1px solid var(--line); border-radius: 14px; padding: 20px; min-height: 140px; }
.card h3 { margin: 0 0 8px; font-size: 18px; }
.card p { margin: 0; color: var(--muted); }

@media (max-width: 860px) {
    .shell { grid-template-columns: 64px minmax(0, 1fr); }
    .panel { display: none; }
    .cards { grid-template-columns: minmax(0, 1fr); }
}

/* Button that re-opens the text menu: shown only while the panel is closed. */
.head-left { display: flex; align-items: center; gap: 12px; }
.panel-open {
    display: none; width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line);
    background: #fff; place-items: center;
}
.panel-open:hover { background: var(--active); }
.shell.panel-closed .panel-open { display: grid; }
.area[hidden] { display: none; }

/* ---------- Settings > Sandbox ---------- */
.sandbox-form { max-width: none; display: flex; flex-direction: column; gap: 6px; }
.sandbox-intro { margin: 0 0 12px; color: var(--muted); }
.sandbox-form input[type=password], .sandbox-form input[type=url], .sandbox-form input[type=text], .sandbox-form input[type=number] { width: 100%; padding: 11px 12px; font-size: 16px; border: 1px solid #c9c9c9; border-radius: 10px; }
.sandbox-form input[type=password]:focus, .sandbox-form input[type=url]:focus, .sandbox-form input[type=text]:focus, .sandbox-form input[type=number]:focus { outline: 2px solid var(--accent); border-color: transparent; }
.field-label { font-weight: 600; margin-top: 14px; }
.hint { margin: 0; color: var(--muted); font-size: 14px; }
.btn-primary { align-self: flex-end;   /* submit buttons sit on the right of their row */ margin-top: 16px; padding: 11px 22px; border: 0; border-radius: 10px; background: var(--ink); color: #fff; font-weight: 600; }
.btn-primary:hover { background: #2b2b2b; }
.notice-ok { margin: 0 0 16px; padding: 10px 12px; border-radius: 10px; background: #e8f5ec; color: #1d6b3a; border: 1px solid #bfe3cb; }
/* On/Off switch built on a real checkbox */
.switch { display: inline-flex; align-items: center; gap: 12px; cursor: pointer; font-weight: 600; margin-bottom: 8px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { position: relative; width: 50px; height: 28px; border-radius: 14px; background: #c3c5cb; transition: background .15s; flex: none; }
.switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); }
.switch input:checked + .switch-track { background: var(--secondary); }
.switch input:checked + .switch-track::after { transform: translateX(22px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--secondary); outline-offset: 2px; }
.switch .on-text { display: none; }
.switch input:checked ~ .switch-text .on-text { display: inline; }
.switch input:checked ~ .switch-text .off-text { display: none; }

/* Reset Sessions card + confirmation modal */
.sandbox-reset { margin-top: 20px; }
.sandbox-reset { display: flex; flex-direction: column; gap: 6px; }   /* same rhythm as .sandbox-form */
.sandbox-reset h3 { margin: 0; font-size: 18px; }
/* Text -> button gap = 16px, identical to hint -> Guardar in the form above. */
.sandbox-reset .btn-danger { align-self: flex-start; margin-top: 16px; }
.btn-danger { padding: 11px 22px; border: 0; border-radius: 10px; background: var(--secondary); color: #fff; font-weight: 600; }
.btn-danger:hover { background: var(--secondary-dark); }
.btn-secondary { padding: 11px 22px; border: 1px solid #c9c9c9; border-radius: 10px; background: #fff; font-weight: 600; }
.btn-secondary:hover { background: var(--active); }
.modal { border: 0; border-radius: 16px; padding: 28px; width: min(520px, calc(100% - 32px)); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.modal::backdrop { background: rgba(0, 0, 0, .45); }
.modal h2 { margin: 0 0 12px; font-size: 22px; }
.modal p { margin: 0 0 12px; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 20px; }

/* Dropdowns (<select>): ONE global style for every select in the back office, matching the
   text inputs (same height, border, radius, focus ring). appearance:none removes the OS look;
   the chevron is a background image, so it follows the same rules in every browser. */
select {
    -webkit-appearance: none; -moz-appearance: none; appearance: none;
    display: block; width: 100%; height: 44px;
    padding: 0 44px 0 12px;
    font: inherit; font-size: 16px; line-height: 1.4; color: var(--ink);
    border: 1px solid #c9c9c9; border-radius: 10px; cursor: pointer;
    background-color: #fff;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2355585f' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center; background-size: 20px 20px;
}
select:hover { border-color: #9a9ca3; }
select:focus { outline: 2px solid var(--accent); border-color: transparent; }
select:disabled { background-color: var(--panel); color: var(--muted); cursor: not-allowed; }
.field-label.first { margin-top: 0; }

/* Same control height everywhere: text-like inputs match the dropdown (44px). */
.login-card input, .sandbox-form input[type=password], .sandbox-form input[type=url], .sandbox-form input[type=text], .sandbox-form input[type=number] { height: 44px; }

/* Settings pages made of several boxes inside one form: boxes 20px apart (same as the dashboard card grid). */
.settings-form { display: flex; flex-direction: column; gap: 20px; }
.settings-form > .btn-primary { margin-top: 0; }          /* the gap above already gives the spacing */
.sandbox-form h3 { margin: 0 0 6px; font-size: 18px; }   /* box title */

/* Native checkboxes and radios take the secondary colour too (the switches above are custom-drawn). */
input[type=checkbox], input[type=radio] { accent-color: var(--secondary); width: 18px; height: 18px; }
.switch input[type=checkbox] { width: 1px; height: 1px; }   /* the switch hides its real checkbox */

/* Intro text above the first field of a form box: 12px before the switch (higher specificity than ".card p"). */
.sandbox-form .sandbox-intro { margin-bottom: 12px; }

/* ---------- User menu (top right of the content header) ---------- */
.user-menu { position: relative; }
.user-menu > summary {
    display: flex; align-items: center; gap: 8px; list-style: none; cursor: pointer;
    padding: 8px 10px 8px 12px; border-radius: 10px; font-weight: 600; color: var(--ink);
}
.user-menu > summary::-webkit-details-marker { display: none; }
.user-menu > summary:hover, .user-menu[open] > summary { background: var(--active); }
.user-menu > summary svg:last-child { transition: transform .15s; color: var(--muted); }
.user-menu[open] > summary svg:last-child { transform: rotate(180deg); }
.user-menu-list {
    position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 210px; padding: 6px;
    background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, .12);
}
.user-menu-list a, .user-menu-list button {
    display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border: 0; border-radius: 8px;
    background: none; font: inherit; color: var(--ink); text-align: left; cursor: pointer;
}
.user-menu-list a:hover, .user-menu-list button:hover { background: var(--active); }
.user-menu-list .signout { color: var(--secondary); }
.user-menu-list .signout:hover { background: var(--secondary-soft); }

/* ---------- Form grid inside a box: two columns at most, half the width each; one column on narrow panes ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 20px; margin-top: 8px; }
.form-grid .field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.form-grid .field.span-2 { grid-column: 1 / -1; }
.form-grid .field-label { margin-top: 0; }                 /* the grid gap already spaces the fields */
.form-grid .switch { margin-bottom: 0; }
.check-row { display: flex; align-items: center; gap: 8px; margin-top: 2px; cursor: pointer; }
@media (max-width: 860px) { .form-grid { grid-template-columns: minmax(0, 1fr); } }

/* Secret field with an eye button inside the input (right side) */
.secret-wrap { position: relative; }
.secret-wrap input { padding-right: 52px; }
.secret-wrap .eye {
    position: absolute; right: 5px; top: 5px; width: 34px; height: 34px; border: 0; border-radius: 8px;
    background: none; color: var(--muted); cursor: pointer; display: grid; place-items: center; font-size: 16px;
}
.secret-wrap .eye:hover { background: var(--active); color: var(--ink); }
.secret-wrap .eye[aria-pressed="true"] { color: var(--secondary); }
.secret-wrap .eye:disabled { cursor: progress; opacity: .6; }

/* ---------- AI summary: list of AIs, textarea, form actions ---------- */
.ai-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 10px; }
.ai-list li {
    display: grid; grid-template-columns: minmax(150px, 1.1fr) minmax(0, 1.3fr) minmax(0, 2fr) auto; gap: 14px; align-items: center;
    padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px;
}
.ai-name { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.ai-model { color: var(--muted); overflow-wrap: anywhere; }
.badge-state { justify-self: start; padding: 4px 12px; border-radius: 14px; line-height: 1.35; font-size: 15px; font-weight: 600; }
.badge-state.ok { background: #e8f5ec; color: #1d6b3a; border: 1px solid #bfe3cb; }
/* Not ready: same soft tone as .ok, but in the secondary red. */
.badge-state.off { background: var(--secondary-soft); color: var(--secondary); border: 1px solid var(--secondary-line); }
.ai-link { font-weight: 600; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
.ai-link:hover { color: var(--secondary); }
.hint.warn { color: var(--secondary); }
@media (max-width: 860px) { .ai-list li { grid-template-columns: minmax(0, 1fr); gap: 6px; } }

textarea {
    display: block; width: 100%; min-height: 220px; padding: 12px; font: inherit; font-size: 16px; line-height: 1.5;
    color: var(--ink); border: 1px solid #c9c9c9; border-radius: 10px; background: #fff; resize: vertical;
}
textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
textarea[readonly] { background: var(--panel); color: var(--muted); }
.form-actions { display: flex; justify-content: flex-end; gap: 12px; }   /* Save stays on the right */
.form-actions .btn-primary { margin-top: 0; }

/* ---------- Available models box ---------- */
.models-box { margin-top: 20px; }                       /* the form above ends with its own 20px gap logic */
.models-tools { display: flex; gap: 12px; align-items: center; margin-top: 8px; }
.models-filter { flex: 1; min-width: 0; height: 44px; padding: 0 12px; font: inherit; font-size: 16px; border: 1px solid #c9c9c9; border-radius: 10px; }
.models-filter:focus { outline: 2px solid var(--accent); border-color: transparent; }
.models-refresh { height: 44px; padding: 0 18px; white-space: nowrap; }
.models-refresh:disabled { opacity: .6; cursor: progress; }
.models-status { margin-top: 6px; }
.models-status.error { color: var(--secondary); }
.models-list { list-style: none; margin: 8px 0 0; padding: 0; max-height: 380px; overflow-y: auto; border: 1px solid var(--line); border-radius: 12px; }
.models-list li { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) 100px 130px 90px 90px auto; gap: 12px; align-items: center; padding: 8px 12px; border-top: 1px solid var(--line); }
.models-list li:first-child { border-top: 0; }
.models-list li:hover { background: var(--panel); }
.models-list .m-id { font-family: ui-monospace, Menlo, monospace; font-size: 15px; overflow-wrap: anywhere; }
.models-list .m-meta { color: var(--muted); overflow-wrap: anywhere; }
.models-list .m-use { height: 34px; padding: 0 14px; border: 1px solid #c9c9c9; border-radius: 8px; background: #fff; font-weight: 600; cursor: pointer; }
.models-list .m-use:hover { background: var(--active); }
/* Column titles: same grid as a row (the 12px padding + 1px border of the list are mirrored). */
.models-head { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) 100px 130px 90px 90px auto; gap: 12px; margin-top: 8px; padding: 0 30px 0 13px; font-weight: 600; font-size: 15px; color: var(--muted); }
.models-head span:last-child { width: 52px; }                  /* same width as the Use button */
.models-list .m-max, .models-head .m-max { text-align: right; font-variant-numeric: tabular-nums; }
.models-list .m-max { font-family: ui-monospace, Menlo, monospace; font-size: 15px; }
.models-head[hidden] { display: none; }
@media (max-width: 860px) { .models-list li { grid-template-columns: minmax(0, 1fr) auto auto; } .models-list .m-meta, .models-list .m-date, .models-head { display: none; } }

/* ---------- Connection test box ---------- */
.test-box { margin-top: 20px; }
.test-run { align-self: flex-start; height: 44px; padding: 0 18px; white-space: nowrap; }
.test-run:disabled { opacity: .6; cursor: progress; }
.test-status { margin-top: 10px; }
.test-status.ok { color: #1a7f37; }
.test-status.error { color: var(--secondary); }

/* ---------- Articles CRUD ---------- */
.list-tools { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 20px; }
.list-tools input[type=search] { flex: 1; min-width: 220px; height: 44px; padding: 0 12px; font: inherit; font-size: 16px; border: 1px solid #c9c9c9; border-radius: 10px; }
.list-tools input[type=search]:focus { outline: 2px solid var(--accent); border-color: transparent; }
.list-tools select { width: auto; min-width: 190px; }
.list-tools .btn-secondary, .list-tools .btn-primary { height: 44px; padding-top: 0; padding-bottom: 0; }
.list-tools .btn-primary { margin: 0; }
.btn-link { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; }      /* links styled as buttons */
.btn-primary.btn-link, .btn-danger.btn-link { color: #fff; }
.btn-secondary.btn-link { color: var(--ink); }
.btn-primary.btn-link { margin-top: 0; }
.table-card { padding: 0; overflow: hidden; }
.table-card > .hint { padding: 14px 20px 0; }
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 16px; }
.data-table th { text-align: left; padding: 12px 16px; font-size: 15px; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data-table td { padding: 12px 16px; border-top: 1px solid var(--line); vertical-align: top; }
.data-table tbody tr:first-child td { border-top: 0; }
.data-table .sub { display: block; color: var(--muted); font-size: 15px; }
.data-table .empty { text-align: center; color: var(--muted); padding: 28px; }
.data-table .actions { text-align: right; white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.icon-act { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; color: var(--ink); }
.icon-act:hover { background: var(--active); }
.icon-act.danger { color: var(--secondary); }
.icon-act.danger:hover { background: var(--secondary-soft); }
.table-card nav { padding: 14px 20px; }
.table-card .pagination { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; margin: 0; padding: 0; }
.table-card .pagination a, .table-card .pagination li.active span { display: inline-block; padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; text-decoration: none; }
.table-card .pagination li.active span { background: var(--ink); color: #fff; border-color: var(--ink); }
.table-card .pagination a:hover { background: var(--active); }
.check-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 20px; }
.check-row { display: flex; align-items: center; gap: 8px; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 20px; margin: 8px 0 0; }
.detail-grid .span-2 { grid-column: 1 / -1; }
.detail-grid dt { font-weight: 600; margin-bottom: 2px; }
.detail-grid dd { margin: 0; overflow-wrap: anywhere; }
.body-preview { border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; max-height: 420px; overflow: auto; }
.body-preview img { max-width: 100%; height: auto; }
textarea.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
@media (max-width: 860px) { .check-grid, .detail-grid { grid-template-columns: minmax(0, 1fr); } }

/* Form validation: red message under the label, red frame on the control (secondary colour). */
.field-error { margin: 0; color: var(--secondary); font-size: 15px; font-weight: 600; }
.has-error input[type=text], .has-error select, .has-error textarea { border-color: var(--secondary); background-color: var(--secondary-soft); }
.has-error .field-label { color: var(--secondary); }

/* ---------- AI > Stats ---------- */
.range-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 20px; }
.range-bar .field-label { margin: 0 6px 0 0; }
.range-btn { padding: 8px 14px; border: 1px solid #c9c9c9; border-radius: 10px; background: #fff; font-weight: 600; text-decoration: none; color: var(--ink); }
.range-btn:hover { background: var(--active); }
.range-btn.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.legend { display: flex; flex-wrap: wrap; gap: 20px; list-style: none; margin: 0 0 8px; padding: 0; }
.legend li { display: flex; align-items: center; gap: 8px; }
.swatch { width: 14px; height: 14px; border-radius: 3px; flex: none; }
.chart-scroll { overflow-x: auto; }
.chart-scroll .hit:hover { fill: rgba(0, 0, 0, .06); }
.chart-table { margin-top: 12px; }
.chart-table summary { cursor: pointer; font-weight: 600; margin-bottom: 8px; }
.data-table .num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.detail-grid .bad { color: var(--secondary); font-weight: 600; }

/* ---------- Ads > Ad positions ---------- */
.code-view { margin: 4px 0 0; padding: 12px 16px; max-height: 460px; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
             font: 15px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre; tab-size: 2; }
.plain-list { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }

/* Sortable table headers (mng_sort_th): the whole label is the link; the arrow shows the direction. */
.data-table th.sortable a { display: inline-flex; align-items: center; gap: 6px; color: inherit; text-decoration: none; }
.data-table th.sortable a:hover, .data-table th.sortable a:focus-visible { color: var(--accent); }
.data-table th.sortable svg { opacity: .35; flex: none; }
.data-table th.sorted { color: var(--ink); }
.data-table th.sorted svg { opacity: 1; }

/* Secondary link under the sign-in / password-recovery forms ("Forgot your password?", "Back to sign in"). */
.login-alt { margin: 18px 0 0; text-align: center; font-size: 15px; }
.login-alt a { color: var(--accent); }

/* ---------- Forms in blocks (Downloaders, Extractors) ----------
   The user's rule: ONE FIELD PER ROW. The blocks are stacked one under the other (one column, full width),
   and inside each block every field has its own row. */
.form-blocks { display: flex; flex-direction: column; gap: 24px; padding: 24px; background: var(--rail); border-radius: 16px; }
@media (max-width: 600px) { .form-blocks { padding: 12px; gap: 16px; } .block-head, .block-fields { padding-left: 16px; padding-right: 16px; } }
.form-blocks-col { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.form-block-wide { }   /* kept for the markup: every block is full width now */

/* Each box: white on the grey tray, so every subject of the form is clearly its own box. */
.form-block { border: 1px solid #dcdcdc; border-radius: 14px; background: #fff; min-width: 0; }
/* Box head: a quiet icon chip (light grey, dark glyph — the only black on the page stays the Save button),
   then the title and one line on what the box is for. */
.block-head { display: flex; align-items: center; gap: 14px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.block-icon { flex: none; width: 40px; height: 40px; border-radius: 50%; background: var(--rail); color: var(--ink);
              display: grid; place-items: center; font-size: 16px; }
.block-head-text { min-width: 0; }
.block-head h3 { margin: 0; font-size: 18px; }
.block-head p { margin: 2px 0 0; color: var(--muted); font-size: 15px; }
.block-fields { padding: 18px 20px 20px; display: flex; flex-direction: column; gap: 18px; }
.block-fields .field { display: flex; flex-direction: column; gap: 6px; min-width: 0; margin: 0; }
.block-fields .field-label { margin-top: 0; }
.block-fields input[type=text], .block-fields input[type=url], .block-fields input[type=number] {
    width: 100%; height: 44px; padding: 0 12px; font: inherit; font-size: 16px; color: var(--ink);
    border: 1px solid #c9c9c9; border-radius: 10px; background: #fff;
}
.block-fields input[type=text]:focus, .block-fields input[type=url]:focus, .block-fields input[type=number]:focus { outline: 2px solid var(--accent); border-color: transparent; }
.block-fields input.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 15px; }
.block-fields textarea { min-height: 110px; }
.block-fields .switch { margin-bottom: 0; }
.has-error input[type=url], .has-error input[type=number] { border-color: var(--secondary); background-color: var(--secondary-soft); }

/* Method: two choices, each with what it means (a radio per row, the whole row is clickable). */
.method-options { border: 0; padding: 0; }
.method-options legend { padding: 0; margin-bottom: 6px; }
.method-option { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border: 1px solid #c9c9c9; border-radius: 10px; cursor: pointer; }
.method-option + .method-option { margin-top: 8px; }
.method-option input { margin-top: 3px; flex: none; }
.method-option-text { display: flex; flex-direction: column; gap: 2px; }
.method-option-name { font-weight: 600; }
.method-option:has(input:checked) { border-color: var(--ink); background: var(--panel); }
.method-option:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Interval with its unit inside the box. */
.input-suffix { position: relative; max-width: 220px; }
.input-suffix input { padding-right: 64px !important; }
.input-suffix span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }

/* A field that only counts when another is on (Extractor needs "Insert into articles"): indented under it,
   dimmed while it does not apply (it stays usable, so the choice can be prepared). */
.depends { padding-left: 16px; border-left: 3px solid var(--line); transition: opacity .15s; }
.block-fields fieldset.depends { padding-left: 16px; border-left: 3px solid var(--line); }
.depends.is-off { opacity: .5; }
/* A field in a box of its own that only applies with another one (Translate fields needs "Insert into articles"):
   just dimmed while it does not apply. */
.dimmable { transition: opacity .15s; }
.dimmable.is-off { opacity: .5; }
/* Checkbox groups are fieldsets: no browser frame, the legend reads like the other field labels. */
.block-fields fieldset.field { border: 0; margin: 0; padding: 0; min-width: 0; }
.block-fields fieldset.field legend { padding: 0; margin-bottom: 6px; }
@media (prefers-reduced-motion: reduce) { .depends, .dimmable { transition: none; } }

/* Detail pages: the record in the same boxes as the form, one item per row (label left, value right;
   the label goes above the value on narrow screens). */
.detail-rows { margin: 0; padding: 4px 20px 8px; }
.detail-row { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 4px 20px; padding: 12px 0; border-top: 1px solid var(--line); }
.detail-row:first-child { border-top: 0; }
.detail-row dt { color: var(--muted); font-weight: 600; }
.detail-row dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
/* Links inside the records and the strips (extractor, downloaders, URL): a quiet underline, so they read as links. */
.detail-row dd a, .run-strip a, .detail-url { text-decoration: underline; text-underline-offset: 3px; text-decoration-color: #b5b7bc; }
.detail-row dd a:hover, .run-strip a:hover { text-decoration-color: currentColor; }
@media (max-width: 700px) { .detail-row { grid-template-columns: minmax(0, 1fr); } }

/* Edit only: last run, result and next run of the downloader, above the form. */
.run-strip { display: flex; flex-wrap: wrap; gap: 12px 32px; align-items: center; margin-bottom: 20px; padding: 14px 20px; border: 1px solid var(--line); border-radius: 14px; }
.run-strip > div { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.run-strip-label { color: var(--muted); font-weight: 600; }
.run-strip-note { color: var(--muted); }

/* The setup in one plain sentence, right above the buttons (written by the form's script). */
.form-summary { margin: 0; padding: 14px 18px; border-left: 3px solid var(--ink); background: var(--panel); border-radius: 0 10px 10px 0; font-size: 16px; line-height: 1.5; }
.form-summary:empty { display: none; }

/* A box's link to its full page (Summary pages): below the rows, on the right. */
.block-link { margin: 0; padding: 0 20px 16px; text-align: right; }
.block-link a { font-weight: 600; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: #b5b7bc; }
.block-link a:hover { text-decoration-color: currentColor; }
