:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e3e6ea;
  --text: #14181d;
  --muted: #667085;
  --accent: #1f6feb;
  --accent-soft: #e8f0fe;
  --ok: #067647;
  --warn: #b54708;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --border: #2a3038;
    --text: #e6e9ee;
    --muted: #98a2b3;
    --accent: #4c8dff;
    --accent-soft: #16243d;
    --ok: #3ccb7f;
    --warn: #f79009;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 12px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

/*
 * The drawer and lightbox are toggled with the `hidden` attribute, but they
 * also set `display: grid` / `position: fixed` via their class — and a class's
 * `display` beats the user-agent `[hidden] { display: none }` rule. Without
 * this, the empty lightbox renders as a full-screen overlay on load and eats
 * every click, so the search box cannot be used. Make `hidden` always win.
 */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* --- top bar --------------------------------------------------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 24px; flex-wrap: wrap;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 38px; height: 38px; border-radius: 9px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; letter-spacing: .5px;
}
.topbar h1 { margin: 0; font-size: 16px; font-weight: 650; }
.sub { margin: 0; font-size: 12px; color: var(--muted); }

.stats { display: flex; gap: 20px; flex-wrap: wrap; }
.stat { text-align: right; }
.stat b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }

main { max-width: 980px; margin: 0 auto; padding: 28px 20px 80px; }

/* --- search ---------------------------------------------------------- */
.search-box {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0 12px; box-shadow: var(--shadow);
  transition: border-color .15s, box-shadow .15s;
}
.search-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-box .icon {
  width: 19px; height: 19px; flex: none;
  fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round;
}
#q {
  flex: 1; border: 0; outline: 0; background: transparent; color: var(--text);
  font-size: 16px; padding: 14px 0;
}
#q::-webkit-search-cancel-button { display: none; }
.clear {
  border: 0; background: transparent; color: var(--muted);
  font-size: 22px; cursor: pointer; line-height: 1; padding: 0 4px;
}
.clear:hover { color: var(--text); }

.hint { font-size: 12.5px; color: var(--muted); margin: 10px 2px 0; }
.hint code {
  background: var(--bg); border: 1px solid var(--border);
  padding: 1px 5px; border-radius: 4px; font-size: 11.5px;
}

.mode {
  margin-top: 14px; font-size: 13px; color: var(--muted);
  display: flex; align-items: center; gap: 8px;
}
.badge {
  background: var(--accent-soft); color: var(--accent);
  padding: 2px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600;
}
.badge.fuzzy { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }

/* --- results --------------------------------------------------------- */
.results { margin-top: 22px; display: grid; gap: 10px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
  cursor: pointer; transition: border-color .12s, transform .12s, box-shadow .12s;
}
.card:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.card:active { transform: translateY(1px); }

.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.card-name { font-weight: 640; font-size: 15.5px; }
.card-meta { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 7px; font-size: 13px; color: var(--muted); }
.card-meta span { display: inline-flex; align-items: center; gap: 5px; }
.chips { display: flex; gap: 6px; flex: none; }
.chip {
  font-size: 11px; padding: 2px 8px; border-radius: 20px;
  background: var(--bg); border: 1px solid var(--border); color: var(--muted);
  white-space: nowrap;
}
.chip.has { border-color: var(--ok); color: var(--ok); }
.matched { font-size: 11.5px; color: var(--ok); font-weight: 600; }

.empty, .loading {
  text-align: center; padding: 56px 20px; color: var(--muted);
}
.empty h3 { margin: 0 0 6px; color: var(--text); font-size: 16px; }

/* --- drawer ---------------------------------------------------------- */
.drawer { position: fixed; inset: 0; z-index: 40; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(9, 12, 16, .5); }
.drawer-panel {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: min(720px, 100%); overflow-y: auto;
  background: var(--bg); border-left: 1px solid var(--border);
  padding: 26px 26px 60px;
  animation: slide .18s ease-out;
}
@keyframes slide { from { transform: translateX(24px); opacity: .4; } }
.drawer-close {
  position: absolute; top: 14px; right: 18px;
  border: 0; background: transparent; color: var(--muted);
  font-size: 27px; cursor: pointer; line-height: 1;
}
.drawer-close:hover { color: var(--text); }

.detail-name { margin: 0 40px 4px 0; font-size: 22px; font-weight: 660; }
.detail-sub { color: var(--muted); font-size: 13px; margin: 0 0 22px; }

.section { margin-bottom: 26px; }
.section h3 {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .7px;
  color: var(--muted); margin: 0 0 10px; font-weight: 650;
}

.fields {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.field {
  display: grid; grid-template-columns: 190px 1fr; gap: 14px;
  padding: 9px 14px; font-size: 13.5px;
  border-bottom: 1px solid var(--border);
}
.field:last-child { border-bottom: 0; }
.field dt { color: var(--muted); overflow-wrap: anywhere; }
.field dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 560px) { .field { grid-template-columns: 1fr; gap: 2px; } }

.ids { display: flex; flex-wrap: wrap; gap: 7px; }
.id-pill {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 7px; padding: 5px 10px; font-size: 12.5px;
}
.id-pill b { color: var(--muted); font-weight: 600; margin-right: 6px; font-size: 11px; text-transform: uppercase; }

/* --- attachments ----------------------------------------------------- */
.files { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 11px; }
.file {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; cursor: pointer;
  transition: border-color .12s;
}
.file:hover { border-color: var(--accent); }
.file-thumb {
  height: 108px; display: grid; place-items: center;
  background: var(--bg); overflow: hidden;
}
.file-thumb img { width: 100%; height: 100%; object-fit: cover; }
.file-thumb .ext {
  font-size: 12px; font-weight: 700; color: var(--muted);
  border: 2px solid var(--border); border-radius: 7px; padding: 9px 13px;
}
.file-info { padding: 7px 9px; }
.file-name { font-size: 11.5px; line-height: 1.35; overflow-wrap: anywhere; }
.file-sub { font-size: 10.5px; color: var(--muted); margin-top: 3px; }

.role-group { margin-bottom: 18px; }
.role-title { font-size: 12.5px; font-weight: 620; margin: 0 0 8px; }

/* --- submissions ----------------------------------------------------- */
.sub-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 10px; overflow: hidden;
}
.sub-head {
  padding: 10px 14px; cursor: pointer; display: flex;
  justify-content: space-between; align-items: center; gap: 10px;
  font-size: 13.5px;
}
.sub-head:hover { background: var(--bg); }
.sub-head b { font-weight: 620; }
.sub-date { color: var(--muted); font-size: 12px; }
.sub-body { border-top: 1px solid var(--border); }
.sub-body[hidden] { display: none; }

/* --- lightbox -------------------------------------------------------- */
.lightbox {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(6, 8, 11, .92);
  display: grid; place-items: center; padding: 30px;
}
.lightbox-content { max-width: 100%; max-height: 100%; display: grid; place-items: center; }
.lightbox img { max-width: 100%; max-height: 88vh; object-fit: contain; border-radius: 6px; }
.lightbox iframe {
  width: min(1000px, 92vw); height: 88vh; border: 0; border-radius: 6px; background: #fff;
}
.lightbox-close {
  position: absolute; top: 16px; right: 22px;
  background: transparent; border: 0; color: #fff; font-size: 34px; cursor: pointer;
}
.lightbox-bar {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 10px; align-items: center;
  color: #fff; font-size: 12.5px;
}
.lightbox-bar a {
  color: #fff; background: rgba(255, 255, 255, .16);
  padding: 6px 13px; border-radius: 6px; text-decoration: none;
}
.lightbox-bar a:hover { background: rgba(255, 255, 255, .28); }

/* ===========================================================================
   Auth + tabbed shell (admin console)
   =========================================================================== */

/* --- login ---------------------------------------------------------------- */
.login-screen {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: linear-gradient(160deg, var(--bg), color-mix(in srgb, var(--accent) 12%, var(--bg)));
  padding: 20px;
}
/* DS&S logo watermark behind the login card. */
.login-screen::before {
  content: ''; position: absolute; inset: 0; z-index: 0; pointer-events: none;
  background: url('assets/ds-logo.jpg') no-repeat center;
  background-size: min(560px, 74vw); opacity: .07;
}
.login-card {
  position: relative; z-index: 1;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow); padding: 32px 30px; width: min(400px, 100%); text-align: center;
}
.login-brand { display: flex; justify-content: center; margin-bottom: 14px; }
.login-brand .logo { width: 48px; height: 48px; border-radius: 11px; font-size: 18px; }
/* Real DS&S logo (login badge + header). */
.brand-logo { width: 56px; height: 56px; border-radius: 13px; object-fit: cover; box-shadow: var(--shadow); }
.brand-logo.sm { width: 38px; height: 38px; border-radius: 9px; }
.login-card h1 { font-size: 19px; margin: 0 0 2px; }
.login-sub { color: var(--muted); font-size: 13px; margin: 0 0 22px; }
.login-step { display: flex; flex-direction: column; gap: 13px; text-align: left; }
.login-step label { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 5px; }
.login-step input {
  padding: 11px 12px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--bg); color: var(--text); font-size: 15px;
}
.login-step input:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#login-otp { font-size: 24px; letter-spacing: 6px; text-align: center; }
.remember-row { margin: -4px 0 2px; }

/* --- custom ALTCHA captcha ------------------------------------------------ */
.captcha {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--border); border-radius: 9px;
  padding: 11px 13px; background: var(--surface); font-size: 13.5px; cursor: default;
  user-select: none;
}
.captcha[data-state="error"] { cursor: pointer; border-color: var(--warn); }
.captcha-check {
  width: 20px; height: 20px; flex: none; border-radius: 5px;
  border: 2px solid var(--border); position: relative; transition: all .15s;
}
.captcha[data-state="solving"] .captcha-check {
  border-color: var(--accent); border-right-color: transparent;
  border-radius: 50%; animation: captcha-spin .7s linear infinite;
}
.captcha[data-state="verified"] .captcha-check {
  border-color: var(--ok); background: var(--ok);
}
.captcha[data-state="verified"] .captcha-check::after {
  content: ""; position: absolute; left: 5px; top: 1px; width: 5px; height: 10px;
  border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.captcha[data-state="error"] .captcha-check { border-color: var(--warn); }
@keyframes captcha-spin { to { transform: rotate(360deg); } }
.captcha-label { flex: 1; color: var(--muted); }
.captcha[data-state="verified"] .captcha-label { color: var(--text); }
.captcha-badge {
  font-size: 10px; font-weight: 700; letter-spacing: .5px; color: var(--muted);
  border: 1px solid var(--border); border-radius: 4px; padding: 2px 5px;
}
.otp-hint { font-size: 13px; color: var(--muted); margin: 0 0 4px; }
.otp-timer { margin: 0; font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.otp-timer b { font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 700; }
.otp-timer.expired { color: var(--warn); }
.otp-timer.expired b { color: var(--warn); }
.login-error {
  margin: 14px 0 0; color: var(--warn); font-size: 13px;
  background: color-mix(in srgb, var(--warn) 12%, transparent);
  padding: 8px 10px; border-radius: 8px; text-align: left;
}

/* --- buttons -------------------------------------------------------------- */
.btn-primary {
  background: var(--accent); color: #fff; border: 0; border-radius: 9px;
  padding: 11px 16px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-secondary {
  background: var(--surface); color: var(--accent); border: 1px solid var(--border);
  border-radius: 9px; padding: 9px 14px; font-size: 13.5px; font-weight: 600; cursor: pointer;
  text-decoration: none; display: inline-block;
}
.btn-secondary:hover { border-color: var(--accent); }
.btn-secondary[disabled] { opacity: .45; pointer-events: none; }
.btn-link { background: 0; border: 0; color: var(--accent); cursor: pointer; font-size: 13px; padding: 4px; }
.btn-link:hover { text-decoration: underline; }
.btn-mini {
  background: var(--bg); border: 1px solid var(--border); border-radius: 7px;
  padding: 4px 9px; font-size: 12px; cursor: pointer; color: var(--text); margin-right: 5px;
}
.btn-mini:hover { border-color: var(--accent); }
.btn-mini.danger { color: var(--warn); }
.btn-mini.danger:hover { border-color: var(--warn); }

/* --- tabs ----------------------------------------------------------------- */
.tabs { display: flex; gap: 4px; flex: 1; justify-content: center; flex-wrap: wrap; }
.tab {
  background: 0; border: 0; border-bottom: 2px solid transparent; color: var(--muted);
  padding: 8px 14px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 20px; }
.user-menu { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--muted); }

/* --- sub-tabs (admin) ----------------------------------------------------- */
.subtabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: 20px; flex-wrap: wrap; }
.subtab {
  background: 0; border: 0; border-bottom: 2px solid transparent; color: var(--muted);
  padding: 9px 14px; font-size: 13.5px; font-weight: 600; cursor: pointer;
}
.subtab:hover { color: var(--text); }
.subtab.active { color: var(--accent); border-bottom-color: var(--accent); }
.panel-title { font-size: 17px; margin: 0 0 16px; }

/* --- forms & tables ------------------------------------------------------- */
.admin-form { margin-bottom: 20px; }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.form-row input, .select, .smtp-grid input {
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font-size: 13.5px;
}
.form-row input:focus, .select:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.checkbox { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); }
.import-box { margin-bottom: 18px; border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.import-box summary { cursor: pointer; font-weight: 600; font-size: 13.5px; }
.import-box textarea, #imp-text {
  width: 100%; margin: 8px 0; padding: 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font-family: ui-monospace, monospace; font-size: 12.5px;
}
.table-wrap { overflow-x: auto; }
.grid-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.grid-table th {
  text-align: left; padding: 9px 11px; border-bottom: 1px solid var(--border);
  color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; white-space: nowrap;
}
.grid-table td { padding: 8px 11px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.grid-table.small { font-size: 12px; }
.grid-table.small td { padding: 5px 9px; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid-table .center, .center { text-align: center; }
.muted { color: var(--muted); }
.issued-key {
  background: color-mix(in srgb, var(--ok) 12%, transparent); border: 1px solid var(--ok);
  border-radius: 9px; padding: 12px 14px; margin-bottom: 16px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
}
.key-value { background: var(--bg); padding: 5px 9px; border-radius: 6px; font-size: 13px; word-break: break-all; }

/* --- SGBD ----------------------------------------------------------------- */
.sgbd { display: grid; grid-template-columns: 280px 1fr; gap: 18px; align-items: start; }
@media (max-width: 720px) { .sgbd { grid-template-columns: 1fr; } }
.sgbd-list { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.sgbd-filter { width: 100%; padding: 10px 12px; border: 0; border-bottom: 1px solid var(--border); background: var(--surface); color: var(--text); }
.sgbd-filter:focus { outline: 0; }
.sgbd-tables { max-height: 62vh; overflow-y: auto; }
.sgbd-tab { display: flex; flex-direction: column; gap: 2px; width: 100%; text-align: left; background: 0; border: 0; border-bottom: 1px solid var(--border); padding: 9px 12px; cursor: pointer; }
.sgbd-tab:hover { background: var(--bg); }
.sgbd-tab-name { font-size: 13px; font-family: ui-monospace, monospace; color: var(--text); }
.sgbd-tab-rows { font-size: 11px; color: var(--muted); }
.sgbd-view { min-height: 200px; }
.sgbd-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.sgbd-head h4 { margin: 0; font-family: ui-monospace, monospace; font-size: 16px; }
.sgbd-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.struct-box { margin-bottom: 16px; border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; }
.struct-box summary { cursor: pointer; font-weight: 600; font-size: 13px; }

/* --- media gallery -------------------------------------------------------- */
.media-filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; align-items: center; }
.media-search { flex: 1; min-width: 200px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); color: var(--text); }
.media-search:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.media-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; cursor: pointer; transition: border-color .12s; }
.media-card:hover { border-color: var(--accent); }
.media-thumb { height: 130px; display: grid; place-items: center; background: var(--bg); overflow: hidden; }
.media-thumb img { width: 100%; height: 100%; object-fit: cover; }
.media-thumb .ext { font-size: 13px; font-weight: 700; color: var(--muted); border: 2px solid var(--border); border-radius: 8px; padding: 10px 14px; }
.media-info { padding: 8px 10px; }
.media-name { font-size: 12px; line-height: 1.35; overflow-wrap: anywhere; max-height: 3.2em; overflow: hidden; }
.media-sub { font-size: 10.5px; color: var(--muted); margin-top: 3px; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin-top: 22px; }
.pager-info { font-size: 13px; color: var(--muted); }

/* --- SMTP form ------------------------------------------------------------ */
.field-label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); }
.smtp-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; max-width: 620px; margin-bottom: 18px; }
@media (max-width: 560px) { .smtp-grid { grid-template-columns: 1fr; } }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.search-icon { font-size: 20px; color: var(--muted); }

/* --- toast ---------------------------------------------------------------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 10px;
  font-size: 13.5px; box-shadow: var(--shadow); z-index: 80; max-width: 90vw;
}
.toast-error { background: var(--warn); color: #fff; }
.toast-ok { background: var(--ok); color: #fff; }

/* --- self-service portal -------------------------------------------------- */
.self-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.self-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; max-width: 720px; margin-bottom: 18px; }
@media (max-width: 560px) { .self-grid { grid-template-columns: 1fr; } }
.self-grid input {
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font-size: 13.5px; width: 100%;
}
.self-grid input:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.self-grid input:disabled { background: var(--bg); color: var(--muted); }
.self-docs { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.self-doc { border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: var(--surface); }
.self-doc-label { font-weight: 600; font-size: 13px; margin-bottom: 8px; }
.self-doc-empty { color: var(--muted); font-size: 12.5px; padding: 16px 0; text-align: center; border: 1px dashed var(--border); border-radius: 8px; }
.self-doc-view { display: block; text-decoration: none; color: inherit; }
.self-doc-view img { width: 100%; height: 120px; object-fit: cover; border-radius: 7px; }
.self-doc-view img.self-doc-thumb { object-position: top; background: #fff; border: 1px solid var(--border); }
.self-doc-view .ext { display: grid; place-items: center; height: 120px; font-weight: 700; color: var(--muted); border: 2px solid var(--border); border-radius: 7px; }
.self-doc-name { display: block; font-size: 11.5px; color: var(--muted); margin-top: 6px; overflow-wrap: anywhere; }
.self-doc-sub { font-size: 11px; color: var(--muted); margin-top: 6px; }
.self-doc-actions { margin-top: 8px; }

/* --- logs ----------------------------------------------------------------- */
.logs-controls { display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.logs-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.logs-status { margin-bottom: 12px; }
.logs-count {
  background: color-mix(in srgb, var(--ok) 12%, transparent); border-left: 3px solid var(--ok);
  padding: 10px 14px; border-radius: 8px; font-weight: 600; font-size: 13px;
}
.logs-table td { max-width: 320px; }
.logs-table .log-cell-error, .logs-table .log-cell-500, .logs-table .log-cell-warn { color: var(--warn); font-weight: 600; }
.logs-table tr.log-error td:first-child, .logs-table tr.log-warn td:first-child { border-left: 2px solid var(--warn); }

/* --- Modal overlay ------------------------------------------------------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center;
  background: rgba(16, 24, 40, .5); padding: 20px;
}
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); width: min(680px, 100%); max-height: 88vh; display: flex; flex-direction: column;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head h4 { margin: 0; font-size: 16px; }
.modal-x { border: 0; background: none; font-size: 24px; line-height: 1; cursor: pointer; color: var(--muted); }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--border); }
.modal-form { display: flex; flex-direction: column; gap: 12px; }
.modal-form h5 { margin: 6px 0 2px; font-size: 13px; color: var(--muted); }
.inline-field { display: inline-flex; align-items: center; gap: 4px; }

/* --- Survey manager / assignment ---------------------------------------- */
.survey-list { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.survey-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.survey-row code { background: var(--accent-soft); color: var(--accent); padding: 2px 8px; border-radius: 6px; font-weight: 600; }
.survey-label-input { padding: 5px 8px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); color: var(--text); min-width: 150px; }
.survey-assign { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.survey-assign .chips { flex-wrap: wrap; gap: 10px; }

/* --- Publish form + recipient picker ------------------------------------ */
.publish-form { border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin-bottom: 20px; display: flex; flex-direction: column; gap: 12px; }
.publish-form h4 { margin: 0; }
.publish-surveys, .publish-recipients { display: flex; flex-direction: column; gap: 8px; }
.recipient-picker { position: relative; display: flex; flex-direction: column; gap: 8px; max-width: 560px; }
.recipient-results {
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
  max-height: 220px; overflow-y: auto; box-shadow: var(--shadow);
}
.recipient-hit { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--border); background: none; padding: 7px 10px; cursor: pointer; color: var(--text); }
.recipient-hit:last-child { border-bottom: 0; }
.recipient-hit:hover { background: var(--accent-soft); }
.recipient-chips { flex-wrap: wrap; gap: 6px; }
.chip.removable { display: inline-flex; align-items: center; gap: 4px; }
.chip-x { border: 0; background: none; color: var(--warn); font-size: 15px; line-height: 1; cursor: pointer; padding: 0 2px; }
.recipient-current { display: flex; flex-direction: column; gap: 6px; }
.recipient-row { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid var(--border); }

/* --- SweetAlert-style dialogs -------------------------------------------- */
.swal-overlay {
  position: fixed; inset: 0; z-index: 90; display: flex; align-items: center; justify-content: center;
  background: rgba(16, 24, 40, .55); padding: 20px; animation: swalFade .18s ease;
}
.swal-overlay.leaving { animation: swalFade .15s ease reverse; }
@keyframes swalFade { from { opacity: 0; } to { opacity: 1; } }
.swal-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 10px 40px rgba(16, 24, 40, .25); width: min(500px, 100%); max-height: 88vh; overflow-y: auto;
  padding: 26px 26px 20px; text-align: center; animation: swalPop .2s cubic-bezier(.2, .9, .4, 1.2);
}
@keyframes swalPop { from { transform: scale(.9); opacity: .4; } to { transform: scale(1); opacity: 1; } }
.swal-icon {
  width: 60px; height: 60px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  margin: 4px auto 16px; font-size: 32px; font-weight: 700; border: 3px solid;
}
.swal-icon-success { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.swal-icon-error   { color: #d92d20; border-color: color-mix(in srgb, #d92d20 40%, transparent); }
.swal-icon-warning { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.swal-icon-info    { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.swal-icon-question{ color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.swal-title { margin: 0 0 8px; font-size: 20px; font-weight: 660; }
.swal-text { color: var(--muted); font-size: 14.5px; line-height: 1.5; margin-bottom: 6px; word-break: break-word; }
.swal-input {
  width: 100%; margin: 14px 0 4px; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 9px; background: var(--bg); color: var(--text); font-size: 14px; box-sizing: border-box;
}
.swal-input:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.swal-error { color: #d92d20; font-size: 13px; margin-top: 8px; text-align: left; }
.swal-actions { display: flex; gap: 10px; justify-content: center; margin-top: 22px; flex-wrap: wrap; }
.swal-btn { padding: 10px 22px; border-radius: 9px; border: 1px solid transparent; font-size: 14px; font-weight: 600; cursor: pointer; }
.swal-confirm { background: var(--accent); color: #fff; }
.swal-confirm:hover { filter: brightness(1.05); }
.swal-confirm:disabled { opacity: .6; cursor: default; }
.swal-cancel { background: transparent; border-color: var(--border); color: var(--text); }
.swal-cancel:hover { border-color: var(--muted); }
.swal-footer { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--muted); }
/* Dialogs that host a form body align it left. */
.swal-card .modal-form, .swal-card .self-grid, .swal-card .recipient-picker { text-align: left; }

/* --- Toasts -------------------------------------------------------------- */
.swal-toasts { position: fixed; top: 16px; right: 16px; z-index: 95; display: flex; flex-direction: column; gap: 10px; }
.swal-toast {
  display: flex; align-items: center; gap: 10px; min-width: 240px; max-width: 380px;
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--muted);
  border-radius: 10px; box-shadow: var(--shadow); padding: 12px 14px; font-size: 13.5px;
  transform: translateX(120%); opacity: 0; transition: transform .28s ease, opacity .28s ease;
}
.swal-toast.shown { transform: translateX(0); opacity: 1; }
.swal-toast.leaving { transform: translateX(120%); opacity: 0; }
.swal-toast-icon { width: 22px; height: 22px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 13px; font-weight: 700; flex: 0 0 auto; }
.swal-toast-success { border-left-color: var(--ok); }
.swal-toast-success .swal-toast-icon { background: var(--ok); }
.swal-toast-error { border-left-color: #d92d20; }
.swal-toast-error .swal-toast-icon { background: #d92d20; }
.swal-toast-warning { border-left-color: var(--warn); }
.swal-toast-warning .swal-toast-icon { background: var(--warn); }
.swal-toast-info { border-left-color: var(--accent); }
.swal-toast-info .swal-toast-icon { background: var(--accent); }
.swal-toast-msg { line-height: 1.35; }

/* --- Language toggle ----------------------------------------------------- */
.lang-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.lang-toggle button { border: 0; background: var(--surface); color: var(--muted); padding: 5px 10px; font-size: 12px; font-weight: 700; cursor: pointer; }
.lang-toggle button.active { background: var(--accent); color: #fff; }
.login-card .lang-toggle { position: absolute; top: 14px; right: 14px; }

/* --- SGBD data grid ------------------------------------------------------ */
.data-grid-host { margin-top: 8px; }
.grid-toolbar { display: flex; align-items: center; gap: 12px; margin: 10px 0 8px; flex-wrap: wrap; }
.grid-pager { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.grid-pager .select { padding: 4px 8px; }
.data-grid th { position: relative; vertical-align: top; }
.data-grid .grid-col-name { cursor: pointer; user-select: none; white-space: nowrap; font-weight: 700; }
.data-grid .grid-col-name:hover { color: var(--accent); }
.data-grid .grid-check { width: 30px; text-align: center; }
.data-grid .grid-filter-row th { padding: 3px 4px; background: color-mix(in srgb, var(--muted) 6%, transparent); }
.data-grid .grid-filter {
  width: 100%; min-width: 60px; box-sizing: border-box; padding: 4px 6px; font-size: 12px;
  border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text);
}
.data-grid .grid-filter:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.data-grid tr.row-selected td { background: var(--accent-soft); }

/* --- Excel/CSV import row ------------------------------------------------ */
.import-file-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; font-size: 13px; }
.import-file-row input[type=file] { font-size: 12.5px; }
.recipient-file-input { width: 100%; font-size: 12.5px; padding: 8px; border: 1px dashed var(--border); border-radius: 8px; background: var(--bg); color: var(--text); box-sizing: border-box; }

/* --- Two SMTP profiles + inner tabs -------------------------------------- */
.smtp-profile { border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; margin-bottom: 18px; }
.smtp-profile h4 { margin: 0 0 4px; }
.inner-tabs { margin-bottom: 14px; }

/* --- Signature Contrats -------------------------------------------------- */
.sign-contracts { display: flex; flex-direction: column; gap: 10px; }
.sign-card { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.sign-head { display: flex; align-items: center; gap: 12px; padding: 12px 14px; cursor: pointer; background: color-mix(in srgb, var(--muted) 5%, transparent); }
.sign-head b { flex: 1; }
.sign-recipients { padding: 6px 14px 12px; display: flex; flex-direction: column; gap: 4px; }
.sign-row { display: flex; align-items: center; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.sign-row:last-child { border-bottom: 0; }
.sign-bulk { display: flex; justify-content: flex-end; padding: 2px 0 8px; }
.recipient-filter { width: 100%; padding: 7px 10px; margin: 0 0 6px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; }
/* Signatures & stamps library */
.sig-asset-section { margin-top: 18px; }
.sig-asset-section h4 { margin: 0 0 8px; }
.sig-asset-grid { display: flex; flex-wrap: wrap; gap: 12px; }
.sig-asset-card { width: 168px; border: 1px solid var(--border); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 8px; background: #fff; }
.sig-asset-card.active { border-color: #188038; box-shadow: 0 0 0 1px #188038 inset; }
.sig-asset-img { width: 100%; height: 110px; object-fit: contain; background: repeating-conic-gradient(#f3f4f6 0% 25%, #fff 0% 50%) 50% / 16px 16px; border-radius: 6px; }
.sig-asset-meta { display: flex; flex-direction: column; gap: 2px; min-height: 34px; }
.sig-asset-badge { color: #188038; font-weight: 600; font-size: 12px; }
.sig-asset-label { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sig-asset-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.sig-asset-actions .danger { color: #d92d20; }
.sig-asset-card.add { align-items: center; justify-content: center; cursor: pointer; border-style: dashed; min-height: 150px; color: var(--muted, #5f6368); }
.sig-asset-card.add:hover { border-color: #1a73e8; color: #1a73e8; }
/* Message templates */
.tpl-card { border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin: 12px 0; background: #fff; }
.tpl-card.add { border-style: dashed; }
.tpl-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.tpl-badge { font-size: 11px; font-weight: 600; color: #1a73e8; background: #e8f0fe; border-radius: 999px; padding: 2px 8px; }
.tpl-vars { margin: 4px 0 8px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tpl-var { background: #f1f3f4; border-radius: 5px; padding: 1px 6px; font-size: 12px; color: #1a237e; }
.tpl-card textarea { border: 1px solid var(--border); border-radius: 8px; padding: 8px; font-size: 13px; }
.tpl-card input { border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px; font-size: 13px; }
/* Rich-text editor for message bodies */
.rte { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.rte-toolbar { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; padding: 6px; background: #f7f8fb; border-bottom: 1px solid var(--border); }
.rte-btn { min-width: 30px; height: 28px; border: 1px solid var(--border); background: #fff; border-radius: 6px; cursor: pointer; font-size: 14px; }
.rte-btn:hover { border-color: #1a73e8; color: #1a73e8; }
.rte-sel { height: 28px; border: 1px solid var(--border); border-radius: 6px; background: #fff; font-size: 13px; }
.rte-color { width: 30px; height: 28px; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: #fff; cursor: pointer; }
.rte-area { min-height: 150px; padding: 10px 12px; font-size: 14px; line-height: 1.5; outline: none; overflow-wrap: anywhere; }
.rte-area:focus { box-shadow: inset 0 0 0 2px rgba(26,115,232,.15); }
.sign-select { width: 16px; height: 16px; flex: none; cursor: pointer; }
.btn-mini.primary { background: var(--brand, #1a73e8); color: #fff; border-color: transparent; }
.sign-name { flex: 1; min-width: 160px; }
.sign-status { font-size: 12.5px; white-space: nowrap; }
.sign-status.ok { color: var(--ok); }
.sign-status.pending { color: var(--warn); }
.sign-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* --- Signature pad (self-portal) ---------------------------------------- */
.sign-modal { display: flex; flex-direction: column; gap: 8px; }
.sign-pad { width: 100%; max-width: 440px; height: auto; aspect-ratio: 44 / 17; border: 1px dashed var(--border); border-radius: 10px; background: #fff; touch-action: none; cursor: crosshair; }
.self-doc-signed { color: var(--ok); font-weight: 600; font-size: 13px; margin-top: 4px; }
.self-doc-pending { color: var(--warn); font-weight: 600; font-size: 13px; margin-top: 4px; }

/* --- Batch-import preview grid ------------------------------------------- */
.import-preview:not(:empty) { border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; margin: 6px 0 18px; background: color-mix(in srgb, var(--accent) 3%, var(--surface)); }
.import-preview h4 { margin: 0 0 10px; }
.preview-toolbar { display: flex; gap: 18px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.preview-toolbar .inline-field { display: inline-flex; align-items: center; gap: 6px; }
.import-preview .data-grid thead th { vertical-align: top; }
.import-preview .data-grid thead .select { margin-top: 4px; min-width: 96px; }

/* --- Password show/hide toggle + view dialog ---------------------------- */
.pw-field { position: relative; display: inline-flex; align-items: center; }
.pw-field input { padding-right: 30px; }
.pw-toggle { position: absolute; right: 4px; border: 0; background: none; cursor: pointer; font-size: 15px; opacity: .55; line-height: 1; padding: 2px; }
.pw-toggle:hover, .pw-toggle.on { opacity: 1; }
.view-password { display: flex; gap: 8px; align-items: center; }
.view-password .swal-input { margin: 0; font-family: ui-monospace, monospace; letter-spacing: 1px; }
