:root {
  --bg: #f3f3ef;
  --surface: #ffffff;
  --ink: #191b1a;
  --muted: #747873;
  --line: #d9dcd6;
  --soft: #e9ebe6;
  --green: #235c43;
  --green-dark: #174531;
  --lime: #d7f05a;
  --danger: #a63832;
  font-family: "DM Sans", "Noto Sans SC", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--bg); }
button, input { font: inherit; }
button { cursor: pointer; }

.topbar {
  height: 72px;
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: rgba(243, 243, 239, .94);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; background: var(--ink); color: white; font-weight: 700; }
.brand strong, .brand small { display: block; letter-spacing: 0; }
.brand strong { font-size: 17px; line-height: 1.15; }
.brand small { color: var(--muted); font-size: 11px; margin-top: 3px; }
.top-actions { display: flex; align-items: center; gap: 14px; }
.admin-nav { display: flex; align-items: center; height: 36px; border: 1px solid var(--line); padding: 3px; }
.admin-nav button { height: 28px; padding: 0 12px; border: 0; background: transparent; color: var(--muted); font-size: 11px; }
.admin-nav button.active { background: var(--ink); color: white; }
.credit-balance { padding: 7px 10px; background: #e8f0eb; color: var(--green); font-size: 11px; }
.credit-balance b { font-size: 14px; }
.account-button { width: 34px; height: 34px; border: 0; border-radius: 50%; background: var(--green); color: white; font-weight: 700; text-transform: uppercase; }
.service-status { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); }
.service-status i { width: 7px; height: 7px; border-radius: 50%; background: #b1b4b0; }
.service-status.ready i { background: #2c9a61; box-shadow: 0 0 0 4px rgba(44,154,97,.1); }
.service-status.error i { background: var(--danger); }
.icon-button { width: 38px; height: 38px; border: 1px solid var(--line); background: transparent; font-size: 21px; line-height: 1; }
.icon-button:hover { background: var(--surface); }

.workspace { display: grid; grid-template-columns: minmax(330px, 420px) minmax(0, 1fr); min-height: calc(100vh - 72px); }
.setup { padding: 32px; border-right: 1px solid var(--line); background: var(--surface); }
.results { padding: 32px 36px 56px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 30px; }
.section-heading > div { display: flex; align-items: center; gap: 12px; }
.section-heading h1, .section-heading h2 { margin: 0; font-size: 20px; line-height: 1.2; letter-spacing: 0; }
.step { font-size: 11px; font-weight: 700; color: var(--green); border-bottom: 2px solid var(--lime); padding-bottom: 2px; }
.capacity, .field-row > span { font-size: 12px; color: var(--muted); }
.upload-group { margin-bottom: 28px; }
.field-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 10px; }
.field-row { display: flex; align-items: center; justify-content: space-between; }

.dropzone { border: 1px dashed #adb2ab; background: #fafbf8; position: relative; overflow: hidden; transition: border-color .2s, background .2s; }
.dropzone:hover, .dropzone.dragging { border-color: var(--green); background: #f4f8f3; }
.reference-drop { width: 100%; aspect-ratio: 4 / 3; min-height: 220px; }
.empty-upload { width: 100%; height: 100%; display: grid; place-content: center; justify-items: center; gap: 7px; }
.upload-symbol { width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid var(--line); background: white; font-size: 22px; font-weight: 400; }
.empty-upload strong, .target-drop strong { font-size: 13px; font-weight: 600; }
.empty-upload small, .target-drop small { color: var(--muted); font-size: 11px; display: block; margin-top: 3px; }
.reference-preview { width: 100%; height: 100%; }
.reference-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.remove-file { position: absolute; top: 9px; right: 9px; width: 28px; height: 28px; border: 0; background: rgba(25,27,26,.82); color: white; font-size: 19px; line-height: 1; }
.file-badge { position: absolute; left: 9px; bottom: 9px; padding: 6px 9px; background: rgba(255,255,255,.9); font-size: 10px; font-weight: 700; }
.target-drop { min-height: 78px; padding: 16px; display: flex; align-items: center; justify-content: center; gap: 11px; }
.target-previews { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.target-thumb { aspect-ratio: 3/4; position: relative; background: var(--soft); overflow: hidden; }
.target-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.target-thumb button { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border: 0; background: rgba(25,27,26,.8); color: white; line-height: 1; }
.target-thumb span { position: absolute; left: 5px; bottom: 5px; min-width: 20px; padding: 3px 5px; text-align: center; background: rgba(255,255,255,.9); font-size: 10px; font-weight: 700; }

.primary-button { width: 100%; height: 50px; padding: 0 18px; border: 0; background: var(--green); color: white; display: flex; align-items: center; justify-content: space-between; font-weight: 600; }
.primary-button:hover:not(:disabled) { background: var(--green-dark); }
.primary-button b { color: var(--lime); font-size: 12px; }
.primary-button:disabled { background: #c7cac5; cursor: not-allowed; }
.primary-button.loading { cursor: wait; }

.download-all { height: 36px; padding: 0 14px; border: 1px solid var(--green); color: var(--green); background: transparent; font-weight: 600; font-size: 12px; }
.download-all:hover { background: var(--green); color: white; }
.result-summary { padding: 16px 0 22px; border-top: 1px solid var(--line); }
.result-summary > div:first-child { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.result-summary strong { font-size: 13px; }
.result-summary span { font-size: 12px; color: var(--muted); }
.overall-track { height: 3px; background: #dfe2dd; overflow: hidden; }
.overall-track i { display: block; width: 0; height: 100%; background: var(--green); transition: width .35s; }
.empty-results { min-height: 480px; display: grid; place-content: center; justify-items: center; color: var(--muted); }
.empty-results strong { color: var(--ink); font-size: 14px; margin-top: 18px; }
.empty-results small { font-size: 11px; margin-top: 5px; }
.empty-frame { width: 82px; height: 98px; position: relative; border: 1px solid #c8ccc6; display: block; }
.empty-frame i { position: absolute; background: var(--bg); border: 1px solid #c8ccc6; width: 54px; height: 70px; }
.empty-frame i:nth-child(1) { left: -24px; top: 14px; }
.empty-frame i:nth-child(2) { right: -24px; top: 14px; }
.empty-frame i:nth-child(3) { inset: 13px; width: auto; height: auto; background: var(--soft); }
.result-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.result-item { background: var(--surface); border: 1px solid var(--line); min-width: 0; }
.result-media { position: relative; aspect-ratio: 2/3; background: #e7e9e4; overflow: hidden; }
.result-media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.result-state { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 12px; padding: 20px; text-align: center; background: #e7e9e4; }
.result-state strong { font-size: 12px; }
.result-state small { max-width: 190px; color: var(--danger); font-size: 10px; overflow-wrap: anywhere; }
.spinner { width: 28px; height: 28px; border: 2px solid #c8ccc6; border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.item-track { width: 110px; height: 3px; background: #d5d8d2; }
.item-track i { display: block; height: 100%; background: var(--green); transition: width .3s; }
.result-meta { min-height: 52px; padding: 10px 11px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.result-meta > div { min-width: 0; }
.result-meta strong, .result-meta small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-meta strong { font-size: 11px; }
.result-meta small { color: var(--muted); font-size: 10px; margin-top: 2px; }
.result-meta a, .retry-button { width: 30px; height: 30px; display: grid; place-items: center; flex: 0 0 auto; border: 1px solid var(--line); background: transparent; color: var(--ink); text-decoration: none; font-size: 16px; }
.result-meta a:hover, .retry-button:hover { border-color: var(--green); color: var(--green); }
.toast { position: fixed; right: 24px; bottom: 24px; max-width: 360px; padding: 12px 15px; background: var(--ink); color: white; font-size: 12px; opacity: 0; transform: translateY(10px); pointer-events: none; transition: .2s; z-index: 20; }
.toast.show { opacity: 1; transform: translateY(0); }
.auth-screen { position: fixed; inset: 0; z-index: 50; background: #eef0eb; padding: 28px; overflow: auto; }
.auth-shell { width: min(1080px, 100%); min-height: calc(100vh - 56px); margin: auto; display: grid; grid-template-columns: 1.05fr .95fr; position: relative; background: var(--surface); box-shadow: 0 16px 50px rgba(24,32,27,.08); }
.auth-brand { position: absolute; top: 28px; left: 30px; display: flex; align-items: center; gap: 10px; z-index: 2; }
.auth-brand strong, .auth-brand small { display: block; }
.auth-brand small { color: var(--muted); font-size: 11px; margin-top: 2px; }
.auth-copy { background: var(--green); color: white; padding: 130px 54px 60px; display: flex; flex-direction: column; justify-content: center; background-image: linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px); background-size: 36px 36px; }
.auth-copy span { color: var(--lime); font-size: 11px; font-weight: 700; }
.auth-copy h1 { font-size: 38px; line-height: 1.28; margin: 20px 0; letter-spacing: 0; }
.auth-copy p { color: rgba(255,255,255,.72); font-size: 13px; }
.auth-form { align-self: center; width: min(350px, calc(100% - 60px)); margin: auto; }
.auth-tabs { display: flex; border-bottom: 1px solid var(--line); margin-bottom: 38px; }
.auth-tabs button { flex: 1; height: 42px; border: 0; background: transparent; color: var(--muted); }
.auth-tabs button.active { color: var(--green); border-bottom: 2px solid var(--green); font-weight: 700; }
.auth-form h2 { margin: 0; font-size: 24px; }
.auth-form > p { margin: 8px 0 28px; color: var(--muted); font-size: 12px; }
.auth-form label { display: block; font-size: 12px; font-weight: 600; margin-top: 17px; }
.auth-form input { display: block; width: 100%; height: 44px; margin-top: 7px; border: 1px solid var(--line); padding: 0 12px; outline: none; }
.auth-form input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(35,92,67,.08); }
.auth-submit { margin-top: 26px; }
.auth-error { min-height: 20px; margin-top: 12px; color: var(--danger); font-size: 11px; }
.account-menu { position: fixed; z-index: 30; top: 62px; right: 75px; width: 190px; padding: 14px; background: white; border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(0,0,0,.08); }
.account-menu strong, .account-menu small { display: block; }
.account-menu small { color: var(--muted); margin-top: 3px; font-size: 10px; }
.account-menu button { width: 100%; height: 34px; margin-top: 13px; border: 1px solid var(--line); background: transparent; color: var(--danger); font-size: 11px; }
.admin-panel { min-height: calc(100vh - 72px); padding: 34px; background: var(--bg); }
.admin-inner { max-width: 1160px; margin: auto; }
.admin-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 18px; }
.stat-box { padding: 18px; background: white; border: 1px solid var(--line); }
.stat-box strong, .stat-box small { display: block; }
.stat-box strong { font-size: 24px; }
.stat-box small { color: var(--muted); font-size: 11px; margin-top: 4px; }
.user-table-wrap { overflow-x: auto; border: 1px solid var(--line); background: white; }
.user-table { width: 100%; border-collapse: collapse; min-width: 720px; }
.user-table th, .user-table td { padding: 13px 15px; text-align: left; border-bottom: 1px solid var(--line); font-size: 12px; }
.user-table th { color: var(--muted); font-size: 10px; background: #f7f8f5; }
.user-cell strong, .user-cell small { display: block; }
.user-cell small { color: var(--muted); font-size: 10px; margin-top: 2px; }
.credit-number { font-size: 17px; font-weight: 700; color: var(--green); }
.credit-controls { display: flex; gap: 5px; align-items: center; }
.credit-controls button { height: 30px; padding: 0 9px; border: 1px solid var(--line); background: white; font-size: 10px; }
.credit-controls button:hover { border-color: var(--green); color: var(--green); }
.credit-controls input { width: 74px; height: 30px; border: 1px solid var(--line); padding: 0 7px; }
.ledger-section { margin-top: 28px; }
.ledger-section h3 { font-size: 14px; }
.ledger-list { background: white; border: 1px solid var(--line); }
.ledger-row { display: grid; grid-template-columns: 1fr 90px 150px; gap: 12px; padding: 11px 14px; border-bottom: 1px solid var(--line); font-size: 11px; }
.ledger-row:last-child { border-bottom: 0; }
.ledger-row span:nth-child(2) { font-weight: 700; }
.ledger-row .positive { color: #298153; }
.ledger-row .negative { color: var(--danger); }

@media (max-width: 1040px) {
  .workspace { grid-template-columns: 360px minmax(0, 1fr); }
  .setup { padding: 26px; }
  .results { padding: 26px; }
  .result-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .topbar { height: 62px; padding: 0 16px; }
  .service-status span { display: none; }
  .admin-nav button { padding: 0 8px; }
  .top-actions { gap: 8px; }
  .credit-balance { padding: 6px 8px; }
  .workspace { display: block; min-height: calc(100vh - 62px); }
  .setup { padding: 22px 16px 28px; border-right: 0; border-bottom: 1px solid var(--line); }
  .results { padding: 24px 16px 40px; }
  .reference-drop { aspect-ratio: 16/10; min-height: 190px; }
  .target-previews { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .empty-results { min-height: 300px; }
  .result-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .result-meta { padding: 8px; }
  .auth-screen { padding: 0; }
  .auth-shell { min-height: 100vh; display: block; }
  .auth-brand { position: static; padding: 20px; }
  .auth-copy { padding: 32px 22px; min-height: 210px; }
  .auth-copy h1 { font-size: 28px; margin: 13px 0; }
  .auth-form { width: calc(100% - 40px); padding: 34px 0 50px; }
  .admin-panel { padding: 24px 16px; }
  .admin-stats { grid-template-columns: 1fr 1fr; }
  .ledger-row { grid-template-columns: 1fr 60px; }
  .ledger-row span:last-child { display: none; }
}
@media (max-width: 410px) {
  .result-grid { grid-template-columns: 1fr; }
}
