/* ===== Theme & Reset ===== */
:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-card: #0f3460;
  --bg-card-header: #1a4a7a;
  --bg-input: #233554;
  --bg-action-sheet: #1e2a3a;

  --text-primary: #e8e8e8;
  --text-secondary: #a0aec0;
  --text-muted: #6b7a8d;

  --accent: #4fc3f7;
  --accent-hover: #29b6f6;

  --status-confirmed: #4caf50;
  --status-confirmed-bg: rgba(76, 175, 80, 0.15);
  --status-assigned: #78909c;
  --status-assigned-bg: rgba(120, 144, 156, 0.15);
  --status-needs-sub: #ff9800;
  --status-needs-sub-bg: rgba(255, 152, 0, 0.15);
  --status-suggested: #9e9e9e;
  --status-suggested-bg: rgba(158, 158, 158, 0.1);

  --btn-confirm: #388e3c;
  --btn-confirm-hover: #2e7d32;
  --btn-needs-sub: #e65100;
  --btn-needs-sub-hover: #bf360c;
  --btn-revert: #546e7a;
  --btn-revert-hover: #455a64;

  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);

  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ===== Screens ===== */
.screen {
  min-height: 100dvh;
}

.screen[hidden] {
  display: none !important;
}

/* ===== Login ===== */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 32px 24px;
  box-shadow: var(--shadow);
}

.login-header {
  text-align: center;
  margin-bottom: 28px;
}

.login-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--accent);
}

.login-header .subtitle {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ===== Form fields ===== */
.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.field input,
.field select {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 1rem;
  outline: none;
  transition: border-color var(--transition);
  min-height: 44px;
}

.field input:focus,
.field select:focus {
  border-color: var(--accent);
}

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

.field select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23a0aec0' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), opacity var(--transition);
  min-height: 44px;
  padding: 10px 20px;
  color: #fff;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

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

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn-full {
  width: 100%;
}

.btn-primary {
  background: var(--accent);
  color: #0a1929;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 8px 12px;
  min-height: 36px;
  font-size: 0.8125rem;
}

.btn-ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.06);
}

.btn-small {
  font-size: 0.8125rem;
  min-height: 36px;
  padding: 6px 12px;
}

.btn-action {
  width: 100%;
  margin-bottom: 8px;
  font-size: 1rem;
  padding: 14px 20px;
  border-radius: var(--radius-sm);
}

.btn-confirm {
  background: var(--btn-confirm);
}

.btn-confirm:hover:not(:disabled) {
  background: var(--btn-confirm-hover);
}

.btn-needs-sub {
  background: var(--btn-needs-sub);
}

.btn-needs-sub:hover:not(:disabled) {
  background: var(--btn-needs-sub-hover);
}

.btn-revert {
  background: var(--btn-revert);
}

.btn-revert:hover:not(:disabled) {
  background: var(--btn-revert-hover);
}

.btn-action.active {
  outline: 2px solid #fff;
  outline-offset: -2px;
  opacity: 0.7;
}

/* ===== Spinner ===== */
.btn-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto 12px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== Error message ===== */
.error-msg {
  margin-top: 12px;
  padding: 10px 14px;
  background: rgba(244, 67, 54, 0.12);
  border: 1px solid rgba(244, 67, 54, 0.3);
  border-radius: var(--radius-sm);
  color: #ef5350;
  font-size: 0.875rem;
  text-align: center;
}

/* ===== App Header ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header h1 {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--accent);
}

.schedule-toolbar {
  display: flex;
  justify-content: flex-end;
  padding: 8px 16px 4px;
}

.refresh-icon {
  font-size: 1.1rem;
}

/* ===== Loading ===== */
.loading {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-secondary);
}

/* ===== Empty state ===== */
.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
  font-size: 0.9375rem;
}

/* ===== Meeting List ===== */
.meeting-list {
  padding: 8px 12px 24px;
}

/* ===== Meeting Card ===== */
.meeting-card {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.meeting-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  min-height: 52px;
  transition: background var(--transition);
}

.meeting-card-header:active {
  background: rgba(255, 255, 255, 0.04);
}

.meeting-card-header .date {
  font-size: 0.9375rem;
  font-weight: 600;
}

.meeting-card-header .chevron {
  font-size: 0.75rem;
  color: var(--text-muted);
  transition: transform var(--transition);
}

.meeting-card.expanded .chevron {
  transform: rotate(180deg);
}

.meeting-card-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s ease;
}

.meeting-card.expanded .meeting-card-body {
  max-height: 2000px;
}

.meeting-card-content {
  padding: 0 16px 16px;
}

.week-text {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: 14px;
  font-style: italic;
}

/* ===== Section Headers ===== */
.section-header {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  padding: 10px 0 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  margin-bottom: 2px;
}

.section-header.roles-header {
  color: var(--accent);
}

.section-header.treasures {
  color: #8d6e63;
}

.section-header.field-ministry {
  color: #ffb74d;
}

.section-header.living {
  color: #ef5350;
}

/* ===== Assignment / Role Rows ===== */
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 4px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  min-height: 44px;
  transition: background var(--transition);
}

.row:last-child {
  border-bottom: none;
}

.row:active {
  background: rgba(255, 255, 255, 0.04);
}

.row-left {
  flex: 1;
  min-width: 0;
  margin-right: 8px;
}

.row-title {
  font-size: 0.875rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-assistant {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-top: 2px;
  padding-left: 12px;
}

.row-right {
  flex-shrink: 0;
}

/* ===== Status Pill ===== */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 100px;
  white-space: nowrap;
}

.status-pill.confirmed {
  background: var(--status-confirmed-bg);
  color: var(--status-confirmed);
}

.status-pill.assigned {
  background: var(--status-assigned-bg);
  color: var(--status-assigned);
}

.status-pill.needs-sub {
  background: var(--status-needs-sub-bg);
  color: var(--status-needs-sub);
}

.status-pill.suggested {
  background: var(--status-suggested-bg);
  color: var(--status-suggested);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.confirmed { background: var(--status-confirmed); }
.status-dot.assigned { background: var(--status-assigned); }
.status-dot.needs-sub { background: var(--status-needs-sub); }
.status-dot.suggested { background: var(--status-suggested); }

/* ===== Action Sheet ===== */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 200;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.backdrop.visible {
  opacity: 1;
}

.action-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-action-sheet);
  border-radius: var(--radius) var(--radius) 0 0;
  z-index: 201;
  transform: translateY(100%);
  transition: transform 0.3s ease;
  max-height: 85dvh;
  overflow-y: auto;
  padding-bottom: calc(16px + var(--safe-bottom));
}

.action-sheet.visible {
  transform: translateY(0);
}

.action-sheet-handle {
  width: 36px;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  margin: 10px auto 8px;
}

.action-sheet-header {
  padding: 8px 20px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.action-sheet-header h3 {
  font-size: 1rem;
  font-weight: 600;
}

.action-sheet-person {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

.action-sheet-assistant {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.action-sheet-body {
  padding: 16px 20px 8px;
}

.action-close-btn {
  margin: 0 20px 4px;
  width: calc(100% - 40px);
}

/* ===== Needs-Sub Form ===== */
.needs-sub-form {
  padding: 12px 0 8px;
}

.needs-sub-form .field {
  margin-bottom: 12px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  left: 16px;
  right: 16px;
  padding: 12px 16px;
  background: #333;
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.875rem;
  text-align: center;
  z-index: 300;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  box-shadow: var(--shadow);
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  background: #b71c1c;
}

.toast.success {
  background: #2e7d32;
}

/* ===== Responsive ===== */
@media (min-width: 600px) {
  .meeting-list {
    max-width: 560px;
    margin: 0 auto;
    padding: 16px;
  }

  .login-card {
    padding: 40px 32px;
  }

  .action-sheet {
    max-width: 480px;
    left: 50%;
    transform: translate(-50%, 100%);
  }

  .action-sheet.visible {
    transform: translate(-50%, 0);
  }
}

/* Person name on assignment/role rows */
.row-person {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* Assistant row styling for 2-person parts */
.asst-tag {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: normal;
}
.row-assistant-row {
  border-left: 3px solid var(--text-secondary);
  margin-left: 0.5rem;
  padding-left: 0.75rem;
}
