* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: #f5f5f5;
  color: #333;
  min-height: 100vh;
}

.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
}

/* ===== Card ===== */
.card {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

/* ===== Header ===== */
.header {
  text-align: center;
  padding: 32px 16px;
}

.header h1 {
  font-size: 22px;
  color: #1890ff;
  margin-bottom: 4px;
}

.header p {
  font-size: 13px;
  color: #999;
}

/* ===== Form ===== */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
  color: #555;
}

.form-group label .required {
  color: #ff4d4f;
  margin-left: 2px;
}

input[type="text"],
input[type="password"],
input[type="tel"],
input[type="number"],
select,
textarea {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid #d9d9d9;
  border-radius: 8px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
  background: #fff;
}

textarea {
  height: 80px;
  padding: 10px 12px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #1890ff;
  box-shadow: 0 0 0 2px rgba(24,144,255,0.15);
}

input[readonly] {
  background: #f5f5f5;
  color: #888;
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'%3E%3C/path%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* ===== Radio / Checkbox ===== */
.radio-group,
.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding-top: 4px;
}

.radio-group label,
.checkbox-group label {
  display: flex;
  align-items: center;
  font-size: 15px;
  font-weight: 400;
  cursor: pointer;
  padding: 8px 14px;
  border: 1px solid #d9d9d9;
  border-radius: 8px;
  transition: all 0.2s;
}

.radio-group label:has(input:checked),
.checkbox-group label:has(input:checked) {
  border-color: #1890ff;
  background: #e6f7ff;
  color: #1890ff;
}

.radio-group input,
.checkbox-group input {
  margin-right: 6px;
  accent-color: #1890ff;
  width: 16px;
  height: 16px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-block;
  height: 44px;
  padding: 0 24px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  line-height: 44px;
  text-decoration: none;
}

.btn-primary {
  background: #1890ff;
  color: #fff;
  width: 100%;
}

.btn-primary:active {
  background: #096dd9;
}

.btn-danger {
  background: #ff4d4f;
  color: #fff;
}

.btn-danger:active {
  background: #cf1322;
}

.btn-default {
  background: #fff;
  color: #333;
  border: 1px solid #d9d9d9;
}

.btn-sm {
  height: 34px;
  line-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

.btn-group {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.btn-group .btn {
  flex: 1;
}

/* ===== Table ===== */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 16px;
}

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

table th {
  background: #fafafa;
  padding: 10px 8px;
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid #e8e8e8;
  position: sticky;
  top: 0;
}

table td {
  padding: 10px 8px;
  border-bottom: 1px solid #f0f0f0;
}

table tbody tr:active {
  background: #fafafa;
}

/* ===== Hierarchy filter pickers ===== */
.hf-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.hf-select {
  flex: 1;
  min-width: 70px;
  height: 36px;
  font-size: 13px;
  padding: 0 24px 0 6px;
  border: 1px solid #d9d9d9;
  border-radius: 6px;
  background: #fff;
  color: #333;
  cursor: pointer;
  appearance: auto;
}

.hf-select:disabled {
  color: #bbb;
  background: #f5f5f5;
  cursor: not-allowed;
}

/* ===== Search bar ===== */
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.search-bar input {
  flex: 1;
  min-width: 140px;
}

.search-bar select {
  width: auto;
  min-width: 90px;
  flex-shrink: 0;
  font-size: 14px;
  height: 40px;
  padding: 0 28px 0 8px;
}

/* ===== Toolbar ===== */
.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}

/* ===== Pagination ===== */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
  padding: 12px 0;
}

.pagination button {
  height: 36px;
  min-width: 36px;
  padding: 0 10px;
  border: 1px solid #d9d9d9;
  border-radius: 6px;
  background: #fff;
  font-size: 14px;
  cursor: pointer;
}

.pagination button:active {
  background: #e6f7ff;
}

.pagination button.active {
  background: #1890ff;
  color: #fff;
  border-color: #1890ff;
}

.pagination button:disabled {
  color: #ccc;
  background: #f5f5f5;
}

.pagination .page-info {
  font-size: 13px;
  color: #888;
  margin: 0 12px;
}

/* ===== Bottom nav ===== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  border-top: 1px solid #e8e8e8;
  display: flex;
  justify-content: space-around;
  padding: 6px 0;
  padding-bottom: max(6px, env(safe-area-inset-bottom));
  z-index: 10;
}

.bottom-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-decoration: none;
  color: #999;
  font-size: 11px;
  padding: 4px 16px;
  border-radius: 8px;
}

.bottom-nav a.active {
  color: #1890ff;
}

.bottom-nav a .icon {
  font-size: 22px;
  line-height: 1;
}

/* ===== Alert ===== */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
}

.alert-error {
  background: #fff2f0;
  border: 1px solid #ffccc7;
  color: #cf1322;
}

.alert-success {
  background: #f6ffed;
  border: 1px solid #b7eb8f;
  color: #389e0d;
}

/* ===== Loading ===== */
.loading {
  text-align: center;
  padding: 32px;
  color: #999;
}

/* ===== Empty state ===== */
.empty {
  text-align: center;
  padding: 48px 16px;
  color: #999;
}

.empty .icon {
  font-size: 48px;
  display: block;
  margin-bottom: 12px;
}

/* ===== Misc ===== */
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  margin: 2px;
  background: #e6f7ff;
  color: #1890ff;
}

.text-muted {
  color: #999;
  font-size: 13px;
}

.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }

/* Fix for fixed bottom nav */
body {
  padding-bottom: 60px;
}

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding-bottom: 0;
}

.login-body .container {
  width: 100%;
}

/* ===== Modal ===== */
.modal-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 100;
}

.modal-content {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

.modal-content h3 {
  margin-bottom: 16px;
  font-size: 17px;
}

.import-result {
  white-space: pre-wrap;
  max-height: 200px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 16px;
  padding: 12px;
  background: #fafafa;
  border-radius: 8px;
}

/* Desktop tweaks */
@media (min-width: 769px) {
  .container {
    max-width: 720px;
  }
  table {
    font-size: 14px;
  }
}

/* ===== Home Center Layout ===== */
.home-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 200px);
  gap: 32px;
}

.home-overview {
  display: flex;
  gap: 24px;
}

.home-stat {
  text-align: center;
  background: #fff;
  border-radius: 16px;
  padding: 20px 32px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
  min-width: 120px;
}

.home-stat-value {
  font-size: 36px;
  font-weight: 700;
  color: #1890ff;
  margin-bottom: 4px;
}

.home-stat-label {
  font-size: 13px;
  color: #888;
}

/* ===== Big Add Button ===== */
.btn-add-resident {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 140px;
  height: 140px;
  margin: 24px auto;
  background: linear-gradient(135deg, #1890ff, #40a9ff);
  color: #fff;
  border-radius: 50%;
  text-decoration: none;
  box-shadow: 0 6px 20px rgba(24,144,255,0.35);
  transition: all 0.2s;
}

.btn-add-resident:active {
  transform: scale(0.95);
  box-shadow: 0 4px 12px rgba(24,144,255,0.25);
}

.btn-add-icon {
  font-size: 48px;
  font-weight: 300;
  line-height: 1;
}

.btn-add-resident span:last-child {
  font-size: 16px;
  font-weight: 600;
  margin-top: 4px;
}

/* ===== Breadcrumb ===== */
.breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px 0;
  margin-bottom: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.breadcrumb-item {
  font-size: 14px;
  padding: 4px 10px;
  border-radius: 12px;
  background: #f0f0f0;
  color: #666;
  cursor: pointer;
  white-space: nowrap;
}

.breadcrumb-item.active {
  background: #1890ff;
  color: #fff;
}

.breadcrumb-sep {
  color: #ccc;
  font-size: 12px;
}

.breadcrumb-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #1890ff;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  margin-left: 4px;
}

/* ===== Inline Add ===== */
.inline-add {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  padding: 8px;
  background: #fafafa;
  border-radius: 8px;
}

.inline-add input {
  flex: 1;
  height: 34px;
}

/* ===== Node Grid ===== */
.node-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.node-card {
  position: relative;
  background: #fff;
  border: 1px solid #e8e8e8;
  border-radius: 12px;
  padding: 20px 12px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.node-card:active {
  background: #e6f7ff;
  border-color: #1890ff;
}

.node-delete {
  position: absolute;
  top: 4px;
  right: 8px;
  font-size: 18px;
  color: #ccc;
  cursor: pointer;
  line-height: 1;
  padding: 2px;
}

.node-delete:hover {
  color: #ff4d4f;
}

.node-icon {
  font-size: 32px;
  margin-bottom: 8px;
}

.node-name {
  font-size: 15px;
  font-weight: 600;
  color: #333;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.node-count {
  font-size: 12px;
  color: #999;
}

/* ===== Stats Scope ===== */
.stats-scope {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.stats-scope select {
  flex: 1;
}

/* ===== Stats Dashboard ===== */
.stats-dashboard {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card {
  background: #fff;
  border-radius: 12px;
  padding: 20px 16px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: #1890ff;
  margin-bottom: 6px;
}

.stat-label {
  font-size: 13px;
  color: #888;
}

/* ===== Attribute Distribution ===== */
.attr-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.attr-row {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #fafafa;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
}

.attr-count {
  font-size: 13px;
  color: #666;
  font-weight: 600;
}

/* ===== Hierarchy Add Buttons in Form ===== */
.hierarchy-add-btn {
  flex-shrink: 0;
  white-space: nowrap;
}

/* ===== Age Bar Chart ===== */
.age-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  width: 100%;
}

.age-bar-label {
  font-size: 13px;
  font-weight: 600;
  color: #555;
  min-width: 60px;
}

.age-bar-track {
  flex: 1;
  background: #f0f0f0;
  border-radius: 4px;
  height: 20px;
  overflow: hidden;
}

.age-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #40a9ff, #1890ff);
  border-radius: 4px;
  transition: width 0.3s;
  min-width: 2px;
}

/* ===== Analysis Tabs ===== */
.analysis-tabs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-bottom: 16px;
}

.analysis-tab {
  padding: 10px 4px;
  border: 1px solid #d9d9d9;
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
  font-weight: 600;
  color: #666;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}

.analysis-tab.active {
  background: #1890ff;
  color: #fff;
  border-color: #1890ff;
}

.analysis-tab:active {
  background: #e6f7ff;
}

/* ===== Tab Content ===== */
.tab-content {
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ===== Permission Grid ===== */
.perm-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.perm-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 400;
  cursor: pointer;
  padding: 8px 12px;
  border: 1px solid #d9d9d9;
  border-radius: 8px;
  transition: all 0.2s;
  margin: 0;
}

.perm-item:has(input:checked) {
  border-color: #1890ff;
  background: #e6f7ff;
  color: #1890ff;
}

.perm-item input {
  accent-color: #1890ff;
  width: 16px;
  height: 16px;
}

.perm-tag {
  font-size: 11px;
  padding: 2px 6px;
  margin: 1px;
}

/* Tablet grid */
@media (min-width: 769px) {
  .node-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .stats-dashboard {
    grid-template-columns: repeat(4, 1fr);
  }
  .btn-add-resident {
    width: 160px;
    height: 160px;
  }
}

/* ===== Portal Page ===== */
.portal-body {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.portal-header {
  text-align: center;
  color: #fff;
  margin-bottom: 48px;
}
.portal-header h1 {
  font-size: 36px;
  font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: 4px;
}
.portal-header p {
  font-size: 16px;
  opacity: 0.85;
}
.portal-cards {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 0 32px;
  width: 100%;
  max-width: 400px;
}
.portal-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(255,255,255,0.95);
  border-radius: 20px;
  padding: 36px 24px;
  text-decoration: none;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
  transition: all 0.2s;
}
.portal-card:active { transform: scale(0.96); }
.portal-icon { font-size: 56px; margin-bottom: 16px; line-height: 1; }
.portal-title { font-size: 22px; font-weight: 700; color: #333; margin-bottom: 6px; }
.portal-desc { font-size: 14px; color: #999; }
.portal-footer {
  text-align: center;
  margin-top: 48px;
}
.portal-footer a {
  color: rgba(255,255,255,0.8);
  font-size: 14px;
  text-decoration: none;
}
.portal-footer a:hover { color: #fff; text-decoration: underline; }

.portal-version {
  text-align: center;
  color: rgba(255,255,255,0.4);
  font-size: 12px;
  padding-bottom: 80px;
}

/* ===== Duty System ===== */
.import-result {
  max-height: 300px;
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.6;
}
.import-result .success { color: #52c41a; }
.import-result .error { color: #ff4d4f; }

/* ===== Textarea ===== */
textarea {
  width: 100%;
  border: 1px solid #d9d9d9;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
}
textarea:focus {
  outline: none;
  border-color: #1890ff;
  box-shadow: 0 0 0 2px rgba(24,144,255,0.2);
}
