/* Amobroker Mini App — адаптивно, тема Telegram */
:root {
  --tg-theme-bg-color: #1a1a2e;
  --tg-theme-text-color: #eee;
  --tg-theme-hint-color: #888;
  --tg-theme-link-color: #6ab2f2;
  --tg-theme-button-color: #4a90d9;
  --tg-theme-button-text-color: #fff;
  --tg-theme-secondary-bg-color: #16213e;
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bottom: env(safe-area-inset-bottom, 0);
  --app-top-offset: 40px;
  --nav-height: 56px;
  --header-height: 52px;
  --radius: 12px;
  --gap: 12px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  color: var(--tg-theme-text-color);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-top: calc(var(--safe-top) + var(--app-top-offset));
  padding-bottom: var(--safe-bottom);
  background: linear-gradient(
    180deg,
    var(--tg-theme-secondary-bg-color) 0%,
    var(--tg-theme-secondary-bg-color) calc(var(--safe-top) + var(--app-top-offset)),
    var(--tg-theme-bg-color) calc(var(--safe-top) + var(--app-top-offset)) 100%
  );
}

@media (min-width: 768px) {
  :root {
    --app-top-offset: 0;
  }
}

#root {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--header-height);
  padding: 0 12px 0 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--tg-theme-secondary-bg-color);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}

.header-menu-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--tg-theme-text-color);
  font-size: 1.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-menu-btn:active {
  background: rgba(255,255,255,0.1);
}

.header-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  flex: 1;
}

/* Menu drawer */
.menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}

.menu-overlay.open {
  opacity: 1;
  visibility: visible;
}

.menu-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(280px, 85vw);
  background: var(--tg-theme-secondary-bg-color);
  z-index: 101;
  transform: translateX(-100%);
  transition: transform 0.2s;
  box-shadow: 4px 0 20px rgba(0,0,0,0.2);
}

.menu-drawer.open {
  transform: translateX(0);
}

.menu-inner {
  padding: 16px 0;
  padding-top: calc(var(--safe-top) + var(--app-top-offset) + 16px);
}

.menu-item {
  display: block;
  width: 100%;
  padding: 14px 20px;
  border: none;
  background: none;
  color: var(--tg-theme-text-color);
  font-size: 1rem;
  text-align: left;
  cursor: pointer;
}

.menu-item:active {
  background: rgba(255,255,255,0.08);
}

.report-updated {
  font-size: 0.85rem;
  color: var(--tg-theme-hint-color);
  margin-top: 8px;
}

/* Main content */
.main {
  flex: 1;
  overflow: auto;
  padding: var(--gap) 16px 24px;
  -webkit-overflow-scrolling: touch;
}

.loading, .error {
  text-align: center;
  padding: 24px;
  color: var(--tg-theme-hint-color);
}

.error {
  color: #e57373;
}

/* Экран «Нет доступа» — чёрный фон, текст по центру */
.no-access-screen {
  position: fixed;
  inset: 0;
  background: #000;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  font-size: 1rem;
  line-height: 1.5;
}

/* Report block */
.report-card {
  background: var(--tg-theme-secondary-bg-color);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: var(--gap);
  overflow: hidden;
}

.report-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.report-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--tg-theme-link-color);
}

.report-legend-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  color: var(--tg-theme-hint-color);
  font-size: 1.1rem;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.report-legend-btn:active {
  background: rgba(255,255,255,0.15);
}

.report-meta {
  font-size: 0.9rem;
  color: var(--tg-theme-hint-color);
  margin-bottom: 16px;
}

.report-summary-card {
  background: rgba(0,0,0,0.15);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 12px;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--tg-theme-text-color);
}

.report-body {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.95rem;
  line-height: 1.55;
  margin: 0;
  color: var(--tg-theme-text-color);
  font-family: inherit;
}

/* Карточки по каждому брокеру (ежедневный отчёт) */
.report-broker-card {
  background: rgba(0,0,0,0.15);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 12px;
}

.report-broker-card:last-of-type {
  margin-bottom: 0;
}

.report-broker-name {
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 10px;
  color: var(--tg-theme-text-color);
}

.report-broker-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 0.9rem;
  line-height: 1.5;
  margin-bottom: 4px;
}

.report-broker-row:last-child {
  margin-bottom: 0;
}

.report-label {
  color: var(--tg-theme-hint-color);
  flex-shrink: 0;
}

.report-value {
  color: var(--tg-theme-text-color);
  text-align: right;
}

/* Оверлей с подсказкой */
.report-legend-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
}

.report-legend-popup {
  background: var(--tg-theme-secondary-bg-color);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 100%;
  max-height: 80vh;
  overflow: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.report-legend-popup h3 {
  margin: 0 0 12px;
  font-size: 1rem;
  color: var(--tg-theme-link-color);
}

.report-legend-popup p {
  margin: 0 0 8px;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--tg-theme-text-color);
}

.report-legend-popup p:last-child {
  margin-bottom: 0;
}

.report-legend-close {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 12px;
  border: none;
  border-radius: 8px;
  background: var(--tg-theme-button-color);
  color: var(--tg-theme-button-text-color);
  font-size: 1rem;
  cursor: pointer;
}

.report-back {
  display: inline-block;
  margin-bottom: 12px;
  color: var(--tg-theme-link-color);
  font-size: 0.9rem;
  text-decoration: none;
  cursor: pointer;
}

.report-back:active {
  opacity: 0.8;
}

/* Employee picker */
.picker-title {
  margin: 0 0 12px;
  font-size: 1rem;
  font-weight: 600;
}

.employee-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.employee-list li {
  margin: 0;
}

.employee-btn {
  display: block;
  width: 100%;
  padding: 14px 16px;
  border: none;
  border-radius: var(--radius);
  background: var(--tg-theme-secondary-bg-color);
  color: var(--tg-theme-text-color);
  font-size: 1rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.2s;
}

.employee-btn:active {
  background: rgba(255,255,255,0.1);
}

/* Кнопки «Кому назначить» — явно выделены как кликабельные */
#assign-targets-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

#assign-targets-list li {
  margin-bottom: 10px;
}

.assign-target-btn {
  border: 1px solid rgba(255,255,255,0.2) !important;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  font-weight: 500;
}

.assign-target-btn:hover,
.assign-target-btn:active {
  background: rgba(255,255,255,0.15) !important;
  border-color: var(--tg-theme-link-color) !important;
}

/* Month picker */
.month-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.month-btn {
  padding: 14px;
  border: none;
  border-radius: var(--radius);
  background: var(--tg-theme-secondary-bg-color);
  color: var(--tg-theme-text-color);
  font-size: 0.95rem;
  cursor: pointer;
}

.month-btn:active {
  background: rgba(255,255,255,0.1);
}

/* Help / Settings */
.help-card, .settings-card {
  background: var(--tg-theme-secondary-bg-color);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: var(--gap);
}

.help-card p, .settings-card p {
  margin: 0 0 0.75em;
}

.help-card p:last-child, .settings-card p:last-child {
  margin-bottom: 0;
}

.settings-section {
  margin-bottom: 20px;
}

.settings-section h3 {
  margin: 0 0 10px;
  font-size: 1rem;
  font-weight: 600;
  color: var(--tg-theme-link-color);
}

.row-with-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.row-with-btn:last-child {
  border-bottom: none;
}

.btn-sm {
  padding: 8px 14px;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  flex-shrink: 0;
}

.btn-sm.primary {
  background: var(--tg-theme-button-color);
  color: var(--tg-theme-button-text-color);
}

.btn-sm.danger {
  background: rgba(229, 115, 115, 0.3);
  color: #e57373;
}

.assign-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.assign-toggle label {
  flex: 1;
  cursor: pointer;
}

/* Responsive */
@media (min-width: 600px) {
  .main {
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
  }
}

@media (min-width: 900px) {
  .month-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}
