:root {
  --bg: #f5f1e8;
  --panel: #fffdfa;
  --sidebar: #17352f;
  --text: #1f1f1f;
  --muted: #6b6b6b;
  --line: #dfd7ca;
  --primary: #9e3d19;
  --danger: #b42318;
  --shadow: 0 14px 30px rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(180deg, #f5f1e8 0%, #ece4d5 100%);
  color: var(--text);
}

body.auth-locked {
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(255,255,255,0.88), transparent 30%),
    linear-gradient(145deg, #f5eddf 0%, #e8dccb 55%, #dfd0bc 100%);
}

body.auth-locked .app-shell {
  display: none;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 300px 1fr;
}

.sidebar {
  background: linear-gradient(180deg, var(--sidebar) 0%, #132b26 100%);
  color: #fff;
  padding: 28px 20px;
  height: 100vh;
  overflow-y: auto;
  position: sticky;
  top: 0;
}

.brand h1 {
  margin: 0;
  font-size: 2rem;
}

.brand p {
  margin: 10px 0 16px;
  color: rgba(255,255,255,0.72);
}

.badge {
  display: inline-block;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.9);
  font-size: 0.8rem;
  font-weight: 700;
}

.nav-section {
  margin-top: 26px;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255,255,255,0.6);
}

.nav-btn {
  width: 100%;
  margin-top: 12px;
  border: 0;
  border-radius: 14px;
  text-align: left;
  padding: 14px 16px;
  color: #fff;
  background: transparent;
  cursor: pointer;
  font-size: 1rem;
  touch-action: manipulation;
  font-weight: 600;
}

.nav-btn.active, .nav-btn:hover {
  background: rgba(255,255,255,0.1);
}

.main {
  padding: 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
}

.topbar h2 {
  margin: 0;
  font-size: 2rem;
}

.topbar p {
  margin: 8px 0 0;
  color: var(--muted);
}

.actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-start;
}

.actions button {
  border: 0;
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 700;
  cursor: pointer;
}

.session-panel {
  min-width: 250px;
  background: rgba(255,255,255,0.92);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
}

.session-panel label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.session-name {
  font-size: 1.1rem;
  font-weight: 700;
}

.session-email {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.92rem;
}

.role-chip {
  display: inline-flex;
  margin-top: 8px;
  padding: 5px 10px;
  border-radius: 999px;
  background: #efe5d6;
  color: #6a3c11;
  font-size: 0.8rem;
  font-weight: 700;
}

.role-chip.normal {
  background: #eef2f6;
  color: #334155;
}

.content {
  margin-top: 22px;
  display: grid;
  gap: 18px;
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(0,0,0,0.05);
  border-radius: 20px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.panel h3 {
  margin-top: 0;
}

.hint {
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 18px;
}

.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px;
}

.master-card-btn {
  width: 100%;
  text-align: left;
  cursor: pointer;
  font: inherit;
  touch-action: manipulation;
}

.master-card-btn:hover,
.master-card-btn.active {
  border-color: #c8b89d;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.06);
}

.master-card-btn h3,
.card h3 {
  margin-top: 0;
}

.count {
  font-size: 2rem;
  font-weight: 800;
  margin: 10px 0;
}

.status-note {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid #d7ccb9;
  background: #fffaf2;
  color: #7a4f16;
}

.status-ok {
  background: #edf8f0;
  border-color: #b7dec0;
  color: #196a34;
}

.status-warn {
  background: #fff7e6;
  border-color: #f1d6a3;
  color: #8a5a11;
}

.ghost {
  background: #fff;
  border: 1px solid var(--line);
}

.primary {
  background: var(--primary);
  color: #fff;
}

.danger {
  background: var(--danger);
  color: #fff;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at top left, rgba(255,255,255,0.86), transparent 28%),
    linear-gradient(160deg, #f4ecde 0%, #eadfcf 55%, #dfd2c0 100%);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  z-index: 100;
}

.auth-overlay.open {
  display: flex;
}

.auth-card {
  width: min(100%, 560px);
  background: rgba(255, 253, 250, 0.98);
  border-radius: 28px;
  box-shadow: 0 28px 70px rgba(32, 21, 8, 0.16);
  padding: 34px 34px 28px;
  border: 1px solid rgba(0,0,0,0.06);
}

.auth-card h3 {
  margin: 0 0 10px;
  font-size: 2rem;
}

.auth-card p {
  margin: 0 0 16px;
  color: var(--muted);
}

.auth-brand {
  margin-bottom: 22px;
}

.auth-kicker {
  display: inline-block;
  margin-bottom: 10px;
  padding: 6px 12px;
  border-radius: 999px;
  background: #17352f;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.auth-brand h2 {
  margin: 0;
  font-size: 2.6rem;
  line-height: 1;
}

.auth-brand p {
  margin: 12px 0 0;
  font-size: 1rem;
  max-width: 40ch;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 16px;
}

.field {
  grid-column: span 6;
}

.field.full-span {
  grid-column: 1 / -1;
}

.field label {
  display: block;
  margin-bottom: 8px;
  font-weight: 700;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border-radius: 14px;
  border: 1px solid #d8cdb9;
  background: #fff;
  padding: 14px 16px;
  font: inherit;
}

.field textarea {
  min-height: 110px;
  resize: vertical;
}

.panel-actions {
  display: flex;
  gap: 12px;
}

.panel-actions.wrap {
  flex-wrap: wrap;
}

.muted-btn {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--text);
}

.action-link-btn {
  background: none;
  border: 0;
  color: var(--primary);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.file-trigger-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.permission-note {
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid #d7ccb9;
  background: #fffaf2;
  color: #7a4f16;
}

.table-wrap {
  overflow-x: auto;
}

.entry-table-wrap {
  overflow-x: visible;
}

.operation-line-card {
  border: 1px solid #d9cfbd;
  border-radius: 20px;
  padding: 18px;
  background: #fffefa;
}

.operation-line-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.operation-line-lot {
  font-size: 1.1rem;
  font-weight: 800;
  color: #24323c;
}

.operation-sections {
  display: grid;
  gap: 16px;
}

.operation-sample-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.operation-sample-box,
.operation-meta-box {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #ffffff;
  padding: 16px;
}

.cloud-image-widget {
  display: grid;
  gap: 8px;
  min-width: 220px;
}

.cloud-image-widget.compact {
  min-width: 180px;
}

.cloud-image-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.cloud-image-meta {
  font-size: 0.88rem;
  color: var(--muted);
}

.cloud-image-meta.has-image {
  color: #196a34;
  font-weight: 700;
}

.image-viewer-open {
  overflow: hidden;
}

.image-viewer {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 80;
}

.image-viewer.open {
  display: flex;
}

.image-viewer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.72);
}

.image-viewer-card {
  position: relative;
  width: min(92vw, 960px);
  max-height: 90vh;
  background: var(--panel);
  border-radius: 22px;
  padding: 18px;
  box-shadow: 0 26px 60px rgba(0, 0, 0, 0.28);
  display: grid;
  gap: 12px;
  z-index: 1;
}

.image-viewer-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.image-viewer-body {
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: auto;
}

.image-viewer-body img {
  max-width: 100%;
  max-height: calc(90vh - 90px);
  border-radius: 16px;
  background: #fff;
}

.operation-sample-box h5,
.operation-meta-box h5 {
  margin: 0 0 14px;
  font-size: 1rem;
}

.operation-pair-grid,
.operation-meta-grid {
  display: grid;
  gap: 14px;
}

.operation-pair-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  align-items: end;
}

.operation-meta-grid {
  grid-template-columns: repeat(12, 1fr);
}

.operation-meta-grid .field {
  grid-column: span 4;
}

.operation-meta-grid .field.full-span {
  grid-column: 1 / -1;
}

.audit-json {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  line-height: 1.4;
  max-width: 320px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 14px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  color: #5f6773;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.link-btn {
  background: none;
  border: 0;
  color: var(--primary);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .field,
  .field.full-span {
    grid-column: 1 / -1;
  }

  .sidebar {
    height: auto;
    position: static;
    top: auto;
    padding: 18px 14px 14px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
  }

  .brand {
    width: 100%;
  }

  .brand h1 {
    font-size: 1.65rem;
  }

  .brand p {
    margin: 6px 0 10px;
  }

  .nav-section {
    display: none;
  }

  .nav-btn {
    width: auto;
    margin-top: 0;
    padding: 12px 14px;
    white-space: nowrap;
    border-radius: 999px;
    background: rgba(255,255,255,0.04);
  }

  .main {
    padding: 18px 14px 24px;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .auth-card {
    width: min(100%, 520px);
    padding: 28px 22px 24px;
  }

  .auth-brand h2 {
    font-size: 2.1rem;
  }

  .topbar h2 {
    font-size: 1.8rem;
  }

  .actions {
    width: 100%;
  }

  .session-panel {
    min-width: 0;
    width: 100%;
  }

  .entry-table-mobile {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
  }

  .entry-table-mobile thead {
    display: none;
  }

  .entry-table-mobile tbody,
  .entry-table-mobile tr,
  .entry-table-mobile td {
    display: block;
    width: 100%;
  }

  .entry-table-mobile tr {
    margin-bottom: 14px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #fff;
    padding: 12px 12px 4px;
  }

  .entry-table-mobile td {
    border: 0;
    padding: 0 0 12px;
  }

  .entry-table-mobile td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 6px;
    font-weight: 700;
    color: var(--muted);
  }

  .entry-table-mobile td input,
  .entry-table-mobile td select,
  .entry-table-mobile td textarea {
    width: 100%;
  }

  .operation-sample-grid,
  .operation-pair-row,
  .operation-meta-grid {
    grid-template-columns: 1fr;
  }

  .operation-meta-grid .field {
    grid-column: 1 / -1;
  }
}
