:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e2e4e9;
  --text: #1c1f26;
  --text-muted: #6b7280;
  --primary: #2f5df5;
  --primary-hover: #2448d1;
  --danger: #e5484d;
  --danger-bg: #fdeceb;
  --success: #1a9c5c;
  --success-bg: #e7f7ee;
  --warning: #b46a00;
  --warning-bg: #fff3e0;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171c;
    --surface: #1c1f26;
    --border: #2c3038;
    --text: #e7e9ee;
    --text-muted: #9aa1ac;
    --primary: #5b7dfa;
    --primary-hover: #7692fb;
    --danger: #f27274;
    --danger-bg: #3a2325;
    --success: #34c281;
    --success-bg: #17332a;
    --warning: #e0a84f;
    --warning-bg: #3a2f1a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  --bg: #15171c;
  --surface: #1c1f26;
  --border: #2c3038;
  --text: #e7e9ee;
  --text-muted: #9aa1ac;
  --primary: #5b7dfa;
  --primary-hover: #7692fb;
  --danger: #f27274;
  --danger-bg: #3a2325;
  --success: #34c281;
  --success-bg: #17332a;
  --warning: #e0a84f;
  --warning-bg: #3a2f1a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

/* Классы вроде .auth-form/.modal-overlay задают display напрямую и иначе
   перебивают браузерное правило [hidden]{display:none} (авторские стили
   всегда сильнее UA-стилей независимо от специфичности). */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

button {
  font-family: inherit;
  cursor: pointer;
}

/* ---------- Auth screen ---------- */

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

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
}

.brand {
  margin: 0 0 4px;
  font-size: 22px;
  text-align: center;
}

.brand-sub {
  margin: 0 0 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.tabs {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 20px;
}

.tab {
  flex: 1;
  padding: 8px;
  border: none;
  background: var(--surface);
  color: var(--text-muted);
  font-weight: 500;
}

.tab.active {
  background: var(--primary);
  color: #fff;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-form label,
.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
}

textarea { resize: vertical; min-height: 60px; }

.btn {
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-weight: 600;
  font-size: 14px;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn:disabled { opacity: .6; cursor: default; }

.form-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 16px;
}

/* ---------- App shell ---------- */

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

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

.brand-mini {
  font-weight: 700;
  font-size: 15px;
  padding: 0 10px 20px;
}

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

.nav-item {
  text-align: left;
  padding: 9px 10px;
  border: none;
  background: transparent;
  border-radius: 8px;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 14px;
}

.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--primary); color: #fff; }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.user-name {
  font-size: 13px;
  color: var(--text-muted);
  padding: 0 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.content {
  flex: 1;
  min-width: 0;
  padding: 24px 32px 48px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.topbar h2 { margin: 0; font-size: 20px; }

.view-root { display: flex; flex-direction: column; gap: 20px; }

/* ---------- Cards / tables ---------- */

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

.card-title {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .03em;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.stat-value { font-size: 24px; font-weight: 700; }
.stat-label { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-head h3 { margin: 0; font-size: 15px; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th { color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }

tr:last-child td { border-bottom: none; }

.empty-state {
  color: var(--text-muted);
  text-align: center;
  padding: 24px;
  font-size: 13px;
}

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge-gray { background: var(--border); color: var(--text-muted); }
.badge-blue { background: #e8edfe; color: var(--primary); }
.badge-green { background: var(--success-bg); color: var(--success); }
.badge-red { background: var(--danger-bg); color: var(--danger); }
.badge-orange { background: var(--warning-bg); color: var(--warning); }

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.toolbar input[type="search"] { max-width: 260px; }
.toolbar .spacer { flex: 1; }

.checkbox-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}
.checkbox-inline input { width: auto; }

.property-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.property-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.property-card:hover { border-color: var(--primary); }
.property-card.archived { opacity: .55; }
.property-card h4 { margin: 0; font-size: 15px; }
.property-meta { color: var(--text-muted); font-size: 12px; }

.detail-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}

.detail-tab {
  padding: 8px 14px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-weight: 500;
  border-bottom: 2px solid transparent;
}

.detail-tab.active { color: var(--primary); border-color: var(--primary); }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-grid .full { grid-column: 1 / -1; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, .45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 100;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  box-shadow: 0 10px 40px rgba(16, 24, 40, .2);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { margin: 0; font-size: 16px; }

.modal-close {
  border: none;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  color: var(--text-muted);
  padding: 4px;
}

.modal-body { padding: 20px; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  background: var(--text);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 200;
}

.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

@media (max-width: 720px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; padding: 10px 14px; }
  .brand-mini { padding: 0 10px 0 0; }
  .nav { flex-direction: row; }
  .sidebar-footer { flex-direction: row; border-top: none; padding-top: 0; }
  .content { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
}
