/* =========================================================
   MNL Soft — личный кабинет. Светлая admin-тема.
   Токены дизайна:
   - Акцент: #2952CC (приглушённый синий, перекликается с логотипом сайта)
   - Фон страницы: #F6F7F9, карточки: #FFFFFF
   - Текст: #111827 (основной), #6B7280 (вторичный)
   - Статусы: зелёный/серый/красный/жёлтый
   - Шрифт: Inter
   ========================================================= */

:root {
  --color-bg: #F6F7F9;
  --color-surface: #FFFFFF;
  --color-border: #E5E7EB;
  --color-text: #111827;
  --color-text-secondary: #6B7280;
  --color-text-muted: #9CA3AF;

  --color-accent: #2952CC;
  --color-accent-hover: #1F3FA6;
  --color-accent-soft: #EEF2FF;

  --color-success: #16A34A;
  --color-success-soft: #ECFDF3;
  --color-danger: #DC2626;
  --color-danger-soft: #FEF2F2;
  --color-warning: #D97706;
  --color-warning-soft: #FFFBEB;
  --color-neutral: #6B7280;
  --color-neutral-soft: #F3F4F6;

  --radius-card: 12px;
  --radius-control: 8px;
  --shadow-card: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

/* --- Layout --- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
}

.sidebar-logo {
  font-weight: 700;
  font-size: 16px;
  padding: 8px 12px 20px;
  color: var(--color-text);
}
.sidebar-logo span { color: var(--color-accent); }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-control);
  color: var(--color-text-secondary);
  font-weight: 500;
  font-size: 13.5px;
}
.sidebar-link:hover { background: var(--color-neutral-soft); color: var(--color-text); }
.sidebar-link.active { background: var(--color-accent-soft); color: var(--color-accent); }
.sidebar-link svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--color-border);
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 60px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
}

.topbar-title { font-weight: 600; font-size: 15px; }

.topbar-right { display: flex; align-items: center; gap: 14px; }

.balance-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--color-neutral-soft);
  border-radius: 999px;
  padding: 6px 14px;
  font-weight: 600;
  font-size: 13px;
}

.content {
  flex: 1;
  padding: 28px;
  max-width: 1100px;
  width: 100%;
}

/* --- Cards --- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 20px;
}

.card + .card { margin-top: 16px; }

.card-title {
  font-weight: 600;
  font-size: 14px;
  margin: 0 0 14px;
}

.grid {
  display: grid;
  gap: 16px;
}
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 18px 20px;
}
.stat-label { font-size: 12.5px; color: var(--color-text-secondary); font-weight: 500; }
.stat-value { font-size: 24px; font-weight: 700; margin-top: 6px; }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: var(--radius-control);
  border: 1px solid transparent;
  padding: 8px 14px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s ease;
}
.btn-primary { background: var(--color-accent); color: #fff; }
.btn-primary:hover { background: var(--color-accent-hover); }
.btn-secondary { background: var(--color-surface); border-color: var(--color-border); color: var(--color-text); }
.btn-secondary:hover { background: var(--color-neutral-soft); }
.btn-danger { background: var(--color-danger-soft); color: var(--color-danger); }
.btn-danger:hover { background: #FEE2E2; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* --- Forms --- */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 5px;
}
.field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-control);
  padding: 9px 11px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-surface);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-soft);
}

/* --- Badges / status --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--color-success-soft); color: var(--color-success); }
.badge-danger { background: var(--color-danger-soft); color: var(--color-danger); }
.badge-warning { background: var(--color-warning-soft); color: var(--color-warning); }
.badge-neutral { background: var(--color-neutral-soft); color: var(--color-neutral); }

/* --- Table --- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll table { min-width: 560px; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-secondary);
  padding: 8px 10px;
  border-bottom: 1px solid var(--color-border);
}
td { padding: 12px 10px; border-bottom: 1px solid var(--color-border); font-size: 13.5px; }
tr:last-child td { border-bottom: none; }

/* --- Misc --- */
.text-muted { color: var(--color-text-secondary); }
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--color-text-secondary);
}
.flex-between { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; }
.error-box {
  background: var(--color-danger-soft);
  color: var(--color-danger);
  border-radius: var(--radius-control);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 14px;
  display: none;
}
.success-box {
  background: var(--color-success-soft);
  color: var(--color-success);
  border-radius: var(--radius-control);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 14px;
  display: none;
}

/* --- Адаптив для узких окон / небольших экранов --- */
@media (max-width: 760px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    padding: 10px 14px;
    overflow-x: auto;
    gap: 8px;
  }
  .sidebar-logo { padding: 0 12px 0 0; flex-shrink: 0; }
  .sidebar-nav { flex-direction: row; gap: 2px; }
  .sidebar-link { white-space: nowrap; }
  .sidebar-footer {
    margin-top: 0;
    margin-left: auto;
    padding-top: 0;
    padding-left: 10px;
    border-top: none;
    border-left: 1px solid var(--color-border);
    flex-shrink: 0;
  }
  .content { padding: 16px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .topbar { padding: 0 16px; }
  .card .flex-between { flex-direction: column; align-items: flex-start; }
  .card .flex-between .btn { width: 100%; }
}

/* --- Auth pages --- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  padding: 20px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 32px;
}
.auth-logo { font-weight: 700; font-size: 18px; margin-bottom: 4px; }
.auth-logo span { color: var(--color-accent); }
.auth-subtitle { color: var(--color-text-secondary); font-size: 13px; margin-bottom: 22px; }
.auth-switch { margin-top: 18px; text-align: center; font-size: 13px; color: var(--color-text-secondary); }
.auth-switch a { color: var(--color-accent); font-weight: 600; }

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(17, 24, 39, .4);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--color-surface);
  border-radius: var(--radius-card);
  padding: 24px;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-header h3 { margin: 0; font-size: 15px; }
.modal-close { cursor: pointer; color: var(--color-text-secondary); background: none; border: none; font-size: 18px; }

/* --- Переписка по обращению — пузырьки в стиле iMessage: моя сторона справа, чужая слева --- */
.msg-row { display: flex; margin-bottom: 8px; }
.msg-row.msg-mine { justify-content: flex-end; }
.msg-row.msg-theirs { justify-content: flex-start; }
.msg-bubble { max-width: 78%; padding: 9px 13px; border-radius: 16px; font-size: 13.5px; line-height: 1.4; }
.msg-mine .msg-bubble { background: var(--color-accent); color: #fff; border-bottom-right-radius: 4px; }
.msg-theirs .msg-bubble { background: var(--color-neutral-soft); color: var(--color-text); border-bottom-left-radius: 4px; }
.msg-meta { font-size: 10.5px; margin-top: 3px; opacity: .75; }
.msg-mine .msg-meta { text-align: right; color: var(--color-text-secondary); }
.msg-theirs .msg-meta { text-align: left; color: var(--color-text-secondary); }
.msg-author { font-weight: 600; }
