:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #f0f1ed;
  --border: #dcdfd6;
  --text: #1d211a;
  --muted: #6a7064;
  --accent: #44792a;
  --accent-strong: #36621f;
  --accent-soft: #e6f0dd;
  --danger: #b4382f;
  --danger-soft: #f8e4e2;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 10, .06), 0 4px 16px rgba(20, 30, 10, .05);
  --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141612;
    --surface: #1c1f19;
    --surface-2: #23271f;
    --border: #31362b;
    --text: #e6e9e1;
    --muted: #949b8b;
    --accent: #79c05a;
    --accent-strong: #93d176;
    --accent-soft: #263420;
    --danger: #e0695f;
    --danger-soft: #3a1f1c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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

h1, h2, h3 { line-height: 1.25; margin: 0; }
code, .mono { font-family: var(--mono); font-size: .88em; }
a { color: var(--accent); }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---- buttons & inputs ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 8px 14px; font: inherit; font-weight: 500;
  cursor: pointer; transition: background .15s, border-color .15s, color .15s;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-sm { padding: 5px 10px; font-size: 13.5px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
@media (prefers-color-scheme: dark) { .btn-primary, .btn-primary:hover { color: #10170b; } }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); background: var(--danger); }
.btn-danger-outline { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger-outline:hover { background: var(--danger-soft); }

input, textarea {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px;
}
textarea { resize: vertical; }
input:focus-visible, textarea:focus-visible, .btn:focus-visible, .pack-item:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
label { display: grid; gap: 4px; font-weight: 500; font-size: 14px; }
label small { font-weight: 400; }
.checkbox { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.checkbox input { width: auto; }
.form-error { color: var(--danger); margin: 0; font-size: 14px; }

/* ---- brand ---- */
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; color: var(--text); text-decoration: none; }
.brand-lg { font-size: 22px; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 4px;
  background:
    linear-gradient(#79c05a 0 32%, transparent 32%),
    radial-gradient(circle at 30% 65%, #40632a 0 12%, transparent 13%),
    radial-gradient(circle at 72% 78%, #40632a 0 10%, transparent 11%),
    #6b4a2c;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.15);
}

/* ---- login ---- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(380px, 100%); display: grid; gap: 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px; box-shadow: var(--shadow);
}
.login-card p { margin: 0; }

/* ---- shell ---- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-right { display: flex; align-items: center; gap: 10px; font-size: 14px; }

.layout { display: grid; grid-template-columns: 290px 1fr; min-height: calc(100vh - 53px); }
.sidebar { border-right: 1px solid var(--border); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; }
.sidebar-head h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.pack-list { display: flex; flex-direction: column; gap: 2px; }
.pack-item {
  display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px;
  color: var(--text); text-decoration: none;
}
.pack-item:hover { background: var(--surface-2); }
.pack-item.active { background: var(--accent-soft); }
.pack-item-text { min-width: 0; }
.pack-item-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pack-item-meta { font-size: 12.5px; color: var(--muted); }
.list-empty { color: var(--muted); font-size: 14px; padding: 8px; }

.icon {
  flex: none; width: 36px; height: 36px; border-radius: 6px;
  image-rendering: pixelated; object-fit: cover;
  background: var(--surface-2); border: 1px solid var(--border);
  display: grid; place-items: center; color: var(--muted); font-weight: 700;
}
.icon-lg { width: 72px; height: 72px; border-radius: 10px; font-size: 26px; }

.detail { padding: 24px 28px 48px; min-width: 0; max-width: 1100px; display: flex; flex-direction: column; gap: 20px; }

.pack-head { display: flex; gap: 18px; align-items: center; }
.pack-head h1 { font-size: 24px; }
.pack-head p { margin: 4px 0 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  font-size: 12.5px; padding: 2px 8px; border-radius: 99px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
}
.chip-accent { background: var(--accent-soft); border-color: transparent; color: var(--accent-strong); font-weight: 600; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px;
}
.card > h2 { font-size: 18px; margin-bottom: 14px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 12px; }
.card-head h2 { font-size: 18px; }

.field-row { display: grid; grid-template-columns: 150px 1fr auto; gap: 10px; align-items: center; padding: 6px 0; }
.field-row + .field-row { border-top: 1px dashed var(--border); }
.field-label { color: var(--muted); font-size: 14px; }
.field-value { font-family: var(--mono); font-size: 13.5px; word-break: break-all; }

.snippet {
  position: relative; margin: 14px 0 0; padding: 12px 14px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-family: var(--mono); font-size: 13px; white-space: pre-wrap; word-break: break-all;
}
.snippet .btn { position: absolute; top: 8px; right: 8px; }

.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 24px; text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone strong { display: block; margin-bottom: 4px; }
.upload-form { display: grid; gap: 12px; }
.upload-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.progress { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress > div { height: 100%; width: 100%; background: var(--accent); transform: scaleX(0); transform-origin: left; transition: transform .1s; }

.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn + .btn { margin-left: 4px; }
.notes { color: var(--muted); font-size: 13px; margin-top: 2px; }
.badge-active { display: inline-block; font-size: 11.5px; font-weight: 700; color: var(--accent-strong); background: var(--accent-soft); border-radius: 4px; padding: 1px 6px; margin-left: 6px; vertical-align: 1px; }

.settings-form { display: grid; gap: 12px; }
.settings-actions { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.empty { display: grid; place-items: center; text-align: center; padding: 80px 20px; gap: 12px; color: var(--muted); }
.empty h2 { color: var(--text); }

/* ---- dialogs ---- */
.dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 0;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
  width: min(460px, calc(100vw - 32px));
}
.dialog::backdrop { background: rgba(10, 14, 6, .45); }
.dialog h3 { font-size: 19px; }
.dialog form { display: grid; gap: 14px; padding: 22px; }
.dialog p { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---- toasts ---- */
#toasts { position: fixed; bottom: 16px; right: 16px; display: grid; gap: 8px; z-index: 50; max-width: calc(100vw - 32px); }
.toast {
  background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px;
  box-shadow: var(--shadow); font-size: 14px; animation: toast-in .18s ease-out;
}
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); }
  .pack-list { max-height: 220px; overflow-y: auto; }
  .detail { padding: 16px 16px 40px; }
  .field-row { grid-template-columns: 1fr auto; }
  .field-label { grid-column: 1 / -1; }
  .topbar { padding: 10px 16px; }
  #whoami { display: none; }
}
