:root {
  --bg: #f3f4f6; --card: #fff; --text: #111827; --muted: #6b7280; --line: #e5e7eb;
  --brand: #f59e0b; --dark: #1f2937; --ok: #059669; --warn: #d97706; --bad: #dc2626;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 16px;
  padding-bottom: env(safe-area-inset-bottom);
}
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px;
  background: var(--dark); color: #fff; padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
}
.topbar h1 { font-size: 19px; margin: 0; flex: 1; }
.project-chip { font-size: 13px; background: var(--brand); color: var(--dark); padding: 3px 10px; border-radius: 99px; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-chip:empty { display: none; }
.icon-btn { background: none; border: 0; color: #fff; font-size: 24px; padding: 0 4px; cursor: pointer; }
main { padding: 16px; max-width: 760px; margin: 0 auto; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  background: var(--card); border-radius: 14px; padding: 18px 12px; text-align: center;
  text-decoration: none; color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08);
  display: flex; flex-direction: column; align-items: center; gap: 6px; border: 0; font: inherit; cursor: pointer;
}
.tile .ic { font-size: 34px; }
.tile b { font-size: 16px; }
.tile small { color: var(--muted); font-size: 13px; }
.tile.soon { opacity: .55; }

.card { background: var(--card); border-radius: 14px; padding: 14px; margin-bottom: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.card h3 { margin: 0 0 6px; font-size: 17px; }
.list-item { display: flex; gap: 12px; align-items: center; text-decoration: none; color: inherit; }
.list-item img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; flex: none; }
.list-item .body { flex: 1; min-width: 0; }
.list-item .meta { color: var(--muted); font-size: 13px; }

label { display: block; font-weight: 600; margin: 12px 0 4px; font-size: 15px; }
input, select, textarea {
  width: 100%; font: inherit; padding: 11px 12px; border: 1px solid #d1d5db; border-radius: 10px; background: #fff;
}
textarea { min-height: 90px; resize: vertical; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--dark); color: #fff; border: 0; border-radius: 12px; padding: 13px 16px;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; width: 100%; margin-top: 14px;
}
.btn.brand { background: var(--brand); color: var(--dark); }
.btn.light { background: #e5e7eb; color: var(--text); }
.btn.danger { background: #fee2e2; color: var(--bad); }
.btn.small { width: auto; padding: 8px 12px; margin: 0; font-size: 14px; }
.fab {
  position: fixed; bottom: calc(20px + env(safe-area-inset-bottom)); left: 20px; width: 60px; height: 60px; border-radius: 50%;
  background: var(--brand); color: var(--dark); font-size: 32px; border: 0; box-shadow: 0 4px 12px rgba(0,0,0,.25); cursor: pointer;
}

.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; font-weight: 600; }
.b-open { background: #fee2e2; color: var(--bad); }
.b-progress { background: #fef3c7; color: var(--warn); }
.b-done { background: #d1fae5; color: var(--ok); }
.b-high { background: var(--bad); color: #fff; }
.b-mid { background: var(--warn); color: #fff; }
.b-low { background: #9ca3af; color: #fff; }

.tabs { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; }
.tabs button { flex: none; border: 0; background: #e5e7eb; padding: 8px 14px; border-radius: 99px; font: inherit; font-size: 14px; cursor: pointer; }
.tabs button.on { background: var(--dark); color: #fff; }

.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.photos .ph { position: relative; }
.photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; display: block; }
.photos .x { position: absolute; top: 4px; left: 4px; background: rgba(0,0,0,.6); color: #fff; border: 0; border-radius: 50%; width: 26px; height: 26px; cursor: pointer; }
.photo-add { border: 2px dashed #d1d5db; border-radius: 10px; aspect-ratio: 1; display: flex; align-items: center; justify-content: center; flex-direction: column; color: var(--muted); font-size: 13px; cursor: pointer; background: #fff; }
.photo-add span { font-size: 28px; }

.manpower-row { display: flex; gap: 6px; margin-bottom: 6px; }
.manpower-row input:first-child { flex: 2; }
.manpower-row input { flex: 1; }
.manpower-row button { flex: none; }

.check { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-weight: normal; margin: 0; }
.check input { width: 22px; height: 22px; flex: none; }

.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.empty .ic { font-size: 48px; }
.stat-row { display: flex; gap: 8px; margin-bottom: 12px; }
.stat { flex: 1; background: var(--card); border-radius: 12px; padding: 10px; text-align: center; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.stat b { display: block; font-size: 22px; }
.stat small { color: var(--muted); font-size: 12px; }

.chat { display: flex; flex-direction: column; gap: 8px; margin-bottom: 120px; }
.msg { padding: 10px 12px; border-radius: 14px; max-width: 88%; white-space: pre-wrap; line-height: 1.45; }
.msg.user { background: var(--dark); color: #fff; align-self: flex-start; }
.msg.ai { background: var(--card); align-self: flex-end; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.chat-input { position: fixed; bottom: 0; right: 0; left: 0; background: var(--bg); padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); display: flex; gap: 8px; border-top: 1px solid var(--line); }
.chat-input textarea { min-height: 46px; height: 46px; }
.chat-input .btn { width: auto; margin: 0; }
.hint { color: var(--muted); font-size: 13px; margin-top: 4px; }

.toast { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); background: var(--dark); color: #fff; padding: 10px 18px; border-radius: 99px; z-index: 50; font-size: 14px; }

/* PDF document (rendered off-screen) */
.pdf-doc { letter-spacing: 0.01px; width: 760px; background: #fff; color: #000; padding: 28px; font-size: 13px; direction: rtl; }
.pdf-doc h1 { font-size: 22px; margin: 0 0 4px; }
.pdf-doc .hdr { border-bottom: 3px solid var(--brand); padding-bottom: 10px; margin-bottom: 14px; }
.pdf-doc table { width: 100%; border-collapse: collapse; margin: 8px 0 14px; }
.pdf-doc td, .pdf-doc th { border: 1px solid #ccc; padding: 6px; text-align: right; vertical-align: top; }
.pdf-doc th { background: #f3f4f6; }
.pdf-doc .def { border: 1px solid #ccc; border-radius: 6px; padding: 10px; margin-bottom: 10px; page-break-inside: avoid; }
.pdf-doc .def img { width: 31%; height: 150px; object-fit: cover; margin: 4px 0 0 1%; border-radius: 4px; }
.pdf-doc .sign { display: flex; gap: 30px; margin-top: 30px; }
.pdf-doc .sign div { flex: 1; border-top: 1px solid #000; padding-top: 4px; text-align: center; }

.bell { position: relative; text-decoration: none; font-size: 22px; }
.bell span { position: absolute; top: -6px; left: -8px; background: var(--bad); color: #fff; font-size: 11px; border-radius: 99px; padding: 1px 5px; font-weight: 700; }
.bell span:empty { display: none; }
details summary { cursor: pointer; }
