:root {
  --bg: #f2f4f7;
  --card: #ffffff;
  --ink: #101828;
  --muted: #667085;
  --accent: #0b63e5;
  --accent-press: #084fc0;
  --danger: #d92d20;
  --border: #d0d5dd;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; padding: 0; }

[hidden] { display: none !important; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
.auth-loading > .topbar, .auth-loading > .screen { visibility: hidden; }
.boot-screen {
  position: fixed; inset: 0; z-index: 1000; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; background: var(--bg);
}
body:not(.auth-loading) .boot-screen { display: none; }
.boot-logo { font-size: 23px; font-weight: 800; }
.boot-logo span { color: var(--accent); }
.boot-spinner {
  width: 30px; height: 30px; border: 3px solid #dbe7fa; border-top-color: var(--accent);
  border-radius: 50%; animation: boot-spin .75s linear infinite;
}
.boot-screen p { margin: 0; color: var(--muted); font-size: 13px; }
@keyframes boot-spin { to { transform: rotate(360deg); } }

/* --- yuqori panel --- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: var(--card);
  border-bottom: 1px solid #e4e7ec;
}
.brand { font-weight: 700; font-size: 18px; }
.brand span { color: var(--accent); }

/* --- ekranlar --- */
.screen {
  max-width: 560px; margin: 0 auto;
  padding: 20px 16px calc(80px + env(safe-area-inset-bottom));
}
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 1px 3px rgba(16,24,40,.08);
}
.card h1 { margin: 0 0 6px; font-size: 22px; }
.muted { color: var(--muted); font-size: 14px; margin: 0 0 18px; line-height: 1.45; }

label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 14px 0 6px; }

input, textarea, select {
  width: 100%; font-size: 16px; padding: 13px 14px;
  border: 1.5px solid var(--border); border-radius: 10px;
  background: #fff; color: var(--ink); outline: none;
  font-family: inherit;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(11,99,229,.15);
}
textarea { resize: vertical; line-height: 1.5; }
input[type=file] { padding: 10px; font-size: 14px; }

.code-input {
  text-align: center; font-size: 24px; letter-spacing: 8px; font-weight: 700;
}
.code-error {
  color: var(--danger); font-size: 13.5px; line-height: 1.45;
  margin: 12px 0 0; background: rgba(217,45,32,.08);
  border: 1px solid rgba(217,45,32,.25); border-radius: 10px; padding: 10px 12px;
}

/* --- tugmalar --- */
button.primary {
  width: 100%; margin-top: 18px; min-height: 50px;
  font-size: 16px; font-weight: 600; color: #fff;
  background: var(--accent); border: 0; border-radius: 10px;
  cursor: pointer; touch-action: manipulation;
}
button.primary:active { background: var(--accent-press); }
button.primary:disabled { opacity: .65; }

button.ghost {
  display: block; width: 100%; margin-top: 10px; min-height: 46px;
  font-size: 15px; font-weight: 500; color: var(--accent);
  background: transparent; border: 0; border-radius: 10px; cursor: pointer;
}
button.ghost.small { width: auto; margin: 12px auto 0; min-height: 40px; padding: 0 14px; font-size: 14px; }
#logoutBtn { width: auto; margin: 0; min-height: 40px; padding: 0 14px; font-size: 14px; }

/* --- tablar --- */
.tabs {
  display: flex; gap: 6px; background: #e4e7ec; overflow-x: auto;
  padding: 4px; border-radius: 12px; margin-bottom: 14px;
}
.tab {
  flex: 1 0 auto; min-height: 44px; border: 0; border-radius: 9px; padding: 0 12px;
  font-size: 15px; font-weight: 600; color: var(--muted);
  background: transparent; cursor: pointer;
}
.tab.active { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(16,24,40,.12); }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.toolbar .ghost.small { margin: 0; }
#newsCount { color: var(--muted); font-size: 14px; }

/* --- qo‘shimcha imkoniyatlar --- */
.section-intro { margin: 2px 2px 14px; }
.section-intro h2 { margin: 0 0 5px; font-size: 21px; }
.section-intro p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.45; }
.cache-status {
  margin-top: 10px; padding: 9px 11px; border-radius: 9px;
  background: #eef4ff; color: #175cd3; font-size: 12.5px; line-height: 1.4;
}
.module-groups { display: flex; flex-direction: column; gap: 10px; }
.module-group {
  overflow: hidden; background: var(--card); border: 1px solid #e4e7ec;
  border-radius: var(--radius); box-shadow: 0 1px 3px rgba(16,24,40,.05);
}
.module-group-head {
  width: 100%; min-height: 58px; display: flex; align-items: center; gap: 11px;
  padding: 10px 14px; border: 0; background: var(--card); color: var(--ink);
  font: inherit; text-align: left; cursor: pointer;
}
.module-group-head:active { background: #f5f8ff; }
.module-group-icon { width: 32px; text-align: center; font-size: 22px; }
.module-group-title { flex: 1; font-size: 16px; font-weight: 700; }
.module-chevron { color: var(--muted); font-size: 20px; transition: transform .18s ease; }
.module-group-head[aria-expanded="true"] .module-chevron { transform: rotate(180deg); }
.module-items { border-top: 1px solid #e4e7ec; background: #fbfcfe; }
.module-item {
  width: 100%; border: 0; background: transparent; font-family: inherit; text-align: left;
  min-height: 52px; display: flex; align-items: center; gap: 10px;
  padding: 9px 14px; color: var(--ink); text-decoration: none;
  border-bottom: 1px solid #eef0f3; font-size: 15px; font-weight: 550;
}
.module-item:last-child { border-bottom: 0; }
.module-item:active { background: #eef4ff; }
.module-item-icon { width: 28px; text-align: center; font-size: 19px; }
.module-item > span:nth-child(2) { flex: 1; }
.module-capability { display: block; margin-top: 2px; color: var(--muted); font-size: 11.5px; font-weight: 500; }
.module-open { color: var(--accent); font-size: 18px; }
.module-work-head { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 14px; }
.module-work-head h2 { margin: 2px 0 3px; font-size: 20px; }
.module-work-head p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.4; }
.back-button {
  flex: 0 0 auto; min-height: 40px; padding: 0 12px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--card); color: var(--accent); font-weight: 650; cursor: pointer;
}
.module-records { display: flex; flex-direction: column; gap: 9px; margin-top: 12px; }
.module-record { background: var(--card); border: 1px solid #e4e7ec; border-radius: 12px; padding: 13px; }
.module-record-title { font-size: 15px; font-weight: 700; line-height: 1.4; }
.module-record-meta { margin-top: 4px; color: var(--muted); font-size: 12px; line-height: 1.35; }
.module-record-actions { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.external-badge { color: var(--muted); background: #f2f4f7; border-radius: 8px; padding: 7px 9px; font-size: 12px; }
.module-html-field { min-height: 180px; font-family: inherit; }
.language-divider {
  margin: 22px -4px 2px; padding: 9px 10px; border-radius: 9px;
  background: #eef4ff; color: #175cd3; font-size: 14px; font-weight: 750;
}
.advanced-fields {
  margin-top: 22px; padding: 12px 14px; border: 1px solid #d9e2f2;
  border-radius: 11px; background: #f8faff;
}
.advanced-fields summary { color: #175cd3; font-size: 14px; font-weight: 750; cursor: pointer; }
.advanced-fields > p { margin: 8px 0 2px; color: var(--muted); font-size: 12.5px; line-height: 1.4; }
#moduleFormView { margin-top: 8px; }
#moduleFormView h3 { margin: 0 0 6px; }

/* --- yangiliklar ro'yxati --- */
.news-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.news-item {
  background: var(--card); border-radius: var(--radius); padding: 14px 16px;
  box-shadow: 0 1px 3px rgba(16,24,40,.06);
}
.news-title { font-weight: 600; font-size: 15px; line-height: 1.4; }
.news-meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.empty { color: var(--muted); text-align: center; padding: 30px 10px; font-size: 14px; }
.empty.error { color: var(--danger); }

/* --- "Yaratish" suzuvchi tugmasi --- */
.fab {
  position: fixed; right: 20px; bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 50;
  display: flex; align-items: center; gap: 8px;
  min-height: 54px; padding: 0 20px;
  background: var(--accent); color: #fff;
  border: 0; border-radius: 27px;
  font-size: 17px; font-weight: 700; cursor: pointer;
  box-shadow: 0 6px 18px rgba(11,99,229,.4);
  touch-action: manipulation;
}
.fab:active { background: var(--accent-press); }
.fab span { font-size: 15px; }

/* --- forma --- */
.form { padding-bottom: 24px; }
#imgPreview {
  width: 100%; max-height: 220px; object-fit: cover;
  border-radius: 10px; margin-top: 10px;
}

/* --- API so'rov animatsiyasi (shaffof overlay) --- */
.api-overlay {
  position: fixed; inset: 0; z-index: 300;
  display: flex; align-items: center; justify-content: center;
  background: rgba(242,244,247,.78); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  opacity: 0; transition: opacity .25s ease;
}
.api-overlay.show { opacity: 1; }
.api-overlay-box {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 26px 30px; background: rgba(255,255,255,.9); border-radius: 18px;
  box-shadow: 0 8px 30px rgba(16,24,40,.14); max-width: 82%;
}
.api-spinner {
  width: 34px; height: 34px; border: 3px solid #dbe7fa; border-top-color: var(--accent);
  border-radius: 50%; animation: boot-spin .75s linear infinite;
}
.api-overlay-box p {
  margin: 0; color: var(--ink); font-size: 14.5px; font-weight: 600;
  text-align: center; line-height: 1.4;
}

/* --- toast --- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%); max-width: 90%;
  background: #101828; color: #fff; padding: 12px 18px;
  border-radius: 10px; font-size: 14px; z-index: 100;
  box-shadow: 0 8px 24px rgba(16,24,40,.3);
}
.toast.error { background: var(--danger); }

/* --- skrinshot (debug) --- */
.debug {
  position: fixed; inset: 0; background: rgba(16,24,40,.88); z-index: 200;
  display: flex; flex-direction: column; padding: 16px;
  padding-top: calc(16px + env(safe-area-inset-top));
}
.debug-head {
  display: flex; justify-content: space-between; align-items: center;
  color: #fff; font-size: 12px; word-break: break-all; gap: 10px; margin-bottom: 10px;
}
.debug-head button {
  flex-shrink: 0; background: #fff; border: 0; border-radius: 50%;
  width: 34px; height: 34px; font-size: 16px; cursor: pointer;
}
.debug-body { flex: 1; overflow: auto; }
.debug-body img { width: 100%; border-radius: 10px; }

/* --- foydalanuvchi --- */
.user-box { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.user-box .ghost.small { margin: 0; }
.badge {
  background: var(--accent); color: #fff; font-size: 11px; font-weight: 700;
  border-radius: 8px; padding: 2px 7px; margin-left: 4px;
}

/* --- ulash ekrani --- */
.choice {
  width: 100%; min-height: 56px; margin-top: 10px;
  font-size: 16px; font-weight: 600; color: var(--ink);
  background: var(--card); border: 1.5px solid var(--border); border-radius: 12px;
  cursor: pointer; text-align: left; padding: 0 16px;
}
.choice:active { border-color: var(--accent); background: #f0f5ff; }

/* --- OneID uslubidagi ulash ekrani --- */
#screen-link .oneid-card { padding: 26px 20px; }
#screen-link .oneid-card h1 {
  font-size: 25px; font-weight: 800; line-height: 1.28; letter-spacing: -.3px;
  color: #14161f; margin: 0 0 10px;
}
#screen-link .oneid-card .muted { margin-bottom: 22px; }

.oneid-tabs {
  display: flex; gap: 4px; background: #e9eaf8; border-radius: 14px;
  padding: 4px; margin-bottom: 20px;
}
.oneid-tab {
  flex: 1; min-height: 44px; border: 0; border-radius: 11px;
  font-size: 15px; font-weight: 700; color: #6b7280;
  background: transparent; cursor: pointer; font-family: inherit;
}
.oneid-tab.active { background: #fff; color: var(--accent); box-shadow: 0 1px 4px rgba(11,99,229,.18); }

.password-field { position: relative; }
.password-field input { padding-right: 46px; }
.eye-btn {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 38px; height: 38px; border: 0; background: transparent; cursor: pointer;
  display: flex; align-items: center; justify-content: center; color: #98a2b3; padding: 0;
}
.eye-btn svg { width: 20px; height: 20px; }

.phone-field {
  display: flex; align-items: center; border: 1.5px solid var(--border);
  border-radius: 10px; background: #fff; overflow: hidden;
}
.phone-field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(11,99,229,.12); }
.phone-flag { padding: 0 2px 0 14px; font-size: 18px; line-height: 1; }
.phone-prefix { padding: 0 8px 0 6px; font-weight: 700; color: var(--ink); border-right: 1px solid var(--border); }
.phone-field input { border: 0; border-radius: 0; flex: 1; }
.phone-field input:focus { box-shadow: none; }

button.primary.oneid-btn { background: var(--accent); border-radius: 12px; }
button.primary.oneid-btn:active { background: var(--accent-press); }

/* --- boy matn muharriri --- */
.editor-box {
  border: 1.5px solid var(--border); border-radius: 10px; overflow: hidden; background: #fff;
}
.editor-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(11,99,229,.15); }
.editor-toolbar {
  display: flex; flex-wrap: wrap; gap: 2px; padding: 6px;
  border-bottom: 1px solid #e4e7ec; background: #f9fafb;
}
.editor-toolbar button {
  min-width: 36px; height: 36px; padding: 0 8px;
  border: 0; border-radius: 8px; background: transparent;
  font-size: 15px; font-weight: 600; color: var(--ink); cursor: pointer;
}
.editor-toolbar button:active { background: #e4e7ec; }
#editor {
  min-height: 180px; padding: 12px 14px; font-size: 16px; line-height: 1.55;
  outline: none; word-break: break-word;
}
#editor:empty::before {
  content: attr(data-placeholder); color: #98a2b3; pointer-events: none;
}
#editor h3 { margin: 10px 0 6px; font-size: 18px; }
#editor p { margin: 6px 0; }
#editor ul, #editor ol { margin: 6px 0; padding-left: 22px; }
#editor a { color: var(--accent); }

/* --- tanlovlar --- */
.checks { display: flex; flex-direction: column; gap: 4px; margin-top: 2px; }
.check-line {
  display: flex; align-items: center; gap: 8px;
  font-size: 15px; font-weight: 500; color: var(--ink);
  margin: 8px 0; cursor: pointer; min-height: 32px;
}
.check-line input { width: 18px; height: 18px; margin: 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* --- yangilik amallari --- */
.news-actions { display: flex; gap: 8px; margin-top: 10px; }
.act {
  flex: 1; min-height: 40px; border: 0; border-radius: 9px;
  font-size: 14px; font-weight: 600; cursor: pointer;
}
.act.edit { background: #eef4ff; color: var(--accent); }
.act.del { background: #fdecea; color: var(--danger); }

/* --- foydalanuvchilar --- */
.users-list { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.user-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: #f9fafb; border: 1px solid #e4e7ec; border-radius: 10px; padding: 10px 12px;
}
.user-login { font-weight: 600; font-size: 15px; }
.user-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.user-actions { display: flex; gap: 6px; flex-shrink: 0; }
.user-actions .act { min-height: 36px; padding: 0 12px; flex: none; background: #eef4ff; color: var(--accent); }
.telegram-status { margin-top: 14px; margin-bottom: 0; }

@media (min-width: 600px) {
  .screen { padding-left: 24px; padding-right: 24px; }
}
