/* ====== Base ====== */
:root{
  --bg:#f6f7fb;
  --surface:#ffffff;
  --surface-2:#f3f5fa;
  --text:#0f1222;
  --muted:#6b7280;
  --line:#e7eaf3;
  --brand1:#246BFD;
  --brand2:#1FB8A6;
  --shadow: 0 8px 26px rgba(17,20,40,.08);
  --shadow-2: 0 14px 40px rgba(17,20,40,.12);
}

*{box-sizing:border-box}
html,body{height:100%}
body.ui{
  margin:0; background:var(--bg); color:var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
  -webkit-font-smoothing:antialiased; -moz-osx-font-smoothing:grayscale;
}

.container{max-width:1240px; margin:0 auto; padding:0 20px}

/* ====== Topbar ====== */
.topbar{
  position:sticky; top:0; z-index:30;
  background:rgba(255,255,255,.85); backdrop-filter:saturate(140%) blur(6px);
  border-bottom:1px solid var(--line);
}
.topbar__inner{display:flex; align-items:center; justify-content:space-between; padding:14px 0}
.brand{display:flex; align-items:center; gap:12px}
.brand__mark{
  width:36px; height:36px; display:flex; align-items:center; justify-content:center;
  border-radius:10px; background:linear-gradient(135deg, rgba(36,107,253,.12), rgba(31,184,166,.12));
}
.brand__title{font-weight:700; letter-spacing:.2px}
.brand__sub{font-size:12px; color:var(--muted)}
.actions{display:flex; align-items:center; gap:8px; flex-wrap:wrap; justify-content:flex-end}
.actions .btn--ghost{padding:10px 14px}
.topbar__user{font-size:13px; color:var(--muted)}
.topbar__logout{margin:0}
.account-icon{
  width:42px;
  height:42px;
  display:flex;
  align-items:center;
  justify-content:center;
  border:1px solid #d6d9e4;
  border-radius:50%;
  background:#fff;
  color:#1e2a37;
  text-decoration:none;
}
.account-icon:hover{background:#f9fbff; color:var(--brand1)}

/* ====== Main ====== */
.main{padding:28px 0 40px}
.main--with-history{
  display:grid;
  grid-template-columns:240px minmax(0,1fr);
  gap:20px;
  align-items:start;
}
.main--auth{max-width:540px}
.main--account{max-width:1100px}
.workspace{min-width:0}

/* ====== Panel/Card ====== */
.panel{
  background:var(--surface); border:1px solid var(--line); border-radius:16px; box-shadow:var(--shadow);
  overflow:hidden; margin-bottom:18px;
}
.panel--shadow:hover{box-shadow:var(--shadow-2)}
.panel__head{padding:18px 22px 8px}
.panel__head h2{margin:0 0 6px 0; font-size:20px; font-weight:700}
.panel__body{padding:18px 22px 22px}
.muted{color:var(--muted)}
.small{font-size:12px}
.tiny{font-size:11.5px}

/* ====== History ====== */
.history{
  position:sticky;
  top:86px;
  display:flex;
  flex-direction:column;
  max-height:calc(100vh - 104px);
  box-shadow:none;
}
.history .panel__head{padding:14px 16px 8px}
.history .panel__head h2{font-size:16px}
.history__list{
  display:flex;
  flex-direction:column;
  gap:6px;
  flex:1;
  min-height:0;
  padding:0 10px 10px;
  overflow:auto;
}
.history__item{
  position:relative;
  display:flex;
  flex-direction:column;
  gap:4px;
  padding:10px;
  padding-right:34px;
  color:inherit;
  text-decoration:none;
  border:1px solid var(--line);
  border-radius:8px;
  background:#fff;
}
.history__item:hover{background:#f9fbff; border-color:#d4dcf0}
.history__link{
  display:flex;
  flex-direction:column;
  gap:4px;
  color:inherit;
  text-decoration:none;
}
.history__delete{
  position:absolute;
  top:8px;
  right:8px;
  width:22px;
  height:22px;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:0;
  border:0;
  border-radius:50%;
  background:#eef1f7;
  color:#64748b;
  cursor:pointer;
  font-size:17px;
  line-height:1;
  opacity:0;
  pointer-events:none;
  transition:.15s opacity, .15s background, .15s color;
}
.history__item:hover .history__delete,
.history__delete:focus-visible{
  opacity:1;
  pointer-events:auto;
}
.history__delete:hover{
  background:#fee2e2;
  color:#b91c1c;
}
.history__delete:disabled{
  opacity:.45;
  cursor:wait;
}
.history__date{font-size:13px; font-weight:700}
.history__meta{
  display:block;
  gap:8px;
  color:var(--muted);
  font-size:12px;
}
.history__meta span{display:block; margin-top:2px}
.history__empty{padding:0 14px 16px}
.history__footer{
  padding:10px;
  border-top:1px solid var(--line);
  background:#fff;
}
.history__clear{
  width:100%;
  padding:10px 12px;
  font-size:12px;
  line-height:1.25;
  white-space:normal;
}

/* ====== Uploader ====== */
.uploader{
  position:relative; border:1.5px dashed #d6d9e4; border-radius:14px; background:var(--surface-2);
  padding:22px; display:flex; align-items:center; gap:14px; cursor:pointer;
  transition:.2s border-color, .2s background, .2s box-shadow;
}
.uploader:hover{border-color:#c9cfe3; background:#eef2fa}
.uploader:focus-visible{outline:3px solid rgba(36,107,253,.35)}
.uploader input[type=file]{position:absolute; inset:0; opacity:0; cursor:pointer}
.uploader__icon{width:44px; height:44px; display:flex; align-items:center; justify-content:center; color:var(--brand1)}
.uploader__text{flex:1}
.uploader__filename{margin-top:6px; font-size:13px; color:#333}
.link{color:var(--brand1); text-decoration:underline}

/* ====== Buttons ====== */
.btn{
  appearance:none; border:0; border-radius:12px; padding:12px 16px; cursor:pointer; font-weight:600;
}
.btn--primary{
  color:#fff; background:linear-gradient(90deg, var(--brand1), var(--brand2));
  box-shadow:0 10px 28px rgba(36,107,253,.25);
}
.btn--primary:disabled{opacity:.55; cursor:not-allowed}
.btn--ghost{
  background:#fff; color:#1e2a37; border:1px solid #d6d9e4;
}
.btn--ghost:hover{background:#f9fbff}
.btn--danger{
  color:#fff; background:#dc2626;
  box-shadow:0 10px 28px rgba(220,38,38,.18);
}
.btn--danger:hover{background:#b91c1c}

/* ====== Form actions ====== */
.form__actions{display:flex; gap:10px; align-items:center; margin-top:16px; flex-wrap:wrap}

/* ====== Account ====== */
.auth-panel{margin-top:28px}
.auth-form,
.settings-form{
  display:grid;
  gap:14px;
}
.field{
  display:grid;
  gap:6px;
}
.field span{
  font-size:13px;
  font-weight:700;
}
.field input{
  width:100%;
  border:1px solid #d6d9e4;
  border-radius:10px;
  padding:12px;
  font:inherit;
  color:var(--text);
  background:#fff;
}
.field input:focus{
  outline:3px solid rgba(36,107,253,.18);
  border-color:#8fb2ff;
}
.settings-grid{
  display:grid;
  grid-template-columns:minmax(0,1fr) 220px;
  gap:12px;
}
.settings-options{
  display:grid;
  grid-template-columns:repeat(2, minmax(0, 1fr));
  gap:8px 14px;
  padding:12px;
  border:1px solid var(--line);
  border-radius:10px;
  background:#fbfcff;
}
.check-row{
  display:flex;
  align-items:center;
  gap:9px;
  font-size:13px;
  color:#1e293b;
}
.check-row input{
  width:17px;
  height:17px;
  accent-color:var(--brand1);
}
.form-alert{
  border-radius:9px;
  padding:10px 12px;
  font-size:13px;
  line-height:1.35;
}
.form-alert--error{
  border:1px solid #fecaca;
  background:#fff7f7;
  color:#991b1b;
}
.form-alert--success{
  border:1px solid #bbf7d0;
  background:#f0fdf4;
  color:#166534;
}
.api-reminder .panel__body{
  display:grid;
  gap:10px;
  align-items:start;
}
.api-reminder h2{
  margin:0;
  font-size:30px;
  line-height:1.1;
}
.api-reminder p{margin:0 0 4px}
.api-reminder .btn{justify-self:start}
.account-layout{
  display:grid;
  grid-template-columns:240px minmax(0,1fr);
  gap:20px;
  align-items:start;
}
.account-menu{box-shadow:none}
.account-menu__home{
  display:block;
  margin:12px 12px 4px;
  padding:12px 14px;
  border-radius:10px;
  color:#fff;
  background:linear-gradient(90deg, var(--brand1), var(--brand2));
  box-shadow:0 10px 28px rgba(36,107,253,.22);
  text-align:center;
  text-decoration:none;
  font-weight:800;
}
.account-menu__home:hover{filter:brightness(.98)}
.account-menu__nav{
  display:grid;
  gap:8px;
  padding:0 12px 14px;
}
.account-menu__link{
  display:block;
  padding:11px 12px;
  border:1px solid var(--line);
  border-radius:8px;
  color:#1e293b;
  text-decoration:none;
  font-weight:700;
  font-size:13px;
  background:#fff;
}
.account-menu__link:hover,
.account-menu__link.is-active{
  border-color:#bdd0ff;
  background:#f4f7ff;
  color:#1d4ed8;
}
.account-content{min-width:0}
.stats-grid{
  display:grid;
  grid-template-columns:repeat(2, minmax(0,1fr));
  gap:12px;
}
.stat-card{
  border:1px solid var(--line);
  border-radius:10px;
  padding:18px;
  background:#fbfcff;
}
.stat-card span{
  display:block;
  color:var(--muted);
  font-size:13px;
  margin-bottom:8px;
}
.stat-card strong{
  display:block;
  font-size:34px;
  line-height:1;
}
.license-note{
  padding:12px 14px;
  border:1px solid #bdd0ff;
  border-radius:10px;
  background:#f4f7ff;
  color:#1e3a8a;
  font-size:13px;
  line-height:1.4;
  font-weight:700;
}

/* ====== Progress ====== */
.progress-summary{
  display:flex;
  align-items:center;
  gap:18px;
  margin:16px 0 12px;
}
.progress-donut{
  --done-deg:0deg;
  --recent-deg:0deg;
  --express-deg:0deg;
  --done:#16a34a;
  --recent:#d1d5db;
  --express:#4b5563;
  width:142px;
  height:142px;
  flex:0 0 142px;
  display:grid;
  place-items:center;
  border-radius:50%;
  background:conic-gradient(
    var(--done) 0deg var(--done-deg),
    var(--recent) var(--done-deg) calc(var(--done-deg) + var(--recent-deg)),
    var(--express) calc(var(--done-deg) + var(--recent-deg)) calc(var(--done-deg) + var(--recent-deg) + var(--express-deg)),
    #eef1f7 calc(var(--done-deg) + var(--recent-deg) + var(--express-deg)) 360deg
  );
}
.progress-donut__center{
  width:92px;
  height:92px;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  border-radius:50%;
  background:#fff;
  box-shadow:inset 0 0 0 1px var(--line);
}
.progress-donut__check{
  width:24px;
  height:24px;
  margin-bottom:2px;
  display:flex;
  align-items:center;
  justify-content:center;
  border-radius:50%;
  color:#fff;
  background:#16a34a;
  font-size:15px;
  font-weight:800;
}
.progress-donut__count{
  color:#101827;
  font-size:24px;
  line-height:1;
  font-weight:800;
}
.progress-donut__percent{
  margin-top:4px;
  color:var(--muted);
  font-size:13px;
  font-weight:700;
}
.progress-legend{
  min-width:0;
  flex:1;
  display:grid;
  gap:8px;
}
.progress-legend__item{
  display:grid;
  grid-template-columns:12px minmax(0,1fr) auto;
  align-items:center;
  gap:8px;
  color:#334155;
  font-size:13px;
}
.progress-legend__item strong{
  color:#0f172a;
  font-size:14px;
}
.progress-legend__swatch{
  width:10px;
  height:10px;
  border-radius:50%;
}
.progress-legend__swatch--done{background:#16a34a}
.progress-legend__swatch--recent{background:#d1d5db}
.progress-legend__swatch--express{background:#4b5563}
.progress-result{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding-top:12px;
  border-top:1px solid var(--line);
}
.progress-result__button{
  flex:0 0 auto;
  text-decoration:none;
  text-align:center;
}
.error-report{
  margin-top:14px;
  border:1px solid #fecaca;
  background:#fff7f7;
  border-radius:8px;
  padding:12px 14px;
  color:#7f1d1d;
}
.error-report__title{
  font-weight:800;
  font-size:14px;
  margin-bottom:3px;
}
.error-report__note{
  color:#991b1b;
  font-size:12px;
  margin-bottom:10px;
}
.error-report__list{
  list-style:none;
  margin:0;
  padding:0;
  display:grid;
  gap:8px;
  max-height:220px;
  overflow:auto;
}
.error-report__list li{
  border:1px solid #fee2e2;
  background:#fff;
  border-radius:7px;
  padding:9px 10px;
  display:grid;
  gap:3px;
}
.error-report__list strong{
  color:#7f1d1d;
  font-size:13px;
}
.error-report__list span{
  color:#475569;
  font-size:12px;
  line-height:1.35;
  overflow-wrap:anywhere;
}

/* ====== Footer ====== */
.footer{margin-top:42px; border-top:1px solid var(--line); background:#fffcc0000}
.footer__inner{display:flex; align-items:center; justify-content:space-between; gap:12px; padding:16px 0; flex-wrap:wrap}

/* ====== Misc ====== */
code{background:#f1f3f8; padding:2px 6px; border-radius:6px; border:1px solid #e8ebf3}
.iframe{display:none;width:0;height:0;border:0}

.delete-dialog{
  position:fixed;
  inset:0;
  z-index:80;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:20px;
  background:rgba(15,18,34,.38);
}
.delete-dialog__box{
  width:min(460px, 100%);
  padding:18px;
  border:1px solid var(--line);
  border-radius:12px;
  background:#fff;
  box-shadow:var(--shadow-2);
}
.delete-dialog__title{
  margin-bottom:14px;
  font-size:17px;
  font-weight:700;
}
.delete-dialog__actions{
  display:flex;
  flex-wrap:wrap;
  gap:10px;
}

/* ====== Admin ====== */
.admin-login{
  min-height:100vh;
  display:grid;
  place-items:center;
  padding:24px;
}
.admin-login__box{
  width:min(420px, 100%);
  display:grid;
  gap:14px;
}
.admin-login__box h1{font-size:28px}
.admin-login__box label{
  display:grid;
  gap:7px;
  color:#334155;
  font-size:13px;
  font-weight:700;
}
.admin-shell{
  min-height:100vh;
  display:grid;
  grid-template-columns:260px minmax(0,1fr);
  background:#f4f6fb;
}
.admin-sidebar{
  position:sticky;
  top:0;
  height:100vh;
  display:flex;
  flex-direction:column;
  gap:18px;
  padding:22px 16px;
  border-right:1px solid var(--line);
  background:#fff;
}
.admin-brand{
  padding:0 4px 12px;
  color:#0f172a;
  font-size:18px;
  font-weight:900;
}
.admin-nav{
  display:grid;
  gap:8px;
}
.admin-nav a{
  padding:12px 13px;
  border:1px solid var(--line);
  border-radius:8px;
  color:#1e293b;
  background:#fff;
  font-size:14px;
  font-weight:800;
  text-decoration:none;
}
.admin-nav a:hover,
.admin-nav a.is-active{
  border-color:#bdd0ff;
  color:#1d4ed8;
  background:#f4f7ff;
}
.admin-logout{
  margin-top:auto;
}
.admin-main{
  width:min(1160px, 100%);
  padding:34px;
}
.admin-main h1{
  margin-bottom:20px;
  color:#0f172a;
  font-size:30px;
  line-height:1.15;
}
.admin-dashboard{
  display:grid;
  grid-template-columns:repeat(4, minmax(0,1fr));
  gap:14px;
}
.admin-card{
  min-height:132px;
  display:flex;
  flex-direction:column;
  justify-content:space-between;
  gap:12px;
  padding:18px;
  border:1px solid var(--line);
  border-radius:10px;
  background:#fff;
  box-shadow:0 14px 34px rgba(15,23,42,.06);
  text-decoration:none;
}
.admin-card span{
  color:#64748b;
  font-size:13px;
  font-weight:800;
}
.admin-card strong{
  color:#0f172a;
  font-size:36px;
  line-height:1;
}
.admin-card em{
  color:#64748b;
  font-style:normal;
  font-size:13px;
}
.admin-card--link:hover{
  border-color:#94b5ff;
}
.admin-panel{
  border:1px solid var(--line);
  border-radius:10px;
  background:#fff;
  box-shadow:0 14px 34px rgba(15,23,42,.06);
  overflow:hidden;
}
.table-wrap{
  width:100%;
  overflow:auto;
}
.admin-table{
  width:100%;
  border-collapse:collapse;
  min-width:760px;
}
.admin-table th,
.admin-table td{
  padding:13px 14px;
  border-bottom:1px solid var(--line);
  text-align:left;
  vertical-align:top;
  font-size:13px;
}
.admin-table th{
  color:#475569;
  background:#f8fafc;
  font-weight:900;
}
.admin-table td{
  color:#0f172a;
}
.admin-table tr:last-child td{border-bottom:0}

@media (max-width: 720px){
  .main--with-history{grid-template-columns:1fr}
  .account-layout{grid-template-columns:1fr}
  .history{position:static; max-height:none}
  .history__list{max-height:none}
  .progress-summary{align-items:flex-start}
  .settings-grid,
  .settings-options,
  .stats-grid{grid-template-columns:1fr}
  .admin-shell{grid-template-columns:1fr}
  .admin-sidebar{position:static; height:auto}
  .admin-main{padding:22px 16px}
  .admin-dashboard{grid-template-columns:1fr}
}

@media (max-width: 520px){
  .progress-summary{flex-direction:column}
  .progress-result{align-items:stretch; flex-direction:column}
  .progress-result__button{width:100%}
}
