:root {
	--bg: #f3efe6;
	--surface: #ffffff;
	--surface-2: #faf8f2;
	--border: #e2d8c2;
	--border-strong: #cfc2a3;
	--ink: #221f18;
	--muted: #756f5e;
	--muted-2: #a39a82;

	--brand: #1e5f74;
	--brand-dark: #164a5a;
	--brand-light: #dfeef1;

	--amber: #b96f1e;
	--amber-light: #f6e6cb;

	--ok: #2f7d53;
	--ok-light: #dcefe2;

	--danger: #ae3b2e;
	--danger-light: #f6ded9;

	--radius-sm: 8px;
	--radius-md: 12px;
	--radius-lg: 18px;

	--shadow-sm: 0 1px 2px rgba(34, 31, 24, 0.06);
	--shadow-md: 0 4px 14px rgba(34, 31, 24, 0.08);
	--shadow-lift: 0 8px 24px rgba(34, 31, 24, 0.12);

	color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
	margin: 0;
	font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	font-size: 16px;
	line-height: 1.55;
	background: var(--bg);
	color: var(--ink);
	padding-bottom: 4.75rem; /* espacio para la barra inferior en celular */
	-webkit-font-smoothing: antialiased;
}

/* En celular, todo el texto/espaciado (que usa rem) escala un poco más
   grande — la app se usa casi siempre desde el celular en campo. */
@media (max-width: 719px) {
	html { font-size: 18px; }
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: var(--brand-light); color: var(--brand-dark); }

h1, h2, h3, h4 {
	font-family: "Sora", "Inter", system-ui, sans-serif;
	font-weight: 700;
	letter-spacing: -0.01em;
	color: var(--ink);
	text-wrap: balance;
}
h1 { font-size: 1.5rem; margin: .1rem 0 1.1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .8rem; }
h3 { font-size: 1rem; margin: 0; font-weight: 600; }

/* --- Barra superior --- */
.topbar {
	display: flex;
	align-items: center;
	gap: .8rem;
	padding: .8rem 1.1rem;
	background: var(--surface);
	border-bottom: 1px solid var(--border);
	box-shadow: var(--shadow-sm);
	position: sticky;
	top: 0;
	z-index: 20;
}
.topbar .brand {
	display: flex;
	align-items: center;
	gap: .5rem;
	font-family: "Sora", sans-serif;
	font-weight: 700;
	font-size: 1.02rem;
	color: var(--ink);
}
.topbar .brand .mark {
	width: 28px; height: 28px;
	border-radius: 8px;
	background: var(--brand);
	color: #fff;
	display: flex; align-items: center; justify-content: center;
	font-family: "Sora", sans-serif;
	font-weight: 700;
	font-size: .85rem;
	flex: none;
}
.topbar .spacer { flex: 1; }
.topbar .user { color: var(--muted); font-size: .85rem; font-weight: 500; }
.topbar form { margin: 0; }
.topbar button.link { color: var(--muted); }
.topbar button.link:hover { color: var(--danger); }

/* --- Navegación: barra inferior fija en celular, fila normal en escritorio --- */
nav.tabs {
	display: flex;
	position: fixed;
	left: 0; right: 0; bottom: 0;
	background: var(--surface);
	border-top: 1px solid var(--border);
	box-shadow: 0 -4px 16px rgba(34, 31, 24, 0.07);
	padding-bottom: env(safe-area-inset-bottom, 0);
	z-index: 20;
}
nav.tabs a {
	flex: 1;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: .2rem;
	padding: .55rem .3rem .5rem;
	font-size: .7rem;
	font-weight: 600;
	text-decoration: none;
	color: var(--muted-2);
	transition: color .15s ease;
}
nav.tabs a svg { width: 22px; height: 22px; stroke: currentColor; }
nav.tabs a.active { color: var(--brand); }

@media (min-width: 720px) {
	body { padding-bottom: 0; }
	nav.tabs {
		position: static;
		border-top: none;
		box-shadow: none;
		justify-content: flex-start;
		gap: 1.6rem;
		padding: 0;
		background: transparent;
	}
	nav.tabs a { flex: none; flex-direction: row; padding: 0; font-size: .92rem; gap: .35rem; }
	nav.tabs a svg { width: 17px; height: 17px; }
}

.container { max-width: 780px; margin: 0 auto; padding: 1.25rem 1.1rem 2rem; }

.card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	box-shadow: var(--shadow-sm);
	padding: 1.15rem 1.25rem;
	margin-bottom: 1.1rem;
}
.card.auth { max-width: 400px; margin: 3rem auto; box-shadow: var(--shadow-md); }
.card.auth .lockup {
	display: flex; align-items: center; gap: .6rem; margin-bottom: 1.3rem;
}
.card.auth .lockup .mark {
	width: 36px; height: 36px; border-radius: 10px; background: var(--brand); color: #fff;
	display: flex; align-items: center; justify-content: center; font-family: "Sora", sans-serif;
	font-weight: 700; flex: none;
}
.card.auth .lockup span { font-family: "Sora", sans-serif; font-weight: 700; font-size: 1.05rem; }

label {
	display: block;
	margin-bottom: .9rem;
	font-size: .84rem;
	font-weight: 600;
	color: var(--muted);
}
input, select, textarea {
	width: 100%;
	padding: .65rem .75rem;
	border: 1px solid var(--border-strong);
	border-radius: var(--radius-sm);
	font: 15px/1.4 "Inter", inherit;
	margin-top: .3rem;
	background: var(--surface);
	color: var(--ink);
	transition: border-color .15s ease, box-shadow .15s ease;
}
textarea { min-height: 4.5rem; resize: vertical; font-family: inherit; }
input::placeholder, textarea::placeholder { color: var(--muted-2); }
input:focus, select:focus, textarea:focus {
	outline: none;
	border-color: var(--brand);
	box-shadow: 0 0 0 3px var(--brand-light);
}
input:disabled { background: var(--surface-2); color: var(--muted-2); }

.row { display: flex; flex-wrap: wrap; gap: .7rem; align-items: flex-end; }
.row > * { flex: 1 1 160px; }
.field-hint { font-size: .78rem; color: var(--muted-2); margin-top: .3rem; font-weight: 400; }

button, .btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: .4rem;
	min-height: 44px;
	padding: .6rem 1.15rem;
	border: 0;
	border-radius: var(--radius-sm);
	background: var(--brand);
	color: #fff;
	font: 600 .92rem "Inter", inherit;
	cursor: pointer;
	text-decoration: none;
	text-align: center;
	transition: background .15s ease, transform .05s ease, box-shadow .15s ease;
}
button:hover, .btn:hover { background: var(--brand-dark); text-decoration: none; }
button:active, .btn:active { transform: translateY(1px); }
button:focus-visible, .btn:focus-visible, a:focus-visible, input:focus-visible {
	outline: 2px solid var(--brand); outline-offset: 2px;
}
button.link {
	background: none; color: var(--brand); padding: 0; min-height: auto; font-weight: 600;
}
button.link:hover { background: none; }
button.ghost, .btn.ghost {
	background: transparent; color: var(--brand); border: 1px solid var(--border-strong);
	box-shadow: none;
}
button.ghost:hover, .btn.ghost:hover { background: var(--surface-2); border-color: var(--brand); }
button.small { padding: .4rem .8rem; min-height: auto; font-size: .82rem; }
button.danger-outline { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
button.danger-outline:hover { background: var(--danger-light); }
button:disabled { opacity: .5; cursor: not-allowed; }

.list-item {
	display: block;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	padding: .95rem 1.1rem;
	margin-bottom: .65rem;
	text-decoration: none;
	color: var(--ink);
	box-shadow: var(--shadow-sm);
	transition: box-shadow .15s ease, transform .1s ease, border-color .15s ease;
}
.list-item:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); transform: translateY(-1px); text-decoration: none; }
.list-item .titulo { font-weight: 600; }
.list-item .meta { color: var(--muted); font-size: .85rem; margin-top: .2rem; }

.pill {
	display: inline-flex;
	align-items: center;
	gap: .35rem;
	padding: .2rem .6rem;
	border-radius: 999px;
	font-size: .74rem;
	font-weight: 600;
	background: var(--surface-2);
	color: var(--muted);
	border: 1px solid var(--border);
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.pendiente { background: var(--surface-2); color: var(--muted); }
.pill.en_progreso { background: var(--amber-light); color: var(--amber); border-color: transparent; }
.pill.cerrada { background: var(--ok-light); color: var(--ok); border-color: transparent; }
.pill.vencida { background: var(--danger-light); color: var(--danger); border-color: transparent; }

.alert { padding: .7rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1.1rem; font-size: .92rem; font-weight: 500; }
.alert.error { background: var(--danger-light); color: var(--danger); border: 1px solid #ecc0b6; }
.alert.info { background: var(--brand-light); color: var(--brand-dark); border: 1px solid #c6dee2; }

.muted { color: var(--muted); }
.section-title {
	font-size: .76rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: .07em;
	color: var(--muted-2);
	margin: 1.6rem 0 .6rem;
}
.section-title:first-child { margin-top: 0; }

/* --- Info de cliente --- */
.info-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
	gap: .9rem 1.4rem;
}
.info-grid dt {
	font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
	color: var(--muted-2); font-weight: 700; margin-bottom: .2rem;
}
.info-grid dd { margin: 0; font-size: .95rem; }
.card-header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: .6rem 1rem; margin-bottom: 1rem; }
.card-header h1 { flex: 1 1 auto; min-width: 0; }
.card-header .btn-row { display: flex; flex-wrap: wrap; gap: .5rem; flex: 0 1 auto; }

/* --- Checklist de actividades / subactividades --- */
.todo { list-style: none; margin: 0; padding: 0; }
.todo li {
	display: flex;
	align-items: flex-start;
	gap: .65rem;
	background: var(--surface-2);
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	padding: .65rem .8rem;
	margin-bottom: .5rem;
}
.todo input[type="checkbox"] {
	width: 20px; height: 20px; margin-top: .1rem; flex: none;
	accent-color: var(--brand); cursor: pointer;
}
.todo .cuerpo { flex: 1; display: flex; flex-direction: column; gap: .3rem; }
.todo .titulo.hecho { text-decoration: line-through; color: var(--muted); }

.avatar-chip {
	display: inline-flex; align-items: center; gap: .4rem;
	font-size: .78rem; color: var(--muted); font-weight: 500;
}
.avatar-chip .dot {
	width: 18px; height: 18px; border-radius: 50%; background: var(--brand-light); color: var(--brand-dark);
	display: flex; align-items: center; justify-content: center; font-size: .65rem; font-weight: 700; flex: none;
}

/* --- Cadena de cobro --- */
.chain { display: flex; flex-direction: column; }
.chain-step { display: flex; gap: .8rem; padding: .6rem 0; }
.chain-rail { display: flex; flex-direction: column; align-items: center; width: 16px; }
.chain-dot {
	width: 14px; height: 14px; border-radius: 50%; background: var(--surface);
	border: 2px solid var(--border-strong); flex: none; margin-top: .15rem;
}
.chain-dot.hecho { background: var(--ok); border-color: var(--ok); }
.chain-line { width: 2px; flex: 1; background: var(--border-strong); margin-top: .15rem; min-height: 1.3rem; }
.chain-body { flex: 1; display: flex; flex-direction: column; gap: .35rem; }
.chain-body.bloqueado { opacity: .5; }

/* --- Historial (feed cronológico por cliente) --- */
.history-feed { display: flex; flex-direction: column; }
.history-item { display: flex; gap: .8rem; }
.history-rail { display: flex; flex-direction: column; align-items: center; width: 16px; }
.history-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--brand); margin-top: .45rem; flex: none; }
.history-line { width: 2px; flex: 1; background: var(--border); min-height: .6rem; }
.history-body { flex: 1; padding-bottom: 1.2rem; }
.history-body .fecha { font-size: .76rem; color: var(--muted-2); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.history-body h4 { margin: .15rem 0 .2rem; font-size: .95rem; font-weight: 600; }
.history-body .comentario { font-size: .9rem; color: var(--ink); margin: .3rem 0; }
.history-body .cargo-tag { font-size: .8rem; color: var(--muted); }

/* --- Panel de comentarios --- */
.comment-list { display: flex; flex-direction: column; gap: .8rem; margin-bottom: 1.1rem; }
.comment {
	background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
	padding: .7rem .9rem;
}
.comment-head { display: flex; justify-content: space-between; gap: .6rem; margin-bottom: .3rem; }
.comment-autor { font-size: .84rem; font-weight: 700; }
.comment-fecha { font-size: .76rem; color: var(--muted-2); }
.comment-texto { font-size: .92rem; white-space: pre-wrap; }
.comment-form textarea { min-height: 3.4rem; }

.empty-state {
	color: var(--muted); font-size: .9rem; padding: .5rem 0 1rem;
}

/* --- Chat del equipo (burbuja flotante) --- */
.chat-bubble {
	position: fixed;
	right: 1.1rem;
	bottom: calc(4.9rem + env(safe-area-inset-bottom, 0));
	width: 56px; height: 56px;
	border-radius: 50%;
	border: none;
	background: var(--brand);
	color: #fff;
	display: flex; align-items: center; justify-content: center;
	box-shadow: var(--shadow-lift);
	cursor: pointer;
	z-index: 25;
	transition: background .15s ease, transform .1s ease;
}
.chat-bubble:hover { background: var(--brand-dark); transform: scale(1.05); }
.chat-bubble svg { width: 26px; height: 26px; }
.chat-badge {
	position: absolute; top: -2px; right: -2px;
	background: var(--danger); color: #fff;
	font-size: .68rem; font-weight: 700; font-family: "Inter", sans-serif;
	min-width: 19px; height: 19px; border-radius: 999px;
	display: flex; align-items: center; justify-content: center;
	padding: 0 4px;
	border: 2px solid var(--bg);
}
@media (min-width: 720px) {
	.chat-bubble { bottom: 1.5rem; }
}

.chat-panel {
	position: fixed;
	left: 1.1rem; right: 1.1rem;
	top: 4.4rem;
	bottom: calc(4.9rem + 68px + env(safe-area-inset-bottom, 0));
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius-lg);
	box-shadow: var(--shadow-lift);
	display: flex; flex-direction: column;
	overflow: hidden;
	z-index: 24;
}
@media (min-width: 480px) {
	.chat-panel {
		left: auto; width: 370px;
		top: auto; height: 500px;
		bottom: calc(1.5rem + 68px + .7rem);
	}
}

.chat-panel[hidden] { display: none; }

.chat-panel-header {
	display: flex; justify-content: space-between; align-items: center;
	padding: .8rem 1.1rem; border-bottom: 1px solid var(--border);
	background: var(--surface-2);
	font-family: "Sora", sans-serif; font-weight: 700; font-size: .95rem;
	flex: none;
}
.chat-channels {
	display: flex; gap: .4rem; padding: .6rem .9rem;
	border-bottom: 1px solid var(--border); background: var(--surface-2);
	overflow-x: auto; flex: none;
}
.chat-channel {
	flex: none;
	display: inline-flex; align-items: center;
	border: 1px solid var(--border-strong); background: var(--surface);
	color: var(--muted); font: 600 .8rem "Inter", inherit;
	padding: .35rem .75rem; border-radius: 999px; cursor: pointer;
	white-space: nowrap;
}
.chat-channel.activo { background: var(--brand); border-color: var(--brand); color: #fff; }
.chat-channel-dot {
	display: inline-block; width: 7px; height: 7px; border-radius: 50%;
	background: var(--danger); margin-left: .4rem;
}
.chat-channel.activo .chat-channel-dot { background: #fff; }
.chat-messages {
	flex: 1; overflow-y: auto; padding: 1rem 1.1rem;
	display: flex; flex-direction: column; gap: .7rem;
}
.chat-msg { max-width: 82%; display: flex; flex-direction: column; gap: .2rem; }
.chat-msg.mio { align-self: flex-end; align-items: flex-end; }
.chat-msg.otro { align-self: flex-start; align-items: flex-start; }
.chat-msg-meta { font-size: .7rem; color: var(--muted-2); font-weight: 600; }
.chat-msg-texto {
	padding: .5rem .8rem; border-radius: var(--radius-sm);
	font-size: .88rem; line-height: 1.4; white-space: pre-wrap; word-break: break-word;
}
.chat-msg.mio .chat-msg-texto { background: var(--brand); color: #fff; border-bottom-right-radius: 3px; }
.chat-msg.otro .chat-msg-texto { background: var(--surface-2); border: 1px solid var(--border); border-bottom-left-radius: 3px; }

.chat-form { display: flex; gap: .5rem; padding: .7rem; border-top: 1px solid var(--border); flex: none; }
.chat-form textarea {
	flex: 1; resize: none; min-height: 40px; max-height: 90px; margin-top: 0;
	font-size: .9rem; padding: .55rem .7rem; line-height: 1.35;
}
.chat-form button { min-height: 40px; padding: .5rem 1rem; flex: none; }
