:root {
  --bg: #F8F9FA;
  --surface: #FFFFFF;
  --text: #1A1D1F;
  --text-muted: #6C757D;
  --border: #E2E5E9;
  --green: #1E8E3E;
  --green-bg: #E8F5E9;
  --overdue-bg: #FFF8E6;
  --overdue-border: #F2D28B;
  --overdue-text: #8A5A00;
  --danger: #C62828;
  --danger-bg: #FDECEA;
  --nav-height: 62px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

.hidden {
  display: none !important;
}

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

/* Banners */
.banner {
  position: sticky;
  top: 0;
  z-index: 40;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.banner-offline {
  background: #FFF3CD;
  color: #664D03;
  border-bottom: 1px solid #FFECB5;
}

.banner-error {
  background: var(--danger-bg);
  color: var(--danger);
  border-bottom: 1px solid #F5C2C7;
}

/* Layout */
.screen {
  min-height: 100vh;
  padding: calc(16px + var(--safe-top)) 16px calc(24px + var(--safe-bottom));
}

.center-screen {
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-box {
  width: 100%;
  max-width: 400px;
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}

.brand-icon {
  border-radius: 14px;
}

.app-title {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
}

.app-shell {
  min-height: 100vh;
  padding-top: var(--safe-top);
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
}

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

/* Cards & Surfaces */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.stack-sm {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stack-md {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.stack-lg {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-label {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
}

.page-header {
  margin-bottom: 14px;
}

.page-title {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
}

.page-subtitle {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--text-muted);
}

/* Progress Bar */
.progress-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-top: 10px;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 600;
}

.progress-track {
  width: 100%;
  height: 10px;
  background: #E9ECEF;
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--green);
  border-radius: 999px;
}

/* Buttons & Inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 10px 16px;
  font-size: 16px;
  font-weight: 600;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--green);
  border-color: var(--green);
  color: #FFFFFF;
}

.btn-danger {
  background: var(--surface);
  border-color: var(--danger);
  color: var(--danger);
}

.btn-sm {
  min-height: 38px;
  padding: 6px 12px;
  font-size: 14px;
}

.btn-block {
  width: 100%;
}

.btn-link {
  background: none;
  border: none;
  padding: 4px 6px;
  color: inherit;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  text-decoration: underline;
  font-family: inherit;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 14px;
  font-weight: 600;
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.textarea {
  min-height: 76px;
  resize: vertical;
}

.input-pin {
  text-align: center;
  font-size: 22px;
  letter-spacing: 6px;
}

.form-error {
  margin: 0;
  font-size: 14px;
  color: var(--danger);
  font-weight: 500;
}

.form-success {
  margin: 0;
  font-size: 14px;
  color: var(--green);
  font-weight: 500;
}

/* User selector pills */
.user-selector {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.user-pill {
  min-height: 48px;
  padding: 10px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.user-pill.active {
  background: var(--green-bg);
  border-color: var(--green);
  color: var(--green);
}

/* Task list */
.task-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.task-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}

.task-item.task-completed {
  background: var(--green-bg);
  border-color: #B7DFC0;
}

.task-item.task-overdue {
  background: var(--overdue-bg);
  border-color: var(--overdue-border);
}

.task-item.task-common {
  background: #F1F3F5;
  border-color: #E2E5E9;
  color: var(--text-muted);
}

.task-check-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  margin: -4px 0 -4px -4px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

.task-check-box {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  border: 2px solid #9AA1A8;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #FFFFFF;
  font-size: 16px;
  font-weight: 700;
}

.task-completed .task-check-box {
  background: var(--green);
  border-color: var(--green);
}

.task-readonly-badge {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  margin-top: 2px;
  border-radius: 6px;
  border: 2px solid #B8BEC4;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: #FFFFFF;
}

.task-completed .task-readonly-badge {
  background: var(--green);
  border-color: var(--green);
}

.task-body {
  flex: 1 1 auto;
  min-width: 0;
}

.task-time {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.task-overdue .task-time {
  color: var(--overdue-text);
}

.task-title {
  font-size: 16px;
  font-weight: 500;
  word-break: break-word;
}

.task-completed .task-title {
  text-decoration: line-through;
  color: var(--text-muted);
}

.task-desc {
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-muted);
  word-break: break-word;
}

.task-tag {
  display: inline-block;
  margin-top: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--overdue-text);
}

/* Family cards */
.family-card {
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
}

.family-card-name {
  font-size: 18px;
  font-weight: 700;
}

.family-next-task {
  margin-top: 10px;
  font-size: 14px;
  color: var(--text-muted);
}

/* History summary */
.summary-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  font-family: inherit;
  color: var(--text);
}

.summary-row.active {
  border-color: var(--green);
  background: var(--green-bg);
}

/* Settings & Schedule Editor */
.template-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.template-card.inactive {
  opacity: 0.65;
}

.template-title {
  font-size: 16px;
  font-weight: 600;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.template-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}

.weekday-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.weekday-btn {
  min-height: 42px;
  padding: 6px 2px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.weekday-btn.active {
  background: var(--green);
  border-color: var(--green);
  color: #FFFFFF;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  cursor: pointer;
}

.checkbox-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--green);
}

.status-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 14px;
}

.status-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.info-box {
  padding: 12px;
  border-radius: 10px;
  background: #F1F3F5;
  font-size: 14px;
  color: var(--text);
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}

.nav-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  min-height: 48px;
}

.nav-tab.active {
  color: var(--green);
}

.nav-icon {
  width: 22px;
  height: 22px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
}

@media (min-width: 560px) {
  .modal-backdrop {
    align-items: center;
  }
}

.modal-sheet {
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 14px;
  padding: 18px 16px calc(18px + var(--safe-bottom));
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
