:root {
  --navy: #1f3864;
  --navy-dark: #152847;
  --navy-soft: #e8edf6;
  --ink: #1b1f27;
  --ink-2: #4a5160;
  --muted: #6b7280;
  --line: #dde1e8;
  --bg: #f5f6f8;
  --card: #ffffff;
  --ok: #1e7b4a;
  --ok-bg: #e7f5ed;
  --warn: #8a5a00;
  --warn-bg: #fdf3dc;
  --bad: #b3261e;
  --bad-bg: #fdeceb;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-size: 15px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--navy); }
a:hover { color: var(--navy-dark); }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; line-height: 1.25; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
p { margin: 0 0 .75rem; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85rem; }
pre { white-space: pre-wrap; word-break: break-word; background: #f3f4f6; padding: .75rem; border-radius: 6px;
      max-height: 360px; overflow: auto; margin: 0; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar { background: var(--navy); color: #fff; position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1200px; margin: 0 auto; display: flex; align-items: center; gap: 1rem;
                padding: 0 16px; min-height: 56px; flex-wrap: wrap; }
.brand { color: #fff; font-weight: 700; text-decoration: none; font-size: 1.05rem; white-space: nowrap; }
.brand:hover { color: #fff; }
.nav { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.nav a { color: #d6deed; text-decoration: none; padding: .45rem .7rem; border-radius: 6px; font-size: .93rem; }
.nav a:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.nav a.active { background: rgba(255, 255, 255, .16); color: #fff; }
.user-menu { display: flex; align-items: center; gap: .5rem; font-size: .88rem; color: #d6deed; }
.user-menu .who { text-align: right; line-height: 1.2; }
.user-menu .who small { display: block; color: #aebbd3; }
.user-menu button { background: transparent; color: #fff; border: 1px solid rgba(255, 255, 255, .35); }
.user-menu button:hover { background: rgba(255, 255, 255, .12); }
.nav-toggle { display: none; background: transparent; color: #fff; border: 1px solid rgba(255, 255, 255, .35); }

@media (max-width: 860px) {
  .nav-toggle { display: inline-flex; margin-left: auto; }
  .nav, .user-menu { display: none; width: 100%; }
  .topbar.open .nav { display: flex; flex-direction: column; padding-bottom: .5rem; }
  .topbar.open .user-menu { display: flex; justify-content: space-between; padding-bottom: .75rem; }
  .user-menu .who { text-align: left; }
}

/* ---------- layout ---------- */
.main { max-width: 1200px; margin: 0 auto; padding: 24px 16px 64px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap;
             margin-bottom: 1.25rem; }
.page-head p { margin: 0; color: var(--ink-2); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
        padding: 20px; margin-bottom: 16px; }
.card.narrow { max-width: 440px; margin: 48px auto; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }
.stack > * + * { margin-top: .75rem; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85rem; }
.pre-line { white-space: pre-line; }
.step { display: flex; gap: .75rem; align-items: baseline; }
.step-num { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--navy); color: #fff;
            display: inline-flex; align-items: center; justify-content: center; font-size: .85rem; font-weight: 600; }
.tool-card h3 { margin-bottom: .25rem; }
.tool-card p { color: var(--ink-2); font-size: .93rem; min-height: 2.8em; }

/* ---------- forms ---------- */
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .3rem; }
.field { margin-bottom: 14px; }
.field .hint { font-weight: 400; color: var(--muted); font-size: .84rem; margin-top: .25rem; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], input[type=search],
select, textarea {
  width: 100%; padding: .55rem .7rem; font: inherit; color: var(--ink); background: #fff;
  border: 1px solid #c9ced8; border-radius: 6px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid #5b7fc4; outline-offset: 1px; border-color: #5b7fc4;
}
input[type=file] { font: inherit; max-width: 100%; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0 16px; }
.inline-check { display: flex; gap: .5rem; align-items: center; font-weight: 400; }
.inline-check input { width: auto; }

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-weight: 600; font-size: .92rem; line-height: 1.2;
  padding: .55rem 1rem; border-radius: 6px; border: 1px solid var(--navy);
  background: var(--navy); color: #fff; cursor: pointer; text-decoration: none; white-space: nowrap;
}
button:hover, .btn:hover { background: var(--navy-dark); color: #fff; }
button.secondary, .btn.secondary { background: #fff; color: var(--navy); border-color: #b9c3d6; }
button.secondary:hover, .btn.secondary:hover { background: var(--navy-soft); color: var(--navy-dark); }
button.danger { background: #fff; color: var(--bad); border-color: #e3b4b1; }
button.danger:hover { background: var(--bad-bg); }
button.link { background: none; border: none; color: var(--navy); padding: 0; font-weight: 600; text-decoration: underline; }
button.small, .btn.small { padding: .3rem .6rem; font-size: .84rem; }
button:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- messages ---------- */
.alert { border-radius: 6px; padding: .7rem .9rem; margin-bottom: 12px; border: 1px solid; font-size: .93rem; }
.alert ul { margin: .35rem 0 0 1.1rem; padding: 0; }
.alert.error { background: var(--bad-bg); border-color: #f1c4c0; color: #7c1b15; }
.alert.ok { background: var(--ok-bg); border-color: #b9e0c9; color: #14532f; }
.alert.warn { background: var(--warn-bg); border-color: #f0dca8; color: #6b4600; }
.alert.info { background: var(--navy-soft); border-color: #cdd7ea; color: var(--navy-dark); }
.notice-area { position: fixed; top: 64px; right: 16px; z-index: 30; display: flex; flex-direction: column; gap: 8px;
               max-width: min(420px, calc(100vw - 32px)); }
.notice-area .alert { box-shadow: var(--shadow); margin: 0; }
.secret { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 1.05rem;
          background: #fff; border: 1px dashed #b9c3d6; padding: .4rem .6rem; border-radius: 6px; user-select: all; }

/* ---------- badges ---------- */
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 600;
         background: #eef0f4; color: var(--ink-2); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.navy { background: var(--navy-soft); color: var(--navy); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .55rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #f7f8fa; font-weight: 600; color: var(--ink-2); white-space: nowrap; position: sticky; top: 0; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { white-space: nowrap; text-align: right; }
td.actions button + button { margin-left: .35rem; }
.preview td { white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.grid-table th:first-child, .grid-table td:first-child { position: sticky; left: 0; background: #fff; z-index: 1;
                                                          min-width: 200px; }
.grid-table th:first-child { background: #f7f8fa; z-index: 2; }
.grid-table select { width: auto; min-width: 120px; padding: .3rem .4rem; }
.grid-table select.lvl-download { background: var(--ok-bg); }
.grid-table select.lvl-view { background: var(--navy-soft); }

/* ---------- misc ---------- */
.meter { height: 10px; background: #eceff4; border-radius: 999px; overflow: hidden; margin: .4rem 0; }
.meter > span { display: block; height: 100%; background: var(--navy); }
.meter.warn > span { background: #d18b00; }
.meter.bad > span { background: var(--bad); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.kpi .value { font-size: 1.5rem; font-weight: 700; }
details > summary { cursor: pointer; font-weight: 600; color: var(--navy); margin: .25rem 0; }
.filelist { list-style: none; padding: 0; margin: 0; }
.filelist li { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .55rem 0;
               border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.filelist li:last-child { border-bottom: none; }
.empty { text-align: center; padding: 32px 16px; color: var(--muted); }
.progress { display: flex; align-items: center; gap: .6rem; color: var(--ink-2); }
.spinner { width: 16px; height: 16px; border: 2px solid #c7cfdd; border-top-color: var(--navy); border-radius: 50%;
           animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.banner { background: var(--warn-bg); border: 1px solid #f0dca8; color: #6b4600; border-radius: 6px;
          padding: .6rem .9rem; margin-bottom: 16px; font-weight: 600; }
.loading { padding: 24px 0; }

.dialog { border: none; border-radius: 10px; padding: 0; width: min(520px, calc(100vw - 32px));
          box-shadow: 0 10px 30px rgba(0, 0, 0, .2); }
.dialog::backdrop { background: rgba(16, 24, 40, .45); }
.dialog .dialog-body { padding: 20px; }
.dialog .dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; padding: 12px 20px;
                          border-top: 1px solid var(--line); background: #fafbfc; border-radius: 0 0 10px 10px; }

@media (max-width: 600px) {
  .main { padding-top: 16px; }
  .card { padding: 16px; }
  h1 { font-size: 1.3rem; }
  td.actions { white-space: normal; }
}
.footnote { margin-top: 1rem; margin-bottom: 0; }
