@font-face {
  font-family: "UyghurUI";
  src: url("../fonts/uyghur.woff2") format("woff2"),
       url("../fonts/uyghur.ttf") format("truetype");
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF;
}

:root {
  --ink: #14201c;
  --muted: #5a6b64;
  --line: rgba(20, 40, 34, 0.10);
  --surface: rgba(255, 252, 247, 0.92);
  --surface-solid: #fffaf3;
  --accent: #0b7a66;
  --accent-deep: #065445;
  --accent-soft: #d8f3ec;
  --warm: #e8a054;
  --danger: #c23b3b;
  --ok: #1d8a4a;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 12px 40px rgba(10, 40, 32, 0.10);
  --nav-h: 72px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --app-max: 480px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html {
  direction: rtl;
  height: 100%;
  overflow-x: hidden;
  max-width: 100%;
}
body {
  margin: 0;
  min-height: 100%;
  max-width: 100%;
  overflow-x: hidden;
  font-family: "UyghurUI", "UKIJ Tuz", "ALKATIP Basma", Tahoma, sans-serif;
  color: var(--ink);
  line-height: 1.65;
  background:
    radial-gradient(900px 480px at 100% -10%, rgba(11, 122, 102, 0.22), transparent 55%),
    radial-gradient(700px 420px at -10% 20%, rgba(232, 160, 84, 0.18), transparent 50%),
    linear-gradient(165deg, #e7f4ef 0%, #f4efe6 42%, #efe6d8 100%);
  background-attachment: fixed;
}
a { color: var(--accent-deep); text-decoration: none; }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }

/* ---- App shell (H5) ---- */
.app-shell {
  width: min(100%, var(--app-max));
  max-width: 100%;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  overflow-x: hidden;
  padding-bottom: calc(var(--nav-h) + var(--safe-b) + 20px);
}
.app-shell.auth-shell {
  padding-bottom: calc(24px + var(--safe-b));
  display: flex;
  flex-direction: column;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 12px;
  background: rgba(244, 239, 230, 0.78);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  animation: fadeDown 0.45s ease both;
}
.app-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand-mark {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.brand {
  margin: 0;
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  background: linear-gradient(120deg, var(--accent-deep), #178f75);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand-sub {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  max-width: 58vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-chip {
  font-size: 0.78rem;
  color: var(--accent-deep);
  background: var(--accent-soft);
  border: 1px solid rgba(11, 122, 102, 0.18);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  white-space: nowrap;
}

.app-main {
  padding: 14px 14px 8px;
  max-width: 100%;
  overflow-x: hidden;
  animation: fadeUp 0.5s ease both;
}

/* ---- Auth H5 ---- */
.auth-hero {
  padding: calc(48px + env(safe-area-inset-top, 0px)) 22px 18px;
  text-align: center;
  animation: fadeUp 0.55s ease both;
}
.auth-hero .brand {
  font-size: clamp(2.6rem, 12vw, 3.4rem);
  line-height: 1.15;
}
.auth-hero .sub {
  margin: 0.65rem auto 0;
  max-width: 16em;
  color: var(--muted);
  font-size: 0.95rem;
}
.auth-panel {
  margin: 0 14px;
  animation: fadeUp 0.65s 0.08s ease both;
}
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 6px;
  background: rgba(255,255,255,0.55);
  border-radius: 999px;
  border: 1px solid var(--line);
  margin-bottom: 14px;
}
.auth-tabs a {
  text-align: center;
  padding: 0.7rem 0.5rem;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 600;
  transition: background 0.2s, color 0.2s, transform 0.15s;
}
.auth-tabs a.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 20px rgba(11, 122, 102, 0.28);
}
.auth-tabs a:active { transform: scale(0.97); }

/* ---- Surfaces ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1rem 1.1rem;
  margin-bottom: 12px;
  backdrop-filter: blur(8px);
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.card h2, .card h3, .card h4 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 0.85rem;
}

/* ---- Forms ---- */
label {
  display: block;
  margin: 0.85rem 0 0.3rem;
  color: var(--muted);
  font-size: 0.88rem;
}
input[type=text],
input[type=password],
input[type=number],
input[type=datetime-local],
input[type=file],
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.85rem 0.95rem;
  font: inherit;
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus, select:focus, textarea:focus {
  border-color: rgba(11, 122, 102, 0.55);
  box-shadow: 0 0 0 4px rgba(11, 122, 102, 0.12);
}
textarea { min-height: 96px; resize: vertical; }
.form-actions {
  margin-top: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 44px;
  padding: 0.65rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: transform 0.12s, background 0.2s, box-shadow 0.2s;
  max-width: 100%;
  white-space: normal;
  text-align: center;
  word-break: break-word;
  line-height: 1.3;
}
.btn:active { transform: scale(0.97); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 10px 24px rgba(11, 122, 102, 0.28);
}
.btn.danger {
  background: linear-gradient(135deg, #d45454, var(--danger));
  border-color: transparent;
  color: #fff;
}
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-block { width: 100%; }
.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}
.row-actions .btn { min-height: 38px; padding: 0.45rem 0.8rem; font-size: 0.88rem; }

.flash {
  margin: 0 0 12px;
  padding: 0.8rem 0.95rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  animation: fadeUp 0.35s ease both;
}
.flash.ok { background: #e7f7ee; border-color: #bfe5cd; color: var(--ok); }
.flash.err { background: #fdeceb; border-color: #f0c2bf; color: var(--danger); }

/* ---- Stats ---- */
.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.85rem;
  box-shadow: var(--shadow);
}
.stat .n {
  font-size: 1.45rem;
  font-weight: 700;
  direction: ltr;
  color: var(--accent-deep);
}
.stat .l { color: var(--muted); font-size: 0.8rem; margin-top: 0.15rem; }

/* ---- Tables: scroll inside card, not whole page ---- */
.table-scroll {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  min-width: 460px;
}
th, td {
  border-bottom: 1px solid var(--line);
  padding: 0.65rem 0.3rem;
  text-align: right;
  vertical-align: middle;
  word-break: break-word;
  max-width: 9.5em;
}
th { color: var(--muted); font-weight: 600; white-space: nowrap; max-width: none; }
td .row-actions { max-width: 12em; }

.thumb {
  width: 52px !important;
  height: 52px !important;
  max-width: 52px !important;
  max-height: 52px !important;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #eee;
}
.thumb-link {
  display: inline-block;
  padding: 0;
  border: 0;
  background: none;
  cursor: zoom-in;
  line-height: 0;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 0.5rem 0 0.75rem;
}
.preview-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  padding: 0;
  cursor: zoom-in;
  width: 100%;
  aspect-ratio: 1;
}
.preview-card img,
.preview-card .thumb {
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  max-height: none !important;
  object-fit: cover;
  display: block;
}

/* ---- Bottom tab bar: always fixed to screen bottom (WeChat-safe) ---- */
.tabbar {
  position: fixed !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100% !important;
  max-width: var(--app-max);
  margin: 0 auto;
  height: calc(var(--nav-h) + var(--safe-b));
  padding: 6px 4px calc(6px + var(--safe-b));
  display: flex;
  gap: 2px;
  justify-content: space-around;
  align-items: stretch;
  background: rgba(255, 250, 243, 0.96);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  z-index: 9999 !important;
  box-shadow: 0 -8px 30px rgba(10, 40, 32, 0.12);
  /* no transform — breaks position:fixed in WeChat */
}
.tabbar a {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  max-width: 20%;
  border-radius: 12px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  padding: 4px 1px;
  transition: background 0.2s, color 0.2s;
}
.tabbar a .ico {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  font-size: 0.9rem;
  background: transparent;
  flex-shrink: 0;
}
.tabbar a.active {
  color: var(--accent-deep);
  background: var(--accent-soft);
}
.tabbar a.active .ico {
  background: rgba(11, 122, 102, 0.16);
}
.tabbar .label {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 1px;
}

/* ---- Mobile list cards (replace wide tables) ---- */
.list-stack { display: flex; flex-direction: column; gap: 10px; }
.list-item {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.75rem;
}
.list-item-top {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.list-item-top .thumb,
.list-item-top .thumb-link { flex-shrink: 0; }
.list-item-body { flex: 1; min-width: 0; }
.list-item-title {
  margin: 0 0 0.35rem;
  font-weight: 700;
  font-size: 0.98rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.list-check { margin-top: 4px; flex-shrink: 0; }
.meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 8px;
  margin: 0.35rem 0 0.65rem;
}
.meta-grid .m {
  background: rgba(11, 122, 102, 0.06);
  border-radius: 10px;
  padding: 0.4rem 0.5rem;
  min-width: 0;
}
.meta-grid .m .k {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.meta-grid .m .v {
  display: block;
  font-weight: 600;
  font-size: 0.86rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.list-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.list-actions .btn {
  width: 100%;
  min-height: 40px;
  font-size: 0.82rem;
  padding: 0.45rem 0.4rem;
}
.list-actions .btn.span2 { grid-column: 1 / -1; }
.filter-bar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 12px;
}
.filter-bar select,
.filter-bar input { width: 100%; }
.batch-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}
.batch-bar .btn { width: 100%; font-size: 0.85rem; }

/* User download: one original image per row */
.source-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.source-row {
  display: flex;
  gap: 12px;
  align-items: stretch;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px;
}
.source-thumb {
  flex: 0 0 112px;
  width: 112px;
  height: 112px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  overflow: hidden;
  background: #f3f0ea;
  cursor: zoom-in;
}
.source-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.source-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
}
.source-title {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.35;
  word-break: break-word;
}
.source-meta {
  font-size: 0.85rem;
}
.source-info .btn {
  min-height: 42px;
  font-size: 0.95rem;
}

.footer {
  margin-top: 18px;
  padding-bottom: 8px;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
  word-break: break-all;
}

.topbar { display: none; } /* legacy */
.nav { display: none; }
.tabs { display: flex; gap: 0.4rem; margin-bottom: 1rem; flex-wrap: wrap; }
.muted { color: var(--muted); }

/* lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(12, 24, 20, 0.86);
  display: none !important;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 1rem;
}
.lightbox.open { display: flex !important; }
.lightbox-inner {
  position: relative;
  max-width: min(960px, 96vw);
  max-height: 92vh;
  background: #fff;
  border-radius: 16px;
  padding: 0.75rem;
  box-shadow: var(--shadow);
  animation: fadeUp 0.25s ease both;
}
.lightbox-inner img {
  display: block;
  max-width: 100%;
  max-height: calc(92vh - 3.5rem);
  margin: 0 auto;
  border-radius: 10px;
}
.lightbox-caption {
  margin-top: 0.5rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  direction: ltr;
}
.lightbox-close {
  position: absolute;
  top: 0.4rem;
  left: 0.4rem;
  border: 0;
  background: var(--danger);
  color: #fff;
  border-radius: 999px;
  width: 2rem;
  height: 2rem;
  cursor: pointer;
  font: inherit;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (min-width: 640px) {
  .stats { grid-template-columns: repeat(4, 1fr); }
  .preview-grid { grid-template-columns: repeat(6, 1fr); }
  .form-actions { flex-direction: row; flex-wrap: wrap; }
  .btn-block { width: auto; min-width: 160px; }
}
