:root {
  --bg: #f5f4ef;
  --bg-alt: #fffdf7;
  --ink: #1a1f2e;
  --muted: #6f7687;
  --accent: #1f8a70;
  --accent-strong: #126f59;
  --danger: #b94040;
  --line: #d8d2c6;
  --panel: #fffefa;
  --shadow: 0 14px 32px rgba(26, 31, 46, 0.09);
  --space-1: 8px;
  --space-2: 12px;
  --space-3: 16px;
  --space-4: 24px;
  --radius-card: 20px;
  --radius-panel: 14px;
  --min-touch-target: 44px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: var(--tg-vh, 100vh);
  font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 10% 10%, #efe6d3 0, transparent 38%),
    radial-gradient(circle at 90% 12%, #dceadf 0, transparent 35%), var(--bg);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.bg-shape {
  position: fixed;
  z-index: -1;
  border-radius: 999px;
  filter: blur(30px);
  opacity: 0.5;
}

.bg-shape--left {
  width: 260px;
  height: 260px;
  left: -80px;
  top: 45%;
  background: #d4e5d9;
}

.bg-shape--right {
  width: 300px;
  height: 300px;
  right: -120px;
  top: 8%;
  background: #f0d9ba;
}

.layout {
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 16px calc(42px + env(safe-area-inset-bottom, 0));
}

.card {
  background: linear-gradient(180deg, var(--panel), var(--bg-alt));
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
}

.auth-card {
  padding: 24px;
  margin-bottom: 20px;
}

h1,
h2,
h3 {
  margin: 0 0 10px;
  font-family: "Gill Sans", "Avenir Next", sans-serif;
}

h1 {
  font-size: 1.8rem;
  letter-spacing: 0.02em;
}

h2 {
  font-size: 1.35rem;
}

h3 {
  font-size: 1.1rem;
}

.h3-with-hint {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.muted {
  margin: 0;
  color: var(--muted);
}

.status-line {
  min-height: 1.25rem;
  margin-top: 10px;
  color: var(--accent-strong);
}

.app-card {
  padding: 18px;
}

.hidden {
  display: none;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-2);
}

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

.tabs {
  display: flex;
  flex-wrap: nowrap;
  gap: var(--space-1);
  margin: 16px 0 14px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
}

.tab {
  border: 1px solid var(--line);
  background: #fcfaf2;
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 0.92rem;
  cursor: pointer;
  min-height: var(--min-touch-target);
  white-space: nowrap;
  flex: 0 0 auto;
}

.tab.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.tab-panel {
  display: none;
}

.tab-panel.is-active {
  display: block;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.panel {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: var(--radius-panel);
  padding: var(--space-2);
  animation: panel-in 160ms ease-out;
}

label {
  display: block;
  margin-bottom: 10px;
  font-size: 0.9rem;
  color: var(--muted);
  min-width: 160px;
  flex: 1 1 180px;
}

input,
select,
button,
textarea {
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  margin-top: 6px;
  border: 1px solid #ccc4b6;
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
  min-height: var(--min-touch-target);
}

textarea {
  resize: vertical;
  min-height: 88px;
}

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

.checkbox input {
  width: auto;
  margin: 0;
}

.btn {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f3efe4;
  color: var(--ink);
  cursor: pointer;
  padding: 10px 14px;
  min-height: var(--min-touch-target);
}

.btn:hover {
  filter: brightness(0.98);
}

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

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

.btn-ghost {
  background: transparent;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  align-items: flex-end;
}

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

.item {
  border: 1px solid #ddd6c9;
  border-radius: 10px;
  padding: 10px 12px;
  background: #fffcf3;
}

.item .title {
  font-weight: 700;
}

.album-editor {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed #d8cfbf;
}

.album-item-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  border: 1px solid #e4ddcf;
  border-radius: 8px;
  background: #fffdfa;
  padding: 8px 10px;
}

.album-item-head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
}

.album-item-preview {
  width: 64px;
  height: 64px;
  border: 1px dashed #d2c8b7;
  border-radius: 8px;
  background: #f8f4ea;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.72rem;
  flex: 0 0 64px;
}

.album-item-preview img,
.album-item-preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.album-item-main {
  font-size: 0.88rem;
  color: var(--ink);
}

.album-item-actions {
  display: flex;
  gap: 6px;
}

.btn-mini {
  min-height: 32px;
  padding: 6px 10px;
  font-size: 0.82rem;
}

.hint-box {
  border: 1px dashed #c8bfaf;
  border-radius: 10px;
  background: #f9f6ed;
  padding: 10px 12px;
  margin-bottom: 12px;
}

.hint-list {
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--ink);
}

.hint-list li {
  margin: 4px 0;
}

.hint-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  border: 1px solid #c7bead;
  background: #f8f3e7;
  color: #5d5a53;
  font-size: 0.75rem;
  line-height: 1;
  cursor: help;
  position: relative;
}

.hint-icon::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translate(-50%, 6px);
  width: min(280px, 70vw);
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #d4cab9;
  background: #fffdf8;
  color: var(--ink);
  box-shadow: 0 8px 18px rgba(26, 31, 46, 0.12);
  font-size: 0.8rem;
  font-weight: 500;
  text-align: left;
  white-space: normal;
  pointer-events: none;
  opacity: 0;
  transition: opacity 120ms ease, transform 120ms ease;
  z-index: 30;
}

.hint-icon:hover::after,
.hint-icon:focus-visible::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

.calendar-list-item {
  display: block;
  width: 100%;
  text-align: left;
  cursor: pointer;
}

.run-item {
  display: block;
  width: 100%;
  text-align: left;
  cursor: pointer;
}

.run-item.is-active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.calendar-grid-header {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.calendar-cell {
  border: 1px solid #ddd6c9;
  border-radius: 10px;
  min-height: 86px;
  background: #fffcf3;
  color: var(--ink);
  padding: 7px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-start;
  cursor: pointer;
}

.calendar-cell.is-outside {
  opacity: 0.45;
}

.calendar-cell-date {
  font-weight: 700;
  font-size: 0.9rem;
}

.calendar-cell-total {
  font-size: 0.82rem;
  color: var(--muted);
}

.media-preview {
  width: 120px;
  height: 120px;
  border: 1px dashed #d2c8b7;
  border-radius: 10px;
  background: #f8f4ea;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin: 8px 0;
  padding: 4px;
  color: var(--muted);
  font-size: 0.8rem;
}

.media-preview-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0;
}

.media-preview--small {
  width: 72px;
  height: 72px;
  margin: 0;
  padding: 2px;
}

.media-album-card .title {
  color: var(--accent-strong);
}

.media-preview img,
.media-preview video {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  object-fit: cover;
}

.result-box {
  background: #161d27;
  color: #ecf2ff;
  border-radius: 10px;
  min-height: 112px;
  padding: 10px;
  margin: 8px 0 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.report-box {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.report-header-line {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.report-title {
  font-weight: 700;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.82rem;
  border: 1px solid #d5cdbf;
  background: #f6f1e7;
}

.status-pill.is-success {
  border-color: #89c0ae;
  background: #e5f3ee;
  color: #0f5f4c;
}

.status-pill.is-muted {
  color: var(--muted);
}

.status-pill.is-warning {
  border-color: #dcc583;
  background: #fbf4db;
  color: #7a611d;
}

.status-pill.is-danger {
  border-color: #e0b0b0;
  background: #fae9e9;
  color: #8d3030;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.metric-card {
  border: 1px solid #ddd6c9;
  border-radius: 10px;
  background: #fffcf3;
  padding: 8px 10px;
}

.metric-label {
  font-size: 0.78rem;
  color: var(--muted);
}

.metric-value {
  font-size: 1.15rem;
  font-weight: 700;
}

.table-wrap {
  border: 1px solid #ddd6c9;
  border-radius: 10px;
  background: #fffdf8;
  overflow: hidden;
}

.table-title {
  padding: 8px 10px;
  border-bottom: 1px solid #e4ddcf;
  font-weight: 700;
  background: #f6f2e8;
}

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

.data-table th,
.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #efe8d8;
  text-align: left;
  font-size: 0.88rem;
  vertical-align: top;
}

.data-table th {
  color: var(--muted);
  font-weight: 600;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.num-cell {
  text-align: right !important;
  font-variant-numeric: tabular-nums;
}

.error-cell {
  overflow-wrap: anywhere;
  color: #4a3b2a;
}

.detail-lines {
  display: grid;
  gap: 4px;
}

.empty-note {
  padding: 10px;
  color: var(--muted);
}

.pager-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-top: 1px solid #e7dfcf;
}

.pager-info {
  font-size: 0.82rem;
  color: var(--muted);
}

.pager-btn {
  min-height: 34px;
  padding: 6px 12px;
}

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

body.is-miniapp {
  background: linear-gradient(180deg, #f7f6ef, #f3f1e8);
}

body.is-miniapp .bg-shape {
  opacity: 0.25;
}

body.is-miniapp .layout {
  max-width: 980px;
  padding-top: calc(12px + env(safe-area-inset-top, 0));
  padding-left: max(12px, env(safe-area-inset-left, 0));
  padding-right: max(12px, env(safe-area-inset-right, 0));
}

body.is-miniapp .auth-card {
  border-radius: 16px;
}

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

  .layout {
    padding: 14px;
  }

  .app-card {
    padding: 12px;
  }

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

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .tabs {
    position: sticky;
    top: 0;
    z-index: 10;
    background: linear-gradient(180deg, rgba(245, 244, 239, 0.96), rgba(245, 244, 239, 0.9));
    backdrop-filter: blur(6px);
    padding-top: 4px;
    margin-top: 10px;
  }

  .calendar-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .calendar-grid-header {
    display: none;
  }

  .calendar-cell {
    min-height: 74px;
  }

  label {
    min-width: 0;
    flex: 1 1 100%;
  }
}

@media (max-width: 520px) {
  .auth-card,
  .app-card {
    border-radius: 14px;
  }

  h1 {
    font-size: 1.5rem;
  }

  h2 {
    font-size: 1.2rem;
  }

  .panel {
    padding: 10px;
  }

  .row .btn {
    width: 100%;
  }

  .pager-controls {
    flex-wrap: wrap;
    justify-content: center;
  }

  .pager-info {
    width: 100%;
    text-align: center;
  }

  .data-table th,
  .data-table td {
    font-size: 0.82rem;
    padding: 7px 8px;
  }
}
