:root {
  color-scheme: light;
  font-family: Arial, Helvetica, sans-serif;
  --ink: #111111;
  --muted: #68686f;
  --line: #dddddf;
  --surface: #ffffff;
  --canvas: #f2f2f0;
  --soft: #f7f7f5;
  --accent: #16162a;
  --accent-soft: #e8e8f0;
  --danger: #9a2c2c;
  --success: #27643c;
  --card-radius: 22px;
  --control-radius: 13px;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--canvas); }

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

.auth-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
  background: var(--accent);
}

.auth-card {
  width: min(100%, 560px);
  min-height: min(620px, calc(100dvh - 48px));
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: clamp(28px, 7vw, 52px);
  border-radius: 34px;
  background: var(--surface);
}

.brand { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -.02em; }
.brand-light { color: #ffffff; }
.auth-copy { margin: auto 0; }
.kicker {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}

h1, h2, h3, p { overflow-wrap: anywhere; }
h1 {
  max-width: 11ch;
  margin: 0 0 18px;
  font-size: clamp(36px, 10vw, 64px);
  line-height: .98;
  letter-spacing: -.055em;
}
h2 { margin: 0; font-size: clamp(30px, 7vw, 48px); line-height: 1; letter-spacing: -.045em; }
h3 { margin: 0; font-size: 20px; letter-spacing: -.025em; }
.muted { color: var(--muted); }

.progress-track { height: 3px; overflow: hidden; background: var(--line); border-radius: 99px; }
.progress-track span {
  display: block;
  width: 40%;
  height: 100%;
  background: var(--accent);
  animation: progress 1.4s ease-in-out infinite alternate;
}
@keyframes progress { to { transform: translateX(150%); } }

.app-shell { min-height: 100dvh; }
.app-header {
  min-height: 170px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: max(28px, env(safe-area-inset-top)) clamp(20px, 5vw, 64px) 38px;
  background: var(--accent);
  color: #ffffff;
}
.header-note { max-width: 28ch; margin: 18px 0 0; color: #c9c9d1; line-height: 1.45; }

.tabs {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 12px clamp(14px, 4vw, 56px);
  border-bottom: 1px solid var(--line);
  background: rgba(242, 242, 240, .96);
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  min-height: 44px;
  flex: 0 0 auto;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}
.tab:hover { border-color: var(--line); color: var(--ink); }
.tab.is-active { background: var(--accent); color: #ffffff; }

.workspace { width: min(100%, 1180px); margin: 0 auto; padding: 42px clamp(16px, 4vw, 48px) 100px; }
.view { animation: enter .24s ease-out; }
@keyframes enter { from { opacity: 0; transform: translateY(5px); } }
.section-heading {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(220px, .8fr);
  align-items: end;
  gap: 32px;
  margin-bottom: 30px;
}
.section-copy { max-width: 38ch; margin: 0; color: var(--muted); line-height: 1.5; }

.button {
  min-height: 44px;
  padding: 0 17px;
  border: 1px solid var(--line);
  border-radius: var(--control-radius);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-weight: 700;
  transition: transform .15s ease, background-color .15s ease, border-color .15s ease;
}
.button:hover { border-color: #b7b7ba; background: var(--soft); }
.button:active { transform: scale(.98); }
.button:focus-visible, .tab:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(22, 22, 42, .22);
  outline-offset: 2px;
}
.button-primary { border-color: var(--accent); background: var(--accent); color: #ffffff; }
.button-primary:hover { border-color: #30304a; background: #30304a; }
.button-light { border-color: #46465b; background: #ffffff; color: var(--accent); }
.button-danger { color: var(--danger); }
.button-small { min-height: 38px; padding: 0 13px; font-size: 14px; }
button:disabled { cursor: wait; opacity: .55; }

.notice {
  margin: 0 0 24px;
  padding: 15px 17px;
  border: 1px solid var(--line);
  border-radius: var(--control-radius);
  background: var(--surface);
  line-height: 1.45;
}
.notice.is-error { border-color: #dcb7b7; color: var(--danger); }
.notice.is-success { border-color: #b5d3bf; color: var(--success); }

.loading-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.loading-grid span {
  min-height: 150px;
  border-radius: var(--card-radius);
  background: #e6e6e3;
  animation: skeleton 1.1s ease-in-out infinite alternate;
}
@keyframes skeleton { to { opacity: .45; } }

.overview-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 14px; }
.metric-card {
  grid-column: span 4;
  min-height: 170px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--card-radius);
  background: var(--surface);
}
.metric-card.is-wide { grid-column: span 8; }
.metric-card.is-accent { border-color: var(--accent); background: var(--accent); color: #ffffff; }
.metric-label { margin: 0; color: var(--muted); font-size: 14px; font-weight: 700; }
.is-accent .metric-label { color: #c9c9d1; }
.metric-value { margin: 28px 0 0; font-size: clamp(34px, 7vw, 58px); font-weight: 700; letter-spacing: -.05em; }
.metric-detail { margin: 8px 0 0; color: var(--muted); line-height: 1.4; }
.is-accent .metric-detail { color: #c9c9d1; }

.action-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 12px;
  margin-bottom: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--card-radius);
  background: var(--surface);
}
.action-form-wide { grid-template-columns: .7fr 1.3fr auto; }
label, .field-label { display: grid; gap: 8px; margin: 0; color: var(--muted); font-size: 13px; font-weight: 700; }
input, select, textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid #c7c7ca;
  border-radius: var(--control-radius);
  background: #ffffff;
  color: var(--ink);
}
input, select { padding: 0 13px; }
textarea { padding: 15px; resize: vertical; }
input::placeholder, textarea::placeholder { color: #929297; }

.stack { display: grid; gap: 12px; }
.entity-card {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--card-radius);
  background: var(--surface);
}
.entity-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.entity-id { margin: 0; font-size: 21px; font-weight: 700; letter-spacing: -.025em; }
.entity-meta { margin: 7px 0 0; color: var(--muted); font-size: 14px; line-height: 1.4; }
.status { padding: 7px 10px; border-radius: 999px; background: var(--soft); font-size: 12px; font-weight: 700; }
.status.active { color: var(--success); }
.status.blocked { color: var(--danger); }
.entity-body { display: grid; gap: 15px; margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.control-row { display: flex; flex-wrap: wrap; align-items: end; gap: 8px; }
.control-row label { min-width: min(100%, 220px); flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--soft);
  font-size: 13px;
}
.chip button { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-weight: 700; }

.catalog-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.catalog-item { padding: 20px; border: 1px solid var(--line); border-radius: var(--card-radius); background: var(--surface); }
.catalog-key { margin: 0; font-family: ui-monospace, Consolas, monospace; font-weight: 700; }
.catalog-description { margin: 14px 0 0; color: var(--muted); line-height: 1.45; }

.feature-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 20px; border: 1px solid var(--line); border-radius: var(--card-radius); background: var(--surface); }
.feature-key { margin: 0; font-family: ui-monospace, Consolas, monospace; font-weight: 700; }
.feature-state { margin: 7px 0 0; color: var(--muted); font-size: 14px; }
.switch { position: relative; width: 54px; height: 32px; flex: 0 0 auto; padding: 0; border: 0; border-radius: 999px; background: #c9c9cc; cursor: pointer; }
.switch::after { content: ""; position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; border-radius: 50%; background: #ffffff; transition: transform .18s ease; }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(22px); }

.audit-list { overflow: hidden; border: 1px solid var(--line); border-radius: var(--card-radius); background: var(--surface); }
.audit-row { display: grid; grid-template-columns: 150px minmax(0, 1fr) minmax(0, 1fr); gap: 18px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.audit-row:last-child { border-bottom: 0; }
.audit-time { color: var(--muted); font-size: 13px; }
.audit-action, .audit-target { margin: 0; font-family: ui-monospace, Consolas, monospace; font-size: 13px; overflow-wrap: anywhere; }

.markdown-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.editor-card, .preview-card { min-height: 430px; padding: 20px; border: 1px solid var(--line); border-radius: var(--card-radius); background: var(--surface); }
.editor-card { display: flex; flex-direction: column; }
.editor-card label { flex: 1; }
#markdown-source { min-height: 320px; flex: 1; font-family: ui-monospace, Consolas, monospace; line-height: 1.5; }
.editor-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; color: var(--muted); font-size: 13px; }
.telegram-preview { margin-top: 18px; white-space: pre-wrap; line-height: 1.45; overflow-wrap: anywhere; }
.telegram-preview pre { overflow-x: auto; padding: 12px; border-radius: 10px; background: var(--soft); }
.telegram-preview code { font-family: ui-monospace, Consolas, monospace; }
.telegram-preview blockquote { margin: 12px 0; padding-left: 13px; border-left: 3px solid var(--accent); }
.preview-message + .preview-message { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }

.empty { padding: 32px 20px; border: 1px dashed #c5c5c8; border-radius: var(--card-radius); color: var(--muted); text-align: center; }

@media (max-width: 760px) {
  .app-header { min-height: 150px; padding-bottom: 30px; }
  .header-note { display: none; }
  .workspace { padding-top: 32px; }
  .section-heading { grid-template-columns: 1fr; gap: 14px; }
  .overview-grid { grid-template-columns: 1fr 1fr; }
  .metric-card, .metric-card.is-wide { grid-column: span 1; }
  .metric-card.is-wide { grid-column: span 2; }
  .action-form, .action-form-wide { grid-template-columns: 1fr; }
  .catalog-grid, .markdown-layout { grid-template-columns: 1fr; }
  .audit-row { grid-template-columns: 1fr; gap: 6px; }
}

@media (max-width: 430px) {
  .app-header { padding-inline: 18px; }
  .button-light { padding-inline: 13px; }
  .overview-grid { grid-template-columns: 1fr; }
  .metric-card, .metric-card.is-wide { grid-column: 1; }
  .entity-head { align-items: flex-start; }
  .control-row > .button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
