:root {
  --bg: #f3efe6;
  --bg-deep: #e8e0d2;
  --ink: #1c2418;
  --muted: #5f6b58;
  --line: rgba(28, 36, 24, 0.12);
  --panel: rgba(255, 252, 246, 0.88);
  --accent: #2f6b3a;
  --accent-2: #c45c26;
  --danger: #a33b2d;
  --ok: #2f6b3a;
  --shadow: 0 18px 40px rgba(28, 36, 24, 0.08);
  --radius: 18px;
  --font: "DM Sans", sans-serif;
  --display: "Instrument Serif", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 18%, rgba(47, 107, 58, 0.12), transparent 34%),
    radial-gradient(circle at 88% 8%, rgba(196, 92, 38, 0.12), transparent 28%),
    linear-gradient(160deg, var(--bg), var(--bg-deep));
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 36px 32px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  animation: rise 0.55s ease both;
}

.login-card .logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.brand-mark, .logo-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #2f6b3a, #1f4a28);
  color: #f7f3ea;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.login-card h1 {
  font-family: var(--display);
  font-weight: 400;
  font-size: 2.2rem;
  margin: 0 0 8px;
}

.login-card p {
  margin: 0 0 24px;
  color: var(--muted);
}

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 0.85rem;
  margin-bottom: 6px;
  color: var(--muted);
}
.field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fffdf8;
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
}
.field input[type="checkbox"],
.field input[type="radio"] {
  width: 18px;
  height: 18px;
  min-width: 18px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  flex-shrink: 0;
  accent-color: var(--accent);
  box-shadow: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: rgba(47, 107, 58, 0.45);
  box-shadow: 0 0 0 3px rgba(47, 107, 58, 0.12);
}
.field input[type="checkbox"]:focus,
.field input[type="radio"]:focus {
  box-shadow: none;
}

.check-list {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fffdf8;
  margin-bottom: 16px;
}
.check-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0;
  cursor: pointer;
  color: var(--ink, #1c2418);
  font-size: 0.95rem;
  line-height: 1.35;
}
.check-row input[type="checkbox"] {
  margin-top: 2px;
}
.check-row .check-text strong {
  display: inline;
  color: inherit;
}
.check-row .check-hint {
  display: block;
  margin-top: 2px;
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 400;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 12px;
  padding: 12px 18px;
  background: var(--accent);
  color: #f7f3ea;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease;
}
.btn:hover { filter: brightness(1.05); transform: translateY(-1px); }
.btn-secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn-danger { background: var(--danger); }
.btn-block { width: 100%; }

.error, .flash {
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 16px;
}
.error, .flash-error {
  background: rgba(163, 59, 45, 0.1);
  color: var(--danger);
  border: 1px solid rgba(163, 59, 45, 0.2);
}
.flash-ok {
  background: rgba(47, 107, 58, 0.1);
  color: var(--ok);
  border: 1px solid rgba(47, 107, 58, 0.2);
}

.capital-alert {
  margin-bottom: 18px;
  padding: 16px 18px;
  border-radius: 12px;
  border: 2px solid;
}
.capital-alert-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 8px;
}
.capital-alert p {
  margin: 0 0 6px;
  line-height: 1.5;
}
.capital-alert p:last-of-type {
  margin-bottom: 0;
}
.capital-alert-meta {
  margin-top: 10px;
  opacity: 0.9;
}
.capital-alert-critical {
  background: rgba(163, 59, 45, 0.14);
  border-color: var(--danger);
  color: #7a2a1f;
}
.capital-alert-critical .capital-alert-title {
  color: var(--danger);
}
.capital-alert-loss {
  background: rgba(163, 59, 45, 0.1);
  border-color: rgba(163, 59, 45, 0.45);
  color: #6b2d22;
}
.capital-alert-loss .capital-alert-title {
  color: var(--danger);
}
.capital-alert-warning {
  background: #fff8e6;
  border-color: #e8c547;
  color: #6b4e12;
}
.capital-alert-warning .capital-alert-title {
  color: #9a6b12;
}

body:has(.sidebar) {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
  border-right: 1px solid var(--line);
  background: rgba(255, 252, 246, 0.72);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  gap: 24px;
  animation: slide 0.45s ease both;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 4px 8px;
}
.brand strong { display: block; font-size: 1.05rem; }
.brand small { color: var(--muted); }

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
  overflow-y: auto;
  padding-right: 2px;
}
.nav-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-group-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.75;
  padding: 0 14px 6px;
}
.sidebar nav a {
  padding: 9px 14px;
  border-radius: 12px;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.94rem;
}
.sidebar nav a:hover { background: rgba(28, 36, 24, 0.05); color: var(--ink); }
.sidebar nav a.active {
  background: rgba(47, 107, 58, 0.12);
  color: var(--accent);
}

.sidebar-foot {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  border-top: 1px solid var(--line);
}
.user-chip {
  font-size: 0.92rem;
  font-weight: 600;
}
.logout { color: var(--muted); font-size: 0.88rem; }
.logout:hover { color: var(--danger); }

.main { min-width: 0; }
.topbar {
  padding: 28px 32px 8px;
  animation: rise 0.45s ease both;
}
.topbar h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(1.85rem, 2.8vw, 2.4rem);
}
.page-lead {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.98rem;
  max-width: 52rem;
  line-height: 1.45;
}
.content { padding: 16px 32px 40px; }

.hub-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.hub-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 20px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, border-color 0.15s ease;
  animation: rise 0.5s ease both;
}
.hub-card:hover {
  transform: translateY(-2px);
  border-color: rgba(47, 107, 58, 0.35);
}
.hub-card .hub-step {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}
.hub-card strong {
  font-size: 1.15rem;
  line-height: 1.25;
}
.hub-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
  flex: 1;
}
.hub-card .hub-go {
  color: var(--accent);
  font-weight: 600;
  font-size: 0.9rem;
}

.btn-sm {
  padding: 8px 12px;
  font-size: 0.88rem;
  border-radius: 10px;
}
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 0;
  padding: 8px 10px;
}
.btn-ghost:hover { color: var(--ink); background: rgba(28, 36, 24, 0.05); }

.action-menu {
  position: relative;
  display: inline-block;
}
.action-menu-panel {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  min-width: 180px;
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 30;
}
.action-menu.open .action-menu-panel { display: flex; flex-direction: column; gap: 2px; }
.action-menu-panel a,
.action-menu-panel button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: 0;
  background: transparent;
  border-radius: 8px;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-weight: 500;
}
.action-menu-panel a:hover,
.action-menu-panel button:hover {
  background: rgba(28, 36, 24, 0.05);
}
.action-menu-panel .danger {
  color: var(--danger);
}

.money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.tiny { font-size: 0.78rem; line-height: 1.35; }

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.insight {
  padding: 12px 14px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: #fffdf8;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow);
  animation: rise 0.5s ease both;
}
.stat:nth-child(2) { animation-delay: 0.05s; }
.stat:nth-child(3) { animation-delay: 0.1s; }
.stat:nth-child(4) { animation-delay: 0.15s; }
.stat span { color: var(--muted); font-size: 0.88rem; }
.stat strong {
  display: block;
  margin-top: 8px;
  font-size: 1.8rem;
  font-family: var(--display);
  font-weight: 400;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: rise 0.55s ease both;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 {
  margin: 0;
  font-size: 1.05rem;
}
.panel-body { padding: 18px; }

table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
}
tr:last-child td { border-bottom: 0; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: rgba(28, 36, 24, 0.06);
}
.badge-own { background: rgba(47, 107, 58, 0.12); color: var(--accent); }
.badge-partner { background: rgba(196, 92, 38, 0.12); color: var(--accent-2); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.form-grid .full { grid-column: 1 / -1; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.empty {
  padding: 28px 18px;
  color: var(--muted);
  text-align: center;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
@keyframes slide {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 980px) {
  body:has(.sidebar) { grid-template-columns: 1fr; }
  .sidebar {
    position: relative;
    height: auto;
  }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; gap: 8px; }
  .nav-group { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 4px; }
  .nav-group-label { width: 100%; padding-bottom: 2px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hub-grid { grid-template-columns: 1fr; }
  .content, .topbar { padding-left: 18px; padding-right: 18px; }
  .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .stats { grid-template-columns: 1fr; }
  table { display: block; overflow-x: auto; }
}

.worker-photo-field {
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}
.worker-photo-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.worker-photo-preview,
.worker-photo-placeholder {
  width: 56px !important;
  height: 56px !important;
  max-width: 56px !important;
  max-height: 56px !important;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  overflow: hidden;
  display: block;
}
.worker-photo-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--green);
  color: #fff;
  font-size: 1.2rem;
  font-weight: 700;
}
.worker-photo-controls {
  flex: 1;
  min-width: 0;
}
.worker-photo-controls form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 0;
}
.worker-photo-controls input[type="file"] {
  width: auto !important;
  max-width: 220px;
  padding: 6px 0 !important;
  border: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  font-size: 0.85rem;
}
.worker-photo-controls .btn {
  padding: 8px 12px;
  font-size: 0.85rem;
}
.worker-photo-hint {
  margin: 6px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}
.worker-name-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}
.worker-photo-thumb {
  width: 32px !important;
  height: 32px !important;
  max-width: 32px !important;
  max-height: 32px !important;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  display: block;
  overflow: hidden;
}
.worker-photo-thumb-empty {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
}

/* Obyekt kataloqu */
.catalog-search {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.object-catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.object-tile {
  display: block;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  transition: transform 0.15s ease, border-color 0.15s ease;
  animation: rise 0.45s ease both;
}
.object-tile:hover {
  transform: translateY(-3px);
  border-color: rgba(47, 107, 58, 0.4);
}
.object-tile.has-debt {
  border-color: rgba(176, 48, 48, 0.35);
  background: linear-gradient(180deg, #fffaf9 0%, var(--panel) 48%);
}
.object-tile.is-inactive {
  opacity: 0.65;
}
.object-tile-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.object-tile-id {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
}
.object-tile-name {
  display: block;
  font-size: 1.05rem;
  line-height: 1.3;
  margin-bottom: 4px;
}
.object-tile-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
}
.object-tile-foot {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 0.82rem;
  color: var(--muted);
}

/* Obyekt profil ledger */
.ledger-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  margin-bottom: 10px;
  background: #fff;
  overflow: hidden;
}
.ledger-card.ledger-debt {
  border-color: rgba(176, 48, 48, 0.3);
}
.ledger-card.ledger-cancelled {
  opacity: 0.72;
}
.ledger-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  align-items: center;
}
.ledger-summary::-webkit-details-marker { display: none; }
.ledger-summary-main {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.ledger-summary-money {
  text-align: right;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.ledger-body {
  padding: 0 14px 14px;
  border-top: 1px solid var(--line);
  background: #fbfaf6;
}
.ledger-h {
  margin: 14px 0 8px;
  font-size: 0.92rem;
}
.ledger-table {
  width: 100%;
  font-size: 0.9rem;
}
.ledger-table th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.78rem;
}

@media (max-width: 640px) {
  .object-catalog-grid { grid-template-columns: 1fr; }
  .ledger-summary { flex-direction: column; align-items: flex-start; }
  .ledger-summary-money { text-align: left; }
}
