:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --text: #1a1d23;
    --text-muted: #6b7280;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --border: #e5e7eb;
    --danger: #dc2626;
    --success: #16a34a;
    --radius: 14px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

button {
    font-family: inherit;
}

/* ---- Login ---- */
.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.login-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 32px 24px;
    max-width: 340px;
    width: 100%;
    box-shadow: 0 10px 30px rgba(0,0,0,0.08);
    text-align: center;
}
.login-card h1 { margin: 0 0 4px; font-size: 24px; }
.login-card .subtitle { color: var(--text-muted); margin: 0 0 24px; font-size: 14px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-card input {
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    font-size: 16px;
}
.login-card button {
    padding: 12px;
    border: none;
    border-radius: 10px;
    background: var(--primary);
    color: white;
    font-size: 16px;
    font-weight: 600;
}
.login-card .error { color: var(--danger); font-size: 14px; margin: 0 0 12px; }

/* ---- App shell ---- */
.app-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: calc(var(--safe-top) + 14px) 16px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.app-header h1 { font-size: 18px; margin: 0; }
.app-header a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
}

.tabs {
    display: flex;
    gap: 4px;
    padding: 10px 16px 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.tab-btn {
    flex: 1;
    border: none;
    background: transparent;
    padding: 10px 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
}
.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

main {
    padding: 16px 16px calc(var(--safe-bottom) + 100px);
    max-width: 640px;
    margin: 0 auto;
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 60px 20px;
    font-size: 15px;
}

.task-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.task-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 14px;
    display: flex;
    gap: 12px;
    align-items: flex-start;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.task-check {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--surface);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin-top: 2px;
}
.task-card.completed .task-check {
    background: var(--success);
    border-color: var(--success);
    color: white;
}

.task-body { flex: 1; min-width: 0; }
.task-text {
    font-size: 15px;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
}
.task-card.completed .task-text {
    color: var(--text-muted);
    text-decoration: line-through;
}
.task-meta {
    margin-top: 6px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}
.badge {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 100px;
    background: #eef2ff;
    color: var(--primary-dark);
}
.badge.cliente { background: #fef3c7; color: #92400e; }
.badge.fecha { background: #fee2e2; color: #991b1b; }
.meta-date { font-size: 12px; color: var(--text-muted); }

.task-delete {
    flex-shrink: 0;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 18px;
    padding: 4px 6px;
    cursor: pointer;
}

.fab {
    position: fixed;
    right: 20px;
    bottom: calc(var(--safe-bottom) + 24px);
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    border: none;
    font-size: 28px;
    box-shadow: 0 8px 20px rgba(37,99,235,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

/* ---- Modal ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: none;
    align-items: flex-end;
    z-index: 20;
}
.modal-overlay.open { display: flex; }
.modal-sheet {
    background: var(--surface);
    width: 100%;
    border-radius: 20px 20px 0 0;
    padding: 20px 20px calc(var(--safe-bottom) + 20px);
    max-height: 85vh;
    overflow-y: auto;
}
.modal-sheet h2 { margin: 0 0 16px; font-size: 18px; }
.field { margin-bottom: 14px; }
.field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.field textarea,
.field input,
.field select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 16px;
    font-family: inherit;
}
.field textarea {
    min-height: 100px;
    resize: vertical;
}
.dictado-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}
.modal-actions button {
    flex: 1;
    padding: 13px;
    border-radius: 10px;
    border: none;
    font-size: 15px;
    font-weight: 600;
}
.btn-cancel { background: var(--bg); color: var(--text); }
.btn-save { background: var(--primary); color: white; }
