:root {
  --tg-blue: #2aabee;
  --tg-blue-2: #229ed9;
  --grad: linear-gradient(135deg, #2aabee 0%, #229ed9 55%, #1e88c7 100%);
  --bg: #e6ebf0;
  --surface: #ffffff;
  --surface-2: #f4f5f7;
  --text: #0f1720;
  --text-2: #6c7883;
  --border: #e4e8ec;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .08);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .08);
  --radius: 16px;
  --radius-sm: 12px;
  --danger: #e53935;
  --green: #31a24c;
  --amber: #f0a500;
}

[data-theme="dark"] {
  --bg: #0e1621;
  --surface: #17212b;
  --surface-2: #1f2b38;
  --text: #f2f5f7;
  --text-2: #8b9aa6;
  --border: #26313e;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(circle at 12% 15%, rgba(42, 171, 238, .12), transparent 42%),
    radial-gradient(circle at 88% 8%, rgba(34, 158, 217, .12), transparent 40%);
  background-attachment: fixed;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

a { color: var(--tg-blue-2); text-decoration: none; }
a:hover { text-decoration: underline; }

svg { display: block; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: rgba(128, 128, 128, .35); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: rgba(128, 128, 128, .55); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--grad);
  color: #fff;
  box-shadow: 0 2px 12px rgba(34, 158, 217, .35);
}

.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-logo {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, .18);
  border-radius: 50%;
  flex: 0 0 auto;
  backdrop-filter: blur(4px);
}

.brand-title { font-size: 18px; font-weight: 700; letter-spacing: .2px; line-height: 1.15; }
.brand-sub { font-size: 12.5px; opacity: .85; }

.spacer { flex: 1 1 auto; }

.icon-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, .16);
  color: #fff;
  cursor: pointer;
  transition: background .15s ease, transform .1s ease;
}
.icon-btn:hover { background: rgba(255, 255, 255, .28); }
.icon-btn:active { transform: scale(.94); }

.container { max-width: 1080px; margin: 0 auto; padding: 26px 20px 60px; }

.toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.search {
  position: relative;
  flex: 1 1 320px;
  min-width: 220px;
}
.search svg {
  position: absolute; left: 16px; top: 50%; transform: translateY(-50%);
  color: var(--text-2); pointer-events: none;
}
.search input {
  width: 100%;
  padding: 13px 16px 13px 46px;
  border-radius: 30px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  box-shadow: var(--shadow-sm);
}
.search input:focus { border-color: var(--tg-blue); box-shadow: 0 0 0 4px rgba(42, 171, 238, .18); }
.search input::placeholder { color: var(--text-2); }

.count-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-2);
  padding: 10px 16px;
  border-radius: 30px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 18px;
}
.grid.view-list { grid-template-columns: 1fr; }
.grid.view-two { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.seg {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 30px;
  padding: 3px;
  box-shadow: var(--shadow-sm);
}
.seg-btn {
  width: 40px; height: 34px;
  display: grid; place-items: center;
  border: none;
  border-radius: 26px;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: background .15s, color .15s, transform .1s;
}
.seg-btn:hover { background: var(--surface-2); }
.seg-btn:active { transform: scale(.94); }
.seg-btn.active { background: var(--grad); color: #fff; box-shadow: 0 3px 10px rgba(42, 171, 238, .35); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform .15s ease, box-shadow .2s ease, border-color .15s;
  position: relative;
  overflow: hidden;
}
.card::before {
  content: "";
  position: absolute; inset: 0 auto 0 0;
  width: 4px;
  background: var(--grad);
  opacity: 0;
  transition: opacity .2s ease;
}
.card:hover { transform: translateY(-3px); box-shadow: 0 12px 32px rgba(16, 24, 40, .14); }
.card:hover::before { opacity: 1; }

.card-head { display: flex; align-items: flex-start; gap: 12px; }

.card-avatar {
  width: 44px; height: 44px; flex: 0 0 auto;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--grad);
  color: #fff;
  font-weight: 700;
  font-size: 17px;
  box-shadow: 0 4px 12px rgba(42, 171, 238, .35);
}

.card-titles { min-width: 0; flex: 1 1 auto; }
.card-title { font-size: 16.5px; font-weight: 700; margin: 0; word-break: break-word; }
.card-desc {
  font-size: 14px;
  color: var(--text-2);
  margin: 0;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card.open .card-desc {
  -webkit-line-clamp: unset;
  display: block;
  overflow: visible;
}

.card-actions { display: flex; gap: 8px; flex: 0 0 auto; flex-wrap: wrap; justify-content: flex-end; }

.more-btn {
  align-self: flex-start;
  margin-top: 4px;
  min-width: 32px; height: 32px;
  padding: 0 14px;
  border-radius: 30px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--tg-blue-2);
  font-size: 19px; font-weight: 700; line-height: 1;
  cursor: pointer;
  transition: background .15s, transform .1s, color .15s;
}
.more-btn:hover { background: rgba(42, 171, 238, .14); }
.more-btn:active { transform: scale(.93); }

[dir="rtl"] { text-align: right; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 30px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text);
  transition: transform .1s ease, background .15s, box-shadow .15s, opacity .15s;
  white-space: nowrap;
  font-family: inherit;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--grad); color: #fff; box-shadow: 0 4px 14px rgba(42, 171, 238, .35); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-soft { background: rgba(42, 171, 238, .12); color: var(--tg-blue-2); }
.btn-soft:hover { background: rgba(42, 171, 238, .2); }
.btn-danger { background: rgba(229, 57, 53, .12); color: var(--danger); }
.btn-danger:hover { background: rgba(229, 57, 53, .2); }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-icon { width: 38px; height: 38px; padding: 0; border-radius: 50%; }

.link-toggle {
  background: none; border: none; padding: 0;
  color: var(--tg-blue-2); font-weight: 600; font-size: 13px;
  cursor: pointer; font-family: inherit;
}
.link-toggle:hover { text-decoration: underline; }

.empty {
  text-align: center;
  padding: 70px 20px;
  color: var(--text-2);
}
.empty svg { margin: 0 auto 16px; opacity: .5; }
.empty h3 { color: var(--text); margin: 0 0 6px; }

.page-foot {
  text-align: center;
  color: var(--text-2);
  font-size: 13px;
  padding: 24px 20px 40px;
}
.page-foot a { font-weight: 600; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 120%);
  background: #1f2b38;
  color: #fff;
  padding: 12px 20px;
  border-radius: 30px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .3);
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 120;
  transition: transform .3s cubic-bezier(.2, .8, .3, 1), opacity .3s;
  opacity: 0;
  pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.success { background: var(--green); }
.toast.error { background: var(--danger); }

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(9, 14, 20, .55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s ease, visibility .2s;
}
.modal-backdrop.show { opacity: 1; visibility: visible; }

.modal {
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .35);
  transform: translateY(14px) scale(.98);
  transition: transform .22s cubic-bezier(.2, .8, .3, 1);
}
.modal-backdrop.show .modal { transform: translateY(0) scale(1); }

.modal-head {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
  background: var(--surface);
  z-index: 2;
}
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { padding: 20px; }
.modal-foot {
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  position: sticky; bottom: 0;
  background: var(--surface);
}

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.field .hint { font-size: 12px; color: var(--text-2); font-weight: 400; }
.field input,
.field textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  resize: vertical;
}
.field textarea { min-height: 150px; font-family: "SFMono-Regular", ui-monospace, Consolas, monospace; font-size: 13px; }
.field textarea.ta-plain { min-height: 90px; font-family: inherit; font-size: 14px; }
.field input:focus, .field textarea:focus {
  border-color: var(--tg-blue);
  box-shadow: 0 0 0 4px rgba(42, 171, 238, .16);
  background: var(--surface);
}

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 34px 28px;
  text-align: center;
}
.login-logo {
  width: 74px; height: 74px;
  margin: 0 auto 18px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--grad);
  color: #fff;
  box-shadow: 0 12px 30px rgba(42, 171, 238, .4);
}
.login-card h1 { font-size: 22px; margin: 0 0 6px; }
.login-card p { color: var(--text-2); font-size: 14px; margin: 0 0 22px; }

.admin-layout { max-width: 1000px; margin: 0 auto; padding: 24px 20px 80px; }

.admin-header {
  display: flex; align-items: center; gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.admin-header h1 { font-size: 22px; margin: 0; }
.admin-header .muted { color: var(--text-2); font-size: 13.5px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  transition: background .15s;
}
.list-row:last-child { border-bottom: none; }
.list-row:hover { background: var(--surface-2); }
.list-row.dragging { opacity: .45; }
.list-row.drop-target { box-shadow: inset 0 3px 0 -1px var(--tg-blue); }

.drag-handle {
  cursor: grab;
  color: var(--text-2);
  padding: 4px;
  border-radius: 8px;
  flex: 0 0 auto;
}
.drag-handle:active { cursor: grabbing; }
.drag-handle:hover { background: var(--surface-2); color: var(--text); }

.row-index {
  width: 26px; height: 26px; flex: 0 0 auto;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-2);
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700;
}

.row-main { flex: 1 1 auto; min-width: 0; }
.row-name { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-desc { font-size: 13px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.row-actions { display: flex; gap: 6px; flex: 0 0 auto; }

.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); font-weight: 700; margin: 0 0 12px; }

.divider { height: 1px; background: var(--border); margin: 22px 0; border: none; }

.danger-zone {
  border: 1px solid rgba(229, 57, 53, .35);
  border-radius: var(--radius);
  padding: 18px 20px;
  background: rgba(229, 57, 53, .05);
}
.danger-zone h3 { margin: 0 0 4px; font-size: 15px; color: var(--danger); }
.danger-zone p { margin: 0 0 14px; font-size: 13px; color: var(--text-2); }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  background: rgba(42, 171, 238, .15);
  color: var(--tg-blue-2);
  vertical-align: middle;
}

@media (max-width: 620px) {
  .brand-sub { display: none; }
  .grid { grid-template-columns: 1fr; }
  .grid.view-two { grid-template-columns: 1fr; }
  .container { padding: 18px 14px 50px; }
  .admin-layout { padding: 18px 14px 70px; }
  .row-actions .label { display: none; }
}
