:root {
  --bg: #F6F4EF;
  --surface: #FFFEFB;
  --surface-soft: #F0EDE5;
  --ink: #2C2A26;
  --ink-soft: #6B665C;
  --line: #E4DFD4;
  --sage: #6E7F5C;
  --sage-dark: #556345;
  --sage-soft: #E7EDE1;
  --warm: #C4A37A;
  --danger: #A65D4E;
  --pending: #B08D57;
  --shadow: 0 10px 30px rgba(44, 42, 38, 0.06);
  --radius: 18px;
  --font-body: 'IBM Plex Sans Arabic', system-ui, sans-serif;
  --font-display: 'Noto Kufi Arabic', 'IBM Plex Sans Arabic', system-ui, sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100dvh;
}

button, input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: none;
}

ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

.app {
  width: min(480px, 100%);
  margin: 0 auto;
  min-height: 100dvh;
  padding:
    calc(16px + var(--safe-top))
    16px
    calc(88px + var(--safe-bottom));
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.topbar h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.status-cluster {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #F4E8D4;
  color: #7A5A24;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge.offline {
  background: #F3E2DE;
  color: var(--danger);
}

.badge.syncing {
  background: var(--sage-soft);
  color: var(--sage-dark);
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 1.1rem;
  line-height: 1;
}

.icon-btn:active {
  transform: scale(0.96);
}

.content {
  display: grid;
  gap: 14px;
}

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

.card.primary {
  border-color: #D5DFCB;
  background: linear-gradient(180deg, #FFFEFB 0%, #F8FAF5 100%);
}

.card.journal {
  background: linear-gradient(180deg, #FFFEFB 0%, #F7F2EA 100%);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.section-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
}

.count {
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-soft);
  color: var(--ink-soft);
  font-size: 0.8rem;
  font-weight: 600;
}

.capture-form {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

#captureInput {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 14px;
  padding: 14px 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#captureInput:focus {
  border-color: var(--sage);
  box-shadow: 0 0 0 3px rgba(110, 127, 92, 0.15);
}

.type-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.type-chip {
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid transparent;
}

.type-chip.active {
  background: var(--sage-soft);
  color: var(--sage-dark);
  border-color: #C9D6BE;
}

.primary-btn,
.secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 16px;
  border-radius: 14px;
  font-weight: 700;
}

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

.primary-btn:active {
  background: var(--sage-dark);
}

.primary-btn:disabled {
  opacity: 0.6;
}

.secondary-btn {
  width: 100%;
  background: var(--surface-soft);
  color: var(--sage-dark);
  border: 1px solid var(--line);
}

.list {
  display: grid;
  gap: 8px;
}

.item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-radius: 14px;
  background: var(--surface-soft);
  border: 1px solid transparent;
}

.item.pending {
  border-color: #E7D4B0;
  background: #FFF8EC;
}

.item.done .item-title {
  color: var(--ink-soft);
  text-decoration: line-through;
}

.check {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 2px solid #B7C2AB;
  background: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: transparent;
  font-size: 0.85rem;
  flex: 0 0 auto;
}

.check.on {
  background: var(--sage);
  border-color: var(--sage);
  color: #fff;
}

.item-main {
  min-width: 0;
}

.item-title {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 600;
  line-height: 1.45;
  word-break: break-word;
}

.item-meta {
  margin: 3px 0 0;
  color: var(--ink-soft);
  font-size: 0.78rem;
}

.ghost-btn {
  padding: 8px 10px;
  border-radius: 10px;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.7);
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.ghost-btn:active {
  background: #fff;
}

.empty {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
  line-height: 1.6;
}

.journal-prompt {
  margin: 0 0 12px;
  color: var(--ink-soft);
  line-height: 1.7;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(78px + var(--safe-bottom));
  transform: translateX(-50%);
  max-width: min(420px, calc(100% - 24px));
  padding: 12px 16px;
  border-radius: 14px;
  background: #2C2A26;
  color: #fff;
  font-size: 0.9rem;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
  z-index: 20;
}

.skeleton .item {
  min-height: 54px;
  background: linear-gradient(90deg, #EFEBE3, #F7F4EE, #EFEBE3);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite linear;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

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

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(480px, 100%);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px 16px calc(10px + var(--safe-bottom));
  background: rgba(255, 254, 251, 0.94);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(10px);
  z-index: 15;
}

.nav-btn {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 8px 10px;
  border-radius: 14px;
  color: var(--ink-soft);
  font-size: 0.78rem;
  font-weight: 600;
}

.nav-btn.active {
  background: var(--sage-soft);
  color: var(--sage-dark);
}

.nav-icon {
  font-size: 1.15rem;
  line-height: 1;
}

.muted-card {
  background: #F3F0E8;
  box-shadow: none;
}

.collapse-head {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: right;
}

.section-head-inline {
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-head-inline h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
}

.chevron {
  color: var(--ink-soft);
  transition: transform 0.15s ease;
}

.collapse-head[aria-expanded="true"] .chevron {
  transform: rotate(180deg);
}

.collapse-body {
  margin-top: 12px;
}

.step-group {
  margin-top: 10px;
}

.step-group:first-child {
  margin-top: 0;
}

.step-group-label {
  margin: 0 0 8px;
  color: var(--sage-dark);
  font-size: 0.86rem;
  font-weight: 700;
}

.quiet-list .item {
  background: rgba(255, 255, 255, 0.55);
  padding: 10px 12px;
}

.quiet-list .item-title {
  font-size: 0.9rem;
  font-weight: 500;
}

.quiet-list .item-meta {
  font-size: 0.74rem;
}

.follow-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  font-weight: 600;
}

.follow-badge::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--pending);
}

.follow-badge.watch::before {
  background: #8A9BB0;
}

.follow-badge.deadline::before {
  background: #B08D57;
}

.action-icon {
  width: 28px;
  text-align: center;
  flex: 0 0 auto;
}

.kanban {
  display: grid;
  gap: 12px;
}

.kanban-col {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  min-height: 120px;
}

.kanban-col-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.kanban-col-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1rem;
}

.kanban-list {
  display: grid;
  gap: 8px;
  min-height: 48px;
}

.kanban-card {
  display: grid;
  gap: 4px;
  padding: 12px;
  border-radius: 14px;
  background: var(--surface-soft);
  border: 1px solid transparent;
  touch-action: none;
  user-select: none;
  cursor: grab;
}

.kanban-card:active {
  cursor: grabbing;
}

.kanban-card.sortable-ghost {
  opacity: 0.45;
}

.kanban-card.sortable-chosen {
  border-color: #C9D6BE;
  background: #F8FAF5;
  box-shadow: var(--shadow);
}

.kanban-card.pending {
  border-color: #E7D4B0;
  background: #FFF8EC;
}

.kanban-card-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.4;
}

.kanban-card-meta {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.78rem;
}

.kanban-card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
}

.kanban-empty {
  text-align: center;
  margin-top: 8px;
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 30;
}

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

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(44, 42, 38, 0.35);
}

.sheet-panel {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(480px, 100%);
  max-height: min(92dvh, 820px);
  overflow: auto;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -12px 40px rgba(44, 42, 38, 0.16);
  padding: 16px 16px calc(20px + var(--safe-bottom));
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.sheet-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.1rem;
}

.step-form {
  display: grid;
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field > span {
  color: var(--ink-soft);
  font-size: 0.84rem;
  font-weight: 600;
}

.field input,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 14px;
  padding: 12px 14px;
  outline: none;
}

.field input:focus,
.field select:focus {
  border-color: var(--sage);
  box-shadow: 0 0 0 3px rgba(110, 127, 92, 0.15);
}

.ac-wrap {
  position: relative;
}

.ac-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 5;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  max-height: 220px;
  overflow: auto;
}

.ac-list button {
  width: 100%;
  text-align: right;
  padding: 10px 12px;
  border-radius: 10px;
  font-weight: 600;
}

.ac-list button:active,
.ac-list button:hover {
  background: var(--sage-soft);
}

.ac-list small {
  color: var(--ink-soft);
  font-weight: 500;
  margin-right: 6px;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--sage-soft);
  color: var(--sage-dark);
  font-size: 0.84rem;
  font-weight: 600;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

