:root {
  --bg: #f3efe7;
  --bg-accent: #e8ddc8;
  --panel: #fffdf8;
  --ink: #241f17;
  --muted: #6e6457;
  --line: #d8ccb8;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --danger: #b42318;
  --danger-soft: #fff2f0;
  --ok: #0f9d58;
  --shadow: 0 14px 36px rgba(70, 48, 20, 0.12);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  font-family: "Trebuchet MS", "Gill Sans", sans-serif;
  background:
    radial-gradient(circle at 10% 5%, #fffdf6 0%, #f3efe7 55%),
    linear-gradient(140deg, #f6f2ea 0%, #ece2d1 100%);
}

a { color: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid rgba(36, 31, 23, 0.12);
  backdrop-filter: blur(10px);
  background: rgba(255, 252, 245, 0.75);
}

.brandWrap { display: flex; flex-direction: column; }
.brandTitle { font-size: 22px; font-weight: 900; letter-spacing: 0.2px; }
.brandSub { color: var(--muted); font-size: 12px; }

.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.tabs {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.tab {
  border: 1px solid var(--line);
  background: #fbf6ec;
  color: #3a3228;
  border-radius: 999px;
  padding: 9px 16px;
  cursor: pointer;
  font-weight: 700;
}

.tab.active {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-ink);
}

.tabPanel { display: none; }
.tabPanel.active { display: block; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.cardHeader h2 { margin: 0; }
.cardHeader { margin-bottom: 12px; }
.h3 { margin: 0 0 8px 0; font-size: 18px; }

.muted {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

label {
  display: block;
  margin-top: 8px;
  margin-bottom: 4px;
  font-size: 13px;
  color: #4f4437;
  font-weight: 700;
}

input,
select,
textarea,
button {
  font-family: inherit;
  font-size: 14px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #ccbda6;
  border-radius: 12px;
  padding: 10px 12px;
  background: #fffefb;
  color: var(--ink);
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #84a59d;
  box-shadow: 0 0 0 3px rgba(132, 165, 157, 0.2);
}

textarea { resize: vertical; }

button {
  border: 1px solid #147d75;
  background: #0f766e;
  color: #fff;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
}

button.primary {
  background: #ef6c00;
  border-color: #ef6c00;
}

button.ghost {
  background: transparent;
  color: #22524d;
  border-color: #7ea8a2;
}

button.danger,
.tinyDanger {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #f8c7c0;
}

.tinyDanger {
  margin-left: auto;
  padding: 3px 8px;
  border-radius: 8px;
  font-size: 11px;
}

button[disabled] {
  opacity: 0.65;
  cursor: not-allowed;
}

.gridMain {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.8fr);
  gap: 16px;
  align-items: start;
}

.grid2tight {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.grid3 {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
  margin-top: 8px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.inlineRow {
  display: flex;
  gap: 8px;
  align-items: center;
}

.inlineRow > * { flex: 1; }
.inlineRow .check { flex: initial; }

.infoBox {
  border: 1px solid #b9d9d2;
  background: #edf9f6;
  border-radius: 12px;
  padding: 10px 12px;
  color: #204a45;
  font-size: 13px;
}

.hidden { display: none; }

.subCard {
  border: 1px solid #e2d8c7;
  border-radius: 14px;
  padding: 10px;
  background: #fffaf1;
}

.subCard h3 {
  margin: 0 0 8px 0;
  color: #403629;
  font-size: 16px;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.toolbar {
  display: grid;
  grid-template-columns: 1.6fr 1fr auto auto;
  gap: 8px;
  margin-bottom: 10px;
}

.pager {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.pager .meta {
  font-size: 12px;
  color: var(--muted);
}

.notice {
  min-height: 18px;
  border: 1px dashed #b6aa99;
  background: #fff;
  color: #6c6255;
  border-radius: 10px;
  padding: 8px 10px;
}
.notice.ok { border-color: #8fd6b1; color: #0c7a41; background: #effcf4; }
.notice.bad { border-color: #f2b8b2; color: #a61b11; background: #fff6f5; }
.notice.info { border-color: #a6c6f8; color: #134794; background: #f3f8ff; }

.table {
  border: 1px solid #d6c9b4;
  border-radius: 12px;
  overflow: hidden;
  background: #fffdf8;
}

.thead,
.trow {
  display: grid;
  grid-template-columns: 1fr 2fr 58px;
  gap: 8px;
  padding: 8px;
}

.thead {
  background: #f5ecdd;
  font-weight: 800;
  color: #5a4c3a;
}

.trow {
  border-top: 1px solid #efe5d3;
}

.trow input { margin: 0; }

.checklist {
  border: 1px solid #d7cab8;
  border-radius: 12px;
  background: #fff;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 13px;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.item {
  border: 1px solid #dfd3bf;
  border-radius: 12px;
  background: #fffcf6;
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.itemStack {
  align-items: stretch;
}

.itemMain {
  flex: 1;
  min-width: 0;
}

.title { font-weight: 800; }

.detailBox {
  border: 1px solid #dccfb9;
  background: #fffefb;
  border-radius: 12px;
  padding: 10px;
  font-size: 14px;
}

.detailBox pre {
  background: #faf4e8;
  border: 1px solid #e8dcc8;
  border-radius: 10px;
  padding: 8px;
  white-space: pre-wrap;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: rgba(31, 22, 11, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal.hidden {
  display: none;
}

.modalCard {
  width: min(920px, 100%);
  max-height: 88vh;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 16px;
  position: relative;
}

.modalClose {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid #bda98b;
  background: #fff6e8;
  color: #6e3e19;
  padding: 0;
  line-height: 1;
  font-size: 20px;
}

.item pre {
  margin: 8px 0 0;
  background: #faf4e8;
  border: 1px solid #e8dcc8;
  border-radius: 10px;
  padding: 8px;
  white-space: pre-wrap;
}

.tg-preview {
  background: linear-gradient(180deg, #f9f3e8 0%, #f7eee0 100%);
  border: 1px solid #e4d6bf;
  border-radius: 16px;
  padding: 10px;
}

.tg-bubble {
  background: #ffffff;
  border: 1px solid #ded2c1;
  border-radius: 14px;
  padding: 10px;
}

.tg-media img,
.tg-media video {
  width: 100%;
  max-height: 280px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid #e4d9ca;
}

.tg-text {
  margin-top: 8px;
  white-space: pre-wrap;
}

.tg-buttons {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tg-btn-row {
  display: flex;
  gap: 6px;
}

.tg-btn {
  flex: 1;
  text-align: center;
  text-decoration: none;
  border: 1px solid #bad2df;
  background: #edf7ff;
  color: #1f4563;
  border-radius: 8px;
  padding: 7px;
  font-weight: 700;
}

#loadingOverlay {
  position: fixed;
  inset: 0;
  background: rgba(40, 27, 11, 0.25);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

#loadingOverlay.show { display: flex; }

.loaderBox {
  border: 1px solid #dbc8aa;
  background: #fffdf8;
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 3px solid #c4b8a5;
  border-top-color: #0f766e;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 980px) {
  .gridMain { grid-template-columns: 1fr; }
  .grid2tight { grid-template-columns: 1fr; }
  .grid3 { grid-template-columns: 1fr; }
  .toolbar { grid-template-columns: 1fr; }
  .inlineRow { flex-direction: column; align-items: stretch; }
  .item { flex-direction: column; align-items: stretch; }
}
