:root {
  --bg: #f7f4ef;
  --panel: #fffdf9;
  --ink: #1d1a17;
  --muted: #756d63;
  --line: #e7ded3;
  --soft: #eee7dd;
  --brand: #111111;
  --accent: #a67642;
  --good: #176b4d;
  --warn: #a15c00;
  --danger: #a73a2b;
  --shadow: 0 12px 32px rgba(32, 25, 18, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: 100%;
  min-height: 100vh;
  max-width: 720px;
  margin: 0 auto;
  background: var(--bg);
}

.hidden {
  display: none !important;
}

.login-view {
  min-height: 100vh;
  padding: 28px 18px;
  display: grid;
  align-content: center;
  gap: 22px;
}

.brand-block {
  padding: 20px 2px;
}

.brand-mark {
  width: 58px;
  height: 58px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-block p,
.topbar p,
.eyebrow {
  margin: 12px 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.brand-block h1 {
  margin: 0;
  max-width: 420px;
  font-size: 34px;
  line-height: 1.08;
  letter-spacing: 0;
}

.login-panel,
.form-card,
.tool-panel,
.greeting-card,
.report-panel,
.boss-section,
.customer-card,
.detail-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-panel,
.form-card {
  padding: 16px;
  display: grid;
  gap: 14px;
}

.role-entry-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.role-entry {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.role-entry.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

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

.form-actions {
  display: grid;
  gap: 10px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 48px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

textarea {
  resize: vertical;
  line-height: 1.5;
}

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

.primary-action,
.secondary-action,
.small-button,
.icon-button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 800;
}

.primary-action {
  width: 100%;
  background: var(--brand);
  color: #fff;
}

.secondary-action {
  background: var(--soft);
  color: var(--ink);
}

.small-button {
  min-height: 40px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink);
}

.small-button.dark {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.icon-button {
  background: var(--soft);
  color: var(--ink);
  min-height: 40px;
}

.app-view {
  min-height: 100vh;
  padding-bottom: 116px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 14px 10px;
  background: rgba(247, 244, 239, 0.96);
  border-bottom: 1px solid var(--line);
}

.topbar > div:first-child {
  min-width: 0;
}

.topbar h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0;
}

.topbar-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.topbar-actions .icon-button {
  min-width: 58px;
  padding: 0 12px;
}

.sync-status {
  position: sticky;
  top: 67px;
  z-index: 19;
  padding: 7px 14px;
  border-bottom: 1px solid rgba(23, 107, 77, 0.18);
  background: #eef9f2;
  color: #0f5b3d;
  font-size: 12px;
  font-weight: 900;
  line-height: 1.3;
}

.sync-status[data-mode="syncing"] {
  background: #fff6d8;
  color: #715000;
}

.sync-status[data-mode="error"] {
  background: #ffe9e4;
  color: #9a2418;
}

main {
  padding: 14px;
}

.page {
  display: none;
}

.active-page {
  display: block;
}

.greeting-card {
  padding: 16px;
  margin-bottom: 12px;
}

.greeting-card h3 {
  margin: 0 0 8px;
  font-size: 22px;
}

.greeting-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.stat-card {
  min-height: 92px;
  padding: 14px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
}

.stat-card strong {
  display: block;
  font-size: 28px;
  line-height: 1;
}

.stat-card span {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.danger-card {
  border-color: rgba(167, 58, 43, 0.45);
  background: #fff3f0;
}

.danger-card strong,
.danger-card span {
  color: var(--danger);
}

.good-card {
  border-color: rgba(23, 107, 77, 0.35);
  background: #edf7f2;
}

.good-card strong,
.good-card span {
  color: var(--good);
}

.warn-card {
  border-color: rgba(161, 92, 0, 0.35);
  background: #fff7e6;
}

.warn-card strong,
.warn-card span {
  color: var(--warn);
}

.info-card {
  border-color: rgba(42, 93, 153, 0.3);
  background: #eff6ff;
}

.info-card strong,
.info-card span {
  color: #245995;
}

.home-focus {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}

.home-focus div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
}

.home-focus span {
  color: var(--muted);
  font-weight: 800;
}

.home-focus strong {
  color: var(--ink);
}

.sticky-action {
  margin-top: 14px;
}

.tool-panel {
  padding: 12px;
  margin-bottom: 12px;
}

.search-wrap {
  margin-bottom: 10px;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.filter-grid label:last-child {
  grid-column: 1 / -1;
}

.filter-grid select,
.filter-grid input {
  min-height: 42px;
  padding: 9px 10px;
}

.quick-filters {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.quick-chip {
  flex: 0 0 auto;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 13px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.quick-chip.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.card-list {
  display: grid;
  gap: 12px;
}

.service-hidden {
  display: none;
}

.service-progress {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.service-mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.service-mode-tabs button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 14px;
  font-weight: 900;
}

.service-mode-tabs button.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.service-progress div {
  min-height: 66px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.service-progress span,
.cockpit-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.service-progress strong,
.cockpit-grid strong {
  display: block;
  margin-top: 5px;
  font-size: 18px;
}

.progress-card-primary {
  border-color: rgba(23, 107, 77, 0.45) !important;
  background: #e9f8ef !important;
}

.progress-card-primary strong {
  color: #0f5b3d;
  font-size: 22px;
}

.progress-card-primary em {
  display: block;
  margin-top: 3px;
  color: #9a2418;
  font-size: 12px;
  font-style: normal;
  font-weight: 900;
}

.work-card {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.service-customer-list {
  display: grid;
  gap: 10px;
}

.work-card-done {
  border-color: rgba(23, 107, 77, 0.35);
}

.contact-strip {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  margin: 8px 0;
}

.contact-strip div {
  padding: 8px 10px;
  border: 1px solid rgba(23, 107, 77, 0.18);
  border-radius: 8px;
  background: #f0faf5;
}

.contact-line {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  column-gap: 8px;
}

.contact-strip span {
  display: block;
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.contact-strip strong {
  display: block;
  margin-top: 2px;
  color: #0f5b3d;
  font-size: 18px;
  line-height: 1.2;
  word-break: break-all;
}

.copy-phone-button {
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid rgba(15, 91, 61, 0.28);
  border-radius: 7px;
  background: #fff;
  color: #0f5b3d;
  font-size: 12px;
  font-weight: 900;
}

.ai-summary,
.priority-panel,
.script-box,
.task-done-panel {
  display: grid;
  gap: 5px;
  margin: 8px 0;
  padding: 9px 10px;
  border: 1px solid #cfe0f5;
  border-radius: 8px;
  background: #f8fbff;
  color: #1f4c75;
  line-height: 1.35;
}

.priority-panel {
  border-color: rgba(36, 89, 149, 0.18);
  color: var(--ink);
}

.priority-panel span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.priority-panel strong {
  font-size: 17px;
}

.priority-panel p {
  margin: 0;
  color: inherit;
}

.priority-green {
  border-color: rgba(23, 107, 77, 0.22);
  background: #eefaf5;
  color: #14553e;
}

.priority-yellow {
  border-color: rgba(182, 106, 0, 0.24);
  background: #fff8e9;
  color: #7c4b00;
}

.priority-red {
  border-color: rgba(177, 57, 43, 0.24);
  background: #fff1ef;
  color: #8b2c22;
}

.priority-blue {
  border-color: rgba(36, 89, 149, 0.24);
  background: #eef6ff;
  color: #1f4c75;
}

.ai-summary strong,
.script-box strong {
  color: #163a5f;
}

.big-action-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 8px 0;
}

.big-action {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  padding: 0 10px;
  color: #fff;
  font-size: 14px;
  font-weight: 900;
}

.result-main-action {
  grid-column: 1 / -1;
  min-height: 56px;
  background: #111111;
  font-size: 18px;
  letter-spacing: 0;
  box-shadow: 0 8px 16px rgba(17, 17, 17, 0.14);
}

.phone-action,
.good-action {
  background: var(--good);
}

.whatsapp-action {
  background: #128c7e;
}

.follow-action,
.neutral-action {
  background: #245995;
}

.boss-action {
  background: var(--danger);
}

.compact-next-action {
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #f7f3ed;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.task-summary {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.task-summary strong {
  font-size: 16px;
}

.task-summary span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.task-summary-danger {
  border-color: rgba(167, 58, 43, 0.45);
  background: #fff3f0;
}

.customer-card {
  padding: 14px;
}

.customer-card-danger {
  border-color: rgba(167, 58, 43, 0.45);
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.card-head h3 {
  margin: 0;
  font-size: 18px;
}

.grade-badge,
.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.task-status {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  background: #edf7f2;
  color: var(--good);
  font-size: 13px;
  font-weight: 900;
}

.task-status span {
  color: inherit;
  font-weight: 800;
}

.task-status-danger {
  background: #fff3f0;
  color: var(--danger);
}

.grade-a {
  color: #fff;
  background: var(--danger);
}

.grade-b {
  color: #fff;
  background: var(--warn);
}

.grade-c {
  color: #fff;
  background: var(--good);
}

.grade-d {
  color: var(--muted);
  background: var(--soft);
}

.status-badge {
  color: var(--ink);
  background: #f3eadf;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.meta-item {
  padding: 9px;
  border-radius: 8px;
  background: #faf7f1;
  border: 1px solid var(--line);
}

.meta-item span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.meta-item strong {
  display: block;
  margin-top: 4px;
  font-size: 13px;
  word-break: break-word;
}

.next-action {
  padding: 10px;
  border-radius: 8px;
  background: #fff;
  border: 1px dashed var(--line);
  color: var(--ink);
  line-height: 1.45;
}

.second-follow-reason {
  margin-top: 8px;
  padding: 10px;
  border-radius: 8px;
  background: #fff7e6;
  border: 1px solid rgba(172, 111, 28, 0.35);
  color: #7a4a08;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.45;
}

.assign-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 10px;
}

.assign-box select {
  min-height: 40px;
  padding: 8px 10px;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.button-grid .small-button {
  min-height: 52px;
  font-size: 14px;
}

.button-grid .wide {
  grid-column: 1 / -1;
}

.detail-card {
  padding: 14px;
  margin-bottom: 12px;
}

.detail-card h3,
.form-card h3,
.boss-section h3 {
  margin: 0 0 12px;
}

.history-list {
  display: grid;
  gap: 8px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.history-list li {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.history-list strong {
  display: block;
  margin-bottom: 4px;
}

.grade-rules {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.grade-rules strong {
  color: var(--ink);
  font-size: 13px;
}

.choice-section,
.ai-panel,
.auto-next-box {
  display: grid;
  gap: 9px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.choice-section strong,
.ai-panel strong {
  color: var(--ink);
  font-size: 14px;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.choice-grid button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #faf7f1;
  color: var(--ink);
  font-weight: 900;
}

.choice-grid button.active {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}

.checkbox-grid button.active {
  background: #edf7f2;
  border-color: rgba(38, 122, 87, 0.4);
  color: var(--good);
}

.compact-ai {
  background: #f8fbff;
  border-color: #cfe0f5;
  color: #1f4c75;
  font-size: 12px;
  line-height: 1.45;
}

.ai-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.ai-list li {
  padding: 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.75);
}

.auto-next-box {
  background: #fff7e6;
  border-color: rgba(172, 111, 28, 0.35);
  color: #7a4a08;
  font-weight: 900;
  font-size: 13px;
}

.fixed-save-action {
  position: fixed;
  left: 50%;
  bottom: calc(72px + env(safe-area-inset-bottom));
  z-index: 45;
  width: min(calc(100% - 28px), 692px);
  min-height: 58px;
  transform: translateX(-50%);
  box-shadow: 0 12px 28px rgba(17, 17, 17, 0.22);
}

.backup-path-panel {
  display: grid;
  gap: 7px;
  padding: 12px;
  border: 1px solid rgba(167, 58, 43, 0.35);
  border-radius: 8px;
  background: #fff3f0;
  color: var(--danger);
  font-size: 12px;
  line-height: 1.45;
}

.backup-path-panel strong {
  color: var(--danger);
  font-size: 14px;
}

.backup-path-panel span {
  word-break: break-word;
}

.backup-path-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 4px;
}

.muted {
  color: var(--muted);
  line-height: 1.5;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  font-weight: 800;
}

.inline-check input {
  width: 20px;
  height: 20px;
  margin: 0;
}

.control-flow {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.control-flow span {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--brand);
  font-weight: 900;
  text-align: center;
}

.cockpit-panel {
  background: #fffdf9;
}

.cockpit-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.cockpit-grid div {
  min-height: 76px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.sales-funnel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.compact-funnel {
  margin: 10px 0;
}

.funnel-step {
  padding: 10px;
  border-radius: 8px;
  color: #fff;
}

.funnel-step span {
  display: block;
  font-size: 12px;
  font-weight: 800;
  opacity: 0.92;
}

.funnel-step strong {
  display: block;
  margin-top: 3px;
  font-size: 20px;
}

.funnel-green {
  background: var(--good);
}

.funnel-yellow {
  background: var(--warn);
}

.funnel-red {
  background: var(--danger);
}

.funnel-blue {
  background: #245995;
}

.report-list,
.rank-list {
  display: grid;
  gap: 10px;
}

.report-row,
.rank-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.report-row span,
.rank-row span {
  color: var(--muted);
  font-weight: 700;
}

.report-row strong,
.rank-row strong {
  text-align: right;
}

.boss-section {
  padding: 14px;
  margin-bottom: 12px;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 30;
  width: 100%;
  max-width: 720px;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255, 253, 249, 0.98);
  border-top: 1px solid var(--line);
}

.bottom-nav button {
  min-height: 52px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.bottom-nav button.active {
  background: var(--brand);
  color: #fff;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 88px;
  z-index: 50;
  transform: translateX(-50%);
  width: min(92vw, 420px);
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  text-align: center;
  font-weight: 800;
}

.csv-hint {
  max-width: 100%;
  overflow: auto;
  padding: 12px;
  border-radius: 8px;
  background: #1f1f1f;
  color: #fff;
  font-size: 12px;
}

.import-result {
  color: var(--good);
  font-weight: 800;
}

.warning-text {
  margin: 0;
  color: #b42318;
  font-weight: 800;
}

.sync-note {
  margin: 0;
  color: var(--good);
  font-weight: 900;
  line-height: 1.5;
}

.danger-section {
  border-color: rgba(167, 58, 43, 0.5);
  background: #fff3f0;
}

.danger-section h3,
.danger-section p {
  color: var(--danger);
}

#importPage {
  display: none;
  gap: 12px;
}

#importPage.active-page {
  display: grid;
}

#followPage .form-card {
  padding-bottom: 92px;
}

@media (min-width: 640px) {
  .stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .filter-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .filter-grid label:last-child {
    grid-column: auto;
  }

  .card-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-grid,
  .form-actions,
  .backup-path-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .cockpit-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .sales-funnel {
    grid-template-columns: repeat(7, minmax(0, 1fr));
  }
}
