* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: #f0ede6;
  color: #2b2b2b;
}

header {
  background: linear-gradient(135deg, #2c3e66, #40599c);
  color: #fff;
  padding: 1.2rem 2rem;
}
header h1 { margin: 0; font-size: 1.6rem; }
header p { margin: .2rem 0 0; opacity: .85; }

main {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 1rem;
  max-width: 1200px;
  margin: 1.2rem auto;
  padding: 0 1rem;
  align-items: start;
}

.panel {
  background: #fff;
  border-radius: 10px;
  padding: 1rem 1.2rem;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
}
.panel h2 { margin-top: 0; font-size: 1.05rem; color: #40599c; }

textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: .6rem;
  font-size: .95rem;
}

.dropzone {
  margin-top: .8rem;
  border: 2px dashed #a8b6d8;
  border-radius: 8px;
  padding: .8rem;
  text-align: center;
  transition: background .15s;
}
.dropzone.dragover { background: #eef2fb; border-color: #40599c; }
.file-label { color: #40599c; text-decoration: underline; cursor: pointer; }
.hint { font-size: .8rem; color: #888; margin: .3rem 0 0; }
.file-name { font-weight: 600; color: #2c3e66; margin: .3rem 0 0; }

.settings-panel label {
  display: block;
  margin-bottom: .8rem;
  font-size: .9rem;
}
.settings-panel select,
.settings-panel input[type=range] {
  width: 100%;
  margin-top: .25rem;
}
.settings-panel select {
  padding: .4rem;
  border: 1px solid #ccc;
  border-radius: 6px;
}

.models-panel .model-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .45rem 0;
  border-bottom: 1px solid #eee;
}
.models-panel .model-item:last-child { border-bottom: none; }
.models-panel .model-meta { font-size: .78rem; color: #888; }
.models-panel code { font-size: .75rem; }

.connection-panel label {
  display: block;
  margin-bottom: .7rem;
  font-size: .9rem;
}
.connection-panel input[type=text],
.connection-panel input[type=password] {
  width: 100%;
  margin-top: .25rem;
  padding: .4rem;
  border: 1px solid #ccc;
  border-radius: 6px;
}
.secondary {
  width: 100%;
  padding: .55rem;
  background: #fff;
  color: #40599c;
  border: 1px solid #40599c;
  border-radius: 8px;
  cursor: pointer;
}
.secondary:hover { background: #eef2fb; }

.primary {
  display: inline-block;
  width: 100%;
  padding: .7rem;
  background: #40599c;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
}
.primary:hover { background: #2c3e66; }
.primary:disabled { background: #9aa7cc; cursor: wait; }

.error { color: #c0392b; font-size: .9rem; min-height: 1.2em; }

.result-panel { grid-column: 1 / -1; }
.preview-wrap {
  margin-top: .8rem;
  text-align: center;
}
.preview-pager {
  position: relative;
  display: inline-block;
  max-width: 100%;
}
.preview-pager img {
  display: block;
  max-width: 100%;
  border: 1px solid #ccc;
  border-radius: 6px;
  box-shadow: 0 3px 12px rgba(0,0,0,.15);
}
/* левая/правая половины листа — зоны клика для листания */
.pager-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  display: flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
}
.pager-zone.left { left: 0; justify-content: flex-start; cursor: w-resize; }
.pager-zone.right { right: 0; justify-content: flex-end; cursor: e-resize; }
.pager-zone span {
  margin: 0 .6rem;
  width: 2.6rem;
  height: 2.6rem;
  line-height: 2.4rem;
  border-radius: 50%;
  background: rgba(30, 40, 80, .55);
  color: #fff;
  font-size: 2rem;
  text-align: center;
  opacity: 0;
  transition: opacity .15s;
}
.pager-zone:hover span { opacity: 1; }
.pager-zone.disabled { cursor: default; }
.pager-zone.disabled span { display: none; }
.page-counter {
  margin: .5rem 0 0;
  color: #555;
  font-size: .95rem;
}

.spinner {
  width: 36px; height: 36px;
  border: 4px solid #d5dcef;
  border-top-color: #40599c;
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: .5rem auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 800px) {
  main { grid-template-columns: 1fr; }
}

/* ===== общий каркас (кабинеты, админка) ===== */
.topbar {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  flex-wrap: wrap;
}
.topbar .brand { color: #fff; text-decoration: none; }
.topbar .brand h1 { margin: 0; font-size: 1.4rem; }
.topbar .brand p { margin: .1rem 0 0; font-size: .85rem; opacity: .85; }
.topbar nav { display: flex; gap: .3rem; flex-wrap: wrap; margin-left: auto; align-items: center; }
.topbar nav a, .topbar nav button.linklike {
  color: #fff; text-decoration: none; padding: .35rem .7rem; border-radius: 6px;
  font-size: .92rem; background: none; border: none; cursor: pointer; font-family: inherit;
}
.topbar nav a:hover, .topbar nav button.linklike:hover { background: rgba(255,255,255,.15); }
.topbar nav a.active { background: rgba(255,255,255,.22); }
.topbar .wallet {
  background: rgba(255,255,255,.14); border-radius: 8px; padding: .3rem .7rem;
  font-size: .88rem; line-height: 1.25; text-decoration: none; color: #fff;
}
.topbar .wallet b { font-size: 1rem; }
.topbar form { margin: 0; }
.badge-count {
  background: #e67e22; color: #fff; border-radius: 9px; padding: 0 .4rem;
  font-size: .75rem; margin-left: .2rem;
}

.page { max-width: 1200px; margin: 1.2rem auto; padding: 0 1rem; }
.page.narrow { max-width: 460px; margin-top: 3rem; }
.page > .panel + .panel, .stack > * + * { margin-top: 1rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; align-items: start; }
@media (max-width: 900px) {
  main, .grid2, .grid3 { grid-template-columns: 1fr; }
}

.flashes { list-style: none; padding: 0; margin: 0 0 1rem; }
.flashes li {
  padding: .7rem 1rem; border-radius: 8px; margin-bottom: .5rem; font-size: .95rem;
}
.flashes .ok { background: #e3f4e8; color: #1e6b37; border: 1px solid #b6e0c2; }
.flashes .error { background: #fbe9e7; color: #a5301f; border: 1px solid #f1c2b9; }
.notice {
  background: #fff7e0; border: 1px solid #f0d78c; color: #6b5310;
  padding: .7rem 1rem; border-radius: 8px; font-size: .92rem;
}
.notice form { display: inline; }

.form label { display: block; margin-bottom: .8rem; font-size: .9rem; }
.form input[type=text], .form input[type=email], .form input[type=password],
.form input[type=number], .form input[type=date], .form select, .form textarea {
  width: 100%; margin-top: .25rem; padding: .5rem; border: 1px solid #ccc;
  border-radius: 6px; font-size: .95rem; font-family: inherit; background: #fff;
}
.form .row { display: flex; gap: .6rem; align-items: flex-end; flex-wrap: wrap; }
.form .row > * { flex: 1; min-width: 120px; }
.form .row > .shrink { flex: 0 0 auto; }
.btn {
  display: inline-block; padding: .5rem .9rem; border-radius: 7px; border: 1px solid #40599c;
  background: #40599c; color: #fff; cursor: pointer; font-size: .9rem; text-decoration: none;
  font-family: inherit; white-space: nowrap;
}
.btn:hover { background: #2c3e66; }
.btn.light { background: #fff; color: #40599c; }
.btn.light:hover { background: #eef2fb; }
.btn.danger { background: #fff; color: #b03a2e; border-color: #d99a92; }
.btn.danger:hover { background: #fbe9e7; }
.btn.small { padding: .25rem .55rem; font-size: .8rem; }
.inline { display: inline; margin: 0; }
.muted { color: #888; }
.small { font-size: .82rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.links { font-size: .9rem; margin-top: 1rem; display: flex; justify-content: space-between; }
.links a, a.link { color: #40599c; }

table.data { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.data th, table.data td {
  padding: .45rem .5rem; border-bottom: 1px solid #eee; text-align: left; vertical-align: top;
}
table.data th { color: #666; font-weight: 600; background: #f8f7f3; position: sticky; top: 0; }
table.data td.num, table.data th.num { text-align: right; white-space: nowrap; }
table.data tr:hover td { background: #fafaf7; }
table.data tfoot td { font-weight: 700; border-top: 2px solid #ddd; }
.table-wrap { overflow-x: auto; }
.plus { color: #1e7b3c; }
.minus { color: #b03a2e; }

.tag {
  display: inline-block; padding: .05rem .45rem; border-radius: 5px; font-size: .78rem;
  background: #eef2fb; color: #2c3e66; white-space: nowrap;
}
.tag.green { background: #e3f4e8; color: #1e6b37; }
.tag.red { background: #fbe9e7; color: #a5301f; }
.tag.amber { background: #fff3d6; color: #7a5a00; }
.tag.grey { background: #eee; color: #666; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .8rem; }
.stat {
  background: #fff; border-radius: 10px; padding: .9rem 1rem;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
}
.stat .label { font-size: .8rem; color: #777; }
.stat .value { font-size: 1.45rem; font-weight: 700; color: #2c3e66; margin-top: .15rem; }
.stat .sub { font-size: .78rem; color: #888; margin-top: .2rem; }
.stat.good .value { color: #1e7b3c; }
.stat.bad .value { color: #b03a2e; }

.tabs { display: flex; gap: .3rem; flex-wrap: wrap; margin-bottom: 1rem; }
.tabs a {
  padding: .4rem .8rem; border-radius: 7px; background: #fff; color: #40599c;
  text-decoration: none; font-size: .9rem; box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.tabs a.active { background: #40599c; color: #fff; }

.model-pick { display: flex; flex-direction: column; gap: .35rem; }
.model-pick label {
  display: flex; gap: .5rem; align-items: center; padding: .45rem .6rem;
  border: 1px solid #e2e2e2; border-radius: 7px; cursor: pointer; margin: 0;
}
.model-pick label:has(input:checked) { border-color: #40599c; background: #eef2fb; }
.progress { height: 8px; background: #eee; border-radius: 4px; overflow: hidden; margin-top: .3rem; }
.progress > div { height: 100%; background: #40599c; }
.balance-big { font-size: 2rem; font-weight: 700; color: #2c3e66; }
.landing { max-width: 900px; margin: 2rem auto; padding: 0 1rem; }
.landing .hero { text-align: center; padding: 2rem 1rem; }
.landing .hero h2 { font-size: 1.8rem; margin: 0 0 .6rem; color: #2c3e66; }
.landing .hero p { font-size: 1.1rem; color: #555; }
.landing .cta { display: flex; gap: .8rem; justify-content: center; margin-top: 1.4rem; }
.landing .cta .btn { padding: .7rem 1.4rem; font-size: 1rem; }
pre.mail { white-space: pre-wrap; font-size: .82rem; background: #f8f7f3; padding: .6rem;
  border-radius: 6px; margin: .3rem 0 0; max-height: 220px; overflow: auto; }
details > summary { cursor: pointer; color: #40599c; }

/* атрибут hidden сильнее display:block у label */
[hidden] { display: none !important; }
textarea { font-family: inherit; }
.page > * + * { margin-top: 1rem; }

/* карточки ИИ-подключений в настройках */
.provider-card {
  border: 1px solid #e4e4e4; border-radius: 10px; padding: .8rem 1rem; margin-bottom: .8rem;
}
.provider-card.active { border-color: #9fd3ae; background: #f7fcf8; }
.provider-head { display: flex; gap: 1.2rem; align-items: flex-start; flex-wrap: wrap; }
.provider-title { flex: 1 1 260px; min-width: 0; overflow-wrap: anywhere; }
.provider-facts { display: flex; gap: 1.4rem; }
.provider-actions { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.provider-edit { margin-top: .6rem; }
.provider-form { margin-top: .8rem; padding-top: .8rem; border-top: 1px dashed #ddd; }
.provider-form .grid2 { gap: 0 1rem; }
.form label.check { display: flex; gap: .5rem; align-items: baseline; }
.form label.check input { width: auto; margin: 0; }
