:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --text: #1a2233;
  --muted: #6b7489;
  --border: #e3e7f0;
  --primary: #3b5bdb;
  --primary-hover: #2f4ac0;
  --primary-soft: #eef2ff;
  --ok: #2b8a3e;
  --ok-soft: #e6f6ea;
  --warn: #b25e09;
  --warn-soft: #fff4e5;
  --danger: #c92a2a;
  --danger-soft: #fdecec;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px rgba(16, 24, 40, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f131c;
    --surface: #171c28;
    --text: #e6e9f2;
    --muted: #949cb2;
    --border: #283044;
    --primary: #6d8cff;
    --primary-hover: #8aa2ff;
    --primary-soft: #1d2540;
    --ok: #63c27a;
    --ok-soft: #16301f;
    --warn: #f0a447;
    --warn-soft: #33260f;
    --danger: #ff6b6b;
    --danger-soft: #3a1a1c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--primary); }
h1, h2 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.15rem; }
code { font-family: ui-monospace, Consolas, monospace; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.lead { color: var(--muted); margin: 0 0 1.25rem; }
[hidden] { display: none !important; }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  border: 1px solid transparent; border-radius: 10px;
  padding: .7rem 1.2rem; font: inherit; font-weight: 600;
  cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: var(--primary-soft); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--border); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.block { width: 100%; }
.btn.small { padding: .45rem .9rem; font-size: .9rem; }
.btn.xs { padding: .3rem .6rem; font-size: .78rem; border-radius: 8px; }
input {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: .7rem .85rem;
}
input:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: transparent; }
label { font-weight: 500; font-size: .92rem; }
form.inline { display: inline; }

/* ---------- Alerts / badges ---------- */
.alert { border-radius: 10px; padding: .8rem 1rem; margin-bottom: 1rem; font-size: .95rem; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.badge {
  display: inline-block; font-size: .82rem; font-weight: 600;
  padding: .3rem .7rem; border-radius: 99px; background: var(--primary-soft); color: var(--primary);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- Brand / top bar ---------- */
.brand { display: inline-flex; align-items: center; gap: .55rem; font-weight: 700; font-size: 1.05rem; color: var(--text); text-decoration: none; }
.brand-mark {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, #3b5bdb, #7048e8); color: #fff;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: .9rem clamp(16px, 4vw, 40px); background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-right { display: flex; align-items: center; gap: .75rem; }

/* ---------- Activation ---------- */
.activate-wrap {
  flex: 1; display: grid; place-items: center; padding: 2rem 16px;
  background: radial-gradient(circle at 20% 0%, rgba(59, 91, 219, .14), transparent 50%),
              radial-gradient(circle at 90% 100%, rgba(112, 72, 232, .12), transparent 50%);
}
.activate-card {
  width: 100%; max-width: 460px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; box-shadow: var(--shadow); padding: 2rem;
}
.activate-card .brand { margin-bottom: 1.5rem; }
.key-form { display: grid; gap: .6rem; margin-bottom: 1.5rem; }
#activation_key { font-family: ui-monospace, Consolas, monospace; font-size: 1.15rem; letter-spacing: .08em; text-align: center; text-transform: uppercase; }
.contact-box {
  display: flex; gap: .9rem; align-items: flex-start; padding: 1rem; border-radius: 12px;
  background: var(--primary-soft); font-size: .93rem;
}
.contact-icon { color: var(--primary); flex-shrink: 0; margin-top: 2px; }
.contact-title { font-weight: 600; }
.phone { font-weight: 700; text-decoration: none; white-space: nowrap; }
.phone.big { display: inline-block; font-size: 1.25rem; margin-top: .25rem; }

/* ---------- Converter ---------- */
.container { width: 100%; max-width: 820px; margin: 0 auto; padding: 2rem 16px 3rem; flex: 1; }
.container.wide { max-width: 1240px; }
.hero { text-align: center; margin-bottom: 1.5rem; }
.tabs {
  display: grid; grid-template-columns: repeat(var(--tabs, 3), 1fr); gap: .4rem; padding: .35rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; margin-bottom: 1rem;
}
.tab {
  display: flex; align-items: center; justify-content: center; gap: .45rem;
  border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600;
  padding: .75rem .5rem; border-radius: 10px; cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--primary); color: #fff; }
.tool-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.5rem; }
.tool-info p { color: var(--muted); margin: 0 0 1.25rem; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: .5rem; text-align: center;
  padding: 2.5rem 1rem; border: 2px dashed var(--border); border-radius: 14px; cursor: pointer;
  color: var(--primary); transition: background .15s, border-color .15s;
}
.dropzone:hover, .dropzone.over { background: var(--primary-soft); border-color: var(--primary); }
.dz-title { color: var(--text); font-weight: 600; font-size: 1.05rem; }
.dz-hint { color: var(--muted); font-size: .88rem; font-weight: 400; }

/* Multi-file list (MBOX folders, PDF merge order) */
.file-list { margin-top: 1rem; }
.file-rows { display: grid; gap: .5rem; }
.file-row {
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
  border: 1px solid var(--border); border-radius: 12px; padding: .7rem .8rem; background: var(--surface);
}
.file-row.invalid { border-color: var(--danger); background: var(--danger-soft); }
.file-icon {
  flex-shrink: 0; width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: .75rem;
}
.file-main { flex: 1 1 220px; min-width: 0; }
.file-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { font-size: .84rem; color: var(--muted); }
.file-row.invalid .file-meta .note { color: var(--danger); font-weight: 600; }
.file-meta .note { color: var(--primary); }
.file-folder { flex: 0 1 260px; min-width: 200px; }
.picker { display: grid; gap: .35rem; }
select {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: .55rem .7rem;
}
select:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.picker input { padding: .5rem .7rem; }
.order { display: flex; gap: .25rem; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--border); background: transparent;
  color: var(--muted); font-size: 1.05rem; line-height: 1; cursor: pointer; flex-shrink: 0;
}
.icon-btn:hover:not(:disabled) { background: var(--primary-soft); color: var(--text); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn.remove:hover { background: var(--danger-soft); color: var(--danger); }
.list-footer { display: flex; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-top: 1rem; }
.pst-name { display: grid; gap: .3rem; flex: 1 1 220px; }
.list-total { margin-left: auto; align-self: center; }
.list-error { margin: .75rem 0 0; }

/* Tool grid */
.g-mail { --accent: #3b5bdb; }
.g-ai { --accent: #0c8599; }
.g-organize { --accent: #d6336c; }
.g-optimize { --accent: #2b8a3e; }
.g-to { --accent: #e8590c; }
.g-from { --accent: #1971c2; }
.g-edit { --accent: #7048e8; }
.g-security { --accent: #495057; }
@media (prefers-color-scheme: dark) {
  .g-mail { --accent: #7b96ff; }
  .g-ai { --accent: #3bc9db; }
  .g-organize { --accent: #f06595; }
  .g-optimize { --accent: #63c27a; }
  .g-to { --accent: #ff922b; }
  .g-from { --accent: #4dabf7; }
  .g-edit { --accent: #9775fa; }
  .g-security { --accent: #adb5bd; }
}
.tool-home .hero { margin-bottom: 1rem; }
.group-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 1.6rem 0 .7rem; }
.tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(210px, 100%), 1fr)); gap: .8rem; }
.tool-card {
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto 1fr; gap: .2rem .75rem; align-items: start;
  padding: 1rem; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border);
  color: var(--text); text-decoration: none; box-shadow: var(--shadow); transition: transform .12s, border-color .12s;
}
.tool-card:hover, .tool-card:focus-visible { border-color: var(--accent); transform: translateY(-2px); outline: none; }
.tool-card-icon {
  display: grid; place-items: center; width: 42px; height: 42px; border-radius: 11px; flex-shrink: 0;
  color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent);
}
.tool-card .tool-card-icon { grid-row: span 2; }
.tool-card-name { font-weight: 700; }
.tool-card-desc { grid-column: 2; font-size: .86rem; color: var(--muted); line-height: 1.4; }
.tool-view { max-width: 820px; margin: 0 auto; }
.back-link { display: inline-block; margin-bottom: .9rem; font-weight: 600; text-decoration: none; }
.tool-head { display: flex; align-items: center; gap: .75rem; margin-bottom: .5rem; }
.tool-head h2 { margin: 0; font-size: 1.3rem; }
.file-icon img { width: 100%; height: 100%; object-fit: cover; border-radius: 10px; }

/* Tool settings */
.options { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(200px, 100%), 1fr)); gap: .8rem 1rem; margin-top: 1rem; }
.opt { display: grid; gap: .3rem; align-content: start; }
.opt.wide { grid-column: 1 / -1; }
.opt.check { align-content: end; }
.opt.check label { display: flex; align-items: center; gap: .5rem; font-weight: 500; cursor: pointer; }
.opt.check input { width: auto; }
.opt input { padding: .55rem .7rem; }
.opt-help { font-size: .8rem; color: var(--muted); }
.history { margin-top: 2rem; }
.container.wide .history { max-width: 820px; margin-left: auto; margin-right: auto; }
.history > p { margin: 0 0 1rem; }
.job-details { margin-top: .5rem; font-size: .84rem; color: var(--muted); }

.jobs { display: grid; gap: .75rem; margin-top: 1.25rem; }
.job { border: 1px solid var(--border); border-radius: 12px; padding: .9rem 1rem; }
.job-top, .job-bottom { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.job-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.job-tool { font-size: .78rem; color: var(--muted); white-space: nowrap; }
.job-msg { font-size: .88rem; color: var(--muted); }
.bar { height: 8px; border-radius: 99px; background: var(--primary-soft); overflow: hidden; margin: .6rem 0; }
.bar span { display: block; height: 100%; width: 2%; background: var(--primary); border-radius: 99px; transition: width .4s; }
.job.done .bar span { background: var(--ok); }
.job.done .job-msg { color: var(--ok); }
.job.error .bar span { background: var(--danger); }
.job.error .job-msg { color: var(--danger); }
.job.partial .bar span { background: var(--warn); }
.job.partial .job-msg { color: var(--warn); }
.job-action { display: flex; gap: .5rem; flex-shrink: 0; }

/* ---------- Public pages (home and tool landing pages) ---------- */
.nav-link { color: var(--text); text-decoration: none; font-weight: 500; font-size: .95rem; }
.nav-link:hover { color: var(--primary); }
.landing { width: 100%; max-width: 1140px; margin: 0 auto; padding: 2rem 16px 3rem; flex: 1; }
.landing-hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 440px); gap: 2.5rem; align-items: start; }
.landing-intro h1 { font-size: clamp(1.7rem, 4vw, 2.6rem); line-height: 1.15; margin: .4rem 0 1rem; letter-spacing: -.01em; }
.landing-intro .lead { font-size: 1.05rem; }
.landing-hero .activate-card { max-width: none; padding: 1.5rem; }
.activate-card h2 { margin: 0 0 .25rem; font-size: 1.25rem; }
.checks { list-style: none; padding: 0; margin: 0 0 1.5rem; display: grid; gap: .45rem; }
.checks li { position: relative; padding-left: 1.7rem; }
.checks li::before { content: ""; position: absolute; left: 0; top: .2rem; width: 1.1rem; height: 1.1rem; border-radius: 50%; background: var(--ok-soft); }
.checks li::after { content: ""; position: absolute; left: .38rem; top: .38rem; width: .3rem; height: .55rem; border: solid var(--ok); border-width: 0 2px 2px 0; transform: rotate(45deg); }
.landing-section { margin-top: 3rem; }
.landing-section > h2 { font-size: 1.5rem; margin: 0 0 1rem; }
.steps { margin: 0; padding-left: 1.4rem; display: grid; gap: .6rem; max-width: 760px; }
.faq { display: grid; gap: .5rem; max-width: 820px; }
.faq details { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .8rem 1rem; }
.faq summary { font-weight: 600; cursor: pointer; }
.faq details p { margin: .6rem 0 0; color: var(--muted); }
.breadcrumb { font-size: .88rem; color: var(--muted); margin-bottom: 1rem; }
.breadcrumb a { color: var(--primary); text-decoration: none; }
.footer-links { display: flex; flex-wrap: wrap; justify-content: center; gap: .35rem 1.1rem; margin-bottom: .4rem; }
.footer-links a { color: var(--muted); text-decoration: none; }
.footer-links a:hover { color: var(--primary); }
@media (max-width: 900px) {
  .landing-hero { grid-template-columns: 1fr; gap: 1.5rem; }
}
@media (max-width: 560px) {
  .topbar-right .nav-link { display: none; }
}

/* ---------- Sign PDF ---------- */
.sign-bar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-top: 1rem; }
.sign-text-add { display: inline-flex; gap: .4rem; flex: 1 1 260px; }
.sign-text-add input { flex: 1; min-width: 0; padding: .45rem .7rem; }
.swatches { display: inline-flex; gap: .35rem; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--border); background: var(--ink); cursor: pointer; padding: 0; }
.swatch[data-ink="#111111"] { --ink: #111111; }
.swatch[data-ink="#1c3faa"] { --ink: #1c3faa; }
.swatch[aria-checked="true"] { outline: 2px solid var(--primary); outline-offset: 2px; }
.sign-help { margin: .5rem 0; }
.sign-pages { max-height: 75vh; overflow: auto; display: grid; gap: 1rem; padding: 1rem; border-radius: 12px; background: var(--primary-soft); }
.sign-page { position: relative; width: 100%; max-width: 820px; margin: 0 auto; background: #fff; box-shadow: var(--shadow); }
.sign-page canvas { display: block; width: 100%; height: 100%; }
.sign-page-no { position: absolute; right: .4rem; bottom: .4rem; font-size: .72rem; padding: .1rem .45rem; border-radius: 99px; background: rgba(0, 0, 0, .55); color: #fff; }
.sign-item { position: absolute; outline: 2px dashed var(--primary); outline-offset: 2px; cursor: move; touch-action: none; user-select: none; }
.sign-item.moving { outline-style: solid; }
.sign-item img { display: block; width: 100%; height: 100%; pointer-events: none; }
.sign-del { position: absolute; top: -12px; right: -12px; width: 22px; height: 22px; border-radius: 50%; border: 0; padding: 0; line-height: 22px; font-size: 15px; background: var(--danger); color: #fff; cursor: pointer; }
.sign-resize { position: absolute; right: -8px; bottom: -8px; width: 16px; height: 16px; border-radius: 4px; background: var(--primary); cursor: nwse-resize; }
.sign-dialog { width: min(640px, calc(100vw - 32px)); border: 1px solid var(--border); border-radius: var(--radius); padding: 0; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.sign-dialog::backdrop { background: rgba(10, 14, 24, .55); }
.sign-dialog-body { display: grid; gap: .75rem; padding: 1.25rem; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.dialog-head h3 { margin: 0; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); }
.tab { border: 0; background: none; color: var(--muted); padding: .5rem .8rem; font: inherit; font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: grid; gap: .5rem; }
.tab-panel[hidden] { display: none; }
.tab-panel input[type=text], .tab-panel select { padding: .5rem .7rem; }
.sign-pad, .sign-preview { width: 100%; height: auto; background: #fff; border: 1px dashed var(--border); border-radius: 10px; }
.sign-pad { touch-action: none; cursor: crosshair; }
.tab-panel .btn.xs { justify-self: start; }
.check-line { display: flex; align-items: center; gap: .5rem; font-size: .9rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; }

/* ---------- Admin ---------- */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: .75rem; margin-bottom: 1.25rem; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .9rem 1rem;
  text-decoration: none; color: var(--text); display: flex; flex-direction: column;
}
.stat.current { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.stat-num { font-size: 1.6rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: .85rem; }
.s-active .stat-num { color: var(--ok); }
.s-expired .stat-num { color: var(--warn); }
.s-revoked .stat-num { color: var(--danger); }
.admin-grid { display: grid; grid-template-columns: 300px 1fr; gap: 1.25rem; align-items: start; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.card-head h2 { margin: 0; }
.search input { padding: .5rem .75rem; width: 240px; max-width: 100%; }
.stack { display: grid; gap: .7rem; }
.stack label { display: grid; gap: .3rem; }
.pw { margin-top: 1rem; border-top: 1px solid var(--border); padding-top: .8rem; }
.pw summary { cursor: pointer; color: var(--muted); font-size: .9rem; margin-bottom: .6rem; }
.new-key {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  background: var(--primary-soft); border: 1px solid var(--primary); border-radius: var(--radius);
  padding: 1rem 1.25rem; margin-bottom: 1.25rem;
}
.key-code { font-family: ui-monospace, Consolas, monospace; font-size: 1.6rem; font-weight: 700; letter-spacing: .06em; color: var(--primary); word-break: break-all; }
.table-wrap { overflow-x: auto; }
table.keys { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.keys th { text-align: left; color: var(--muted); font-weight: 500; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; padding: .5rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.keys td { padding: .65rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
table.keys td.actions { white-space: nowrap; text-align: right; }
table.keys td.actions .btn { margin: 0 0 .25rem .2rem; }
.copyable { cursor: pointer; padding: .15rem .35rem; border-radius: 6px; background: var(--bg); white-space: nowrap; }
.copyable.copied { background: var(--ok-soft); color: var(--ok); }
.pill { display: inline-block; font-size: .76rem; font-weight: 600; padding: .15rem .55rem; border-radius: 99px; white-space: nowrap; }
.pill.active { background: var(--ok-soft); color: var(--ok); }
.pill.unused { background: var(--primary-soft); color: var(--primary); }
.pill.expired { background: var(--warn-soft); color: var(--warn); }
.pill.revoked { background: var(--danger-soft); color: var(--danger); }
.empty { color: var(--muted); text-align: center; padding: 2rem 0; }

/* ---------- Footer ---------- */
.site-footer {
  text-align: center; padding: 1.25rem 16px; border-top: 1px solid var(--border);
  background: var(--surface); font-size: .92rem; display: grid; gap: .25rem;
}

@media (max-width: 900px) {
  .admin-grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 560px) {
  .tabs { grid-template-columns: 1fr 1fr; }
  .file-folder { flex-basis: 100%; }
  .list-total { margin-left: 0; }
  .list-footer .btn { width: 100%; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .activate-card { padding: 1.5rem; }
  h1 { font-size: 1.45rem; }
}
