:root {
  --bg: #F4F5FA;
  --card: #FFFFFF;
  --border: #E5E7EB;
  --text: #111827;
  --muted: #6B7280;
  --primary: #4F46E5;
  --primary-dark: #4338CA;
  --primary-soft: #EEF0FF;
  --success: #16A34A;
  --warning: #D97706;
  --error: #DC2626;
  --profit-bg: #EAF7EE;
  --loss-bg: #FDECEC;
  --low-margin-bg: #FFF3D6;
  --shadow-sm: 0 1px 2px rgba(17, 24, 39, .05), 0 1px 1px rgba(17, 24, 39, .03);
  --shadow-md: 0 8px 20px rgba(17, 24, 39, .06), 0 2px 6px rgba(17, 24, 39, .04);
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); }

/* ---- бренд (лого) ------------------------------------------------- */

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  font-weight: 800;
  font-size: 15px;
  letter-spacing: -.01em;
  overflow: hidden;
  white-space: nowrap;
  min-width: 0;
}
.brand-mark {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
}
.brand-mark svg { width: 17px; height: 17px; }
.brand-standalone { justify-content: center; margin: 8px 0 28px; font-size: 16px; }

/* ---- каркас приложения (залогинен) ---------------------------------- */

.app-shell {
  display: flex;
  align-items: stretch;
  min-height: 100vh;
}

.sidebar {
  width: 236px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  transition: width .18s ease;
}
html.sidebar-collapsed .sidebar { width: 72px; }
html.sidebar-collapsed .brand-text,
html.sidebar-collapsed .nav-label { display: none; }
html.sidebar-collapsed .sidebar-toggle svg { transform: rotate(180deg); }
html.sidebar-collapsed .nav-item { justify-content: center; padding-left: 10px; padding-right: 10px; }
html.sidebar-collapsed .sidebar-top { justify-content: center; }
html.sidebar-collapsed .sidebar-toggle { position: absolute; top: 18px; right: -12px; background: var(--card); border: 1px solid var(--border); box-shadow: var(--shadow-sm); }
html.sidebar-collapsed .brand { justify-content: center; }

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 6px 20px;
  position: relative;
}

.sidebar-toggle {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.sidebar-toggle:hover { background: var(--bg); color: var(--text); }
.sidebar-toggle svg { width: 15px; height: 15px; transition: transform .18s ease; }

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

.nav-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  padding: 16px 12px 6px;
  white-space: nowrap;
  overflow: hidden;
}
html.sidebar-collapsed .nav-section-title {
  height: 1px;
  padding: 0;
  margin: 12px 10px;
  overflow: hidden;
  text-indent: -9999px;
  background: var(--border);
}
.sidebar-bottom { display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--border); padding-top: 10px; margin-top: 10px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 9px;
  text-decoration: none;
  color: var(--muted);
  font-weight: 600;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  transition: background .12s ease, color .12s ease;
}
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); }
.nav-icon { flex-shrink: 0; width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; }
.nav-icon svg { width: 20px; height: 20px; }
.nav-form { width: 100%; }

.content { flex: 1; min-width: 0; padding: 28px 32px 56px; }

@media (max-width: 720px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100% !important;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    gap: 4px;
  }
  .sidebar-top, .sidebar-nav, .sidebar-bottom { display: contents; }
  .sidebar-top .brand { display: none; }
  .sidebar-toggle { display: none; }
  .nav-label { display: none; }
  .nav-item { width: auto; padding: 10px; }
  .content { padding: 20px 16px 40px; }
}

/* ---- неавторизованные страницы (вход/регистрация) ------------------- */

.container {
  max-width: 1200px;
  margin: 24px auto;
  padding: 0 16px 40px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 26px 28px;
}

.auth-card {
  max-width: 380px;
  margin: 40px auto;
}

h1 { font-size: 21px; font-weight: 800; letter-spacing: -.01em; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }

label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 4px; }
label .hint { font-weight: 400; color: var(--muted); display: block; font-size: 12px; margin-top: 2px; }

input[type=text], input[type=email], input[type=password], input[type=number] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
  transition: border-color .12s ease, box-shadow .12s ease;
}
input[type=text]:focus, input[type=email]:focus, input[type=password]:focus, input[type=number]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.checkbox-row { display: flex; align-items: center; gap: 8px; margin: 14px 0; }
.checkbox-row input { width: auto; }
.checkbox-row label { margin: 0; }

button, .btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
  font-family: inherit;
  padding: 9px 16px;
  border-radius: 9px;
  cursor: pointer;
  text-decoration: none;
  transition: background .12s ease, box-shadow .12s ease, border-color .12s ease;
}
button:hover, .btn:hover { background: var(--bg); border-color: #D5D9E3; }
button.primary, .btn.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(79, 70, 229, .25);
}
button.primary:hover, .btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
button:disabled { opacity: .55; cursor: not-allowed; }

.actions-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 16px 0; }
.actions-row .spacer { flex: 1; }

.error-box {
  background: var(--loss-bg);
  border: 1px solid var(--error);
  color: var(--error);
  padding: 10px 14px;
  border-radius: 10px;
  margin-bottom: 16px;
  font-size: 13px;
}
.success-box {
  background: var(--profit-bg);
  border: 1px solid var(--success);
  color: var(--success);
  padding: 10px 14px;
  border-radius: 10px;
  margin-bottom: 16px;
  font-size: 13px;
}
.note-box {
  background: #F6F7FC;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 10px 14px;
  border-radius: 10px;
  margin-bottom: 16px;
  font-size: 13px;
}

.table-scroll { overflow-x: auto; overflow-y: auto; max-height: 700px; border-radius: 10px; }

table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; text-align: right; }
th:nth-child(1), th:nth-child(2), td:nth-child(1), td:nth-child(2) { text-align: left; white-space: normal; }
th {
  background: #FAFAFD;
  position: sticky;
  top: 0;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}
th a { color: inherit; text-decoration: none; }
tbody tr:hover { background: #FAFAFD; }

tr.profit { background: var(--profit-bg); }
tr.loss { background: var(--loss-bg); }
tr.low-margin { background: var(--low-margin-bg); }
tr.profit:hover, tr.loss:hover, tr.low-margin:hover { filter: brightness(0.98); }

.section-title { font-weight: 700; margin: 24px 0 10px; }
.section-title.err { color: var(--error); }
.section-title.warn { color: var(--warning); }

.total-line { font-size: 16px; font-weight: 700; text-align: right; }
.total-note { font-size: 12px; color: var(--muted); text-align: right; }

.muted { color: var(--muted); font-size: 12px; }
