@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg: #0b0d12;
  --panel: #11141b;
  --panel-2: #171b24;
  --panel-hover: #1c212c;
  --border: #252b36;
  --text: #f4f7fb;
  --muted: #8c96a8;
  --accent: #6d5dfc;
  --accent-hover: #7d70ff;
  --danger: #ef596f;
  --success: #42c98a;
  --shadow: 0 24px 70px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { min-height: 100%; }

body {
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 15% 10%, rgba(109, 93, 252, .10), transparent 28%),
    radial-gradient(circle at 85% 90%, rgba(72, 121, 255, .06), transparent 25%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}

button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

button { cursor: pointer; }
a { color: inherit; text-decoration: none; }

/* ---------- Common ---------- */

.container {
  width: min(920px, calc(100% - 40px));
  margin: 0 auto;
  padding: 46px 0;
}

.container > h1,
.subjects-card > h1 {
  font-size: clamp(26px, 4vw, 36px);
  letter-spacing: -.04em;
}

.back-link,
.container > p > a {
  color: var(--muted);
  transition: color .2s ease;
}

.back-link:hover,
.container > p > a:hover { color: var(--text); }

.alerts, .flash-list { margin: 18px 0; }

.alert, .flash {
  padding: 12px 15px;
  border-radius: 10px;
  border: 1px solid var(--border);
  margin-bottom: 9px;
  font-size: 14px;
}

.alert.success, .flash.success {
  background: rgba(66, 201, 138, .08);
  border-color: rgba(66, 201, 138, .25);
  color: #8ce2b8;
}

.alert.error, .flash.error {
  background: rgba(239, 89, 111, .08);
  border-color: rgba(239, 89, 111, .25);
  color: #ff9baa;
}

/* ---------- Auth ---------- */

.auth-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(420px, 520px) minmax(320px, 520px);
  justify-content: center;
  align-items: center;
  gap: clamp(50px, 8vw, 130px);
  padding: 50px;
}

.auth-brand { align-self: start; margin-top: 10px; }

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #4c8dff);
  box-shadow: 0 12px 35px rgba(109, 93, 252, .28);
  font-weight: 700;
  margin-bottom: 28px;
}

.auth-brand h1 {
  font-size: clamp(42px, 5vw, 66px);
  line-height: .98;
  letter-spacing: -.065em;
  max-width: 560px;
  margin-bottom: 22px;
}

.auth-brand h1 span { color: var(--accent); }

.auth-brand p {
  max-width: 510px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.8;
}

.auth-card {
  width: 100%;
  background: rgba(17, 20, 27, .88);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 32px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.auth-card h2 { font-size: 24px; margin-bottom: 7px; letter-spacing: -.035em; }
.auth-card .subtitle { color: var(--muted); font-size: 14px; margin-bottom: 24px; }

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  gap: 4px;
  background: #0c0f14;
  border: 1px solid var(--border);
  border-radius: 11px;
  margin-bottom: 22px;
}

.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 10px;
  border-radius: 8px;
  transition: .2s ease;
}

.tab.active { background: var(--panel-2); color: var(--text); box-shadow: 0 2px 10px rgba(0,0,0,.2); }

.form input,
.auth-card input,
.subject-form input {
  width: 100%;
  padding: 13px 14px;
  margin: 0 0 11px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #0d1016;
  color: var(--text);
  outline: none;
  transition: border .2s ease, box-shadow .2s ease;
}

.form input::placeholder,
.auth-card input::placeholder,
.subject-form input::placeholder { color: #606a7b; }

.form input:focus,
.auth-card input:focus,
.subject-form input:focus {
  border-color: rgba(109, 93, 252, .7);
  box-shadow: 0 0 0 3px rgba(109, 93, 252, .11);
}

.form button,
.auth-submit,
.auth-card form > button {
  width: 100%;
  border: 0;
  padding: 13px 16px;
  margin-top: 4px;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  font-weight: 600;
  transition: transform .2s ease, background .2s ease;
}

.form button:hover,
.auth-submit:hover,
.auth-card form > button:hover { background: var(--accent-hover); transform: translateY(-1px); }

.auth-card p a { color: #9a91ff; font-size: 13px; }
.auth-card p { text-align: center; margin-top: 16px; }

/* ---------- Main ---------- */

.main-container {
  width: min(1120px, calc(100% - 48px));
  min-height: 650px;
  margin: 30px auto;
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: rgba(17, 20, 27, .84);
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  position: relative;
}

.user-info {
  grid-column: 1 / -1;
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  padding: 0 4px 18px;
}

.user-info h3 {
  margin-right: auto;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
}

.user-info h3::first-letter { color: var(--text); }

.user-info button {
  border: 1px solid var(--border);
  padding: 9px 14px;
  background: var(--panel-2);
  color: var(--text);
  border-radius: 9px;
  font-size: 13px;
  transition: .2s ease;
}

.user-info button:hover { background: var(--panel-hover); border-color: #343c4a; }
.user-info form button { color: #ff9baa; }

.half {
  min-height: 470px;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 40px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  position: relative;
  overflow: hidden;
  background: linear-gradient(145deg, rgba(255,255,255,.025), transparent 65%);
}

.half::after {
  content: "";
  position: absolute;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  filter: blur(60px);
  opacity: .18;
  right: -80px;
  bottom: -80px;
  background: var(--accent);
}

.half.left::after { background: #4c8dff; }

.half h2 { font-size: 25px; letter-spacing: -.04em; margin-bottom: 10px; z-index: 1; }
.half p { color: var(--muted); font-size: 14px; line-height: 1.6; max-width: 300px; margin-bottom: 25px; z-index: 1; }

.half button {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 1;
  transition: .2s ease;
}

.half button:hover { background: var(--accent); border-color: var(--accent); transform: translateY(-2px); }

/* ---------- Cards / subjects ---------- */

.container {
  background: rgba(17, 20, 27, .82);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.container > h1 { padding: 0 32px; }
.container > p { padding: 0 32px; }

.subject-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin: 28px 32px;
}

.subject-btn {
  min-height: 88px;
  display: flex;
  align-items: flex-end;
  padding: 17px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--panel-2);
  color: var(--text);
  font-weight: 600;
  transition: .2s ease;
}

.subject-btn::before { content: "▣"; color: var(--accent); margin-right: 9px; }
.subject-btn:hover { background: var(--panel-hover); border-color: #394151; transform: translateY(-2px); }

/* ---------- Subjects page ---------- */

.subjects-page {
  min-height: 100vh;
  padding: 50px 20px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.subjects-card {
  width: min(950px, 100%);
  padding: 36px;
  background: rgba(17, 20, 27, .86);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.subjects-card > h1 { margin-bottom: 8px; }
.subjects-card > h1::after { content: ""; display: block; width: 45px; height: 3px; background: var(--accent); margin-top: 12px; border-radius: 3px; }

.subjects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
  margin: 30px 0;
}

.subject-item,
.add-subject-card {
  min-height: 82px;
  border-radius: 13px;
}

.subject-item {
  padding: 15px 16px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-weight: 600;
}

.subject-item span { overflow-wrap: anywhere; }

.delete-subject {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  border: 1px solid rgba(239,89,111,.25);
  border-radius: 8px;
  background: rgba(239,89,111,.08);
  color: #ff8e9e;
  font-size: 20px;
}

.add-subject-card {
  border: 1px dashed #3b4352;
  background: transparent;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: .2s ease;
}

.add-subject-card:hover { border-color: var(--accent); color: var(--text); background: rgba(109,93,252,.06); }
.plus { font-size: 30px; line-height: 30px; color: var(--accent); }

.subject-form { margin: 20px auto; max-width: 600px; }
.subject-form form { display: flex; gap: 10px; }
.subject-form form button, .cancel-button {
  padding: 12px 17px;
  border: 0;
  border-radius: 9px;
  font-weight: 600;
}
.subject-form form button { background: var(--accent); color: white; }
.cancel-button { margin-top: 8px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); }
.hidden { display: none !important; }
.back-link { display: inline-block; margin-top: 18px; }
.subjects-hint { color: var(--muted); margin-top: 20px; line-height: 1.6; }

/* ---------- Files ---------- */

.container > h2 { margin: 28px 32px 12px; font-size: 17px; }
.container > form { margin: 0 32px 25px; }
.container input[type="file"] {
  width: 100%;
  padding: 14px;
  border: 1px dashed #3b4352;
  border-radius: 11px;
  background: #0d1016;
  color: var(--muted);
  margin-bottom: 10px;
}

.container form button[type="submit"] {
  border: 0;
  background: var(--accent);
  color: white;
  border-radius: 9px;
  padding: 11px 16px;
  font-weight: 600;
}

.file-list {
  list-style: none;
  margin: 0 32px 28px;
  border: 1px solid var(--border);
  border-radius: 13px;
  overflow: hidden;
}

.file-list li {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  background: var(--panel-2);
}
.file-list li:last-child { border-bottom: 0; }
.file-list li::before { content: "↳"; color: var(--accent); }
.file-list a { color: var(--text); font-weight: 500; }
.file-list a:hover { color: #a69fff; }
.file-list form { margin-left: auto; }
.file-list form button { background: transparent !important; color: #ff8e9e; padding: 4px 8px !important; }

.container > p { margin-top: 10px; margin-bottom: 10px; }

@media (max-width: 900px) {
  .auth-page { grid-template-columns: 1fr; max-width: 620px; margin: 0 auto; gap: 35px; padding: 35px 20px; }
  .auth-brand { text-align: center; margin: 0; }
  .auth-brand p { margin: 0 auto; }
  .auth-card { order: 2; }
}

@media (max-width: 700px) {
  .main-container { width: calc(100% - 24px); margin: 12px auto; padding: 14px; grid-template-columns: 1fr; }
  .user-info { min-height: 90px; flex-wrap: wrap; }
  .user-info h3 { flex-basis: 100%; margin-bottom: 3px; }
  .half { min-height: 270px; padding: 28px; }
  .subjects-card { padding: 24px 18px; }
  .subject-form form { flex-direction: column; }
  .subject-form form button { width: 100%; }
  .container { width: calc(100% - 24px); padding: 28px 0; }
  .container > h1 { padding: 0 22px; }
  .subject-list, .file-list { margin-left: 22px; margin-right: 22px; }
  .container > h2 { margin-left: 22px; margin-right: 22px; }
  .container > form { margin-left: 22px; margin-right: 22px; }
  .container > p { padding: 0 22px; }
}

.hidden-field{display:none!important}.secondary-auth-btn{width:100%;margin-top:10px;padding:.8rem 1rem;border:1px solid #334155;border-radius:8px;background:transparent;color:#cbd5e1;cursor:pointer;transition:.2s}.secondary-auth-btn:hover{background:#1e293b;border-color:#475569}.username-page{min-height:100vh;width:100%;display:flex;align-items:center;justify-content:center;padding:24px}.username-card{width:100%;max-width:560px;padding:48px;background:#0f172a;border:1px solid #263449;border-radius:20px;box-shadow:0 24px 70px rgba(0,0,0,.35)}.username-card .brand-mark{margin-bottom:22px}.username-card h1{margin-bottom:14px;color:#f8fafc}.username-description{margin-bottom:28px;color:#94a3b8;line-height:1.7}.username-card .form{display:flex;flex-direction:column;gap:12px}.username-card .form input{margin:0}.username-card .form button{margin-top:4px}.auth-card .form input.hidden-field{display:none}.auth-card .form input{transition:border-color .2s,box-shadow .2s}.auth-card .form input:focus{border-color:#64748b;box-shadow:0 0 0 3px rgba(100,116,139,.12)}

/* ---------- Password Toggle Styles ---------- */
.password-wrapper {
  position: relative;
  width: 100%;
  margin-bottom: 11px;
}

.password-wrapper input {
  margin-bottom: 0 !important;
  padding-right: 42px;
}

.password-wrapper.hidden-field {
  display: none !important;
}

.form button.toggle-password {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: auto;
  height: auto;
  margin-top: 0;
  padding: 6px;
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .2s ease;
  z-index: 2;
}

.form button.toggle-password:hover {
  background: transparent;
  color: var(--text);
  transform: translateY(-50%);
}

.toggle-password svg {
  pointer-events: none;
  display: block;
}

/* ---------- Telegram Promo ---------- */
.telegram-promo {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-top: 36px;
  padding: 20px;
  background: rgba(17, 20, 27, .88);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  width: fit-content;
}

/* Специфичные стили для главной страницы (растягивание на 2 колонки) */
.telegram-promo.main-promo {
  grid-column: 1 / -1;
  width: 100%;
  margin-top: 6px;
  background: linear-gradient(145deg, rgba(255,255,255,000), transparent 65%), var(--panel);
}

.telegram-promo .qr-code {
  width: 200px;
  height: 200px;
  border-radius: 10px;
  background: #ffffff; /* Белый фон обязателен для корректного считывания QR-кода телефонами */
  padding: 4px;
  flex-shrink: 0;
}

.telegram-text {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.telegram-text span {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  max-width: 280px;
}

.telegram-promo.main-promo .telegram-text span {
  max-width: none;
}

.telegram-link {
  display: inline-block;
  color: white;
  background: var(--accent);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  transition: transform .2s ease, background .2s ease;
  text-align: center;
  width: fit-content;
}

.telegram-link:hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
}

/* Адаптивность для мобильных устройств */
@media (max-width: 700px) {
  .telegram-promo {
    flex-direction: column;
    text-align: center;
    align-items: center;
    width: 100%;
  }

  .telegram-link {
    width: 100%;
  }
}