/* ================================================================
   AI Content Studio — Design System
   Версии: light / dark через [data-theme="light"] на <html>
   ================================================================ */

/* ---- Токены ---- */
:root {
  /* Тёмная тема (по умолчанию) */
  --bg:           #0a0a0f;
  --surface:      #13131a;
  --surface-2:    #1a1a24;
  --border:       #1e1e2a;
  --text:         #e4e4e8;
  --text-dim:     #8b8b9e;
  --accent:       #7c3aed;
  --accent-hover: #6d28d9;
  --accent-glow:  #a78bfa;
  --green:        #10b981;
  --red:          #ef4444;
  --yellow:       #f59e0b;
  --radius:       14px;
  --radius-sm:    8px;
  --sidebar-w:    260px;
  --transition:   0.15s ease;
  --shadow:       0 4px 24px rgba(0,0,0,0.4);
  --shadow-sm:    0 2px 8px rgba(0,0,0,0.2);
}

[data-theme="light"] {
  --bg:           #f5f5fa;
  --surface:      #ffffff;
  --surface-2:    #eeeef5;
  --border:       #dddde8;
  --text:         #0f0f18;
  --text-dim:     #6b6b80;
  --accent:       #7c3aed;
  --accent-hover: #6d28d9;
  --accent-glow:  #6d28d9;
  --shadow:       0 4px 24px rgba(0,0,0,0.08);
  --shadow-sm:    0 2px 8px rgba(0,0,0,0.06);
}

/* ---- Reset ---- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html { font-size: 16px; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-glow); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ================================================================
   LAYOUTS
   ================================================================ */

/* Auth layout — карточка по центру */
.layout-auth {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

/* App layout — sidebar + main */
.layout-app {
  display: flex;
  min-height: 100vh;
}

/* ================================================================
   SIDEBAR
   ================================================================ */

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
  min-height: 100vh;
  position: sticky;
  top: 0;
  max-height: 100vh;
  overflow-y: auto;
}

.sidebar-logo {
  font-size: 1.15rem;
  font-weight: 800;
  padding: 8px 10px 18px;
  text-decoration: none;
  color: var(--text);
  display: block;
}
.sidebar-logo span { color: var(--accent-glow); }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
}
.nav-item:hover { background: rgba(124,58,237,0.08); color: var(--text); text-decoration: none; }
.nav-item.active { background: rgba(124,58,237,0.14); color: var(--text); }
.nav-item .icon { width: 18px; text-align: center; flex-shrink: 0; opacity: 0.8; }

.sidebar-divider { border: none; border-top: 1px solid var(--border); margin: 10px 0; }

.sidebar-footer { margin-top: auto; }

.user-box {
  padding: 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.user-box .user-email {
  font-size: 0.8rem;
  color: var(--text-dim);
  word-break: break-all;
}
.user-box .user-stats {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-top: 4px;
}

.tariff-badge {
  display: inline-block;
  background: var(--accent);
  color: white;
  padding: 2px 9px;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 700;
  margin-top: 5px;
}

.credit-badge {
  font-size: 0.78rem;
  color: var(--accent-glow);
  margin-top: 4px;
}

.sidebar-links {
  padding: 8px 10px 0;
  font-size: 0.7rem;
  color: var(--text-dim);
  display: flex;
  gap: 8px;
}
.sidebar-links a { color: var(--text-dim); }
.sidebar-links a:hover { color: var(--accent-glow); text-decoration: none; }

/* Logout link */
.sidebar-logout {
  display: block;
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--text-dim);
  padding: 4px 0;
}
.sidebar-logout:hover { color: var(--red); text-decoration: none; }

/* ================================================================
   MAIN CONTENT
   ================================================================ */

.main {
  flex: 1;
  padding: 40px;
  overflow-y: auto;
  min-width: 0;
}

.page-title {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 6px;
}
.page-subtitle {
  color: var(--text-dim);
  margin-bottom: 32px;
  font-size: 0.95rem;
}

/* ================================================================
   AUTH CARD
   ================================================================ */

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 400px;
  max-width: 94vw;
  box-shadow: var(--shadow);
}

.auth-card h2 {
  font-size: 1.35rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 24px;
}

.auth-footer {
  text-align: center;
  margin-top: 16px;
  color: var(--text-dim);
  font-size: 0.85rem;
}

.auth-legal {
  text-align: center;
  margin-top: 16px;
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* ================================================================
   FORM ELEMENTS
   ================================================================ */

.form-group { margin-bottom: 0; }

.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
  margin-top: 16px;
}
.form-label:first-child { margin-top: 0; }

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 10px 13px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.92rem;
  font-family: inherit;
  transition: border-color var(--transition);
  appearance: none;
}

.form-textarea { min-height: 78px; resize: vertical; line-height: 1.5; }
.form-select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238b8b9e' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.form-input::placeholder,
.form-textarea::placeholder { color: var(--text-dim); opacity: 0.6; }

/* ================================================================
   BUTTONS
   ================================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition), transform var(--transition), opacity var(--transition);
  white-space: nowrap;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { border-color: var(--accent); }

.btn-ghost { background: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: rgba(124,58,237,0.08); color: var(--text); }

.btn-danger { background: transparent; border: 1px solid var(--border); color: var(--red); }
.btn-danger:hover { border-color: var(--red); background: rgba(239,68,68,0.07); }

.btn-full { width: 100%; }
.btn-sm { padding: 6px 14px; font-size: 0.82rem; }
.btn-lg { padding: 13px 28px; font-size: 1rem; }

/* ================================================================
   CARDS
   ================================================================ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.card-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

/* ================================================================
   ALERTS / BANNERS
   ================================================================ */

.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 500;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.alert-error   { background: rgba(239,68,68,0.1);   color: var(--red); }
.alert-success { background: rgba(16,185,129,0.1);  color: var(--green); }
.alert-info    { background: rgba(124,58,237,0.1);  color: var(--accent-glow); border: 1px solid rgba(124,58,237,0.2); }
.alert-warn    { background: rgba(245,158,11,0.1);  color: var(--yellow); }

.upgrade-banner {
  background: linear-gradient(135deg, rgba(124,58,237,0.12), rgba(167,139,250,0.06));
  border: 1px solid rgba(124,58,237,0.3);
  border-radius: var(--radius);
  padding: 18px 22px;
  margin-bottom: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
.upgrade-banner-text { font-size: 0.9rem; }
.upgrade-banner-text strong { display: block; margin-bottom: 3px; }
.upgrade-banner-text p { color: var(--text-dim); font-size: 0.83rem; }
.upgrade-banner-text .credit-note { color: var(--accent-glow); margin-top: 4px; font-size: 0.82rem; }

/* ================================================================
   TABLE
   ================================================================ */

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }

th {
  text-align: left;
  padding: 9px 12px;
  color: var(--text-dim);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 11px 12px;
  border-bottom: 1px solid rgba(124,58,237,0.06);
  font-size: 0.88rem;
  color: var(--text-dim);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(124,58,237,0.03); }

td.text-main { color: var(--text); }
.cell-preview { max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ================================================================
   MODAL
   ================================================================ */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.active { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 680px;
  max-width: 96vw;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.modal-title { font-size: 1.2rem; font-weight: 700; margin-bottom: 20px; }
.modal-close { margin-top: 24px; text-align: center; }

/* ================================================================
   TARIFF CARDS
   ================================================================ */

.tariffs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.tariff-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 18px 14px;
  text-align: center;
  position: relative;
  transition: border-color var(--transition);
}
.tariff-card.current { border-color: var(--accent); }
.tariff-card.current::before {
  content: 'Текущий';
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  padding: 2px 10px;
  border-radius: 8px;
  font-size: 0.68rem;
  font-weight: 700;
  white-space: nowrap;
}
.tariff-name { font-weight: 600; font-size: 0.9rem; margin-bottom: 4px; }
.tariff-price { font-size: 1.35rem; font-weight: 800; color: var(--accent-glow); margin-bottom: 6px; }
.tariff-price small { font-size: 0.65em; font-weight: 500; color: var(--text-dim); }
.tariff-desc { font-size: 0.75rem; color: var(--text-dim); line-height: 1.4; }

/* ================================================================
   MISC COMPONENTS
   ================================================================ */

/* Spinner */
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.55s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  z-index: 200;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.toast-ok   { border-color: var(--green);  color: var(--green); }
.toast.toast-err  { border-color: var(--red);    color: var(--red); }

/* Badge */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 8px;
  font-size: 0.72rem;
  font-weight: 700;
  background: rgba(124,58,237,0.15);
  color: var(--accent-glow);
}
.badge-green { background: rgba(16,185,129,0.12); color: var(--green); }
.badge-red   { background: rgba(239,68,68,0.12);  color: var(--red); }

/* Divider */
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 64px 20px;
  color: var(--text-dim);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state p { font-size: 0.95rem; }

/* Stats row */
.stats-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.stats-row strong { color: var(--accent-glow); }

/* Generator layout */
.gen-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}

.gen-output-placeholder {
  color: var(--text-dim);
  text-align: center;
  padding: 64px 20px;
  font-size: 0.92rem;
}

.gen-result-text {
  white-space: pre-wrap;
  line-height: 1.75;
  font-size: 0.92rem;
  color: var(--text);
}

.gen-meta {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--text-dim);
}

.gen-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* ================================================================
   THEME TOGGLE
   ================================================================ */

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1rem;
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}
.theme-toggle:hover { background: var(--surface-2); color: var(--text); }

/* ================================================================
   RESPONSIVE
   ================================================================ */

@media (max-width: 900px) {
  .gen-panel { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .layout-app { flex-direction: column; }

  .sidebar {
    width: 100%;
    min-height: auto;
    max-height: none;
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    padding: 12px;
    gap: 4px;
    overflow-x: auto;
  }

  .sidebar-logo { padding: 6px 8px 6px; margin-right: auto; }
  .sidebar-footer { display: none; }
  .sidebar-divider { display: none; }

  .main { padding: 20px 16px; }
  .page-title { font-size: 1.4rem; }
}
