*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--admin-bg);
  color: var(--admin-ink);
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  color-scheme: dark;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: clip;
  -webkit-tap-highlight-color: transparent;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }

/* Split-screen Login (Matches FEMUTSU Control Room) */
.login-split {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 46%) 1fr;
}
.login-art {
  background: var(--admin-accent);
  color: var(--brand-accent-ink);
  padding: 36px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}
.login-art-top {
  display: flex;
  justify-content: space-between;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.login-monogram {
  font-size: clamp(92px, 12vw, 156px);
  font-weight: 900;
  letter-spacing: -0.04em;
  transform: rotate(-8deg);
  line-height: 1;
  user-select: none;
}
.login-art-foot { font-size: 26px; font-weight: 800; line-height: 1.2; }

.login-pane {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  background: var(--admin-bg);
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--admin-panel);
  border: 1px solid var(--admin-line);
  border-radius: 20px;
  padding: 28px;
}

/* App Shell */
.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
}
.sidebar {
  background: var(--admin-sidebar);
  border-right: 1px solid var(--admin-line);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sb-brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px; }
.sb-logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--admin-accent);
  color: var(--brand-accent-ink);
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 20px;
  flex-shrink: 0;
}
.sb-title { font-weight: 800; letter-spacing: 0.04em; font-size: 15px; }
.sb-sub { color: var(--admin-muted); font-size: 11.5px; }

.sb-label {
  color: var(--admin-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0 10px;
}
.sb-nav { display: flex; flex-direction: column; gap: 4px; }
.sb-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  color: var(--admin-muted);
  font-weight: 600;
  transition: background 0.15s ease, color 0.15s ease;
}
.sb-link:hover { background: var(--admin-panel); color: var(--admin-ink); }
.sb-link.active { background: var(--admin-accent-dark); color: var(--admin-accent); }

.sb-foot {
  margin-top: auto;
  border-top: 1px solid var(--admin-line);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 12.5px;
  color: var(--admin-muted);
}
.api-dot { display: inline-block; width: 8px; height: 8px; border-radius: 99px; background: var(--admin-green); margin-right: 6px; }

/* Main column */
.main-col { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 64px;
  border-bottom: 1px solid var(--admin-line);
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--admin-bg);
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar-right { display: flex; align-items: center; gap: 12px; }
.role-badge {
  border: 1px solid var(--admin-line);
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--admin-muted);
}
.lang-switch {
  display: inline-flex;
  background: var(--admin-panel);
  border: 1px solid var(--admin-line);
  border-radius: 9px;
  padding: 2px;
  gap: 2px;
}
.lang-btn {
  border: none;
  background: transparent;
  color: var(--admin-muted);
  font-size: 11px;
  font-weight: 700;
  padding: 4px 7px;
  border-radius: 6px;
  cursor: pointer;
}
.lang-btn.active { background: var(--admin-accent); color: var(--brand-accent-ink); }

.content { padding: 28px; max-width: 1320px; width: 100%; }
.eyebrow {
  color: var(--admin-accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.page-head h1 { margin: 0; font-size: 28px; font-weight: 800; }
.page-sub { color: var(--admin-muted); margin: 4px 0 0; }

/* Cards & Grids */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}
.card {
  background: var(--admin-panel);
  border: 1px solid var(--admin-line);
  border-radius: var(--admin-radius);
  padding: 20px;
}
.kpi-val { font-size: 32px; font-weight: 800; margin: 10px 0 4px; }
.kpi-meta { color: var(--admin-muted); font-size: 12.5px; }

.two-col { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr); gap: 18px; align-items: start; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }

/* Tabs */
.tabs { display: flex; flex-wrap: wrap; gap: 18px; border-bottom: 1px solid var(--admin-line); margin-bottom: 20px; }
.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 2px;
  color: var(--admin-muted);
  font-weight: 600;
  cursor: pointer;
}
.tab-btn:hover { color: var(--admin-ink); }
.tab-btn.active { color: var(--admin-ink); border-bottom-color: var(--admin-accent); }

.pill-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.pill {
  border: 1px solid var(--admin-line);
  background: var(--admin-panel);
  color: var(--admin-muted);
  padding: 6px 12px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.pill.active { background: var(--admin-accent-dark); color: var(--admin-accent); border-color: var(--brand-accent-border); }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 8px;
  font-size: 11.5px;
  font-weight: 700;
  border: 1px solid var(--admin-line);
  background: var(--admin-panel2);
}
.badge-green { color: var(--admin-green); border-color: color-mix(in srgb, var(--admin-green) 35%, transparent); background: color-mix(in srgb, var(--admin-green) 12%, transparent); }
.badge-yellow { color: var(--admin-yellow); border-color: color-mix(in srgb, var(--admin-yellow) 35%, transparent); background: color-mix(in srgb, var(--admin-yellow) 12%, transparent); }
.badge-red { color: var(--admin-red); border-color: color-mix(in srgb, var(--admin-red) 35%, transparent); background: color-mix(in srgb, var(--admin-red) 12%, transparent); }

/* Buttons & Forms */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 38px;
  padding: 0 15px;
  border-radius: 10px;
  border: 1px solid var(--admin-line);
  background: var(--admin-panel2);
  color: var(--admin-ink);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { border-color: var(--brand-accent-border); }
.btn-primary { background: var(--admin-accent); color: var(--brand-accent-ink); border-color: transparent; font-weight: 700; }
.btn-primary:hover { background: var(--brand-accent-hover); }
.btn-danger { color: var(--admin-red); border-color: color-mix(in srgb, var(--admin-red) 40%, transparent); }
.btn-sm { height: 32px; padding: 0 11px; font-size: 12px; border-radius: 8px; }
.btn-block { width: 100%; }

.provider-yandex { background: #fc3f1d; border-color: transparent; color: #fff; }
.provider-telegram { background: #2aabee; border-color: transparent; color: #fff; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; font-weight: 600; color: var(--admin-muted); }
.input, .select, .textarea {
  width: 100%;
  background: var(--admin-bg);
  border: 1px solid var(--admin-line);
  border-radius: 10px;
  padding: 9px 12px;
  outline: none;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--admin-accent); }
.textarea { min-height: 96px; resize: vertical; }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--admin-line); vertical-align: middle; }
th { color: var(--admin-muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }

.row-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px;
  border-radius: 12px;
  background: var(--admin-panel2);
  border: 1px solid var(--admin-line);
}
.thumb-sm {
  width: 44px;
  height: 58px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--admin-bg);
  flex-shrink: 0;
}

.progress-bar { height: 6px; border-radius: 99px; background: var(--admin-bg); overflow: hidden; margin-top: 8px; }
.progress-bar > div { height: 100%; background: var(--admin-accent); transition: width 0.15s ease; }

/* Modal & Toast */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.72);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-root.open { display: flex; }
.modal-card {
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--admin-panel);
  border: 1px solid var(--admin-line);
  border-radius: 18px;
  padding: 24px;
}
.toast-root { position: fixed; bottom: 20px; right: 20px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--admin-panel);
  border: 1px solid var(--admin-accent);
  padding: 11px 16px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 13px;
}
.toast.error { border-color: var(--admin-red); color: var(--admin-red); }

.sb-hamburger,
.sb-close-btn { display: none; }
.sidebar-backdrop { display: none; }

.marker-form-grid {
  display: grid;
  grid-template-columns: 80px minmax(0, 1fr) minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
}

#admin-google-slot,
#admin-tg-slot {
  max-width: 100%;
  overflow: hidden;
  display: flex;
  justify-content: center;
}

@media (min-width: 1600px) {
  .content { max-width: 1480px; }
}

@media (max-width: 1024px) {
  .shell { grid-template-columns: 1fr; }
  .sb-hamburger,
  .sb-close-btn { display: inline-flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 268px;
    height: 100dvh;
    z-index: 130;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 120;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
  }
  .sidebar-backdrop.open { display: block; }

  .two-col { grid-template-columns: 1fr; }
  .login-split { grid-template-columns: 1fr; }
  .login-art { min-height: 190px; padding: 24px; }
  .login-monogram { font-size: 76px; }
  .login-art-foot { font-size: 20px; }
}

@media (max-width: 768px) {
  .topbar {
    height: 56px;
    padding: 0 14px;
    padding-top: env(safe-area-inset-top, 0px);
  }
  .content { padding: 18px 14px calc(32px + env(safe-area-inset-bottom, 0px)); }
  .hide-sm { display: none; }
  .page-head h1 { font-size: 22px; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .kpi-val { font-size: 26px; }
  .grid-2 { grid-template-columns: 1fr; gap: 12px; }

  /* Prevent iOS Safari input zoom */
  .input, .select, .textarea { font-size: 16px; }

  /* Scrollable tabs on mobile */
  .tabs,
  .pill-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    white-space: nowrap;
  }
  .tabs::-webkit-scrollbar,
  .pill-tabs::-webkit-scrollbar { display: none; }
  .tab-btn, .pill { flex-shrink: 0; }
}

@media (max-width: 560px) {
  .hide-xs { display: none; }
  .card { padding: 15px; border-radius: 14px; }
  .login-pane { padding: 18px 14px; }
  .login-card { padding: 20px 16px; }
  .row-item { flex-wrap: wrap; gap: 10px; }

  .marker-form-grid {
    grid-template-columns: 1fr 1fr;
  }
  .marker-form-grid > strong {
    grid-column: 1 / -1;
  }

  .modal-root { align-items: flex-end; padding: 0; }
  .modal-card {
    max-width: 100%;
    max-height: 92dvh;
    border-radius: 20px 20px 0 0;
    border-bottom: 0;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  }

  .toast-root { left: 14px; right: 14px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
}

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