* { box-sizing: border-box; }
html, body { overflow-x: clip; }

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.appshell {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 auto;
  background: linear-gradient(180deg, var(--color-sidebar) 0%, var(--color-sidebar-2) 100%);
  color: #cbc4b8;
  padding: var(--space-5) 0 var(--space-4);
  display: flex;
  flex-direction: column;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-4) var(--space-4);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: var(--space-3);
}

.sidebar__mark {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  background: rgba(var(--color-accent-rgb), 0.18);
  color: var(--color-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.sidebar__mark svg { width: 18px; height: 15px; }

.sidebar__title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: #fff;
  line-height: 1.25;
}

.sidebar__sub {
  font-size: 11px;
  color: #8f8574;
}

.sidebar__group {
  padding: 0 var(--space-3);
  margin-bottom: var(--space-4);
}

.sidebar__heading {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #786e5c;
  padding: var(--space-2) var(--space-2) var(--space-1);
}

.navitem {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 7px var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  color: #beb6a7;
  text-decoration: none;
  transition: background var(--dur-short) var(--ease-out), color var(--dur-short) var(--ease-out);
}

.navitem:hover { background: rgba(255,255,255,0.06); color: #fff; }

.navitem.is-active {
  background: rgba(var(--color-accent-rgb), 0.18);
  color: #d6eef1;
  font-weight: 600;
  box-shadow: inset 2px 0 0 var(--color-accent);
}

.navitem .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.5;
  flex: none;
}

.sidebar__foot {
  margin-top: auto;
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 11px;
  color: #786e5c;
}

/* ---------- Main column ---------- */

.main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.content {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  padding: var(--space-5) var(--space-6) var(--space-6);
  max-width: 108rem;
  width: 100%;
}

.pagehead { margin-bottom: var(--space-5); }

.pagehead h1 {
  font-size: var(--text-xl);
  font-weight: 600;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
  color: var(--color-ink);
}

.pagehead p {
  margin: 0;
  color: var(--color-ink-2);
  font-size: var(--text-sm);
  max-width: 60ch;
}

/* ---------- Two-column layout: main flow + detail rail ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--rail-w);
  gap: var(--space-5);
  align-items: start;
}

.layout__main { min-width: 0; }
.layout__rail { min-width: 0; display: flex; flex-direction: column; gap: var(--space-4); }

.panel {
  background: var(--color-panel);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  margin-bottom: var(--space-5);
}

.layout__rail .panel { margin-bottom: 0; }

.panel__head {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.panel__head h2 {
  font-size: var(--text-md);
  font-weight: 600;
  margin: 0;
  color: var(--color-ink);
}

.panel__head .tag {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-muted);
}

.panel__body { padding: var(--space-4); }
.panel__body p { margin: 0 0 var(--space-3); color: var(--color-ink-2); font-size: var(--text-sm); }
.panel__body p:last-child { margin-bottom: 0; }

.pkgrow {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--color-shell);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

.pkgrow .file-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: var(--color-accent-bg);
  color: var(--color-accent-dk);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
}

.pkgrow .info { min-width: 0; }

.pkgrow .filename {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--color-ink);
}

.pkgrow .meta {
  font-size: 11.5px;
  color: var(--color-muted);
  margin-top: 2px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--color-accent);
  color: #fff;
  border: 1px solid var(--color-accent-dk);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: var(--text-sm);
  font-weight: 600;
  font-family: inherit;
  text-decoration: none;
  cursor: pointer;
  margin-left: auto;
  transition: background var(--dur-short) var(--ease-out), transform var(--dur-short) var(--ease-out);
  white-space: nowrap;
}

.btn:hover { background: var(--color-accent-dk); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--color-accent-dk); outline-offset: 2px; }
.btn:disabled { background: var(--color-muted); border-color: var(--color-muted); cursor: not-allowed; }

form.upload {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.field label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-ink-2);
  margin-bottom: 6px;
}

.filedrop {
  position: relative;
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-shell);
  padding: var(--space-4);
  text-align: center;
  transition: border-color var(--dur-short) var(--ease-out), background var(--dur-base) var(--ease-out);
}

.filedrop:has(input:focus-visible) { border-color: var(--color-accent); background: var(--color-accent-bg); }

.filedrop input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.filedrop__hint {
  font-size: var(--text-sm);
  color: var(--color-muted);
  pointer-events: none;
}

.filedrop__hint code {
  background: var(--color-panel);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: var(--font-mono);
  font-size: 0.92em;
  color: var(--color-ink-2);
}

select, input[type="text"] {
  width: 100%;
  padding: 8px 9px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: #fff;
  font-size: var(--text-sm);
  font-family: var(--font-body);
  color: var(--color-ink);
}

select:focus-visible, input[type="text"]:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
}

.submit-row { display: flex; justify-content: flex-end; padding-top: var(--space-1); }

/* ---------- Detail rail cards ---------- */

.detaillist { margin: 0; padding: var(--space-4); font-size: var(--text-sm); }
.detaillist > div { padding: var(--space-2) 0; border-bottom: 1px solid var(--color-border); }
.detaillist > div:last-child { border-bottom: none; padding-bottom: 0; }
.detaillist > div:first-child { padding-top: 0; }

.detaillist dt {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-muted);
  margin-bottom: 3px;
  font-weight: 700;
}

.detaillist dd {
  margin: 0;
  color: var(--color-ink);
  overflow-wrap: anywhere;
}

.detaillist dd.hash { font-size: 11px; color: var(--color-ink-2); line-height: 1.5; }

/* ---------- System log result panel ---------- */

.logpanel .panel__head { background: var(--color-sidebar-2); border-bottom-color: #2a251d; }
.logpanel .panel__head h2 { color: #ede6d8; }
.logpanel .panel__head .tag { color: #93897a; }

.console {
  background: #100e0c;
  color: #c2baaa;
  font-family: var(--font-mono);
  font-size: 12.75px;
  line-height: 1.75;
  padding: var(--space-4);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  overflow-x: auto;
}

.console .line { white-space: pre-wrap; }
.console .line .ts { color: #6b6154; margin-right: 8px; }

.console .line.status-ok { color: #97d3ac; border-left: 2px solid var(--color-ok); padding-left: 10px; margin-left: -12px; }
.console .line.status-fail { color: #dcae9e; border-left: 2px solid #c9695a; padding-left: 10px; margin-left: -12px; }

.flagline {
  margin-top: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: #1c3322;
  border: 1px solid #2c4c34;
  color: #a9eec4;
  border-radius: var(--radius-sm);
  word-break: break-all;
  font-weight: 600;
}

.foot {
  margin-top: auto;
  padding: var(--space-4) 0 var(--space-6);
  font-size: 11.5px;
  color: var(--color-muted);
  text-align: center;
}

/* ---------- Responsive ---------- */

@media (max-width: 1180px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .layout__rail { flex-direction: row; flex-wrap: wrap; }
  .layout__rail .panel { flex: 1 1 260px; }
}

@media (max-width: 860px) {
  .appshell { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    padding: var(--space-2) var(--space-3);
    gap: var(--space-3);
    overflow-x: auto;
  }
  .sidebar__brand { border-bottom: none; margin-bottom: 0; padding: 0; }
  .sidebar__group { display: flex; gap: var(--space-2); margin-bottom: 0; padding: 0; }
  .sidebar__heading { display: none; }
  .navitem span:not(.dot) { white-space: nowrap; }
  .sidebar__foot { display: none; }
  .content { padding: var(--space-4); }
}

@media (max-width: 480px) {
  .pkgrow { flex-wrap: wrap; }
  .btn { margin-left: 0; width: 100%; justify-content: center; }
}
