/* Palet warna mengikuti aplikasi Android TimeCraft - dasar putih bersih (gaya Stockbit) + aksen
   warna berani di kartu/status. --bg sebelumnya krem hangat, diganti putih polos supaya latar
   tidak "menyaingi" warna aksen kartu/ikon yang justru ingin ditonjolkan. */
:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-alt: #f1e4d8;
  --primary: #e2632f;
  --primary-contrast: #ffffff;
  --text: #2c2117;
  --text-muted: #7a6a5c;
  --border: #ecdfd2;
  --error-bg: #fbe4de;
  --error-text: #9c3b23;
  --success-bg: #e3f0e1;
  --success-text: #2f6b2a;
  --warn-bg: #fbeecf;
  --warn-text: #8a6414;
  --shadow: 0 2px 10px rgba(44, 33, 23, 0.08);
}

* { box-sizing: border-box; }

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

#app { min-height: 100vh; display: flex; flex-direction: column; }

button { font-family: inherit; }

/* --- Login --- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--surface);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
  width: 100%;
  max-width: 380px;
}
.login-card h1 { margin: 0 0 4px; font-size: 26px; }
.login-card p.subtitle { margin: 0 0 24px; color: var(--text-muted); font-size: 14px; }

/* --- Form fields --- */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text-muted); }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
}
.field textarea { resize: vertical; min-height: 70px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 18px;
  border-radius: 12px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--primary-contrast); }
.btn-outline { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-danger { background: var(--error-text); color: white; }
.btn-text { background: transparent; color: var(--text-muted); }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 13px; }

/* --- Top bar & tabs --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar .brand { font-size: 20px; font-weight: 800; color: var(--text); }
.topbar .actions { display: flex; gap: 8px; align-items: center; }

.tabs {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tab {
  flex: 1;
  min-width: 110px;
  text-align: center;
  padding: 13px 10px;
  cursor: pointer;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 14px;
  border-bottom: 3px solid transparent;
  position: relative;
  white-space: nowrap;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab .badge { margin-left: 4px; }

.content { flex: 1; padding: 20px; max-width: 900px; width: 100%; margin: 0 auto; }

/* --- Cards --- */
.card {
  background: var(--surface);
  border-radius: 18px;
  box-shadow: var(--shadow);
  /* Garis tepi tipis - sejak --bg & --surface sama-sama putih, kartu perlu penanda batas
     selain bayangan supaya tetap kelihatan jelas terpisah dari latar. */
  border: 1px solid var(--border);
  padding: 20px;
  margin-bottom: 16px;
}
.card h2, .card h3 { margin-top: 0; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-card {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 16px;
  /* border dulu (4 sisi tipis untuk batas dari latar putih), border-top BELAKANGAN supaya
     menimpa sisi atas jadi lebih tebal + warna aksen (lihat .stat-card-* di bawah). */
  border: 1px solid var(--border);
  border-top: 4px solid transparent;
}
.stat-card .value { font-size: 28px; font-weight: 800; }
.stat-card .label { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

/* Warna aksen per kartu ringkasan Dashboard - lebih hidup daripada kartu putih polos sebelumnya. */
.stat-card-approval { border-top-color: var(--warn-text); }
.stat-card-approval .value { color: var(--warn-text); }
.stat-card-children { border-top-color: var(--primary); }
.stat-card-children .value { color: var(--primary); }
.stat-card-locked { border-top-color: var(--error-text); }
.stat-card-locked .value { color: var(--error-text); }
.stat-card-tasks { border-top-color: var(--success-text); }
.stat-card-tasks .value { color: var(--success-text); }

.family-code {
  display: inline-block;
  background: #fbe0d0;
  color: var(--primary);
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 14px;
}

/* --- Filters --- */
.filter-row { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.filter-row select { min-width: 160px; }

/* --- Task rows --- */
.task-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow);
  margin-bottom: 8px;
  cursor: pointer;
}
.task-row:hover { background: var(--surface-alt); }
.task-row .info { flex: 1; min-width: 0; }
.task-row .title { font-weight: 700; }
.task-row .meta { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

.status-chip { display: inline-flex; align-items: center; padding: 5px 12px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.status-assigned { background: var(--surface-alt); color: var(--text-muted); }
.status-submitted { background: var(--warn-bg); color: var(--warn-text); }
.status-approved { background: var(--success-bg); color: var(--success-text); }
.status-rejected { background: var(--error-bg); color: var(--error-text); }

.empty-hint { color: var(--text-muted); padding: 20px 0; text-align: center; }

/* --- Approval card --- */
.approval-card { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.approval-card .title { font-weight: 700; font-size: 16px; }
.approval-card .meta { color: var(--text-muted); font-size: 13px; margin: 4px 0 10px; }
.approval-card .evidence-text { font-size: 14px; margin-bottom: 10px; }
.approval-actions { display: flex; gap: 8px; margin-top: 12px; }
.approval-actions .btn { flex: 1; }
.reject-form { margin-top: 10px; display: none; }
.reject-form.open { display: block; }

/* --- Evidence gallery --- */
.evidence-gallery { display: flex; gap: 10px; flex-wrap: wrap; margin: 10px 0; }
.evidence-thumb {
  width: 84px;
  height: 84px;
  border-radius: 12px;
  background: var(--surface-alt);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  padding: 4px;
  border: none;
}
.evidence-thumb img { width: 100%; height: 100%; object-fit: cover; }

/* --- Modal --- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(44, 33, 23, 0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  z-index: 50;
}
.modal {
  background: var(--surface);
  border-radius: 20px;
  max-width: 480px;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  padding: 24px;
}
.modal h2 { margin-top: 0; }
.modal-close-row { display: flex; justify-content: flex-end; margin-top: 20px; gap: 8px; }

/* --- Banners --- */
.banner { border-radius: 14px; padding: 14px 16px; margin-bottom: 14px; font-size: 14px; }
.banner-error { background: var(--error-bg); color: var(--error-text); }
.banner-info { background: var(--success-bg); color: var(--success-text); }
.banner .close { float: right; background: none; border: none; color: inherit; font-weight: 700; cursor: pointer; }

/* --- Image preview --- */
.image-preview img { max-width: 100%; border-radius: 12px; }

.loading-bar {
  position: fixed; top: 0; left: 0; right: 0; height: 3px;
  background: var(--primary);
  z-index: 100;
  animation: loading-pulse 1s ease-in-out infinite;
}
@keyframes loading-pulse { 0%, 100% { opacity: 0.4; } 50% { opacity: 1; } }

/* --- Kunci Perangkat --- */
.lock-summary { font-weight: 700; margin-bottom: 14px; }
.lock-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 8px;
  font-weight: 600;
}

.switch { position: relative; display: inline-block; width: 44px; height: 26px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute; cursor: pointer; inset: 0;
  /* Sedikit lebih gelap dari --border supaya track "nonaktif" tetap terlihat jelas di atas --bg krem. */
  background: #d9c6b2;
  border-radius: 999px;
  transition: background 0.15s;
}
.switch-slider::before {
  content: ""; position: absolute; height: 20px; width: 20px; left: 3px; top: 3px;
  background: white; border-radius: 50%; transition: transform 0.15s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
/* Merah pekat (bukan oranye --primary yang dipakai di mana-mana) saat TERKUNCI - kontras lebih
   tinggi dan lebih jelas maknanya ("terkunci/dibatasi") daripada warna aksen oranye biasa. */
.switch input:checked + .switch-slider { background: var(--error-text); }
.switch input:checked + .switch-slider::before { transform: translateX(18px); }
.switch input:disabled + .switch-slider { opacity: 0.5; cursor: not-allowed; }

/* --- Pengaturan --- */
.settings-child-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}
.settings-child-row:last-of-type { border-bottom: none; }
.settings-child-row > span:first-child { font-weight: 600; }
.settings-child-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* --- Log Aktivitas --- */
.activity-log-list { display: flex; flex-direction: column; gap: 2px; max-height: 420px; overflow-y: auto; }
.activity-log-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.activity-log-row:last-child { border-bottom: none; }
.activity-log-main { min-width: 0; }
.activity-log-actor { font-weight: 700; }
.activity-log-role { color: var(--text-muted); font-size: 12px; }
.activity-log-detail { color: var(--text-muted); }
.activity-log-time { color: var(--text-muted); font-size: 12px; white-space: nowrap; flex-shrink: 0; }

/* --- Dashboard: tugas belum selesai per anak --- */
.dash-child-group { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.dash-child-group:first-of-type { margin-top: 4px; padding-top: 0; border-top: none; }
.dash-child-name { font-weight: 700; margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
.dash-task-mini-empty { color: var(--text-muted); font-size: 13px; padding: 4px 0 2px; }
.dash-task-mini {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  background: var(--surface-alt);
  border-radius: 10px;
  margin-bottom: 6px;
  cursor: pointer;
  font-size: 14px;
}
.dash-task-mini .title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- Dashboard: pratinjau chat grup --- */
.dash-chat-row {
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 6px;
  align-items: baseline;
}
.dash-chat-row:last-of-type { border-bottom: none; }
.dash-chat-sender { font-weight: 700; }
.dash-chat-text { color: var(--text); flex: 1; min-width: 0; }
.dash-chat-time { color: var(--text-muted); font-size: 12px; }

/* --- Sub-tabs (pemilih thread chat, di bawah menu utama - lihat .subtabs) --- */
.subtabs {
  display: flex;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.subtab {
  padding: 9px 16px;
  cursor: pointer;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 13px;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.subtab.active { color: var(--primary); border-bottom-color: var(--primary); background: var(--surface); }
.subtab .badge { margin-left: 4px; }

/* --- Chat --- */
/* +42px dari versi sebelumnya - menyisakan ruang untuk .subtabs yang sekarang selalu tampil bareng tab Chat. */
.content-chat { display: flex; flex-direction: column; height: calc(100vh - 172px); padding-bottom: 0; }
.chat-wrap { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chat-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 2px 16px;
}
.chat-row { display: flex; }
.chat-row.mine { justify-content: flex-end; }
.chat-bubble {
  max-width: 78%;
  background: var(--surface);
  box-shadow: var(--shadow);
  border-radius: 16px;
  padding: 10px 14px;
}
.chat-row.mine .chat-bubble { background: var(--primary); color: var(--primary-contrast); }
.chat-sender { font-size: 12px; font-weight: 700; color: var(--text-muted); margin-bottom: 2px; }
.chat-time { font-size: 11px; opacity: 0.7; margin-top: 4px; text-align: right; }
.chat-photo-slot {
  width: 180px; height: 180px;
  border-radius: 12px;
  background: var(--surface-alt);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
}
.chat-photo-slot img { width: 100%; height: 100%; object-fit: cover; }

.chat-composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 2px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.chat-composer input[type="text"] {
  flex: 1;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 15px;
}
.chat-photo-btn { cursor: pointer; white-space: nowrap; }

/* --- Chat: kutipan balasan --- */
.chat-quote {
  border-left: 3px solid currentColor;
  opacity: 0.85;
  padding: 4px 8px;
  margin-bottom: 6px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.06);
  font-size: 13px;
}
.chat-quote-sender { font-weight: 700; margin-right: 6px; }
.chat-quote-text { opacity: 0.9; }

/* --- Chat: reaksi emoji --- */
.chat-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.chat-reaction-pill {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  cursor: pointer;
}
.chat-row.mine .chat-reaction-pill { background: rgba(255, 255, 255, 0.15); border-color: rgba(255, 255, 255, 0.4); color: inherit; }
.chat-reaction-pill.mine { border-color: var(--primary); font-weight: 700; }
.chat-reaction-picker {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  padding: 6px 8px;
  background: var(--surface);
  border-radius: 999px;
  box-shadow: var(--shadow);
}
.chat-row.mine .chat-reaction-picker { background: var(--surface); } /* selalu terang - popovernya lepas dari warna bubble sendiri */
.chat-reaction-picker button {
  border: none;
  background: none;
  font-size: 18px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 6px;
}
.chat-reaction-picker button:hover { background: var(--surface-alt); }

/* --- Chat: tombol balas/reaksi di tiap bubble --- */
.chat-bubble-actions { display: flex; gap: 10px; margin-top: 4px; }
.chat-action-btn {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 11px;
  color: inherit;
  opacity: 0.75;
  padding: 0;
}
.chat-action-btn:hover { opacity: 1; text-decoration: underline; }

/* --- Chat: strip "sedang membalas" di atas composer --- */
.chat-reply-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface-alt);
  border-radius: 10px;
  margin: 0 2px 8px;
  font-size: 13px;
  border-left: 3px solid var(--primary);
}
.chat-reply-strip-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-reply-strip-close { border: none; background: none; font-size: 18px; cursor: pointer; color: var(--text-muted); line-height: 1; }

/* --- Dashboard: kartu ringkasan yang bisa diklik --- */
.stat-card-clickable { cursor: pointer; transition: transform 0.1s, box-shadow 0.1s; }
.stat-card-clickable:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(44, 33, 23, 0.14); }

@media (max-width: 480px) {
  .content { padding: 14px; }
  .tab { font-size: 12px; padding: 12px 6px; }
}
