:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #1a2332;
  --muted: #5c6b7a;
  --border: #d8e0e8;
  --primary: #1f4b99;
  --primary-dark: #163a78;
  --success: #1f7a4d;
  --warning: #9a6b00;
  --danger: #b42318;
  --shadow: 0 8px 24px rgba(16, 24, 40, 0.08);
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.container {
  width: min(1200px, calc(100% - 2rem));
  margin: 0 auto;
}

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 0;
}

.brand {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}

.main-nav {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.main-nav a {
  color: var(--muted);
  font-weight: 600;
  text-decoration: none;
  padding: 0.35rem 0.5rem;
  border-radius: 8px;
}

.main-nav a.active,
.main-nav a:hover {
  color: var(--primary);
  background: #eef4ff;
  text-decoration: none;
}

.main-content {
  padding: 2rem 0 3rem;
}

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  padding: 1.25rem 0 2rem;
  font-size: 0.9rem;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.page-header h1 {
  margin: 0;
  font-size: 1.8rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

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

.stat-card .label {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
}

.stat-card .value {
  font-size: 1.6rem;
  font-weight: 700;
}

.stat-card .sub {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 0.35rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

.panel-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.panel-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.panel-body {
  padding: 1.25rem;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 0.85rem 0.75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}

tbody tr:hover {
  background: #f8fbff;
}

.text-right {
  text-align: right;
}

.text-muted {
  color: var(--muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border: none;
  border-radius: 8px;
  padding: 0.65rem 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  font-size: 0.95rem;
}

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

.btn-primary:hover {
  background: var(--primary-dark);
  color: #fff;
  text-decoration: none;
}

.btn-secondary {
  background: #eef2f7;
  color: var(--text);
}

.btn-secondary:hover {
  background: #e3eaf2;
  text-decoration: none;
}

.btn-danger {
  background: #fdecec;
  color: var(--danger);
}

.btn-small {
  padding: 0.4rem 0.7rem;
  font-size: 0.85rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

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

label {
  font-weight: 600;
  font-size: 0.9rem;
}

input,
select,
textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  font: inherit;
  background: #fff;
}

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

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.checkbox-row input {
  width: auto;
}

.section-title {
  margin: 0 0 1rem;
  font-size: 1.05rem;
}

.funds-hint {
  margin-top: 0.45rem;
  padding: 0.55rem 0.75rem;
  background: #eef8f1;
  border: 1px solid #c8e6d2;
  border-radius: 8px;
  font-size: 0.9rem;
  color: var(--success);
}

.field-hint {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
}

.readonly-value {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  background: #f8fbff;
  font-weight: 700;
  font-size: 1.05rem;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1.25rem;
}

.alert {
  padding: 0.85rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}

.alert-success {
  background: #e8f7ef;
  color: var(--success);
}

.alert-error {
  background: #fdecec;
  color: var(--danger);
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
}

.badge-active {
  background: #e8f7ef;
  color: var(--success);
}

.badge-sold {
  background: #eef2f7;
  color: var(--muted);
}

.expense-rows {
  display: grid;
  gap: 0.75rem;
}

.expense-row {
  display: grid;
  grid-template-columns: 1.2fr 1.5fr 1fr auto;
  gap: 0.75rem;
  align-items: end;
}

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

.profit-item {
  background: #f8fbff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem;
}

.profit-item .label {
  color: var(--muted);
  font-size: 0.85rem;
}

.profit-item .value {
  font-weight: 700;
  margin-top: 0.2rem;
}

.nav-user {
  color: var(--muted);
  font-size: 0.9rem;
  align-self: center;
}

.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
}

.auth-container {
  width: min(480px, calc(100% - 2rem));
  margin: 2rem auto;
}

.auth-page {
  width: 100%;
}

.auth-card {
  margin-top: 0;
}

.auth-form,
.auth-secondary-form {
  margin-top: 1.5rem;
}

.auth-secondary-form {
  margin-top: 0.75rem;
}

.auth-email-hint {
  margin: 0 0 1rem;
  color: var(--muted);
}

.btn-block {
  width: 100%;
}

@media (max-width: 800px) {
  .expense-row {
    grid-template-columns: 1fr;
  }

  .page-header {
    align-items: flex-start;
  }
}
