/* ════════════════════════════════════════════════════════════
   IC Control CRM — Telegram Mini App Styles
   Uses Telegram WebApp CSS variables for theme sync
   ════════════════════════════════════════════════════════════ */

:root {
  --bg:         var(--tg-theme-bg-color, #ffffff);
  --bg2:        var(--tg-theme-secondary-bg-color, #f0f2f5);
  --text:       var(--tg-theme-text-color, #1a1a2e);
  --hint:       var(--tg-theme-hint-color, #8a8a9a);
  --link:       var(--tg-theme-link-color, #2563eb);
  --accent:     var(--tg-theme-button-color, #2563eb);
  --accent-txt: var(--tg-theme-button-text-color, #ffffff);

  --radius-sm:  8px;
  --radius-md:  14px;
  --radius-lg:  20px;
  --nav-h:      72px;
  --safe-bot:   env(safe-area-inset-bottom, 0px);

  --new-bg:     #dbeafe; --new-c:     #1d4ed8;
  --inwork-bg:  #dcfce7; --inwork-c:  #15803d;
  --done-bg:    #f1f5f9; --done-c:    #475569;
  --blocked-bg: #fee2e2; --blocked-c: #b91c1c;
  --risk-bg:    #ffedd5; --risk-c:    #c2410c;
  --overdue-bg: #fef9c3; --overdue-c: #92400e;

  --low-c:      #64748b;
  --normal-c:   #2563eb;
  --high-c:     #d97706;
  --critical-c: #dc2626;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overscroll-behavior: none;
}

/* ── Splash ─────────────────────────────────────────────── */
.splash {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  height: 100vh;
  gap: 12px;
}
.splash-logo {
  width: 72px; height: 72px;
  background: var(--accent);
  color: var(--accent-txt);
  border-radius: 22px;
  font-size: 26px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 32px rgba(37,99,235,.35);
}
.splash-name { font-size: 20px; font-weight: 700; }
.splash-sub  { font-size: 13px; color: var(--hint); }

/* ── App layout ─────────────────────────────────────────── */
#app {
  height: 100vh;
  overflow-y: auto;
  padding-bottom: calc(var(--nav-h) + var(--safe-bot));
  -webkit-overflow-scrolling: touch;
}

/* ── Bottom navigation ───────────────────────────────────── */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + var(--safe-bot));
  padding-bottom: var(--safe-bot);
  background: var(--bg);
  border-top: 1px solid color-mix(in srgb, var(--hint) 20%, transparent);
  display: flex;
  backdrop-filter: blur(20px);
  z-index: 100;
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 3px; border: none; background: none;
  color: var(--hint); cursor: pointer;
  font-size: 10px; font-weight: 500;
  transition: color .2s;
  padding: 8px 0;
}
.nav-btn svg { width: 22px; height: 22px; fill: currentColor; transition: transform .2s; }
.nav-btn.active { color: var(--accent); }
.nav-btn.active svg { transform: scale(1.15); }

/* ── Page header ─────────────────────────────────────────── */
.page-header {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 16px 8px;
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
}
.page-title { font-size: 22px; font-weight: 800; flex: 1; }
.btn-icon {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--bg2); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text); font-size: 18px;
}

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--bg2);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin: 0 12px 10px;
}
.card-section { padding: 0 12px; }
.section-title {
  font-size: 13px; font-weight: 600; color: var(--hint);
  text-transform: uppercase; letter-spacing: .05em;
  padding: 8px 0 8px 4px;
}

/* ── Stats grid ──────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 4px 12px 12px;
}
.stat-card {
  background: var(--bg2);
  border-radius: var(--radius-md);
  padding: 12px 10px;
  text-align: center;
  cursor: pointer;
  transition: transform .15s, opacity .15s;
}
.stat-card:active { transform: scale(.96); opacity: .85; }
.stat-num {
  font-size: 28px; font-weight: 800;
  line-height: 1.1;
}
.stat-lbl {
  font-size: 11px; color: var(--hint);
  margin-top: 2px;
}

/* ── Task card ───────────────────────────────────────────── */
.task-card {
  cursor: pointer;
  transition: transform .15s, opacity .15s;
}
.task-card:active { transform: scale(.985); opacity: .88; }
.task-header {
  display: flex; align-items: flex-start;
  justify-content: space-between; gap: 8px;
  margin-bottom: 8px;
}
.task-id    { font-size: 12px; color: var(--hint); font-weight: 600; }
.task-title { font-size: 15px; font-weight: 700; flex: 1; }
.task-meta  { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.task-deadline {
  font-size: 12px; color: var(--hint);
  display: flex; align-items: center; gap: 4px;
}
.task-deadline.overdue { color: var(--blocked-c); font-weight: 600; }
.task-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }

/* ── Badges ──────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 9px; border-radius: 20px;
  font-size: 11px; font-weight: 700;
  white-space: nowrap; letter-spacing: .02em;
}
.badge-NEW      { background: var(--new-bg);     color: var(--new-c); }
.badge-IN_WORK  { background: var(--inwork-bg);  color: var(--inwork-c); }
.badge-DONE     { background: var(--done-bg);    color: var(--done-c); }
.badge-BLOCKED  { background: var(--blocked-bg); color: var(--blocked-c); }
.badge-RISK     { background: var(--risk-bg);    color: var(--risk-c); }
.badge-OVERDUE  { background: var(--overdue-bg); color: var(--overdue-c); }

.priority-LOW      { color: var(--low-c); }
.priority-NORMAL   { color: var(--normal-c); }
.priority-HIGH     { color: var(--high-c); font-weight: 700; }
.priority-CRITICAL { color: var(--critical-c); font-weight: 700; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: none; cursor: pointer;
  font-size: 13px; font-weight: 600;
  transition: opacity .15s, transform .1s;
  white-space: nowrap;
}
.btn:active { opacity: .75; transform: scale(.97); }
.btn-primary   { background: var(--accent); color: var(--accent-txt); }
.btn-secondary { background: var(--bg2); color: var(--text); }
.btn-danger    { background: var(--blocked-bg); color: var(--blocked-c); }
.btn-success   { background: var(--inwork-bg); color: var(--inwork-c); }
.btn-full      { width: 100%; justify-content: center; text-align: center; display: block; }
.btn-sm        { padding: 6px 12px; font-size: 12px; }

/* ── Quick actions (home screen) ─────────────────────────── */
.quick-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 4px 12px 16px;
}
.quick-btn {
  background: var(--bg2);
  border: none; border-radius: var(--radius-md);
  padding: 14px 8px 10px;
  display: flex; flex-direction: column;
  align-items: center; gap: 6px;
  cursor: pointer;
  font-size: 12px; font-weight: 600; color: var(--text);
  transition: transform .15s, opacity .15s;
}
.quick-btn:active { transform: scale(.94); opacity: .82; }
.quick-btn .icon  { font-size: 22px; line-height: 1; }

/* ── Greeting header ─────────────────────────────────────── */
.greeting {
  padding: 20px 16px 8px;
  display: flex; align-items: center; gap: 14px;
}
.greeting-avatar {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--accent);
  color: var(--accent-txt);
  font-size: 20px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.greeting-name { font-size: 18px; font-weight: 800; }
.greeting-role { font-size: 12px; color: var(--hint); margin-top: 2px; }

/* ── Filters ─────────────────────────────────────────────── */
.filters {
  display: flex; gap: 8px; overflow-x: auto; padding: 0 12px 12px;
  scrollbar-width: none; -ms-overflow-style: none;
}
.filters::-webkit-scrollbar { display: none; }
.filter-chip {
  flex-shrink: 0; padding: 6px 14px;
  border-radius: 20px; border: 1.5px solid color-mix(in srgb, var(--hint) 30%, transparent);
  background: none; cursor: pointer;
  font-size: 13px; font-weight: 500; color: var(--hint);
  transition: all .2s;
}
.filter-chip.active {
  background: var(--accent); color: var(--accent-txt);
  border-color: var(--accent);
}

/* ── Photo grid ──────────────────────────────────────────── */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  padding: 0 12px 16px;
}
.photo-card {
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  transition: transform .15s;
  background: var(--bg2);
}
.photo-card:active { transform: scale(.96); }
.photo-img {
  width: 100%; aspect-ratio: 1/1;
  object-fit: cover; display: block;
}
.photo-meta {
  padding: 8px;
  font-size: 11px; color: var(--hint);
}
.photo-task { font-weight: 700; color: var(--text); margin-bottom: 2px; }

/* ── Attachment extras ───────────────────────────────────── */
.att-placeholder {
  display: flex; align-items: center; justify-content: center;
  background: var(--bg2); font-size: 36px;
  aspect-ratio: 1/1; width: 100%;
}
.photo-card { position: relative; }
.att-play-icon {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: rgba(0,0,0,.55); color: #fff;
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; pointer-events: none;
}

/* ── Action sheet ────────────────────────────────────────── */
.action-sheet-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 200;
  backdrop-filter: blur(2px);
}
.action-sheet {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: var(--bg);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  z-index: 201; padding: 12px 0 calc(16px + var(--safe-bot));
  transform: translateY(100%);
  transition: transform .25s cubic-bezier(.32,.72,0,1);
  max-height: 80vh; overflow-y: auto;
}
.action-sheet.open { transform: translateY(0); }
.action-sheet-handle {
  width: 36px; height: 4px;
  background: color-mix(in srgb, var(--hint) 35%, transparent);
  border-radius: 2px; margin: 0 auto 12px;
}
.action-sheet-title {
  padding: 4px 20px 12px;
  font-size: 13px; color: var(--hint); font-weight: 500;
}
.action-item {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 20px;
  cursor: pointer; border: none; background: none;
  width: 100%; text-align: left;
  font-size: 16px; color: var(--text);
  transition: background .15s;
}
.action-item:active { background: var(--bg2); }
.action-item .action-icon { font-size: 20px; width: 28px; text-align: center; }
.action-item.danger { color: var(--blocked-c); }
.action-item.success { color: var(--inwork-c); }
.action-divider { height: 1px; background: var(--bg2); margin: 4px 0; }

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end;
  z-index: 300;
  backdrop-filter: blur(3px);
}
.modal {
  background: var(--bg);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 20px 20px calc(24px + var(--safe-bot));
  width: 100%; max-height: 80vh; overflow-y: auto;
}
.modal-title {
  font-size: 18px; font-weight: 700;
  margin-bottom: 16px;
}
.form-group { margin-bottom: 14px; }
.form-label {
  font-size: 13px; color: var(--hint);
  margin-bottom: 6px; display: block; font-weight: 600;
}
.form-input, .form-textarea, .form-select {
  width: 100%; padding: 11px 14px;
  border: 1.5px solid color-mix(in srgb, var(--hint) 25%, transparent);
  border-radius: var(--radius-sm);
  background: var(--bg2); color: var(--text);
  font-size: 15px; font-family: inherit;
  outline: none; transition: border-color .2s;
}
.form-input:focus, .form-textarea:focus, .form-select:focus {
  border-color: var(--accent);
}
.form-textarea { resize: vertical; min-height: 80px; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; }
.form-actions .btn { flex: 1; }

/* ── Toast ───────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + var(--safe-bot) + 12px);
  left: 50%; transform: translateX(-50%);
  background: #1e293b; color: #fff;
  padding: 10px 20px; border-radius: 24px;
  font-size: 14px; font-weight: 500;
  z-index: 500; white-space: nowrap;
  box-shadow: 0 4px 20px rgba(0,0,0,.3);
  animation: toast-in .2s ease;
}
.toast.success { background: var(--inwork-c); }
.toast.error   { background: var(--blocked-c); }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Loading ─────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--bg2) 25%, color-mix(in srgb,var(--hint) 15%,var(--bg2)) 50%, var(--bg2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { to { background-position: -200% 0; } }

.skeleton-card {
  height: 90px; margin: 0 12px 10px;
  border-radius: var(--radius-md);
}
.skeleton-text { height: 14px; margin: 8px 0; }

.loading-center {
  display: flex; align-items: center; justify-content: center;
  padding: 60px 0; flex-direction: column; gap: 12px;
  color: var(--hint); font-size: 14px;
}
.spinner {
  width: 32px; height: 32px; border: 3px solid var(--bg2);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty state ─────────────────────────────────────────── */
.empty {
  padding: 60px 24px; text-align: center;
  color: var(--hint);
}
.empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-title { font-size: 16px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.empty-sub   { font-size: 14px; }

/* ── Task detail ─────────────────────────────────────────── */
.detail-field {
  display: flex; flex-direction: column; gap: 2px;
  padding: 10px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--hint) 15%, transparent);
}
.detail-field:last-child { border-bottom: none; }
.detail-label { font-size: 12px; color: var(--hint); font-weight: 600; }
.detail-value { font-size: 15px; color: var(--text); }

/* ── Admin section ───────────────────────────────────────── */
.user-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid color-mix(in srgb, var(--hint) 12%, transparent);
}
.user-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--accent); color: var(--accent-txt);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700; flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 14px; font-weight: 600; }
.user-meta { font-size: 12px; color: var(--hint); }

/* ── Identity card ───────────────────────────────────────── */
.identity-card { display: flex; align-items: center; gap: 12px; }
.identity-code {
  font-size: 14px; font-weight: 800;
  font-family: monospace;
  background: var(--bg); padding: 4px 10px; border-radius: 8px;
}
.identity-holder { font-size: 13px; color: var(--hint); }
.identity-free { color: var(--inwork-c); font-size: 13px; font-weight: 600; }

/* ── Success screen ──────────────────────────────────────── */
.success-screen {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 60px 32px; gap: 16px; text-align: center;
}
.success-icon { font-size: 64px; }
.success-title { font-size: 22px; font-weight: 800; }
.success-sub   { font-size: 15px; color: var(--hint); }

/* ── Admin tab filters ───────────────────────────────────── */
.tab-bar {
  display: flex; border-bottom: 1.5px solid color-mix(in srgb, var(--hint) 15%, transparent);
  padding: 0 12px; gap: 0; overflow-x: auto;
  scrollbar-width: none;
}
.tab-bar::-webkit-scrollbar { display: none; }
.tab-btn {
  flex-shrink: 0; padding: 10px 14px;
  border: none; background: none; cursor: pointer;
  font-size: 13px; font-weight: 600; color: var(--hint);
  border-bottom: 2.5px solid transparent; margin-bottom: -1.5px;
  transition: color .2s, border-color .2s;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Access Requests ─────────────────────────────────────── */
.req-card { margin-bottom: 10px; }
.req-header {
  display: flex; align-items: flex-start; gap: 12px;
}
.req-avatar {
  width: 40px; height: 40px; flex-shrink: 0;
  border-radius: 50%; background: var(--accent);
  color: var(--accent-txt); font-weight: 700; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
}
.req-info { flex: 1; min-width: 0; }
.req-name   { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.req-handle { font-size: 12px; color: var(--link); }
.req-meta   { font-size: 11px; color: var(--hint); margin-top: 2px; }
.req-comment { font-size: 12px; color: var(--hint); margin-top: 8px; padding-top: 8px; border-top: 1px solid color-mix(in srgb, var(--hint) 15%, transparent); }
.req-actions { display: flex; gap: 8px; margin-top: 12px; }
.req-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  background: var(--blocked-c); color: #fff;
  border-radius: 9px; font-size: 11px; font-weight: 700;
  margin-left: 4px; vertical-align: middle;
}

/* ── Scope toggle (My / All tasks) ──────────────────────────── */
.scope-tabs {
  display: flex; gap: 6px; padding: 0 12px 12px;
}
.scope-tab {
  flex: 1; padding: 7px 12px;
  border-radius: 20px;
  border: 1.5px solid color-mix(in srgb, var(--hint) 30%, transparent);
  background: none; cursor: pointer;
  font-size: 13px; font-weight: 600; color: var(--hint);
  text-align: center; transition: all .2s;
}
.scope-tab.active {
  background: var(--accent); color: var(--accent-txt);
  border-color: var(--accent);
}

/* ── Notification card ───────────────────────────────────────── */
.notif-card {
  margin: 0 12px 12px;
  background: var(--risk-bg); color: var(--risk-c);
  border-radius: var(--radius-md); padding: 12px 16px;
  display: flex; align-items: center; gap: 12px;
  cursor: pointer; font-size: 14px; font-weight: 600;
  transition: opacity .15s;
}
.notif-card:active { opacity: .8; }
.notif-count {
  min-width: 28px; height: 28px; border-radius: 50%;
  background: var(--risk-c); color: #fff;
  font-size: 14px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* ── VPN request card ────────────────────────────────────────── */
.vpn-card { margin-bottom: 10px; }
.vpn-header {
  display: flex; align-items: flex-start;
  justify-content: space-between; gap: 8px; margin-bottom: 8px;
}
.vpn-device { font-size: 15px; font-weight: 700; }
.vpn-meta   { font-size: 12px; color: var(--hint); margin-top: 4px; }
.vpn-actions { display: flex; gap: 8px; margin-top: 10px; }

/* ── Help section ────────────────────────────────────────────── */
.help-category { margin-bottom: 8px; }
.help-category-title {
  font-size: 13px; font-weight: 700; color: var(--accent);
  text-transform: uppercase; letter-spacing: .05em;
  padding: 6px 0 4px;
}
.help-faq { margin-bottom: 6px; }
.help-q {
  font-size: 14px; font-weight: 600; cursor: pointer;
  padding: 10px 14px; background: var(--bg2);
  border-radius: var(--radius-sm);
  display: flex; justify-content: space-between; align-items: center;
  border: none; width: 100%; text-align: left; color: var(--text);
}
.help-q .chevron { font-size: 12px; color: var(--hint); transition: transform .2s; }
.help-q.open .chevron { transform: rotate(180deg); }
.help-a {
  font-size: 13px; color: var(--hint); line-height: 1.6;
  padding: 8px 14px 10px; background: var(--bg2);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  margin-top: -4px; display: none;
}
.help-a.open { display: block; }

/* ── Code card ───────────────────────────────────────────────── */
.code-card {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--hint) 12%, transparent);
}
.code-card:last-child { border-bottom: none; }
.code-label {
  font-family: monospace; font-size: 14px; font-weight: 800;
  background: var(--bg); padding: 3px 8px; border-radius: 6px;
  flex-shrink: 0;
}
.code-desc { flex: 1; min-width: 0; }
.code-title { font-size: 13px; font-weight: 600; }
.code-holder { font-size: 11px; color: var(--hint); }
.code-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── User inactive state ─────────────────────────────────────── */
.user-row.inactive { opacity: .55; }
.user-row.inactive .user-avatar { background: var(--hint); }
