* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: #f3f4f6;
  color: #111;
}

[hidden] { display: none !important; }

.center-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.card {
  width: 100%;
  max-width: 380px;
  padding: 24px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.08);
}

h1 { margin: 0 0 16px; font-size: 1.3rem; }
h2 { margin: 0 0 16px; font-size: 1.2rem; }
h3 { margin: 0 0 16px; font-size: 1rem; }
.muted { color: #6b7280; }

label { display: block; margin: 12px 0 6px; font-size: .9rem; color: #374151; }
input, select {
  width: 100%;
  padding: 11px 12px;
  font-size: 1rem;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #fff;
}
input:focus, select:focus {
  outline: 2px solid #2563eb;
  outline-offset: 1px;
  border-color: transparent;
}
button {
  width: 100%;
  margin-top: 12px;
  padding: 12px;
  font-size: 1rem;
  font-weight: 600;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}
button.primary   { background: #2563eb; color: #fff; }
button.secondary { background: #e5e7eb; color: #111; }
button:disabled  { opacity: .6; cursor: default; }

.status { min-height: 1.2em; margin: 14px 0 0; font-size: .92rem; }
.status.error { color: #b91c1c; }
.status.ok    { color: #15803d; }

/* Приложение */
#app-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 16px;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 700; }

.user-menu { position: relative; }
.user-menu-btn {
  width: auto;
  margin: 0;
  padding: 8px 12px;
  background: #f3f4f6;
  color: #111;
  font-size: .95rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.user-menu-btn .caret { font-size: .8rem; color: #6b7280; }

.user-menu-list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 200px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  padding: 6px;
  z-index: 20;
}
.menu-item {
  width: 100%;
  margin: 0;
  padding: 10px 12px;
  background: transparent;
  color: #111;
  font-weight: 500;
  text-align: left;
  border-radius: 8px;
}
.menu-item:hover { background: #f3f4f6; }

/* Блок с ФИО и логином в меню */
.user-menu-info {
  padding: 8px 12px;
  margin-bottom: 6px;
}
.menu-full-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: #111;
  word-break: break-word;
}
.menu-login {
  font-size: 0.8rem;
  color: #6b7280;
  margin-top: 2px;
}
.menu-divider {
  height: 1px;
  background: #e5e7eb;
  margin: 0 6px 6px 6px;
}

.content {
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

/* Настройки / Отчёты */
.settings-layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}
.settings-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 220px;
}
.settings-tab {
  width: 100%;
  margin: 0;
  padding: 10px 12px;
  background: transparent;
  color: #374151;
  font-weight: 500;
  text-align: left;
  border-radius: 8px;
}
.settings-tab:hover  { background: #eef2ff; }
.settings-tab.active { background: #2563eb; color: #fff; }

.settings-body {
  flex: 1;
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 4px 16px rgba(0,0,0,.06);
  min-width: 0;
}
.tab-panel { width: 100%; }

/* Форма отчёта */
.report-form .row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.report-result {
  margin-top: 16px;
}

/* Группы отчёта */
.report-groups {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.report-group {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
}
.report-group-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: baseline;
  padding: 10px 12px;
  cursor: pointer;
  background: #f9fafb;
  font-weight: 600;
  font-size: .95rem;
}
.report-group-head::-webkit-details-marker { display: none; }
.report-group-head::before {
  content: "▸";
  color: #6b7280;
  margin-right: 4px;
}
.report-group[open] > .report-group-head::before { content: "▾"; }
.rg-card { color: #111; }
.rg-holder { color: #4b5563; font-weight: 400; font-size: .9rem; flex: 1; }
.rg-totals { color: #2563eb; white-space: nowrap; }

.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
.report-table th, .report-table td {
  padding: 8px 10px;
  border-top: 1px solid #f1f5f9;
  text-align: left;
  vertical-align: top;
}
.report-table th {
  background: #f9fafb;
  font-weight: 600;
  color: #374151;
  font-size: .82rem;
  text-transform: none;
}
.report-table td.num, .report-table th.num { text-align: right; white-space: nowrap; }
.report-table tfoot .group-total td {
  font-weight: 700;
  background: #f9fafb;
}

/* Общий итог */
.grand-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  padding: 12px 14px;
  background: #2563eb;
  color: #fff;
  border-radius: 10px;
  font-weight: 700;
}

/* Мобильная версия */
@media (max-width: 720px) {
  .settings-layout {
    flex-direction: column;
    gap: 12px;
  }
  .settings-nav {
    flex-direction: row;
    min-width: 0;
    overflow-x: auto;
    padding-bottom: 4px;
  }
  .settings-tab {
    width: auto;
    white-space: nowrap;
    padding: 8px 14px;
  }
  .settings-body { padding: 14px; }
  .topbar { padding: 0 12px; }
  .content { padding: 16px 12px 32px; }

  .report-form .row-2 {
    grid-template-columns: 1fr;
  }

  /* На мобильном таблица в карточках */
  .report-table thead { display: none; }
  .report-table, .report-table tbody, .report-table tr, .report-table td {
    display: block;
    width: 100%;
  }
  .report-table tr {
    border-top: 1px solid #f1f5f9;
    padding: 8px 10px;
  }
  .report-table td {
    border: 0;
    padding: 3px 0;
    display: flex;
    justify-content: space-between;
    gap: 12px;
  }
  .report-table td::before {
    content: attr(data-label);
    color: #6b7280;
    font-weight: 500;
    flex: 0 0 auto;
  }
  .report-table td.num { text-align: right; }

  .report-table tfoot { display: block; }
  .report-table tfoot tr { background: #f9fafb; }
  .report-table tfoot td { display: block; padding: 4px 10px; }
  .report-table tfoot td::before { content: none; }
  .report-table tfoot td:first-child { display: none; }
}
